Welcome to Doom9's Forum, THE in-place to be for everyone interested in DVD conversion. Before you start posting please read the forum rules. By posting to this forum you agree to abide by the rules. |
|
|
Thread Tools | Search this Thread | Display Modes |
|
1st November 2009, 15:40 | #1 | Link |
Registered User
Join Date: Jan 2007
Posts: 27
|
How-To: Determine the maximum number of Reference Frames
This question has been bugging me for years and I've never gotten a definitive answer from anyone. There was no website or easily identifiable way to figure this out. So, I found a copy of the h.264 spec and did some light reading and updated the h.264 article on Wikipedia.
In short, to determine the maximum number of reference frames, you choose which level you're encoding at, refer to the chart, and specify the target x & y resolution of the encoded video, then do the math. And always round down to the nearest whole number-- meaning 4.989 rounds down to 4. Refer to the article on Wikipedia for the chart & formula. |
1st November 2009, 17:14 | #3 | Link | |
Registered User
Join Date: Jan 2007
Posts: 27
|
Quote:
But... all of that is in the wikipedia article I linked to. The intended audience for this info is for the end-user who is just trying to figure out what to put into MeGUI's x264 editor (or the x264 command line). Since there isn't a mechanism in either application to offer "suggestions" for Reference Frames (MeGUI only has the Levels Checker), the formula will make apparent what choices can be made; even with a non-mod-16 resolution. The lowest-value whole number will always be returned and should always result in a valid option. I realize the forumla (as-is) isn't intended to be applied in an application because it doesn't validate a number of things; it works under the assumption a user has created a valid mod-16 .avs for encoding via MeGUI's "Clever Anamorphic encoding Option" or Resize with "Suggested Resolution (mod16)" selected. Last edited by showergel; 1st November 2009 at 18:50. Reason: forgot something. |
|
1st November 2009, 17:23 | #4 | Link |
Software Developer
Join Date: Jun 2005
Location: Last House on Slunk Street
Posts: 13,248
|
Well, non-mod16 resolutions are padded to mod16 anyway. So you must use the actual padded resolution in shon3i's formula.
To make shon3i's formula to work with non-padded non-mod16 resolutions, it must be extended like this: floor(MaxDPB * 1024 / 1.5 / ([ceiling(w / 16) * 16] * [ceiling(h / 16) * 16]))
__________________
Go to https://standforukraine.com/ to find legitimate Ukrainian Charities 🇺🇦✊ |
2nd November 2009, 01:51 | #5 | Link | |||
Registered User
Join Date: Aug 2007
Posts: 1,430
|
Quote:
Quote:
Quote:
|
|||
2nd November 2009, 12:19 | #6 | Link | |
Video compressionist
Join Date: Jun 2009
Location: Israel
Posts: 126
|
Quote:
Firstly I suggest to replace 1.5 with 3/2, because different platforms use different standards of floating-point (on one platform the result of above formula might be 4 while on another 3). In such case the formula is floor(MaxDPB * 1024*3 / 2 / ([ceiling(w / 16) * 16] * [ceiling(h / 16) * 16])) Secondly, I suggest for sanity check to add clipping, i.e. to clip the result between 1 and 16. |
|
1st November 2009, 21:52 | #8 | Link | |
Software Developer
Join Date: Jun 2005
Location: Last House on Slunk Street
Posts: 13,248
|
Quote:
Finally from the MaxDPB size the maximum number of ref frames can be calculated, depending of the resolution of the individual video clip. No, it won't. I will use the numer of ref frames you specify. x264 can't know for which device you are encoding, can it?
__________________
Go to https://standforukraine.com/ to find legitimate Ukrainian Charities 🇺🇦✊ Last edited by LoRd_MuldeR; 1st November 2009 at 21:55. |
|
1st November 2009, 21:56 | #9 | Link |
Registered User
Join Date: May 2006
Posts: 957
|
If you specify --ref it will, otherwise let x264 know the DPB size with --level and it will limit ref count for you.
__________________
x264 log explained || x264 deblocking how-to preset -> tune -> user set options -> fast first pass -> profile -> level Doom10 - Of course it's better, it's one more. |
1st November 2009, 23:34 | #10 | Link | ||
Registered User
Join Date: Jan 2007
Posts: 27
|
Quote:
Quote:
Last edited by showergel; 1st November 2009 at 23:55. |
||
1st November 2009, 23:44 | #11 | Link |
Registered User
Join Date: May 2006
Posts: 957
|
x264 cannot prevent GUIs from being stupid. If this was supposed to help people who use one, perhaps it would have been better to post this in the GUI forum. I thought megui omitted options that were left at their default settings. Perhaps it now just specifies everything to make it "easier".
__________________
x264 log explained || x264 deblocking how-to preset -> tune -> user set options -> fast first pass -> profile -> level Doom10 - Of course it's better, it's one more. |
1st November 2009, 21:58 | #12 | Link | |
Registered User
Join Date: Mar 2006
Posts: 272
|
Quote:
infact its seems nothing more than ref=3 gives you anything werth mentioning quality wise , and might even stop smooth playback on some players, so tell them to Always use Ref=3 on their HD 1080P HP L4.1 and Be Happy when it also plays on most other players too. just because You Can use a higher Value On anything, Does Not mean You Should. Last edited by popper; 1st November 2009 at 22:01. |
|
1st November 2009, 23:50 | #14 | Link |
Derek Prestegard IRL
Join Date: Nov 2003
Location: Los Angeles
Posts: 5,989
|
x264's behavior seems optimal to this.
If you select a speed:quality preset that has more than 4 references, but also specify --level 41, x264 will obey level 4.1 and keep it at 4. Unless of course you manually specify --ref 6 or something - in which case this takes precedence - overriding level 4.1 I think using the max number of refs supported by your hardware is the way to go - provided you can afford the encoding time. There are indeed benefits all the way up to 16 for certain content. That being said, more than 5 seems to have quite limited benefit for most film content AFAIK. ~MiSfit
__________________
These are all my personal statements, not those of my employer :) |
2nd November 2009, 02:21 | #15 | Link |
Registered User
Join Date: May 2006
Posts: 957
|
@Snowknight26, sorry, that is incorrect.
width = 720, height = 576 ((width+(16-(width%16)))*(height+(16-(height%16)))) = ((720+(16-(720%16)))*(576+(16-(576%16)))) = ((720+(16-0))*(576+(16-0))) = (720+16)*(576+16) = 736 * 592
__________________
x264 log explained || x264 deblocking how-to preset -> tune -> user set options -> fast first pass -> profile -> level Doom10 - Of course it's better, it's one more. Last edited by J_Darnley; 2nd November 2009 at 02:36. |
2nd November 2009, 06:54 | #16 | Link | |
Registered User
Join Date: Aug 2007
Posts: 1,430
|
You're right. I changed my original equation from
Quote:
|
|
2nd November 2009, 07:12 | #17 | Link | |
Registered User
Join Date: Apr 2009
Location: Switzerland
Posts: 69
|
Just throw another modulo in. :P
Quote:
__________________
My nightmares are horrifying, they're all interlaced! Last edited by Boolsheet; 2nd November 2009 at 07:31. Reason: Ah, very clever kemuri ;) |
|
2nd November 2009, 07:30 | #18 | Link |
Compiling Encoder
Join Date: Jan 2007
Posts: 1,348
|
Code:
([ceiling(w / 16) * 16] * [ceiling(h / 16) * 16]) -> (((width+15)&~15) * ((height+15)&~15)) simplicity-wise, what LoRd_MuldeR has would be easiest to read and understand for most people though. Last edited by kemuri-_9; 2nd November 2009 at 07:42. |
7th June 2010, 08:59 | #20 | Link |
Video compressionist
Join Date: Jun 2009
Location: Israel
Posts: 126
|
In the recent version of H.264 standard (dated 03/2009) the issue how to determine the maximal number of reference frames (or MaxDpbFrames) has been clarified and simplified.
For all profiles MaxDpbFrames equal to Min( MaxDpbMbs / ( PicWidthInMbs * FrameHeightInMbs ), 16 ), where MaxDpbMbs is taken from the table A-1. |
Tags |
h.264, maximum, reference frames, wikipedia, x264 |
|
|