From fc5d258890d7ebcc960c1d63d1370f6f22ecbd4d Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Sat, 2 Nov 2024 22:23:25 +0100 Subject: [PATCH] filter/ffmpeg: fill `AVFrame::pts` Some libavfilter plugins don't produce any output if `pts` is never set, e.g. the `lowpass` plugin. Closes https://github.com/MusicPlayerDaemon/MPD/issues/2114 --- NEWS | 2 ++ src/filter/plugins/FfmpegFilter.cxx | 3 +++ src/filter/plugins/FfmpegFilter.hxx | 12 ++++++++---- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/NEWS b/NEWS index 4e5d11826..80f4f0b92 100644 --- a/NEWS +++ b/NEWS @@ -46,6 +46,8 @@ ver 0.24 (not yet released) - sidplay: require libsidplayfp (drop support for the original sidplay) - wavpack: require libwavpack version 5 - fix MixRamp bug +* filter + - ffmpeg: fix for filters producing no output * resampler - soxr: require libsoxr 0.1.2 or later * player diff --git a/src/filter/plugins/FfmpegFilter.cxx b/src/filter/plugins/FfmpegFilter.cxx index afec2455b..55d61c145 100644 --- a/src/filter/plugins/FfmpegFilter.cxx +++ b/src/filter/plugins/FfmpegFilter.cxx @@ -66,6 +66,9 @@ FfmpegFilter::FilterPCM(std::span src) #endif frame->nb_samples = src.size() / in_audio_frame_size; + frame->pts = pts; + pts += frame->nb_samples; + frame.GetBuffer(); memcpy(frame.GetData(0), src.data(), src.size()); diff --git a/src/filter/plugins/FfmpegFilter.hxx b/src/filter/plugins/FfmpegFilter.hxx index eeac8b76a..0ab521e06 100644 --- a/src/filter/plugins/FfmpegFilter.hxx +++ b/src/filter/plugins/FfmpegFilter.hxx @@ -1,14 +1,15 @@ // SPDX-License-Identifier: GPL-2.0-or-later // Copyright The Music Player Daemon Project -#ifndef MPD_FFMPEG_FILTER__HXX -#define MPD_FFMPEG_FILTER__HXX +#pragma once #include "filter/Filter.hxx" #include "lib/ffmpeg/Buffer.hxx" #include "lib/ffmpeg/Filter.hxx" #include "lib/ffmpeg/Frame.hxx" +#include + /** * A #Filter implementation using FFmpeg's libavfilter. */ @@ -30,6 +31,11 @@ class FfmpegFilter final : public Filter { const size_t in_audio_frame_size; const size_t out_audio_frame_size; + /** + * Presentation timestamp. A counter for `AVFrame::pts`. + */ + int_least64_t pts = 0; + bool flushed = false; public: @@ -53,5 +59,3 @@ public: private: std::span ReadOutput(); }; - -#endif