Skip to content

VideoProperties: fix getFps if the average framerate is not defined #290

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/AvTranscoder/properties/VideoProperties.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,12 @@ int VideoProperties::getLevel() const

float VideoProperties::getFps() const
{
return av_q2d(_formatContext->streams[_streamIndex]->avg_frame_rate);
if(! _formatContext)
throw std::runtime_error("unknown format context");

if(_formatContext->streams[_streamIndex]->avg_frame_rate.den)
return av_q2d(_formatContext->streams[_streamIndex]->avg_frame_rate);
return av_q2d(av_inv_q(getTimeBase()));
}

float VideoProperties::getDuration() const
Expand Down
1 change: 1 addition & 0 deletions src/AvTranscoder/properties/VideoProperties.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ class AvExport VideoProperties : public StreamProperties

/**
* @brief Corresponds to the 'fps' returned by ffprobe.
* @note If the average framerate is not defined in the format, return the tbn.
* fps = the average framerate that has come from the AVStream
* tbn = the time base in AVStream that has come from the AVStream
* tbc = the time base in AVCodecContext for the codec used for a particular stream
Expand Down