Ory Band
Ory Band

Reputation: 15714

How do browsers calculate frame rate (fps) for HTML5 <video> for accurate frame-seeking?

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.

Upvotes: 6

Views: 6491

Answers (1)

Gabe
Gabe

Reputation: 86698

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.

Upvotes: 7

Related Questions