Log in

View Full Version : Use bluray-compat with MKV ?


Nico8583
13th February 2014, 19:41
Hi,
I'm trying to create a x264 cmdline to encode a movie to MKV, and I would like to know if there is a problem with some software players or standalone players to use bluray-compat ?
Thanks !

jpsdr
14th February 2014, 09:49
I think you don't need bluray-compat if purpose is to create mkv, just be sure to stay within level 4.1 to be compatible for standalone players. bluray-compat will create some "restrictions" which will (a little) reduce quality. It's intended to be used only if you want to create a blu-ray, otherwise, don't use it, but be sure that your encoder parameters stay within in the 4.1 specs.

Nico8583
14th February 2014, 16:00
Thanks for your response :)

benwaggoner
14th February 2014, 18:26
The Blu-ray spec has some significant constraints (4 slices, max 1 sec GOP, B-frame placement restrictions) that impair compression efficiency versus an encode just constrained by Level 4.1. In practice, the BD spec is a lot more constrained than most real-world Blu-ray players actually need.

Stereodude
14th February 2014, 20:38
The Blu-ray spec has some significant constraints (4 slices, max 1 sec GOP, B-frame placement restrictions) that impair compression efficiency versus an encode just constrained by Level 4.1.Can you define significant? My experimentation with x264 shows removing the Blu-Ray restrictions on a 1080p clip yields a pretty minor file size difference. Like 100MB on a 3.3GB file.

hello_hello
14th February 2014, 22:09
I've played my encodes using several different MKV capable Bluray players and never had a problem. I just use High Profile, Level 4.1, with the default x264 settings (with an appropriate x264 tuning and speed preset).

I've found Bluray compatibility can effect the bitrate by a reasonable amount at times. Assuming the same CRF value produces the same quality each time, 4 slices does seem to make a difference, or I've always assumed that's what does it.

I tried a few little test encodes. Five minutes of SD video (maybe things change if the video is HD?)

Commandline 1:
--level 4.1 --crf 18.0 --vbv-bufsize 78125 --vbv-maxrate 62500
Commandline 2:
--level 4.1 --bluray-compat --crf 18.0 --vbv-bufsize 78125 --vbv-maxrate 62500
Commandline 3:
--level 4.1 --bluray-compat --crf 18.0 --open-gop --slices 4 --vbv-bufsize 30000 --vbv-maxrate 40000

Compared to commandline 1, number two increased the output file size/bitrate by about 1%.
Commandline 3 increased it by about 15%

Stereodude
15th February 2014, 01:55
Maybe that's my problem then... I've kept the vbv restrictions. Something like these:

--crf 18.0 --preset veryslow --tune film --bluray-compat --vbv-maxrate 40000 --vbv-bufsize 30000 --level 4.1 --keyint 30 --open-gop --slices 4 --fake-interlaced --sar 1:1
--crf 18.0 --preset veryslow --tune film --vbv-maxrate 40000 --vbv-bufsize 30000 --level 4.1 --keyint 120 --open-gop --sar 1:1

BTW, isn't your max bufsize illegally large for Level 4.1?

jpsdr
15th February 2014, 09:01
No, these are indeed the max values for the L4.1. You have to specify them, because x264, even if you specify L4.1, uses higher limits if you haven't specify the parameter. This have been discussed somewhere in a discussion thread, and it was there that these values where given.

Stereodude
15th February 2014, 16:19
No, these are indeed the max values for the L4.1. You have to specify them, because x264, even if you specify L4.1, uses higher limits if you haven't specify the parameter. This have been discussed somewhere in a discussion thread, and it was there that these values where given.I found the thread and read it last night after posting that. His values are too large for main profile, but are okay for high.

hello_hello
15th February 2014, 16:31
Maybe that's my problem then... I've kept the vbv restrictions.

I ran few more test encodes and while doing so I realised my previous post wasn't entirely accurate. I'd left MeGUI to fiddle with keyint settings.
When selecting Bluray as the target playback device, MeGUI makes keyint related adjustments based on framerate, and they're not included in the displayed commandline.

Commandline 3, which increased the file size by around 15%, probably should have looked like this:

--level 4.1 --bluray-compat --crf 18.0 --open-gop --slices 4 --keyint 25 --vbv-bufsize 30000 --vbv-maxrate 40000

