Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 853
Ory Band Avatar asked Feb 12 '11 23:02

Ory Band


People also ask

How do I calculate FPS frames?

To calculate frames per second, you just take the number of rendered frames and divide it by the seconds passed.

What is request video frame callback?

The requestVideoFrameCallback() method allows web authors to register a callback that runs in the rendering steps when a new video frame is sent to the compositor.

How can I see my youtube frame rate?

In the quality menu, high frame rate will be listed next to the resolution. For example, a 1080p resolution video at 120 frames per second (FPS) will be listed as 1080p60. Note: Uploading and watching videos at 120 FPS is not supported at this time.


1 Answers

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.

like image 116
Gabe Avatar answered Nov 15 '22 09:11

Gabe