diff --git a/src/filter/plugins/FfmpegFilter.cxx b/src/filter/plugins/FfmpegFilter.cxx index 392fee22e..afec2455b 100644 --- a/src/filter/plugins/FfmpegFilter.cxx +++ b/src/filter/plugins/FfmpegFilter.cxx @@ -52,6 +52,8 @@ FfmpegFilter::ReadOutput() std::span FfmpegFilter::FilterPCM(std::span src) { + assert(!flushed); + /* submit source data into the FFmpeg audio buffer source */ frame.Unref(); @@ -78,3 +80,16 @@ FfmpegFilter::FilterPCM(std::span src) return ReadOutput(); } + +std::span +FfmpegFilter::Flush() +{ + if (!flushed) { + if (int err = av_buffersrc_add_frame(&buffer_src, nullptr); err < 0) + throw MakeFfmpegError(err, "av_buffersrc_write_frame() failed"); + + flushed = true; + } + + return ReadOutput(); +} diff --git a/src/filter/plugins/FfmpegFilter.hxx b/src/filter/plugins/FfmpegFilter.hxx index 7885850e6..eeac8b76a 100644 --- a/src/filter/plugins/FfmpegFilter.hxx +++ b/src/filter/plugins/FfmpegFilter.hxx @@ -30,6 +30,8 @@ class FfmpegFilter final : public Filter { const size_t in_audio_frame_size; const size_t out_audio_frame_size; + bool flushed = false; + public: /** * @param _graph a checked and configured AVFilterGraph @@ -46,6 +48,7 @@ public: /* virtual methods from class Filter */ std::span FilterPCM(std::span src) override; + std::span Flush() override; private: std::span ReadOutput();