I ran some little encodes to see if a particular setting was responsible for the bitrate increase on it's own.

The VBV values made zero difference. The bitrate required for my SD encodes was way too low for that.
slices=4 had very little effect. Maybe if the video was harder to compress, or maybe for HD it'd be different, but for me it only resulted in a 1% file size increase. --bluray-compat on it's own was much the same

"--keyint 25" was the guilty party
I was only running test encodes of a few minutes, but it still increased the file size by around 11% on it's own.

I was looking for something else earlier and as a result....completely coincidentally.... found myself reading this:
http://x264dev.multimedia.cx/archives/328
More detailed documentation on the new Blu-ray support and how to use it can be found in the official commit message. Do keep in mind that you have to export to raw H.264 (not MKV or MP4) or else the buffering information will be slightly incorrect. Finally, also note that the encoding settings given as an example are not a good choice for general-purpose encoding: they are intentionally crippled by Blu-ray restrictions, which will significantly reduce compression for ordinary non-Blu-ray encoding.

sneaker_ger
15th February 2014, 16:52
--keyint has basically no influence on player compatibility anyways, only on spec compliance. Some players (PS3) do seem to need --slices 4 to keep up with high bitrates but I wouldn't bother with all the other Blu-Rays restrictions (except maybe vbv).

Stereodude
16th February 2014, 00:15
--keyint has basically no influence on player compatibility anyways, only on spec compliance. Some players (PS3) do seem to need --slices 4 to keep up with high bitrates but I wouldn't bother with all the other Blu-Rays restrictions (except maybe vbv).So your recommendation is to keep --slices 4 even for encodes that aren't intended for blu-ray, and maybe the vbv restrictions, but dump the rest (--keyint 24, 25, or 30 & --bluray-compat)?

Stereodude
16th February 2014, 05:25
I don't have a blu-ray player myself. I use a PC for blu-ray and media playback. However there's no reason to make files that are potentially incompatible for no real size benefit since I may want to use a HW device in the future.

benwaggoner
17th February 2014, 20:09
So your recommendation is to keep --slices 4 even for encodes that aren't intended for blu-ray, and maybe the vbv restrictions, but dump the rest (--keyint 24, 25, or 30 & --bluray-compat)?
Each extra slice is about a 1% hit in compression efficiency, so avoid them if at all possible.

PS3 should only need slicing for perf if you're using pointlessly high bitrates anyway for 1080i30 or something. 25p should work great at --crf 18 for any real-world content.

Stereodude
17th February 2014, 20:20
Each extra slice is about a 1% hit in compression efficiency, so avoid them if at all possible.
So I decided to compress the same 77690 frame 1080p24/p30 video these two command lines.

--crf 18 --tcfile-in="timecode_tweaked_ext.txt" --preset veryslow --tune film --vbv-maxrate 40000 --vbv-bufsize 30000 --level 4.1 --keyint 120 --open-gop --slices 4 --colorprim "bt709" --transfer "bt709" --colormatrix "bt709" --sar 1:1 -o out.264 source.avs
--crf 18 --tcfile-in="timecode_tweaked_ext.txt" --preset veryslow --tune film --vbv-maxrate 62500 --vbv-bufsize 78125 --level 4.1 --keyint 120 --open-gop --colorprim "bt709" --transfer "bt709" --colormatrix "bt709" --sar 1:1 -o out_free.264 source.avs

The resulting file sizes were 4,282,404,973B and 4,270,359,969B respectively. If I've done the math right that's about 0.28% different.

hello_hello
18th February 2014, 14:09
So I decided to compress the same 77690 frame 1080p24/p30 video these two command lines.

The resulting file sizes were 4,282,404,973B and 4,270,359,969B respectively. If I've done the math right that's about 0.28% different.

It'd would have been interesting to also see the result of an encode without slices=4 but also without the vbv restrictions changing. Or with the standard level 4.1 vbv restrictions plus slices=4. Just to see if it's possible slices=4 didn't increase the bitrate because the vbv restrictions were lower.

According to the Bluray encoding bible, even for Bluray, slices=4 is only required for level 4.1.
http://forum.doom9.org/showthread.php?t=154533
If that's something I'd known previously, then I'd forgotten about it.
Level 4.0 though, seems to require --vbv-maxrate 24000 --vbv-bufsize 30000.

According to the info in the bible, --keyint 120 wouldn't be Bluray compliant.

