Log in

View Full Version : Encoding Video for Blu-Ray using H264/AVC


Pages : [1] 2 3 4 5 6 7 8 9

shon3i
12th May 2010, 22:54
Here is part of specification that apply when encoding with H264/AVC codec, all parameters showed here are not guessing, it's based on original Blu-Ray specification, which are not available in public.

NOTE: This is discussion about settings that are for creating 100% compliant Blu-Ray structures, not for encoding from Blu-Ray sources to matroska/mp4 or other media, if you encode to those skip this nightmare :)

1. GENERAL CONSTRAINTS FOR MPEG-4 H264/AVC

1.1 ALLOWED RESOLUTIONS/FRAMERATES

tom.niko.users.sbb.rs/resolutions.png
https://forum.doom9.org/attachment.php?attachmentid=18660&stc=1&d=1718614590

1.2 ALLOWED LEVELS, PROFILES, REFERENCE FRAMES, VBV

1.2.1 Primary Video Rules

tom.niko.users.sbb.rs/gopsrefs2.png
https://forum.doom9.org/attachment.php?attachmentid=18661&stc=1&d=1718614633

1.2.2 Secondary Video Rules

NOTE: In case of 1080 and 720 resolutions same rules apply as Primary video, while 576 and 480 resolutions have stricter parameters showed in table:

tom.niko.users.sbb.rs/gopsrefs3.png
https://forum.doom9.org/attachment.php?attachmentid=18662&stc=1&d=1718614687


1.3 SIMPLE ASPECT RATIO

tom.niko.users.sbb.rs/sar.png
https://forum.doom9.org/attachment.php?attachmentid=18663&stc=1&d=1718614732


1.4 COLOR CHARACTERISTICS

tom.niko.users.sbb.rs/color.png
https://forum.doom9.org/attachment.php?attachmentid=18664&stc=1&d=1718614748


1.5 OTHER REQUIRED PARAMETERS

8-bit (4:2:0) Colorspace is only allowed
Main and High profiles are allowed
Maximum 3 B-Frames is allowed
NAL-HRD Type 2 capable encoder is needed


2. ENCODE BLU-RAY VIDEO USING x264

2.1 MANDATORY PARAMETERS

Every encode for Blu-Ray must contain this parameters, without it will not meet Blu-Ray specification.

--bluray-compatEnforce x264 to create BD compliant stream, that will reduce x264 settings to BD compatible: bframe<=3, ref<=4 for 1080, ref<=6 for 720/576/480, bpyramid<=strict, weightp<=1, aud=1, nalhrd=vbr

--levelBlu-Ray level, see the table for the appropriate level

--keyintMaximum number displayed pictures in GOP. If you set Maximum bitrate less or equal to 15mbps you can use 2 second long GOP otherwise, 1 second GOP must be used.

--vbv-maxrateMaximum allowed bitrate. Depend of destination media, for normal BD Media, maximum settings is allowed (40000), while for DVD Media (eg BD-5 or BD-9) there is no maximum per Blu-Ray specification, but is strongly recommended that use less or equal to 15000, since DVD reading is slower.


--vbv-bufsizeMaximum allowed buffer, buffer size is in relation with maxrate. Since STD Buffer Delay for Blu-Ray allows maximum 1 second. This mean to divide buffer with maxrate and see if result is less or equal to 1, if not, buffer is need to be reduced to lower value that meet 1 second STD. For BD media, maximum settings is allowed (30000), but if not meet STD Buffer Delay, then need to be reduced to lower value. For DVD media there is no maximum in Blu-Ray specification, but is strongly recommended that use less or equal to 15000, and again need to meet STD delay of 1 second.

For example:

--vbv-bufsize 30000 --vbv-maxrate 40000 is allowed
--vbv-bufsize 30000 --vbv-maxrate 30000 is allowed
--vbv-bufsize 15000 --vbv-maxrate 30000 is allowed
--vbv-bufsize 30000 --vbv-maxrate 15000 is not allowed (delay is greater than 1 second)

