Bump ffmpeg to 5.1.2 "Riemann"
[dcpomatic.git] / src / lib / ffmpeg_decoder.cc
index 9f505ea4303d8a4685c213b468a8335bb0a6b35a..a260a757b22a5b08aa81e2563162100f800bae33 100644 (file)
@@ -254,18 +254,22 @@ FFmpegDecoder::pass ()
  */
 static
 shared_ptr<AudioBuffers>
-deinterleave_audio(shared_ptr<FFmpegAudioStream> stream, AVFrame* frame)
+deinterleave_audio(AVFrame* frame)
 {
        auto format = static_cast<AVSampleFormat>(frame->format);
 
        /* XXX: can't we use swr_convert() to do the format conversion? */
 
-       int const channels = frame->channels;
+       int const channels = frame->ch_layout.nb_channels;
        int const frames = frame->nb_samples;
        int const total_samples = frames * channels;
        auto audio = make_shared<AudioBuffers>(channels, frames);
        auto data = audio->data();
 
+       if (frames == 0) {
+               return audio;
+       }
+
        switch (format) {
        case AV_SAMPLE_FMT_U8:
        {
@@ -360,7 +364,6 @@ deinterleave_audio(shared_ptr<FFmpegAudioStream> stream, AVFrame* frame)
        case AV_SAMPLE_FMT_FLTP:
        {
                auto p = reinterpret_cast<float**> (frame->data);
-               DCPOMATIC_ASSERT(channels <= stream->channels());
                for (int i = 0; i < channels; ++i) {
                        memcpy (data[i], p[i], frames * sizeof(float));
                }
@@ -477,7 +480,7 @@ void
 FFmpegDecoder::process_audio_frame (shared_ptr<FFmpegAudioStream> stream)
 {
        auto frame = audio_frame (stream);
-       auto data = deinterleave_audio(stream, frame);
+       auto data = deinterleave_audio(frame);
 
        auto const time_base = stream->stream(_format_context)->time_base;
 
@@ -631,9 +634,14 @@ FFmpegDecoder::process_video_frame ()
 void
 FFmpegDecoder::decode_and_process_subtitle_packet (AVPacket* packet)
 {
+       auto context = subtitle_codec_context();
+       if (!context) {
+               return;
+       }
+
        int got_subtitle;
        AVSubtitle sub;
-       if (avcodec_decode_subtitle2 (subtitle_codec_context(), &sub, &got_subtitle, packet) < 0 || !got_subtitle) {
+       if (avcodec_decode_subtitle2(context, &sub, &got_subtitle, packet) < 0 || !got_subtitle) {
                return;
        }