Skip to content

Commit

Permalink
filter/ffmpeg: fill AVFrame::pts
Browse files Browse the repository at this point in the history
Some libavfilter plugins don't produce any output if `pts` is never
set, e.g. the `lowpass` plugin.

Closes #2114
  • Loading branch information
MaxKellermann committed Nov 2, 2024
1 parent 7dce7ad commit fc5d258
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
2 changes: 2 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions src/filter/plugins/FfmpegFilter.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ FfmpegFilter::FilterPCM(std::span<const std::byte> 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());
Expand Down
12 changes: 8 additions & 4 deletions src/filter/plugins/FfmpegFilter.hxx
Original file line number Diff line number Diff line change
@@ -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 <cstdint>

/**
* A #Filter implementation using FFmpeg's libavfilter.
*/
Expand All @@ -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:
Expand All @@ -53,5 +59,3 @@ public:
private:
std::span<const std::byte> ReadOutput();
};

#endif

0 comments on commit fc5d258

Please sign in to comment.