Basicly vbv-bufsize should newer been greater than vbv-maxrate, that is whole point.


--sar
Simple Aspect Ratio, must present in stream, see the table for the appropriate settings


--slices
Only when encoding with --level 4.1, slices need to be set to 4 or greater, otherwise you can skip this setting or set it to 1.


-o xxx.264
Output file must be in raw 264 elementary stream (extension .264) otherwise settings will not applied correctly. DO NOT USE MKV OR MP4.

2.2 OPTIONAL PARAMETERS

This parameters is optional and not need for every encode.


--colorprim
--transfer
--colormatrix
Specify color primaries, transfer characteristics and color matrix. This is optional, and not need to be present, see the table for the appropriate settings.


--pic-struct
Need only when fake interlaced is used, and it's default on with interlaced and pulldown. It's fine with progressive aslo, and some BD verification tools request to be present in stream.


--open-gop
Use non-IDR pictures instead classic IDR picture, this will tend to resolve pulsing picture problem that is usually came with short GOP's.


--fake-interlaced
Since 25p or 30p video is not allowed for Primary Video, encoding progressive video that meet Blu-Ray specification is only possible with this option. If use this option you aslo need to specify --pic-struct


--qpfileNeed for chapters.

2.2 EXAMPLES

Progressive

1080p (http://www.x264bluray.com/home/1080i-p)
720p (http://www.x264bluray.com/home/720p-encoding)
576p (http://www.x264bluray.com/home/576p-pal)
480p (http://www.x264bluray.com/home/480p-ntsc)

Interlaced

1080i (http://www.x264bluray.com/home/1080i)
576i (http://www.x264bluray.com/home/576i-pal)
480i (http://www.x264bluray.com/home/480i-ntsc)

b66pak
12th May 2010, 23:19
thanks a lot...
_

Guest
12th May 2010, 23:46
Please advise when it is complete so we can make it a stickie. Thank you.

AnonCrow
13th May 2010, 00:31
Little nitpick : since you're using images and you're hosting them yourself, might want to optimize them for smaller size - pics 1 and 2 went from 50 KiB and 62 KiB to 13 and 16 KiB, respectively , just by decreasing bit-depth and using maximum PNG compression. This without even resorting to PNGOUT or Pngcrush.

ajp_anton
13th May 2010, 02:24
What does "Max bitrate BD, DVD and with or without 2 sec GOP" mean?

And to do 25fps progressive, you have to either double the framerate to 50fps, or encode it as 25fps interlaced?

creamyhorror
13th May 2010, 03:11
Thanks for doing this. I think a specific x264 section with recommended commandlines and workflow notes would be essential.

shon3i
13th May 2010, 07:30
@AnonCrow, thanks for tip. i probably will upload later here as attach, but i will optimize as much as possible.

What does "Max bitrate BD, DVD and with or without 2 sec GOP" mean?It mean, if you target is BD media and if you set VBV maxrate <=15000 then you can use --keyint from Max Frames in 2 sec. GOP. Or if you target media is DVD (BD5/BD9) you aslo may not use higher maxrate/buffer than 15000, coz DVD spin speed is lower, that is some error free maximum for DVD. Still if you set maxrate to 15000 you can choose what you want to use 1 second or 2 second GOP, for BD or DVD.

And to do 25fps progressive, you have to either double the framerate to 50fps, or encode it as 25fps interlaced? You need encode it as interlaced, or convert to 720p50.

Thanks for doing this. I think a specific x264 section with recommended commandlines and workflow notes would be essential. To be continued :) with explanation, examples, and few more tables.

Snowknight26
13th May 2010, 08:00
You need encode it as interlaced, or convert to 720p50.

Doesn't actually have to be interlaced, can just be flagged as interlaced yet contain progressive frames.

kieranrk
13th May 2010, 08:23
Doesn't actually have to be interlaced, can just be flagged as interlaced yet contain progressive frames.

If you had an encoder that can do adaptive PAFF/MBAFF then yes.

Or you could force it manually since the spec says frame_mbs_only shall be 0.

bob0r
13th May 2010, 10:03
May i advice, that instead of an image, maybe make a .html page or something silimar.
So in case of link down, or user absense, people can easy update or repost when needed.

kypec
13th May 2010, 10:06
May i advice, that instead of an image, maybe make a .html page or something silimar.
So in case of link down, or user absense, people can easy update or repost when needed.
+++ Images are nice but hardly maintainable nor usable (copy/paste) and so on.:goodpost:

kolak
13th May 2010, 11:26
I'm preaty sure that 25p is allowed for secondary video stream.


Andrew

mp3dom
13th May 2010, 11:31
Infact it's mentioned in the tab :)
I would like to add that even if it's allowed to have a fullHD secondary video, it's better to prefer SD secondary video because not all the standalone players are able to handle 2 fullhd stream at once.

shh
13th May 2010, 12:06
Doesn't actually have to be interlaced, can just be flagged as interlaced yet contain progressive frames.If you had an encoder that can do "full" PAFF/MBAFF then yes.

Is x264 able to do this already? (= flagging the stream interlaced, but just coding progressive frames)
I've got many progressive PAL-sources (most satellite-streams are p anyway), and wouldn't like to encode that "interlaced". :(

kieranrk
13th May 2010, 13:07
Is x264 able to do this already? (= flagging the stream interlaced, but just coding progressive frames)
I've got many progressive PAL-sources (most satellite-streams are p anyway), and wouldn't like to encode that "interlaced". :(

You could modify x264 to write frame_mbs_only flag as zero. You'd have to write pic_struct too but the spec isn't clear whether it wants you to signal the frame as two fields or as one frame.

ajp_anton
13th May 2010, 13:31
It mean, if you target is BD media and if you set VBV maxrate <=15000 then you can use --keyint from Max Frames in 2 sec. GOP. Or if you target media is DVD (BD5/BD9) you aslo may not use higher maxrate/buffer than 15000, coz DVD spin speed is lower, that is some error free maximum for DVD. Still if you set maxrate to 15000 you can choose what you want to use 1 second or 2 second GOP, for BD or DVD.
But the "with or without 2 sec GOP" means it is 15000 *always*, whether or not you use 2 sec GOP, and this is false, because if you use 1 sec GOP with BD, it's 40000 and not 15000.
Sure 15000 can be used, but it's not max, which is what this tries to tell you.

IMO it should say something like

Max bitrate
2 sec GOP BD
DVD

rack04
13th May 2010, 14:55
Thanks for taking the time to put this together. Here are my comments:

1.) "RESOLITIONS" should be spelled "RESOLUTIONS"
2.) Add a section that includes mandatory items like --aud, --bframes 3, --nal-hrd vbr, etc. I know you mention bframes 3 in the title section of Section 2 but that could easily be overlooked by people who concentrate on big pretty pictures.

Sharc
13th May 2010, 15:00
Thanks a lot shon3i for your initiative :)

Thanks for doing this. I think a specific x264 section with recommended commandlines and workflow notes would be essential.
+++ Would indeed be very helpful.
Could it eventually be included in x264 as 'device presets' or similar?

poisondeathray
13th May 2010, 15:24
Nice work sho3ni!


And to do 25fps progressive, you have to either double the framerate to 50fps, or encode it as 25fps interlaced?

And another option would be to do the slowdown to 24p or 23.976p if you can tolerate the audio shift

shon3i
13th May 2010, 15:52
But the "with or without 2 sec GOP" means it is 15000 *always*, whether or not you use 2 sec GOP, and this is false, because if you use 1 sec GOP with BD, it's 40000 and not 15000.
Sure 15000 can be used, but it's not max, which is what this tries to tell you.

IMO it should say something like

Max bitrate
2 sec GOP BD
DVD
Not exactly because situation looks like this:

1. 15000 is max for DVD
2. 15000 is max i you want use 2 sec GOP besides you use DVD or BD
3. you can still use 1 sec gop.

so if you don't use 2 sec GOP that mean you will use 1 second instead. I will somehow fix this.

@all, be patient :)

kolak
13th May 2010, 15:56
Infact it's mentioned in the tab :)
I would like to add that even if it's allowed to have a fullHD secondary video, it's better to prefer SD secondary video because not all the standalone players are able to handle 2 fullhd stream at once.

I see it now :)

sub24ox7
13th May 2010, 17:32
What we still need are the exact specifications for 100% blu-ray compliant video I have a good idea or at least I am 99% sure I already know all the specifications I just want to be 100% sure.
Now that x264 can produce a 100% compliant blu-ray video I
think it would be a great Idea to have a sticky with he exact encoder settings.

ajp_anton
13th May 2010, 17:40
Not exactly because situation looks like this:

1. 15000 is max for DVD
2. 15000 is max i you want use 2 sec GOP besides you use DVD or BD
3. you can still use 1 sec gop.

so if you don't use 2 sec GOP that mean you will use 1 second instead. I will somehow fix this.

@all, be patient :)
What I suggested means
DVD, 1s GOP: 15000
DVD, 2s GOP: 15000
BD, 1s GOP: 40000 / 24000
BD, 2s GOP: 15000

You could make it even more clear by adding "1 sec GOP" to the 40000/24000 maxrate.

Or is this wrong?

shon3i
13th May 2010, 20:32
You could make it even more clear by adding "1 sec GOP" to the 40000/24000 maxrate.Yes you right, i will fix this somehow.

kolak
13th May 2010, 21:20
What we still need are the exact specifications for 100% blu-ray compliant video I have a good idea or at least I am 99% sure I already know all the specifications I just want to be 100% sure.
Now that x264 can produce a 100% compliant blu-ray video I
think it would be a great Idea to have a sticky with he exact encoder settings.

Keep in mind that x264 was mainly tested with 1920x1080 24p sources. If you start using other possible combination you may find some problems.

Losts of people use 40Mbit as max bitrate- this would be the first thing which I would avoid :) Encoding for BD is not exactly the same as for PC playback.


Andrew

laserfan
16th May 2010, 18:11
Thanks shon3i for the charts.

Question: I've been using --keyint 24 and 15000/15000 for all "BD"-on-DVD work, and given my bitrates are typically in the low 3500-7000 range should I really be using --keyint 48 instead to minimize "pulsing" at GOP changes?

poisondeathray
16th May 2010, 19:05
I can't see any reason NOT to use the longer gop size if you are <15Mbps.

shon3i
16th May 2010, 19:45
I can't see any reason NOT to use the longer gop size if you are <15Mbps.
I agree, longer gop, better compression efficiency, is not that marginal but probably will reduce some pulsing.

laserfan
16th May 2010, 19:53
Thanks for confirming!!! :)

