6

All browsers currently implement HTML5 <video> frame-seeking API as time divisions. e.g. In a video of 10fps, Frame #10 is time=1.0 seconds. Thus, if you want to be able to frame-seek accurately, i.e. advance one frame forward, you need to go to time=1.1 seconds. This frame-to-time calculation is done by knowing the video's frame rate (fps).

However, I don't know how the browsers calculate the frame rate.

They either read the video file's container information for some fps property, or calculate it on their own.

By using FFmpeg, you can get that by FFmpeg -i video.avi which returns Stream #0.0: Video: libvpx, yuv420p, 512x288, PAR 1:1 DAR 16:9, 25 fps, 25 tbr, 1k tbn, 25 tbc , and you can see the fps there.

The question is: Is this accurate? If not, is there an accurate way of calculating this? I just want to mimic the browsers so I can frame-seek accurately.

Ory Band
  • 14,716
  • 14
  • 59
  • 66

1 Answers1

7

The framerate of a video isn't calculated, it's stored as part of the video's metadata. There's just a field in the video's header that says how many frames per second (or possibly the amount of time each frame is shown). It's the same way the browser knows the video's resolution.

Gabe
  • 84,912
  • 12
  • 139
  • 238
  • And what if the metadata fps is wrong/inconsistent? i.e. There may be cases where the fps is variant throughout the video, no? – Ory Band Feb 13 '11 at 23:47
  • 1
    The metadata can't be "wrong". If the framerate is too high, the video will play faster than you want it to. I've never heard of a video format that allows the fps to vary. – Gabe Feb 14 '11 at 00:04
  • 4
    Actually, the metadata can absolutely be wrong, if the fps value in the container is set to something different from the stream's fps. Also, there is such a thing: it's called variable frame rate or VFR. – Hugh Guiney Jan 13 '12 at 21:28