Note that there are some explanatory texts on larger screens.

plurals
  1. POlibavcodec get video duration and framerate
    primarykey
    data
    text
    <p>I have a video encoded in <code>.3gp</code> <code>h.264</code> and I am looking to get its framerate and duration in C. Here is the code I use after opening the file and finding the appropriate codecs:</p> <pre><code>AVRational rational = gVideoCodecCtx-&gt;time_base; LOGI(10, "numerator is %i", rational.num); LOGI(10, "denominator is %i", rational.den); LOGI(10, "duration is %d", gFormatCtx-&gt;duration); LOGI(10, "fps is %d", (double)av_q2d(rational)); </code></pre> <p>And here is the output:</p> <pre><code>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 </code></pre> <p>From the documentation I understand that the duration is meant to be "duration/time_base" which gives me <code>6594490 / 180000 = 36.6</code>. The duration of my video file is <code>6 seconds</code> and I do not know where this factor of <code>6</code> would come from.</p> <p>Also the framerate seems to be completely off.</p> <p>It is currenlty hard to find help as a lot of tutorials use deprecated methods and the documentation does not give examples.</p> <p>Any help would be appreciated.</p> <p>Thanks</p> <p><strong>Edit:</strong> Thanks to the comment below I managed to print the following</p> <pre><code>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 </code></pre> <p>I also managed to find out a frame's timestamp in <code>msec</code> with this:</p> <pre><code>int msec = 1000*(packet.pts * timeBase * gVideoCodecCtx-&gt;ticks_per_frame); </code></pre> <p>This returns me something that's roughly <code>33fps</code> (I expect <code>30</code>). But I can't figure out how to retrieve the duration. The documentation says "duration of the stream, in <code>AV_TIME_BASE</code> fractional seconds" but <code>6594490 * 0.000006 = 39.5</code> - the correct duration is <code>6.3</code> seconds). Also the exact fps is <code>30</code> but nor sure how to get from <code>0.000006</code> to <code>30</code> with the above figures)</p> <p>Thanks</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload