Selur
13th November 2008, 17:24
Wanting to calculate the max number of refs allowed for a specific avc level I searched the forum and then based my calculation on http://forum.doom9.org/showthread.php?t=102048
which gave me
/***
* Restrictions:
* MaxMBPS >= width*height*fps. (w&h measured in macroblocks, i.e. pixels/16 round up in each dimension)
* MaxFS >= width*height
* sqrt(MaxFS*8) >= width
* sqrt(MaxFS*8) >= height
* MaxDPB >= (bytes in a frame) * min(16, ref + (pyramid ? 2 : bframes ? 1 : 0))
* MaxBR >= vbv_maxrate.
* MaxCPB >= vbv_bufsize.
* MaxVmvR >= max_mv_range.
* MaxMvsPer2Mb, MinLumaBiPredSize, direct_8x8_inference_flag : are not enforced by x264. The only way to ensure compliance is to disable p4x4 at level>=3.1, or at level>=3 w/ B-frames.
* MinCR : is not enforced by x264. Won't ever be an issue unless you use lossless.
* SliceRate : I don't know what this limits.latexxx once posted the values needed for these factors:
* VALUES FOR LEVEL: http://forum.doom9.org/showthread.php?t=101345
*
* LEGEND:
* MaxDPB = max decoded picture buffer
* MaxMBPS = max macroblocks per second
* MaxFS = max frame size
* MaxBR = max bitrate
* MaxCPB = max vbv buffer
* MaxVmvR = max motion vetor range
***/
so taking
MaxDPB >= (bytes in a frame) * min(16, ref + (pyramid ? 2 : bframes ? 1 : 0))
as basis I rearranged it to
Min(this->maxDPB(level)/bytesPerFrame - bframeModifier, 16)
where:
maxDPB = 12582912 (for Level 4.1)
bytesPerFrame = (pixel width)*(pixel height)*1.5 (since x264 only support 4:2:0 atm) = 1920*1080*1.5
bframeModifier = 0 when no bframes are used, 1 when bframes are enabled and 2 when bframes&pyramid are enabled.
using this I get:
with bframes:
Min(this->maxDPB(level)/bytesPerFrame - bframeModifier, 16)
maxDPB = 12582912
bytesPerFrame = 3110401
maxDPB/bytesPerFrame = 4
bframeModifier = 0
-> maxRef = 4
with bframes:
Min(this->maxDPB(level)/bytesPerFrame - bframeModifier, 16)
maxDPB = 12582912
bytesPerFrame = 3110401
maxDPB/bytesPerFrame = 4
bframeModifier = 1
-> maxRef = 3
with bframes&pyramid:
Min(this->maxDPB(level)/bytesPerFrame - bframeModifier, 16)
maxDPB = 12582912
bytesPerFrame = 3110401
maxDPB/bytesPerFrame = 4
bframeModifier = 2
-> maxRef = 2
Trahald&Co nutzen die Formel:
min( 1024 * MaxDPB/(PicWidthInMbs * FrameHeightInMbs * 384), 16)
1024 * (12288) / (120 * (( 2 – frame_mbs_only_flag ) * PicHeightInMapUnits) * 384)
maxDPB / (Width/16 * ( 2 – frame_mbs_only_flag ) * Height/16 * 384)
wobei frame_mbs_only_flag = 0 heißt man encoded interlaced
But looking at http://forum.doom9.org/showthread.php?t=136258 Trahald uses a different formula.
maxDPB / (PicWidth/16 * (( 2 – frame_mbs_only_flag ) * FrameHeight/16) * 384)
maxDPB = 12582912 (for Level 4.1)
and frame_mbs_only_flag = 1 assuming the material is progressive (iiirc frame_mbs_only_flag = 0 means material is interlaced)
1st thing about this formula that I registered was that:
a. it doesn't care about B-Frames
b. it cares about interlacing
Thanks for reading up to here. :)
Now here's my question/problem:
How does one calculate the maximum number of frames?
(I suspect that the 'real' formula is a mix of the two above. :))
:thanks:
Cu Selur
which gave me
/***
* Restrictions:
* MaxMBPS >= width*height*fps. (w&h measured in macroblocks, i.e. pixels/16 round up in each dimension)
* MaxFS >= width*height
* sqrt(MaxFS*8) >= width
* sqrt(MaxFS*8) >= height
* MaxDPB >= (bytes in a frame) * min(16, ref + (pyramid ? 2 : bframes ? 1 : 0))
* MaxBR >= vbv_maxrate.
* MaxCPB >= vbv_bufsize.
* MaxVmvR >= max_mv_range.
* MaxMvsPer2Mb, MinLumaBiPredSize, direct_8x8_inference_flag : are not enforced by x264. The only way to ensure compliance is to disable p4x4 at level>=3.1, or at level>=3 w/ B-frames.
* MinCR : is not enforced by x264. Won't ever be an issue unless you use lossless.
* SliceRate : I don't know what this limits.latexxx once posted the values needed for these factors:
* VALUES FOR LEVEL: http://forum.doom9.org/showthread.php?t=101345
*
* LEGEND:
* MaxDPB = max decoded picture buffer
* MaxMBPS = max macroblocks per second
* MaxFS = max frame size
* MaxBR = max bitrate
* MaxCPB = max vbv buffer
* MaxVmvR = max motion vetor range
***/
so taking
MaxDPB >= (bytes in a frame) * min(16, ref + (pyramid ? 2 : bframes ? 1 : 0))
as basis I rearranged it to
Min(this->maxDPB(level)/bytesPerFrame - bframeModifier, 16)
where:
maxDPB = 12582912 (for Level 4.1)
bytesPerFrame = (pixel width)*(pixel height)*1.5 (since x264 only support 4:2:0 atm) = 1920*1080*1.5
bframeModifier = 0 when no bframes are used, 1 when bframes are enabled and 2 when bframes&pyramid are enabled.
using this I get:
with bframes:
Min(this->maxDPB(level)/bytesPerFrame - bframeModifier, 16)
maxDPB = 12582912
bytesPerFrame = 3110401
maxDPB/bytesPerFrame = 4
bframeModifier = 0
-> maxRef = 4
with bframes:
Min(this->maxDPB(level)/bytesPerFrame - bframeModifier, 16)
maxDPB = 12582912
bytesPerFrame = 3110401
maxDPB/bytesPerFrame = 4
bframeModifier = 1
-> maxRef = 3
with bframes&pyramid:
Min(this->maxDPB(level)/bytesPerFrame - bframeModifier, 16)
maxDPB = 12582912
bytesPerFrame = 3110401
maxDPB/bytesPerFrame = 4
bframeModifier = 2
-> maxRef = 2
Trahald&Co nutzen die Formel:
min( 1024 * MaxDPB/(PicWidthInMbs * FrameHeightInMbs * 384), 16)
1024 * (12288) / (120 * (( 2 – frame_mbs_only_flag ) * PicHeightInMapUnits) * 384)
maxDPB / (Width/16 * ( 2 – frame_mbs_only_flag ) * Height/16 * 384)
wobei frame_mbs_only_flag = 0 heißt man encoded interlaced
But looking at http://forum.doom9.org/showthread.php?t=136258 Trahald uses a different formula.
maxDPB / (PicWidth/16 * (( 2 – frame_mbs_only_flag ) * FrameHeight/16) * 384)
maxDPB = 12582912 (for Level 4.1)
and frame_mbs_only_flag = 1 assuming the material is progressive (iiirc frame_mbs_only_flag = 0 means material is interlaced)
1st thing about this formula that I registered was that:
a. it doesn't care about B-Frames
b. it cares about interlacing
Thanks for reading up to here. :)
Now here's my question/problem:
How does one calculate the maximum number of frames?
(I suspect that the 'real' formula is a mix of the two above. :))
:thanks:
Cu Selur