Skip to content

Commit

Permalink
take pts directly from frame for audio filters
Browse files Browse the repository at this point in the history
  • Loading branch information
ElderOrb committed Aug 26, 2023
1 parent f832ad1 commit fef460e
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 14 deletions.
11 changes: 9 additions & 2 deletions Source/Core/AudioStats.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,9 @@ void AudioStats::parseFrame(tinyxml2::XMLElement *Frame)
//***************************************************************************

//---------------------------------------------------------------------------
void AudioStats::StatsFromFrame (struct AVFrame* Frame, int, int)
void AudioStats::StatsFromFrame (const QAVFrame& frame, int, int)
{
auto Frame = frame.frame();
AVDictionary * m= Frame->metadata;
AVDictionaryEntry* e=NULL;
bool statsMapInitialized = !statsValueInfoByKeys.empty();
Expand Down Expand Up @@ -249,8 +250,10 @@ void AudioStats::StatsFromFrame (struct AVFrame* Frame, int, int)
}

//---------------------------------------------------------------------------
void AudioStats::TimeStampFromFrame (struct AVFrame* Frame, size_t FramePos)
void AudioStats::TimeStampFromFrame (const QAVFrame& frame, size_t FramePos)
{
auto Frame = frame.frame();

if (Frequency==0)
return; // Not supported

Expand All @@ -259,9 +262,13 @@ void AudioStats::TimeStampFromFrame (struct AVFrame* Frame, size_t FramePos)

x[0][FramePos]=FramePos;

/* can't use old way, take pts directly from frame
int64_t ts=(Frame->pts == AV_NOPTS_VALUE)?Frame->pkt_dts : Frame->pts; // Using DTS is PTS is not available
if (ts==AV_NOPTS_VALUE && FramePos)
ts=(int64_t)((FirstTimeStamp+x[1][FramePos-1]+durations[FramePos-1])*Frequency); // If time stamp is not present, creating a fake one from last frame duration
*/

int64_t ts = frame.pts() * 1000;
if (ts!=AV_NOPTS_VALUE)
{
if (FirstTimeStamp==DBL_MAX)
Expand Down
4 changes: 2 additions & 2 deletions Source/Core/AudioStats.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ class AudioStats : public CommonStats

// External data
virtual void parseFrame(tinyxml2::XMLElement* frame);
void StatsFromFrame(struct AVFrame* Frame, int Width, int Height);
void TimeStampFromFrame(struct AVFrame* Frame, size_t FramePos);
void StatsFromFrame(const QAVFrame& Frame, int Width, int Height);
void TimeStampFromFrame(const QAVFrame& Frame, size_t FramePos);
std::string StatsToXML(const activefilters& filters);
};

Expand Down
5 changes: 3 additions & 2 deletions Source/Core/CommonStats.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ namespace tinyxml2 {
class XMLElement;
}

class QAVFrame;
class CommonStats
{
public:
Expand Down Expand Up @@ -70,8 +71,8 @@ class CommonStats

// External data
void StatsFromExternalData_Finish() {Frequency=1; StatsFinish();}
virtual void StatsFromFrame(struct AVFrame* Frame, int Width, int Height) = 0;
virtual void TimeStampFromFrame(struct AVFrame* Frame, size_t FramePos) = 0;
virtual void StatsFromFrame(const QAVFrame& Frame, int Width, int Height) = 0;
virtual void TimeStampFromFrame(const QAVFrame& Frame, size_t FramePos) = 0;
virtual void StatsFinish();
virtual std::string StatsToXML(const activefilters& filters) = 0;

Expand Down
8 changes: 4 additions & 4 deletions Source/Core/FileInformation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -994,8 +994,8 @@ FileInformation::FileInformation (SignalServer* signalServer, const QString &Fil

auto stat = Stats[frame.stream().index()];

stat->TimeStampFromFrame(frame.frame(), stat->x_Current);
stat->StatsFromFrame(frame.frame(), 0, 0);
stat->TimeStampFromFrame(frame, stat->x_Current);
stat->StatsFromFrame(frame, 0, 0);

},
// Qt::QueuedConnection
Expand All @@ -1008,8 +1008,8 @@ FileInformation::FileInformation (SignalServer* signalServer, const QString &Fil
if(frame.filterName() == "stats") {
auto stat = Stats[frame.stream().index()];

stat->TimeStampFromFrame(frame.frame(), stat->x_Current);
stat->StatsFromFrame(frame.frame(), frame.size().width(), frame.size().height());
stat->TimeStampFromFrame(frame, stat->x_Current);
stat->StatsFromFrame(frame, frame.size().width(), frame.size().height());

} else if(frame.filterName().startsWith(panelOutputPrefix)) {
auto indexString = frame.filterName().mid(panelOutputPrefix.length());
Expand Down
7 changes: 5 additions & 2 deletions Source/Core/VideoStats.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -255,8 +255,9 @@ void VideoStats::parseFrame(tinyxml2::XMLElement *Frame)

//---------------------------------------------------------------------------

void VideoStats::StatsFromFrame (struct AVFrame* Frame, int Width, int Height)
void VideoStats::StatsFromFrame (const QAVFrame& frame, int Width, int Height)
{
auto Frame = frame.frame();
AVDictionary * m= Frame->metadata;
AVDictionaryEntry* e=NULL;
bool statsMapInitialized = !statsValueInfoByKeys.empty();
Expand Down Expand Up @@ -368,8 +369,10 @@ void VideoStats::StatsFromFrame (struct AVFrame* Frame, int Width, int Height)
}

//---------------------------------------------------------------------------
void VideoStats::TimeStampFromFrame (struct AVFrame* Frame, size_t FramePos)
void VideoStats::TimeStampFromFrame (const QAVFrame& frame, size_t FramePos)
{
auto Frame = frame.frame();

if (Frequency==0)
return; // Not supported

Expand Down
4 changes: 2 additions & 2 deletions Source/Core/VideoStats.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ class VideoStats : public CommonStats

// External data
virtual void parseFrame(tinyxml2::XMLElement* frame);
void StatsFromFrame(struct AVFrame* Frame, int Width, int Height);
void TimeStampFromFrame(struct AVFrame* Frame, size_t FramePos);
void StatsFromFrame(const QAVFrame& Frame, int Width, int Height);
void TimeStampFromFrame(const QAVFrame& Frame, size_t FramePos);
std::string StatsToXML(const activefilters& filters);

int getWidth() const;
Expand Down

0 comments on commit fef460e

Please sign in to comment.