For "future" HW compatibility, I still think plain old "--level 4.1 --vbv-bufsize 78125 --vbv-maxrate 62500" is sufficient.
My android smartphone is a couple of years old and it's hardware decoder seems happy with that up to 1080p. In fact my video card's pretty old (8600GT) but the same encoder settings allow it to do the decoding.

I guess you could always encode to keep Divx HD+ certified devices happy too. According to MeGUI that means "--level 4.0 --vbv-bufsize 25000 --vbv-maxrate 20000"

Nico8583
18th February 2014, 18:20
Thanks to all for your responses :)
What do you mean for these settings :
- Tune : is it a difference between none, film and anim ? What this settings change ?
- Slices : does --bluray-compat forces slices 4 (recommended for bluray) ?
- Fake-interlaced : is it necessary for 25p and 29.97p sources ?
- Color BT709 : is it necessary when transcoding from a bluray to bluray ?
Thanks !

sneaker_ger
18th February 2014, 19:27
For "future" HW compatibility, I still think plain old "--level 4.1 --vbv-bufsize 78125 --vbv-maxrate 62500" is sufficient.
My android smartphone is a couple of years old and it's hardware decoder seems happy with that up to 1080p.
The problem is that you don't know if from a common encode with maybe --crf 18 --vbv-bufsize 78125 --vbv-maxrate 62500 whether or not your hardware can handle those vbv limits. You'd have to do something like --bitrate 62500 to actually exploit the limits to the fullest. --crf ~18 is not nearly sufficient do achieve that for 1080p24. I'd probably go with you recommendation of keeping the limits much lower.

sneaker_ger
18th February 2014, 19:40
- Tune : is it a difference between none, film and anim ? What this settings change ?
Film, none and grain should be equal in terms of compatibility. Animation may increase b and reference frames but those are in turn limited by --level and/or --bluray-compat, so feel free to use it anyways.

- Slices : does --bluray-compat forces slices 4 (recommended for bluray) ?
No. Also, it's not "recommended", it is strictly mandatory for level 4.1 in Blu-Ray (not mkv) and not necessary otherwise.

- Fake-interlaced : is it necessary for 25p and 29.97p sources ?
They do not increase compatibility for mkv, I wouldn't use them.

- Color BT709 : is it necessary when transcoding from a bluray to bluray ?
It is not strictly necessary to use --colormatrix/--transfer/--colorprim. It is recommended to use the same values as your source uses - if you are unsure about them don't set them at all. Better to not set them than to set them wrong. (But most players ignore them anyways)

Stereodude
18th February 2014, 20:32
According to the info in the bible, --keyint 120 wouldn't be Bluray compliant.Yeah, I know but neither is VFR, so there's no point using a blu-ray compliant keyint. I wanted to see the hit of slices and vbv restrictions.

Nico8583
18th February 2014, 21:30
Thanks sneaker_ger for your response ! :)
So OK for tune, fake-interlaced and color matrix. For slices 4, OK for Bluray but is it OK if I use it with MKV (even if it is not necessary) ?

sneaker_ger
18th February 2014, 21:31
But is it OK if I use it with MKV (even if it is not necessary) ?
Yes, it is.

hello_hello
19th February 2014, 19:43
Thanks sneaker_ger for your response ! :)
So OK for tune, fake-interlaced and color matrix. For slices 4, OK for Bluray but is it OK if I use it with MKV (even if it is not necessary) ?

