Skip to content

Commit

Permalink
Merge pull request #386 from valbok/audio-frames
Browse files Browse the repository at this point in the history
Fix audio frames count after filter
  • Loading branch information
valbok authored Jul 20, 2023
2 parents e0991da + 9e9f29e commit 60c00d7
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/QtAVPlayer/qavaudiofilter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ int QAVAudioFilter::write(const QAVFrame &frame)
AVFrame *decoded_frame = frame.frame();
AVRational decoded_frame_tb = frame.stream().stream()->time_base;
// TODO: clear filter_in_rescale_delta_last
if (decoded_frame->pts != AV_NOPTS_VALUE) {
if (!d->inputs.isEmpty() && decoded_frame->pts != AV_NOPTS_VALUE) {
decoded_frame->pts = av_rescale_delta(decoded_frame_tb, decoded_frame->pts,
AVRational{1, decoded_frame->sample_rate},
decoded_frame->nb_samples,
Expand Down Expand Up @@ -111,6 +111,7 @@ int QAVAudioFilter::read(QAVFrame &frame)
if (out.frame()->duration == AV_NOPTS_VALUE || out.frame()->duration == 0)
out.frame()->duration = d->sourceFrame.frame()->duration;
#endif
out.setFrameRate(av_buffersink_get_frame_rate(filter.ctx()));
out.setTimeBase(av_buffersink_get_time_base(filter.ctx()));
out.setFilterName(
!filter.name().isEmpty()
Expand Down
37 changes: 37 additions & 0 deletions tests/auto/integration/qavplayer/tst_qavplayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ private slots:
void audioVideoFilter();
void audioFilterVideoFrames();
void multipleFilters();
void multipleAudioVideoFilters();
void inputFormat();
void inputVideoCodec();
void flushFilters();
Expand Down Expand Up @@ -3042,6 +3043,42 @@ void tst_QAVPlayer::multipleFilters()
QCOMPARE(framesCount["panel_4"], 1);
}

void tst_QAVPlayer::multipleAudioVideoFilters()
{
qputenv("QT_AVPLAYER_NO_HWDEVICE", "1");
QAVPlayer p;
QFileInfo file(testData("test_5beeps.mkv"));
p.setSource(file.absoluteFilePath());
QList<QString> filters = {
"signalstats=stat=tout+vrep+brng [stats]",
"aformat=sample_fmts=flt|fltp,astats=metadata=1:reset=1:length=0.4,aphasemeter=video=0,ebur128=metadata=1,aformat=sample_fmts=flt|fltp [audio]",
};

QMap<QString, int> framesCount;
QAVVideoFrame videoFrame;
QObject::connect(&p, &QAVPlayer::videoFrame, &p, [&](const QAVVideoFrame &f) {
videoFrame = f;
++framesCount[f.filterName()];
}, Qt::DirectConnection);

QAVAudioFrame audioFrame;
QObject::connect(&p, &QAVPlayer::audioFrame, &p, [&](const QAVAudioFrame &f) {
audioFrame = f;
++framesCount[f.filterName()];
}, Qt::DirectConnection);

p.setSynced(false);
p.setFilters(filters);
p.play();
QTRY_COMPARE_WITH_TIMEOUT(p.mediaStatus(), QAVPlayer::EndOfMedia, 15000);
QVERIFY(framesCount.contains("stats"));
QCOMPARE(framesCount["stats"], 125);
QCOMPARE(videoFrame.pts(), 4.963);
QVERIFY(framesCount.contains("audio"));
QCOMPARE(framesCount["audio"], 51);
QVERIFY(audioFrame.pts() < 5.5);
}

void tst_QAVPlayer::inputFormat()
{
QAVPlayer p;
Expand Down
Binary file added tests/auto/integration/testdata/test_5beeps.mkv
Binary file not shown.

0 comments on commit 60c00d7

Please sign in to comment.