Libavcodec Gets Video Duration and Frame Rate

I have a video encoded in .3gp h.264 and I am looking to get its frame rate and duration in C. Here is the code that I use after opening the file and searching for the corresponding codecs:

 AVRational rational = gVideoCodecCtx->time_base; LOGI(10, "numerator is %i", rational.num); LOGI(10, "denominator is %i", rational.den); LOGI(10, "duration is %d", gFormatCtx->duration); LOGI(10, "fps is %d", (double)av_q2d(rational)); 

And here is the conclusion:

 12-02 12:30:19.819: I/FFmpegTest(23903): numerator is 1 12-02 12:30:19.819: I/FFmpegTest(23903): denominator is 180000 12-02 12:30:19.819: I/FFmpegTest(23903): duration is 6594490 12-02 12:30:19.819: I/FFmpegTest(23903): fps is 1692926992 

From the documentation, I understand that duration means "duration / time_base", which gives me 6594490 / 180000 = 36.6 . The duration of my video file is 6 seconds , and I do not know where this factor comes from 6 .

Also, the frame rate seems to be completely off.

It is too difficult to find help, as many textbooks use outdated methods, and the documentation provides no examples.

Any help would be appreciated.

thanks

Edit: Thanks to the comment below, I was able to print the following

 12-02 18:59:36.279: I/FFmpegTest(435): numerator is 1 12-02 18:59:36.279: I/FFmpegTest(435): denominator is 180000 12-02 18:59:36.279: I/FFmpegTest(435): duration is 6594490 12-02 18:59:36.279: I/FFmpegTest(435): fps is 0.000006 

I also managed to find the timestamp of the frame in msec as follows:

 int msec = 1000*(packet.pts * timeBase * gVideoCodecCtx->ticks_per_frame); 

This returns me approximately 33fps (I expect 30 ). But I can’t figure out how to get the duration. The documentation says "stream length, in AV_TIME_BASE fractional seconds", but 6594490 * 0.000006 = 39.5 - the correct duration is 6.3 seconds). The exact fps is 30 , but not sure how to get from 0.000006 to 30 with the numbers above)

thanks

+4
source share
1 answer

Your fps print is garbage because it must be% lf, not% d. Why don't you check other types of parameters again.

-1
source

All Articles