MadMonkey57
18th May 2010, 17:58
And what about --min-keyint ? Does it have to be set with regards to --keyint or x264 default (auto) is blu ray compliant ?

Santa
18th May 2010, 20:55
I'm pretty sure to have a 25p or 30p bluray disc with some demo movies from panasonic.
is it sure that the only allowed progressive framerate for 1920x1080 resolution is 23.976 or 24p and not 25p or 30p?
i'll take a look on that bluray disc as soon as possible.

kieranrk
18th May 2010, 21:17
I'm pretty sure to have a 25p or 30p bluray disc with some demo movies from panasonic.
is it sure that the only allowed progressive framerate for 1920x1080 resolution is 23.976 or 24p and not 25p or 30p?
i'll take a look on that bluray disc as soon as possible.

It is possible using PAFF mode.

shon3i
18th May 2010, 21:37
There are many disc that out of specs even retail's, that disc probably is not done by any "expensive" authoring software, that follow BD Specs, which clearly not allow 25p or 30p as combination.

As kieranrk says, it's possible to encode as 50i or 60i using some of interlace modes, which not skrew PQ

kieranrk
18th May 2010, 23:12
which clearly not allow 25p or 30p as combination.


It doesn't say that per se. It says frame_mbs_only must be zero. This makes it possible to write progressive frames (i.e. all frames are progressive in PAFF mode)

