From: Helge Norberg Date: Tue, 13 Sep 2016 15:44:17 +0000 (+0200) Subject: [ffmpeg] Use last video frame with audio instead of empty frame when audio is longer... X-Git-Tag: 2.1.0_Beta1~56 X-Git-Url: https://git.sesse.net/?p=casparcg;a=commitdiff_plain;h=e48212a5d56ef6dbff39fbcf44956360fe1576e3 [ffmpeg] Use last video frame with audio instead of empty frame when audio is longer than video --- diff --git a/modules/ffmpeg/ffmpeg_pipeline_backend_internal.cpp b/modules/ffmpeg/ffmpeg_pipeline_backend_internal.cpp index 9feb2d734..0329a1662 100644 --- a/modules/ffmpeg/ffmpeg_pipeline_backend_internal.cpp +++ b/modules/ffmpeg/ffmpeg_pipeline_backend_internal.cpp @@ -654,6 +654,7 @@ class memory_sink : public sink core::mutable_audio_buffer audio_samples_; std::queue> video_frames_; + std::shared_ptr last_video_frame_; tbb::concurrent_bounded_queue output_frames_; tbb::atomic running_; @@ -816,6 +817,7 @@ public: } auto output_frame = make_frame(this, spl::make_shared_ptr(video_frames_.front()), *factory_, channel_layout_); + last_video_frame_ = video_frames_.front(); video_frames_.pop(); output_frame.audio_data() = std::move(audio_data); @@ -832,9 +834,15 @@ public: audio_data.swap(audio_samples_); + if (video_frames_.empty() && !audio_data.empty() && last_video_frame_) // More audio samples than video + { + video_frames_.push(last_video_frame_); + } + if (!video_frames_.empty()) { auto output_frame = make_frame(this, spl::make_shared_ptr(video_frames_.front()), *factory_, channel_layout_); + last_video_frame_ = video_frames_.front(); video_frames_.pop(); output_frame.audio_data() = std::move(audio_data);