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
This commit is contained in:
Max Kellermann 2024-11-02 22:23:25 +01:00
parent 7dce7ad32d
commit fc5d258890
3 changed files with 13 additions and 4 deletions

2
NEWS
View File

@ -46,6 +46,8 @@ ver 0.24 (not yet released)
- sidplay: require libsidplayfp (drop support for the original sidplay) - sidplay: require libsidplayfp (drop support for the original sidplay)
- wavpack: require libwavpack version 5 - wavpack: require libwavpack version 5
- fix MixRamp bug - fix MixRamp bug
* filter
- ffmpeg: fix for filters producing no output
* resampler * resampler
- soxr: require libsoxr 0.1.2 or later - soxr: require libsoxr 0.1.2 or later
* player * player

View File

@ -66,6 +66,9 @@ FfmpegFilter::FilterPCM(std::span<const std::byte> src)
#endif #endif
frame->nb_samples = src.size() / in_audio_frame_size; frame->nb_samples = src.size() / in_audio_frame_size;
frame->pts = pts;
pts += frame->nb_samples;
frame.GetBuffer(); frame.GetBuffer();
memcpy(frame.GetData(0), src.data(), src.size()); memcpy(frame.GetData(0), src.data(), src.size());

View File

@ -1,14 +1,15 @@
// SPDX-License-Identifier: GPL-2.0-or-later // SPDX-License-Identifier: GPL-2.0-or-later
// Copyright The Music Player Daemon Project // Copyright The Music Player Daemon Project
#ifndef MPD_FFMPEG_FILTER__HXX #pragma once
#define MPD_FFMPEG_FILTER__HXX
#include "filter/Filter.hxx" #include "filter/Filter.hxx"
#include "lib/ffmpeg/Buffer.hxx" #include "lib/ffmpeg/Buffer.hxx"
#include "lib/ffmpeg/Filter.hxx" #include "lib/ffmpeg/Filter.hxx"
#include "lib/ffmpeg/Frame.hxx" #include "lib/ffmpeg/Frame.hxx"
#include <cstdint>
/** /**
* A #Filter implementation using FFmpeg's libavfilter. * 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 in_audio_frame_size;
const size_t out_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; bool flushed = false;
public: public:
@ -53,5 +59,3 @@ public:
private: private:
std::span<const std::byte> ReadOutput(); std::span<const std::byte> ReadOutput();
}; };
#endif