poisondeathray
18th May 2010, 23:40
But has anyone seen it actually work in a hardware player? (encoding 25p/30p as 50i/60i)

TinTime
19th May 2010, 00:58
I've come across a couple of blu-rays that are nominaly 50i but are sped up films and so 25p. "Brick" and "The Reader" are both like that, in the UK anyway. Both were MBAFF I think.

kieranrk
21st May 2010, 15:21
The new fake-interlaced mode should encode 25p and 30p streams in a Blu-Ray compliant manner.

poisondeathray
21st May 2010, 15:26
The new fake-interlaced mode should encode 25p and 30p streams in a Blu-Ray compliant manner.

Interesting; is this a new patch ?

Can you provide more details on which switches or syntax to use to activate it?

rack04
21st May 2010, 15:30
Interesting; is this a new patch ?

Can you provide more details on which switches or syntax to use to activate it?

http://git.videolan.org/gitweb.cgi?p=x264.git;a=commit;h=1b48874d06c5927808554a3c869e6fd01db238bc

--fake-interlaced

Flag stream as interlaced but encode progressive. Makes it possible to encode 25p and 30p Blu-Ray streams. Ignored in interlaced mode.

poisondeathray
21st May 2010, 15:31
^ thanks for the clarification :)

mp3dom
23rd May 2010, 23:02
If you add the transfer characteristics/color primaries/colormatrix (to bt709) you also need (or, it's better) to add also the videoformat 'ntsc' if you're encoding at 30/60/23.98/24 fps. The pro-encoders do this (you can not add the information, but if you add them also the NTSC video format is specified). I haven't tested it, but probably for 25/50 fps the 'pal' video format is added.

Sagittaire
3rd June 2010, 10:01
Thanks shon3i for the charts.

Question: I've been using --keyint 24 and 15000/15000 for all "BD"-on-DVD work, and given my bitrates are typically in the low 3500-7000 range should I really be using --keyint 48 instead to minimize "pulsing" at GOP changes?

yes will work for all scenario ... and GOP 48 vs GOP 24 produce ~2% better compression efficiency.

laserfan
3rd June 2010, 15:08
... and GOP 48 vs GOP 24 produce ~2% better compression efficiency.Thanks a lot for this--while I'm unlikely to notice this type of improvement, I have changed my default to 48 keyint and the results work in my player! :)

MadMonkey57
4th June 2010, 12:49
And what about --min-keyint ? Does it have to be set with regards to --keyint or x264 default (auto) is blu ray compliant ?

Anyone ?

rack04
4th June 2010, 13:08
Anyone ?

I don't know whether it needs to be set but I error on the side of caution. If I know that something needs to be set I don't rely of a default/preset/tune to set it for me.

MadMonkey57
4th June 2010, 13:38
I agree. That's why I always set --min-key-int to 2 (which most of us use) for my 23.976p encodes.

Still I am wondering for other encodes especially 50p and 25i...

shon3i
4th June 2010, 15:29
Just leave default x264 setting. From revision r1537 x264 automaticly calculate min-keyint with keyint/10. so with Shot GOP min-keyint will be 2 with long 4, wich is just fine.

btw i am currently work to complete this stuff, be patient few more days with all need explanations :)

MadMonkey57
4th June 2010, 16:06
All right.Thanks.

Sharc
4th June 2010, 18:57
Will --fake-interlaced produce blu-ray compliant 576 encodes
of a progressive PAL DVD source? Or do I have to set --tff?

kieranrk
4th June 2010, 19:05
Will --fake-interlaced produce blu-ray compliant 576 encodes
of a progressive PAL DVD source? Or do I have to set --tff?

--fake-interlaced should work. You will need --pic-struct of course.