The tunings are effectively an automatic adjustment of some of x264's advanced settings according to the type of video you're encoding. They're fine to use.
Color matrix is just info written to the video stream. No harm adding it (as long as it's correct).
Slices 4 is okay to use for MKV but completely unnecessary.
There's no need for fake-interlaced.

I use the default x264 settings myself with High Profile Level 4.1 and an appropriate x264 tuning. From there I just pick a CRF value and an x264 speed preset (usually medium of slow, but it's personal choice).

The only thing we don't seem to be able to agree on is the VBV restrictions. Level 4.1 supports --vbv-bufsize 78125 and --vbv-maxrate 62500. In theory any device which supports level 4.1 should play video encoded with those restriction. If it won't, it should state otherwise. Of course that's in a perfect world.... As a general rule, the average encode probably wouldn't approach those limits anyway.

There was a discussion a while back where someone asked about a video they'd encoded and x264 not automatically enforcing the appropriate VBV restrictions for a chosen level. The link to the sample is dead, but the thread is here (http://forum.doom9.org/showthread.php?t=165627) and a screenshot of bitrate viewer displaying the sample is here (http://i.imgur.com/aeZBA.png).
I still had that sample buried on my hard drive, so I put it on a USB stick and gave it a spin. I kind of expected them to lock up, but the media player in my Samsung TV did what my video card does when it's decoding the sample, it stuttered and dropped frames on and off for about 5 seconds towards the end. The Sony Bluray player didn't seem to have a problem with it.

As an experiment I re-encoded it a few times with a lower CRF value than was originally used and with different VBV settings (Level 4.1, slow preset, tuning film).

The first encode increased the average bitrate from 33792kbps to 34993kbps but using the "maximum" Level 4.1 VBV values the video still stuttered when either the video card or the TV's media player was decoding. The following VBV values dropped the average bitrate down to 33145kbps (peak bitrate 78052kbps) and allowed both the video card and TV's media player to decode it smoothly.

--vbv-bufsize 58000 and --vbv-maxrate 58000

I'll confess that surprised me a little. I thought the standard level 4.1 VBV restrictions would do the job. Mind you I'm not sure if there'd be a likelihood I'd encode video where the bitrate would require even those lower VBV restrictions, but considering the result of my test I might drop them down a bit myself from now on.... just to be safe.

hello_hello
19th February 2014, 20:16
I tried one more test encode to see whether slices=4 would allow either the video card or the TV to play the video using higher VBV values. I only tested with the "maximum" VBV values for level 4.1 (--vbv-bufsize 78125 and --vbv-maxrate 62500).
The video still stuttered. Maybe not quite as much, but it still didn't play smoothly.

Nico8583
19th February 2014, 22:05
Thanks again for your responses :)
- OK for tune, but is tune film works with all films, tune animation works with all animations, etc... ? And if I'm wrong and I use film on a animation or animation on a film, is there a visible impact ?
- OK for color matrix but I prefer to not use it, and OK for fake interlaced
- OK for slices 4, is unnecessary but it's not forbidden.

Perhaps I have misunderstood anything but is bluray-compat only for BD creation or any type of movie (MKV, MP4...) read by an standalone BD player ? Because I would like to create MKV in order to play it on my standalone BD player or my PC or my Samsung TV. I think PC reads all format but for both standalone players I don't know...

sneaker_ger
19th February 2014, 23:27
- OK for tune, but is tune film works with all films, tune animation works with all animations, etc... ? And if I'm wrong and I use film on a animation or animation on a film, is there a visible impact ?
If there wasn't any visual impact these options wouldn't exist in the first place. That said I'd say most people will have trouble noticing any difference at all, it's more of an option for enthusiasts.

OK for fake interlaced
I would never use fake interlaced for mkv/mp4. It may not hurt compatibility at best but it will certainly gain you nothing.

Perhaps I have misunderstood anything but is bluray-compat only for BD creation or any type of movie (MKV, MP4...) read by an standalone BD player ?
It is for BD creation. It may impact mkv/mp4 compatibility positively or negatively but unlike BD those are not strictly standardized. Every manufacturer has his own rules, usually badly or not at all documented. Something that may be mandatory on device A might be illegal on device B.

Because I would like to create MKV in order to play it on my standalone BD player or my PC or my Samsung TV. I think PC reads all format but for both standalone players I don't know...
Imho, something like the following will probably suffice while offering great compatibility:
x264 --preset medium --crf 20 --level 4.0 --vbv-maxrate 20000 --vbv-bufsize 20000 --fps 24000/1001 INPUT -o OUTPUT

Note:
* add --tune film, --tune animation or --tune grain at will. If you are uncertain just leave it out.
* level and vbv are a matter of taste. Lower means more compatibility, higher means more freedom for the encoder to put bits into demanding scenes. (I don't want to discuss the choice of my example. There is no definite answer.)
* --fps to ensure a standard framerate. (24000/1001 = 23.976 fps, 30000/1001 = 29.94 fps)
* change --preset if you want to, depending on how much time you're willing to put into the encode (ultrafast, superfast, veryfast, faster, fast, medium, slow, slower, veryslow, placebo)
* if you are unsatisfied with the quality increase or decrease crf

I think this should be more than enough information to get your own tests started at this point.

Nico8583
22nd February 2014, 19:33
Thanks for all your informations, I've made these lines :
MKV : x264 input.avs --preset slow --tune film --profile high --level 4.1 --crf 18 --vbv-bufsize 30000 --vbv-maxrate 30000 --open-gop --output out.264
Bluray : x264 input.avs --preset slow --tune film --profile high --level 4.1 --crf 18 --vbv-bufsize 30000 --vbv-maxrate 40000 --open-gop --bluray-compat --keyint 24 --slices 4 --b-pyramid strict --aud --nal-hrd vbr --output out.264

I'm hesitating to add --ref 4 and --weightp 0 for Bluray or MKV, is it necessary ?
Also for 25p and 30p to Bluray only (I've understand it is not necessary for MKV), is it necessary to use --fake-interlaced and --pic-struct to be Bluray compliant ?
And anyone could tell me what is qpfile ? I've seen several programs to use it but I don't know why

Thanks !!

nhakobian
22nd February 2014, 19:47
I'm hesitating to add --ref 4 and --weightp 0 for Bluray or MKV, is it necessary ?


--bluray-compat and/or your --level options (depending on if you are outputting to bluray or mkv) set these correctly, so you don't need to explicitly set them.


Also for 25p and 30p to Bluray only (I've understand it is not necessary for MKV), is it necessary to use --fake-interlaced and --pic-struct to be Bluray compliant ?


--pic-struct is set by --bluray-compat. For 25p and 30p on bluray you need to use --fake-interlaced to be compliant.

See http://www.x264bluray.com/home/1080i-p


And anyone could tell me what is qpfile ? I've seen several programs to use it but I don't know why


Its a special input file that overrides the automatic choices x264 will make about a specific frame. For example, you can override frame type decision (I, P, B, IDR), or the quantizer level (hence the name qpfile). For blurays its used to force the frame type at chapter boundaries to be IDR so standalone bluray players can properly (and easily) seek to it.

Nico8583
22nd February 2014, 20:05
Thanks for these informations :)

Ok for fake-interlaced, is 25i or 30i (interlaced) exists on Bluray or video is allways progressive ?

Ok for qpfile, so it is based on chapters list. Can I use it with MKV with chapters or is it useless ?

And if you found incorrect or useless parameters in my lines I'm interested ;)

jpsdr
23rd February 2014, 10:33
On Blu-Ray, 25 and 29.97 are always interlaced. Blu-Ray spec don't allow progressive material with 25 or 29.97 fps, this is why when you want to encode 25 or 29.97 progressive video for Blu-Ray, you have to use fake-interlaced. With this, x264 will encode the video in progressive, and just tag a bit flag to make believe video was interlaced.

Nico8583
23rd February 2014, 12:29
Thanks for the info :) so a stupid question : why don't let interlaced ? And is it necessary to use a desinterlace filter when convert a 25/29.97 video bluray to 25p/30p video bluray ?

kabelbrand
23rd February 2014, 12:55
Thanks for the info :) so a stupid question : why don't let interlaced ? And is it necessary to use a desinterlace filter when convert a 25/29.97 video bluray to 25p/30p video bluray ?

If you source really is interlaced you should encode it in this way and use the --tff (top field first) option*
If your souce is progressive use the --fake-interlaced option instead. Both are valid for Blu-ray Disc.

*) there is also --bff (bottom field first) that you might want to try for interlaced NTSC SD video or if your --tff encode looks weird... Most PAL and HD interlaced sources should be ok with --tff.

nhakobian
23rd February 2014, 19:44
Thanks for the info :) so a stupid question : why don't let interlaced ? And is it necessary to use a desinterlace filter when convert a 25/29.97 video bluray to 25p/30p video bluray ?

Encoding progressive video as true interlaced results in less efficient compresion than encoding it as progressive and setting --fake-interlaced.

Nico8583
24th March 2014, 00:19
Thanks :)

A little question on tune : do you have example of "animation" ? Ok for tune "film", it applies to normal films but what is animation (Ice Age, Toy Story or only hand-drawed like The Lion King, ...) ?

jpsdr
24th March 2014, 09:33
For CGI you use "film" (Ice Age, Toy Story), "animation" is for cartoons, so things like The Lion King.

Nico8583
24th March 2014, 21:27
Ok thanks ;)