Skip to content

Commit

Permalink
Avoid use of audio stream timebase for thumbnail framerate
Browse files Browse the repository at this point in the history
Signed-off-by: Maxime Gervais <[email protected]>
  • Loading branch information
g-maxime committed Dec 25, 2024
1 parent 7da6727 commit f025922
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 5 deletions.
8 changes: 4 additions & 4 deletions Source/Core/FileInformation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1603,12 +1603,12 @@ void FileInformation::makeMkvReport(QString exportFileName, QByteArray attachmen
FFmpegVideoEncoder::Metadata streamMetadata;
streamMetadata << FFmpegVideoEncoder::MetadataEntry(QString("title"), QString("Frame Thumbnails"));

auto timeBase = QString::fromStdString(streamsStats->getStreams().begin()->get()->getTime_base());
auto timeBase = streamsStats->getReferenceStream() ? QString::fromStdString(streamsStats->getReferenceStream()->getTime_base()) : QString("1/25");
auto timeBaseSplitted = timeBase.split("/");
int num = timeBaseSplitted[0].toInt();
int den = timeBaseSplitted[1].toInt();

auto codecTimeBase = QString::fromStdString(streamsStats->getStreams().begin()->get()->getCodec_Time_Base());
auto codecTimeBase = streamsStats->getReferenceStream() ? QString::fromStdString(streamsStats->getReferenceStream()->getCodec_Time_Base()) : QString("0/1");
auto codecTimeBaseSplitted = codecTimeBase.split("/");
int codecNum = codecTimeBaseSplitted[0].toInt();
int codecDen = codecTimeBaseSplitted[1].toInt();
Expand Down Expand Up @@ -1706,12 +1706,12 @@ void FileInformation::makeMkvReport(QString exportFileName, QByteArray attachmen
panelSource.height = panelSize().height();

// 2do: take related stream instead of first one
auto timeBase = QString::fromStdString(streamsStats->getStreams().begin()->get()->getTime_base());
auto timeBase = streamsStats->getReferenceStream() ? QString::fromStdString(streamsStats->getReferenceStream()->getTime_base()) : QString("1/25");
auto timeBaseSplitted = timeBase.split("/");
int num = timeBaseSplitted[0].toInt();
int den = timeBaseSplitted[1].toInt();

auto codecTimeBase = QString::fromStdString(streamsStats->getStreams().begin()->get()->getCodec_Time_Base());
auto codecTimeBase = streamsStats->getReferenceStream() ? QString::fromStdString(streamsStats->getReferenceStream()->getCodec_Time_Base()) : QString("0/1");
auto codecTimeBaseSplitted = codecTimeBase.split("/");
int codecNum = codecTimeBaseSplitted[0].toInt();
int codecDen = codecTimeBaseSplitted[1].toInt();
Expand Down
18 changes: 17 additions & 1 deletion Source/Core/StreamsStats.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,11 @@ extern "C"

#include "Core/VideoStreamStats.h"
#include "Core/AudioStreamStats.h"
#include "StreamsStats.h"

using namespace tinyxml2;

StreamsStats::StreamsStats(QVector<QAVStream*> qavstreams)
StreamsStats::StreamsStats(QVector<QAVStream*> qavstreams) : nullCommonStreamStatsPtr(nullptr)
{
for (size_t pos = 0; pos < qavstreams.count(); ++pos)
{
Expand Down Expand Up @@ -112,3 +113,18 @@ int StreamsStats::avSampleFormat() const

return AV_SAMPLE_FMT_NONE;
}

const StreamsStats::CommonStreamStatsPtr& StreamsStats::getReferenceStream() const
{
for(auto& stream : streams) {
if(stream->getType() == AVMEDIA_TYPE_VIDEO)
return stream;
}

for(auto& stream : streams) {
if(stream->getType() == AVMEDIA_TYPE_AUDIO)
return stream;
}

return nullCommonStreamStatsPtr;
}
2 changes: 2 additions & 0 deletions Source/Core/StreamsStats.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,11 @@ class StreamsStats {
int bitsPerRawVideoSample() const;
int avSampleFormat() const;

const CommonStreamStatsPtr& getReferenceStream() const;
const std::list<CommonStreamStatsPtr>& getStreams() const { return streams; }
private:
std::list<CommonStreamStatsPtr> streams;
CommonStreamStatsPtr nullCommonStreamStatsPtr;
};

#endif // StreamsStats_H

0 comments on commit f025922

Please sign in to comment.