Skip to content

Commit

Permalink
Merge pull request #448 from SuslikV/ffmpeg-like-fps
Browse files Browse the repository at this point in the history
Change frame rate detection
  • Loading branch information
ferdnyc committed Mar 27, 2020
2 parents c38c55f + 2701cf9 commit 12dd4d1
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 9 deletions.
13 changes: 10 additions & 3 deletions src/FFmpegReader.cpp
Expand Up @@ -706,9 +706,16 @@ void FFmpegReader::UpdateVideoInfo() {
info.vcodec = pCodecCtx->codec->name;
info.video_bit_rate = (pFormatCtx->bit_rate / 8);

// set frames per second (fps)
info.fps.num = pStream->avg_frame_rate.num;
info.fps.den = pStream->avg_frame_rate.den;
// Frame rate from the container and codec
AVRational framerate = av_guess_frame_rate(pFormatCtx, pStream, NULL);
info.fps.num = framerate.num;
info.fps.den = framerate.den;

ZmqLogger::Instance()->AppendDebugMethod("FFmpegReader::UpdateVideoInfo", "info.fps.num", info.fps.num, "info.fps.den", info.fps.den);

// TODO: remove excessive debug info in the next releases
// The debug info below is just for comparison and troubleshooting on users side during the transition period
ZmqLogger::Instance()->AppendDebugMethod("FFmpegReader::UpdateVideoInfo (pStream->avg_frame_rate)", "num", pStream->avg_frame_rate.num, "den", pStream->avg_frame_rate.den);

if (pStream->sample_aspect_ratio.num != 0) {
info.pixel_ratio.num = pStream->sample_aspect_ratio.num;
Expand Down
34 changes: 28 additions & 6 deletions tests/FFmpegReader_Tests.cpp
Expand Up @@ -36,13 +36,16 @@
using namespace std;
using namespace openshot;

TEST(FFmpegReader_Invalid_Path)
SUITE(FFmpegReader)
{

TEST(Invalid_Path)
{
// Check invalid path
CHECK_THROW(FFmpegReader(""), InvalidFile);
}

TEST(FFmpegReader_GetFrame_Before_Opening)
TEST(GetFrame_Before_Opening)
{
// Create a reader
stringstream path;
Expand All @@ -53,7 +56,7 @@ TEST(FFmpegReader_GetFrame_Before_Opening)
CHECK_THROW(r.GetFrame(1), ReaderClosed);
}

TEST(FFmpegReader_Check_Audio_File)
TEST(Check_Audio_File)
{
// Create a reader
stringstream path;
Expand Down Expand Up @@ -83,7 +86,7 @@ TEST(FFmpegReader_Check_Audio_File)
r.Close();
}

TEST(FFmpegReader_Check_Video_File)
TEST(Check_Video_File)
{
// Create a reader
stringstream path;
Expand Down Expand Up @@ -129,7 +132,7 @@ TEST(FFmpegReader_Check_Video_File)
r.Close();
}

TEST(FFmpegReader_Seek)
TEST(Seek)
{
// Create a reader
stringstream path;
Expand Down Expand Up @@ -186,7 +189,23 @@ TEST(FFmpegReader_Seek)

}

TEST(FFmpegReader_Multiple_Open_and_Close)
TEST(Frame_Rate)
{
// Create a reader
stringstream path;
path << TEST_MEDIA_PATH << "sintel_trailer-720p.mp4";
FFmpegReader r(path.str());
r.Open();

// Verify detected frame rate
openshot::Fraction rate = r.info.fps;
CHECK_EQUAL(24, rate.num);
CHECK_EQUAL(1, rate.den);

r.Close();
}

TEST(Multiple_Open_and_Close)
{
// Create a reader
stringstream path;
Expand Down Expand Up @@ -221,3 +240,6 @@ TEST(FFmpegReader_Multiple_Open_and_Close)
// Close reader
r.Close();
}

} // SUITE(FFmpegReader)

0 comments on commit 12dd4d1

Please sign in to comment.