Better understanding of variable frame rates

General questions or discussion about HandBrake, Video and/or audio transcoding, trends etc.
Post Reply
mod16
Posts: 78
Joined: Sun Jan 12, 2014 11:10 am

Better understanding of variable frame rates

Post by mod16 » Tue Dec 23, 2014 2:17 pm

Hi!

Since I'm using HandBrake (x264 encoder) I'm using the variable frame rate (VFR) setting. My sources are almost always constant frame rate (CFR) and I never had any playback problems, so I really didn't gave it much thought. I read the Wiki/Docs about frame rates and stuff but I'm still not quite sure what the VFR setting really does:

In my understanding so far, VFR does only make a difference if I have a VFR source with mixed frame rates (maybe 24 fps for 20 minutes, and then 10 minutes 30 fps). So by implication if I have a purely CFR source the VFR setting would change absolutely nothing. This "theory" would be backed by my observation, that every CFR source I encode with VFR set to on still produces CFR target videos (at least that's what Mediainfo tells me, which could be wrong, of course):

Code: Select all

Frame rate mode                          : Constant
But what confuses me frequently is, that I sometimes read about VFR being especially effective for presentations and videos containing mostly static scenes. So i.e. if the screen stays the same, frame rate can be "saved" by dynamically reducing it to a minimum. But this would mean, that the frame rate is completely dynamic - not just switchig between "modes" in different parts of the video? Also in my understanding the encoder (x264 in this case) already compresses static content very effectively using B-frames, I-frames etc.. - so would reducing the frame rate really matter that much at all?

But more importantly: What is true for the VFR setting in handbrake? If I choose VFR will the x264 encoder really try to save space by dynamically adjusting the frame rate for each individual scene - even if I provide a CFR source? Or will it really just switch between different frame rate "modes" - if they exist in the source (i.e.: 24 fps --> 30 fps --> 24 fps)?

musicvid
Veteran User
Posts: 3273
Joined: Sat Jun 27, 2009 1:19 am

Re: Better understanding of variable frame rates

Post by musicvid » Tue Dec 23, 2014 2:26 pm

Vfr does not change the base frame rate; it does not "switch" between 24 and 30 fps. You are confusing two entirely separate things.
And vfr does not change the base frame rate by very much-- it saves a little space.
If you can play VFR without sync issues, use it. If not, well, we got along for years without it.
For me, CFR same as source is bulletproof.

User avatar
JohnAStebbins
HandBrake Team
Posts: 5441
Joined: Sat Feb 09, 2008 7:21 pm

Re: Better understanding of variable frame rates

Post by JohnAStebbins » Tue Dec 23, 2014 4:15 pm

VFR makes the duration of each frame of the output video exactly the same as the duration of each frame of the input video. So if your input video changes framerate occasionally, so will the output. If your input video is a collection of static frames, the output will be a collection of static frames.

The primary advantage of VFR is not size reduction. The advantage is a more true reproduction of the input (i.e. better quality). Timing is as important to quality as pixels. If the timing is off for some sources, the playback will not be fluid.

DVDs are especially bad in this regard. DVDs are "constant" framerate. But the frames may be telecined (see https://trac.handbrake.fr/wiki/Telecine). During transcoding you want to reverse the telecine process in order to reproduce the original framerate of the movie. This inverse telecine process will translate a 30fps sequence to 24fps. Then to complicate matters, many DVDs will mix 24fps telecined sequences with 30fps video sequences. TV shows transfered to DVD are notorious for this because they are often a mix of film, video and computer generated graphics.

musicvid
Veteran User
Posts: 3273
Joined: Sat Jun 27, 2009 1:19 am

Re: Better understanding of variable frame rates

Post by musicvid » Tue Dec 23, 2014 6:28 pm

:) Good to know

mod16
Posts: 78
Joined: Sun Jan 12, 2014 11:10 am

Re: Better understanding of variable frame rates

Post by mod16 » Wed Dec 24, 2014 11:36 am

musicvid wrote:Vfr does not change the base frame rate; it does not "switch" between 24 and 30 fps. You are confusing two entirely separate things.
But what exactly are those two things I'm confusing? Maybe the basic principle called VFR ( http://en.wikipedia.org/wiki/Variable_frame_rate ) and the concrete implementation/option called VFR in x264/HandBrake?

mod16
Posts: 78
Joined: Sun Jan 12, 2014 11:10 am

Re: Better understanding of variable frame rates

Post by mod16 » Wed Dec 24, 2014 11:58 am

JohnAStebbins wrote:VFR makes the duration of each frame of the output video exactly the same as the duration of each frame of the input video. So if your input video changes framerate occasionally, so will the output. If your input video is a collection of static frames, the output will be a collection of static frames.
So just to be clear: If the framerate of the input video stays the same from start to end, the output video would be using a CFR even if I selected the VFR option, because there would be simply no need for adjusting anything? Only if the source already uses VFR or different framerates the VFR setting will effectively produce a different result?
The primary advantage of VFR is not size reduction. The advantage is a more true reproduction of the input (i.e. better quality). Timing is as important to quality as pixels. If the timing is off for some sources, the playback will not be fluid.
So if understand it right the VFR setting in HandBrake is more a "passive" feature which allows more flexibility (by not trying to forcefully equalize the framerate) and a side effect of this could also be slightly smaller file. But if the framerate is already constant in the source it will not try to actively compress it better by reducing the framerate i.e. in scenes where static content is shown?

mduell
Veteran User
Posts: 6630
Joined: Sat Apr 21, 2007 8:54 pm

Re: Better understanding of variable frame rates

Post by mduell » Wed Dec 24, 2014 1:18 pm

Yes with some trivial exceptions. Yes. Yes.

User avatar
JohnAStebbins
HandBrake Team
Posts: 5441
Joined: Sat Feb 09, 2008 7:21 pm

Re: Better understanding of variable frame rates

Post by JohnAStebbins » Wed Dec 24, 2014 3:45 pm

mod16 wrote: So just to be clear: If the framerate of the input video stays the same from start to end, the output video would be using a CFR even if I selected the VFR option, because there would be simply no need for adjusting anything? Only if the source already uses VFR or different framerates the VFR setting will effectively produce a different result?
A qualified yes. The frame durations will all be the same, i.e. constant framerate. But there is a flag in the h.264 stream that differentiates CFR from VFR. When this flag is set, the meaning of the timebase field in the h.264 stream is different. For CFR, the timebase field is the framerate. For VFR the timebase field is the minimum time interval that any frame could be. This difference is important because there are some players that do not interpret the timebase field correctly when VFR is enabled and therefore play the stream incorrectly.
So if understand it right the VFR setting in HandBrake is more a "passive" feature which allows more flexibility (by not trying to forcefully equalize the framerate) and a side effect of this could also be slightly smaller file. But if the framerate is already constant in the source it will not try to actively compress it better by reducing the framerate i.e. in scenes where static content is shown?
Yes. It's actually more work for HandBrake to guarantee CFR than to just pass through the original timestamps from the source.

Post Reply