66de8124.patch 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. From 66de8124f496617eee8e6b5c68138a00343882db Mon Sep 17 00:00:00 2001
  2. From: Joe Locash <@jlocash2>
  3. Date: Sat, 4 May 2024 17:08:04 +0200
  4. Subject: [PATCH] ff-load, ff-save: fix build with FFmpeg 7
  5. Fixing issue #371
  6. ---
  7. operations/external/ff-load.c | 8 ++++++++
  8. operations/external/ff-save.c | 24 ++++++++++++++++++++++--
  9. 2 files changed, 30 insertions(+), 2 deletions(-)
  10. diff --git a/operations/external/ff-load.c b/operations/external/ff-load.c
  11. index 6b96fdfdd..dc24a6d59 100644
  12. --- a/operations/external/ff-load.c
  13. +++ b/operations/external/ff-load.c
  14. @@ -250,7 +250,11 @@ decode_audio (GeglOperation *operation,
  15. while (samples_left)
  16. {
  17. int sample_count = samples_left;
  18. +#if LIBAVCODEC_VERSION_MAJOR < 61
  19. int channels = MIN(p->audio_stream->codecpar->channels, GEGL_MAX_AUDIO_CHANNELS);
  20. +#else
  21. + int channels = MIN(p->audio_stream->codecpar->ch_layout.nb_channels, GEGL_MAX_AUDIO_CHANNELS);
  22. +#endif
  23. GeglAudioFragment *af = gegl_audio_fragment_new (o->audio_sample_rate, channels,
  24. AV_CH_LAYOUT_STEREO, samples_left);
  25. //);
  26. @@ -553,7 +557,11 @@ prepare (GeglOperation *operation)
  27. else
  28. {
  29. o->audio_sample_rate = p->audio_stream->codecpar->sample_rate;
  30. +#if LIBAVCODEC_VERSION_MAJOR < 61
  31. o->audio_channels = MIN(p->audio_stream->codecpar->channels, GEGL_MAX_AUDIO_CHANNELS);
  32. +#else
  33. + o->audio_channels = MIN(p->audio_stream->codecpar->ch_layout.nb_channels, GEGL_MAX_AUDIO_CHANNELS);
  34. +#endif
  35. }
  36. }
  37. diff --git a/operations/external/ff-save.c b/operations/external/ff-save.c
  38. index 9196b34aa..ffa5d8bee 100644
  39. --- a/operations/external/ff-save.c
  40. +++ b/operations/external/ff-save.c
  41. @@ -315,8 +315,13 @@ add_audio_stream (GeglProperties *o, AVFormatContext * oc, int codec_id)
  42. }
  43. cp->sample_rate = o->audio_sample_rate;
  44. +#if LIBAVCODEC_VERSION_MAJOR < 61
  45. cp->channel_layout = AV_CH_LAYOUT_STEREO;
  46. cp->channels = 2;
  47. +#else
  48. + cp->ch_layout.u.mask = AV_CH_LAYOUT_STEREO;
  49. + cp->ch_layout.nb_channels = 2;
  50. +#endif
  51. return st;
  52. }
  53. @@ -392,8 +397,13 @@ static AVFrame *alloc_audio_frame(AVCodecContext *c, int nb_samples)
  54. frame->format = c->sample_fmt;
  55. +#if LIBAVCODEC_VERSION_MAJOR < 61
  56. frame->channel_layout = c->channel_layout;
  57. frame->channels = c->channels;
  58. +#else
  59. + frame->ch_layout = c->ch_layout;
  60. + frame->ch_layout.nb_channels = c->ch_layout.nb_channels;
  61. +#endif
  62. frame->sample_rate = c->sample_rate;
  63. frame->nb_samples = nb_samples;
  64. @@ -423,8 +433,13 @@ static void encode_audio_fragments (Priv *p, AVFormatContext *oc, AVStream *st,
  65. {
  66. float left = 0, right = 0;
  67. get_sample_data (p, i + p->audio_read_pos, &left, &right);
  68. +#if LIBAVCODEC_VERSION_MAJOR < 61
  69. ((float*)frame->data[0])[c->channels*i+0] = left;
  70. ((float*)frame->data[0])[c->channels*i+1] = right;
  71. +#else
  72. + ((float*)frame->data[0])[c->ch_layout.nb_channels*i+0] = left;
  73. + ((float*)frame->data[0])[c->ch_layout.nb_channels*i+1] = right;
  74. +#endif
  75. }
  76. break;
  77. case AV_SAMPLE_FMT_FLTP:
  78. @@ -441,8 +456,13 @@ static void encode_audio_fragments (Priv *p, AVFormatContext *oc, AVStream *st,
  79. {
  80. float left = 0, right = 0;
  81. get_sample_data (p, i + p->audio_read_pos, &left, &right);
  82. +#if LIBAVCODEC_VERSION_MAJOR < 61
  83. ((int16_t*)frame->data[0])[c->channels*i+0] = left * (1<<15);
  84. ((int16_t*)frame->data[0])[c->channels*i+1] = right * (1<<15);
  85. +#else
  86. + ((int16_t*)frame->data[0])[c->ch_layout.nb_channels*i+0] = left * (1<<15);
  87. + ((int16_t*)frame->data[0])[c->ch_layout.nb_channels*i+1] = right * (1<<15);
  88. +#endif
  89. }
  90. break;
  91. case AV_SAMPLE_FMT_S32:
  92. @@ -450,8 +470,8 @@ static void encode_audio_fragments (Priv *p, AVFormatContext *oc, AVStream *st,
  93. {
  94. float left = 0, right = 0;
  95. get_sample_data (p, i + p->audio_read_pos, &left, &right);
  96. - ((int32_t*)frame->data[0])[c->channels*i+0] = left * (1<<31);
  97. - ((int32_t*)frame->data[0])[c->channels*i+1] = right * (1<<31);
  98. + ((int32_t*)frame->data[0])[c->ch_layout.nb_channels*i+0] = left * (1<<31);
  99. + ((int32_t*)frame->data[0])[c->ch_layout.nb_channels*i+1] = right * (1<<31);
  100. }
  101. break;
  102. case AV_SAMPLE_FMT_S32P:
  103. --
  104. GitLab