Avidemux Forum

Avidemux => Main version 2.6 => Topic started by: TimW on March 25, 2014, 07:34:51 PM

Title: x264 Blu Ray Settings
Post by: TimW on March 25, 2014, 07:34:51 PM
Hi

Absolutely incredible software this, I haven't found anything else that does such a fantastic job of keeping the audio in sync when editing a broadcast h264 stream.  Thanks to everyone involved, you're creating a great video tool.

I'd like to respectfully suggest that further improvements to the x264 settings are re-introduced in future releases.  Despite some welcome improvements in the latest release, 2.6.8, it is still not possible to access all the settings on the advanced tabs such as Max VBV bitrate, nor can the --bluray-compat flag be set (unless I have missed it).  As a result x264 settings can be set "close" to full blu-ray compatibility, but encoded streams are still not 100% compliant.

Thanks for this great software.

Title: Re: x264 Blu Ray Settings
Post by: Sartre on May 24, 2014, 06:37:05 PM
Yes, I'm curious as to why those advanced settings haven't been reimplemented yet. It's actually been years since 2.6 was introduced and a lot of the basic functionality still isn't there. Lack of VBVMax, Zones and QComp settings make 2.6x mostly unusable for my purposes.
Title: Re: x264 Blu Ray Settings
Post by: AQUAR on May 25, 2014, 02:23:31 AM
To satisfy the curious: because its an open source code, work in progress, by mostly one volunteering developer.

IMHO v2.6 as an editor/recoder for AVC, satisfies a lot of endusers and has come a long way since being introduced.
If you need more from the AVC encoding process you can alway use x264 itself (not meant as criticism!).
Title: Re: x264 Blu Ray Settings
Post by: TimW on May 24, 2015, 12:16:09 PM
Hi All

Pleased to see the new version 2.6.9, but disappointed that advanced x264 settings have again been overlooked, making full blu-ray compatible encoding still impossible.  Appreciate that there are plenty of other ways of encoding with x264, but I haven't found one with the fantastic frame-accurate editing features of avidemux, which has the simplest and most intuitive (and therefore best) front end for video editing I have come across.  It also holds the audio sync way better than anything else.  I'm really not trying to criticise the developer(s) - as I hope the preceding comments show I have the highest regard for avidemux, which trounces paid-for software in almost all respects.  However, hopefully adding advanced x264 options (either in the tabs or as a text box to type in x264 parameters) can once again be considered?  I'm afraid I don't know anything about how this all works under the hood, so I apologise in advance if I'm naively suggesting something that is actually extremely difficult.

If there are any other frame-accurate editing tools out there that allow access to all x264 settings then I'd surely be grateful to know what they are.  I've tried handbrake, but as far as I can tell it doesn't allow editing at all (apart from cropping the start and end, and even then it's clumsy) - avidemux is still the best.

Thanks again.
Title: Re: x264 Blu Ray Settings
Post by: mean on May 24, 2015, 08:17:55 PM
what options are important for BR compatibility ?
Title: Re: x264 Blu Ray Settings
Post by: TimW on May 25, 2015, 11:49:31 AM
Hi mean and thanks for the opportunity to set these out.

Many of the necessary parameters can already be set in avidemux, such as profile level, tune, GOP size, B frame references and some others.  Below I have listed the ones that are mandatory parameters for a blu-ray compatible stream but which canââ,¬â,,¢t currently be accessed from the x264 settings tabs in 2.6.8 and 2.6.9 (most of them are there on the tabs, but disabled).  I canââ,¬â,,¢t take credit for the research, which I distilled from Shon3iââ,¬â,,¢s post at the doom9 forum.

ââ,¬Å"--bluray-compatââ,¬Â  flag : Though it is possible to create a stream that most players will play without this flag, providing you know what youââ,¬â,,¢re doing, it helpfully overrides a number of other settings that might otherwise be incompatible including the bframe ref count (which varies according to resolution, for HD it must be <=3), bpyramid and others.

ââ,¬Å"--vbv-maxrateââ,¬Â  : maximum allowed bitrate.  For bluray media the maximum permissible value is 40000.  This setting is on the ââ,¬Å"Advanced 1 tabââ,¬Â of the avidemux x264 config, but is disabled so that the values cannot be set. 

ââ,¬Å"--vbv-bufsizeââ,¬Â : maximum allowed buffer size.  The blu-ray spec allows a maximum of 1 second buffering, therefore this must be set relative to the vbv-maxrate.   Again this is on the disabled ââ,¬Å"Advanced 1ââ,¬Â tab and therefore cannot be set.

Without the two settings above, both my Sony player and my Samsung player wonââ,¬â,,¢t play the stream.  I get horrible playback speed problems, audio sync issues, and loss of the ability to seek through the stream.

ââ,¬Å"--sarââ,¬Â : simple aspect ratio.  I donââ,¬â,,¢t know whether this is the same as ââ,¬Å"pixel aspect ratioââ,¬Â on the ââ,¬Å"output 1ââ,¬Â tab.  Also I donââ,¬â,,¢t know whether avidemux might be setting it anyway.

ââ,¬Å"--slicesââ,¬Â : this has to be >4 if level  is 4.1.  Again it is on the disabled ââ,¬Å"Advanced 1ââ,¬Â tab.

ââ,¬Å"-o xxx.264ââ,¬Â : the output must be raw 264, however I am guessing that if it is 264 muxed into a ts container all will be okay.  At this point Iââ,¬â,,¢m afraid I donââ,¬â,,¢t know enough about the how the containers relate to the underlying streams.  However by the time it is built into the bluray structure it has to be in an .m2ts container anyway.  I would hope (but I donââ,¬â,,¢t know for certain) that tsmuxer or similar tools will sort that out provided the x264 settings are correct in the first place (with ts output container).

ââ,¬Å"--pic-structââ,¬Â : It is convenient to be able to work with 25p or 30p video, but these will only play if the ââ,¬Å"--fake-interlacedââ,¬Â option is set (this is already accessible on the ââ,¬Å"Frameââ,¬Â) tab.  In this case the ââ,¬Å"--pic-structââ,¬Â must also be set to ââ,¬Å"onââ,¬Â (which it might be by default anyway).

Others:
It would also be nice to set the colour properties on the currently disabled ââ,¬Å"output 2ââ,¬Â tab, and the ââ,¬Å"Open GOPââ,¬Â mode on the ââ,¬Å"frameââ,¬Â tab, but these are not strictly necessary for compliant output.

X264bluray.com gives the following example of x264 parameters that will produce a blu-ray compliant stream for 1080/25p (25fps progressive encoding using the fake interlaced method):

x264 --bitrate XXXXX --preset veryslow --tune film --bluray-compat --vbv-maxrate 40000 --vbv-bufsize 30000 --level 4.1 --keyint 25 --open-gop --slices 4 --fake-interlaced --colorprim "bt709" --transfer "bt709" --colormatrix "bt709" --sar 1:1 --pass 1 -o out.264 input.file

Hope the above helps.  It is the amazing frame-accurate editing (with preview) capability of avidemux and its peerless ability to keep the audio in sync (since 2.6) that make it stand out way above the rest.  If it could produce blu-ray compatible output as well it would be game over for the competition in my view.
Title: Re: x264 Blu Ray Settings
Post by: TimW on July 10, 2015, 11:08:26 AM
Hi all, in the continued hope that someone might get chance to look at this for a future release I have done a detailed comparison of the settings passed to x264 by the excellent bdrebuilder (http://www.jdobbs.com) versus the settings that can be controlled in Avidemux.  Iââ,¬â,,¢ve also picked up some further info from ââ,¬Å"http://forum.doom9.org/showthread.php?t=154533ââ,¬Â

(Aside: bdrebuilder is an excellent front end for x264 that produces blu-ray compliant output with great reliability, while keeping the audio in sync most of the time.  This and other tools like handbrake and some others [and of course x264 itself] can be configured to produce x264 blu-ray compliant output, but there is no editing capability within them, except in some cases cropping the start and end.  Alternatively, they can be used to do the recoding first, and then avidemux can be used to edit.  However, this means cutting is limited to i-frames, which invariably means losing frames and sometime snippets of audio as well ââ,¬â€œ resulting in a bit of a mess.)

In addition to the settings I mentioned in my previous post, it seems that it is also necessary to be able to set the ââ,¬Å"--nal-hrdââ,¬Â  parameter (present, but disabled).  Bdrebuilder also sets the ââ,¬Å"--fillerââ,¬Â  parameter, but I have not been able to determine whether this is compulsory or not (though according to x264 help, it is forced anyway if  --nal-hrd  is set to cbr).  In addition, the bitdepth of the output must be 8, but I donââ,¬â,,¢t think this is a parameter as such and donââ,¬â,,¢t know how to set it ââ,¬â€œ maybe it will be 8 by default.

When combined with my previous post the above deals with all the compulsory settings that are not currently accessible as far as I can tell.  However, the names of the settings in Avidemux are somewhat different from those in x264ââ,¬â,,¢s help documentation.  For example ââ,¬Å"merangeââ,¬Â is called ââ,¬Å"Maximum Motion Vector Search Rangeââ,¬Â (I hope!) in Avidemux.  While Avidemuxââ,¬â,,¢s names are generally more descriptive, due to the different conventions I cannot be 100% certain that I have matched them up correctly and I apologise in advance for any omissions or errors.

For the record there are some other important settings for blu-ray that are either disabled or not present at all.  However, it looks as though they will either be inherited from the source (frame rate, timebase) or else it will still be able to produce blu-ray compliant output with the default setting.  These are  ââ,¬Å"--fpsââ,¬Â,  ââ,¬Å"--timebaseââ,¬Â,  --no-psyââ,¬Â, ââ,¬Å"--open-gopââ,¬Â, and ââ,¬Å"--qcompââ,¬Â. 

For completeness, and since I had to match them up to do the above analysis, I attach a spreadsheet which matches up all the x264 settings used by bdrebuilder on a recent successful run I did to their equivalent names in Avidemux.  Again, due to the different conventions I cannot be certain this is 100% accurate Iââ,¬â,,¢m afraid.

I hope the above will prove helpful if the developers do get chance to refresh x264 settings in a future release. 

Title: Re: x264 Blu Ray Settings
Post by: AQUAR on July 11, 2015, 07:30:13 AM
@TimW,

It's nice to see an ADM end user present a development suggestion, without using some form of "attack mode" phraseology.
And then also follow it up with some self motivated home work to support the suggestion.

Can't speak for the developer('s), but ADM2.6 does continue to evolve with an emphasis on modern codecs.
Lets hope the extra X264 parameters for brd recoding is on their to-do list.
Title: Re: x264 Blu Ray Settings
Post by: mean on July 11, 2015, 09:07:25 PM
Thx, i'll try to add these
Title: Re: x264 Blu Ray Settings
Post by: TimW on July 13, 2015, 02:53:35 PM
mean/AQUAR/all

Thanks.  I've tried what seems like dozens of video editors/recoders.  Most of them are downright laughable and scarcely even run.  Some are good, but even with those, hardly any will hold the audio in sync with an h264 stream (bdrebuilder being an honourable exception), and the ones that will, you can't edit with.  Avidemux therefore seems to be streets ahead of the rest already in my view, so the blu-ray compatibility will be the icing on the cake.

Thanks again for taking the trouble to look into this.
Title: Re: x264 Blu Ray Settings
Post by: mean on July 19, 2015, 03:35:50 PM
Quote
--vbv-maxrateââ,¬Â  : maximum allowed bitrate.  For bluray media the maximum permissible value is 40000.  This setting is on the ââ,¬Å"Advanced 1 tabââ,¬Â of the avidemux x264 config, but is disabled so that the values cannot be set. 

ââ,¬Å"--vbv-bufsizeââ,¬Â : maximum allowed buffer size.  The blu-ray spec allows a maximum of 1 second buffering, therefore this must be set relative to the vbv-maxrate.   Again this is on the disabled ââ,¬Å"Advanced 1ââ,¬Â tab and therefore cannot be set.

That part should work now
Title: Re: x264 Blu Ray Settings
Post by: AQUAR on July 23, 2015, 10:25:02 AM
Thanks,
I will try it out when the win32 nightly build gets updated. 
Title: Re: x264 Blu Ray Settings
Post by: mean on July 23, 2015, 06:41:20 PM
they are
Title: Re: x264 Blu Ray Settings
Post by: TimW on July 24, 2015, 08:36:33 PM
Thanks for looking at this so soon.  Just returned from holiday so I've only had time for a short test (90 secs of video) so far, but the result looks great.  I'll try with a much longer video as soon as I get the chance.  I'll probably never know enough of the technical details to say it's 100% blu-ray compliant by-the-book, but I've managed to replicate as near as I can to what I think are compatible settings and it does play no problem at all in my Samsung, with proper lip sync, and will seek properly.  I set the max bit rate to 15000 and the buffer to 13000 for the test - as suspected those must have been the settings that were doing the damage so many thanks for looking at them first.  (Aside: MediaInfo thinks the output frame rate is 50 instead of the expected 25, but after processing and resetting with tsmuxer it still plays, so it doesn't seem to matter to the player - it's most likely an irrelevant problem with the way I did the deinterlacing.)

Thanks again and I'll report back here with the results of a longer test in a few days.
Title: Re: x264 Blu Ray Settings
Post by: AQUAR on July 25, 2015, 05:23:06 AM
The frame rate doubling is normally the result of various bob included deinterlacing models.

But on ADM 2.6, a field is interpreted as a frame, it is a know minor "quirk" of the time based version of ADM.
It may be a handicap of the ADM 2.6 processing model and probably requires some form of work-around coding on detecting interlaced input.
The developer is aware of it.

Consequently, with ADM 2.6, any recoded interlaced video ends up with meta data that shows double the frame rate of the original, due to frame rate of output being set to field rate of input.

I resolve it by adding the "change fps" filter to the filter chain and setting it to fps-original=fps-input=fps-output.
The filter, when set up this way, only changes some meta data that results in programs like mediainfo reporting the correct frames per second.
Either way video playback of the recoded product is unaffected AFAIK (maybe some media players might playback at double the rate??).
Title: Re: x264 Blu Ray Settings
Post by: TimW on July 25, 2015, 09:54:34 PM
Great result from a couple of longer tests (over 3 hrs of video combined).  I used MediaInfo to check the metadata on the output, recoded with  2.6.10 (150723_efbeb572fce):

Summary
Streams are now playing with no problems on a hardware player (Samsung) with appropriate settings.  There are some blu-ray relevant settings that canââ,¬â,,¢t be altered, but the defaults seem to be working fine with the exception of ââ,¬Å"slicesââ,¬Â (the stream is still playing though ââ,¬â€œ perhaps it wouldnââ,¬â,,¢t in an older player - I don't know why this setting is important, but plenty of sites seem to agree it should be '4' for blu ray).  All in all, a great result, many thanks.  If you want to go for completeness it might be worth looking at the ââ,¬Å"--slices" comments below.

Parameters which worked fine, no issues
ââ,¬Å"--vbv-maxrateââ,¬Â  :  This worked.

ââ,¬Å"--vbv-bufsizeââ,¬Â : This worked.

ââ,¬Å"--bluray-compatââ,¬Â  :  This can now be set on the ââ,¬Å"output 1 tabââ,¬Â and has been set correctly per MediaInfo.

ââ,¬Å"--nal-hrdââ,¬Â  :  I donââ,¬â,,¢t seem to be able to set this explicitly, but according to MediaInfo it was set to ââ,¬Ëœvbrââ,¬â,,¢, which is correct for the recode I did.  Perhaps it is being set correctly anyway by Avidemux in the background, but whatever the reason, there doesnââ,¬â,,¢t seem to be a problem there either.

ââ,¬Å"--fillerââ,¬Â  :  This was also set correctly to ââ,¬Ëœ0ââ,¬â,,¢, but without me actually setting it.  Magic!

Slices
ââ,¬Å"--slices"  : This can now be set on the ââ,¬Å"Advanced 1ââ,¬Â tab, but if you change the setting it doesnââ,¬â,,¢t get saved, and doesnââ,¬â,,¢t appear in the output according to MediaInfo.  That said, my player didnââ,¬â,,¢t complain.  However, the blu ray spec definitely requires this to be set to ââ,¬Ëœ4ââ,¬â,,¢, and bdrebuilder does set it to ââ,¬Ëœ4ââ,¬â,,¢.   In this case the blu ray spec  also requires that  ââ,¬Å"--slice-max-sizeââ,¬Â and ââ,¬Å"--slice-max-mbsââ,¬Â (ââ,¬Ëœmaximum size per sliceââ,¬â,,¢ and ââ,¬Ëœmaximum macroblocks per sliceââ,¬â,,¢ in Avidemux notation) should not be set at all, since they override ââ,¬Å"--slices".  Perhaps the bluray compat flag helped and set it to 4 anyway?  (I am just guessing.)   Though this doesnââ,¬â,,¢t appear to be behaving quite as it should, my player didnââ,¬â,,¢t complain. 

Others, for info only
ââ,¬Å"--pic-structââ,¬Â  :  I couldnââ,¬â,,¢t turn this ââ,¬Ëœonââ,¬â,,¢ (I was using fake interlaced) and there was no sign of it in MediaInfo.  Whether it was actually on or off I donââ,¬â,,¢t really know ââ,¬â€œ according to what I have read it should be ââ,¬Ëœonââ,¬â,,¢ for fake interlaced but again my player didnââ,¬â,,¢t complain.  I have noticed that bdrebuilder doesnââ,¬â,,¢t explicitly set it either as far as I can tell, so perhaps we can just forget that one.

ââ,¬Å"--sarââ,¬Â : I doubt this is needed unless youââ,¬â,,¢re changing the aspect ratio between input and output.  There were certainly no aspect ratio problems with the playback.

ââ,¬Å"--fpsââ,¬Â, and   Ã¢â,¬Å"--timebaseââ,¬Â.  Again not explicitly set, but there was no problem with playback and I doubt theyââ,¬â,,¢d be needed unless there is something funny about the input file or youââ,¬â,,¢re meddling with framerates (AQUAR ââ,¬â€œ thanks for the tip on the FPS filter, it worked just as you said it would).

ââ,¬Å"--open-gopââ,¬Â :  This is optional, I doubt Iââ,¬â,,¢d ever use it in any case.  Though there is a setting for open GOPs specially designed for blu rays, they also work fine with a limited GOP size, and that is more usual anyway.

ââ,¬Å"--qcompââ,¬Â : the default of 0.60 canââ,¬â,,¢t be changed, but seems to work fine, and the highest quality setting of bdrebuilder also uses this value, so there seems little point in changing it.

--no-psyââ,¬Â : canââ,¬â,,¢t be set, but the default setting (ââ,¬Ëœnot setââ,¬â,,¢) is fine. (The only point in being able to control it would be to make sure it's not set anyway.)

ââ,¬Å"--fake-interlacedââ,¬Â  :  this is working fine, but for completeness I thought I should mention that there now seem to be two distinct places where it can be set, first on the ââ,¬Å"Frameââ,¬Â tab, and then again on the ââ,¬Å"Output 1ââ,¬Â tab.  The latter is called ââ,¬Å"generate fake interlacedââ,¬Â while the former is called ââ,¬Å"Interlacedââ,¬Â with a dropdown for the three possible settings.  Perhaps they are doing different things?  It's probably just cosmetic but I thought I should mention it.

I canââ,¬â,,¢t thank you enough for looking at this.  It will save an age in time as all the work can now be done in Avidemux, rather than having to recode in one application then edit in another.  I have scoured the internet, and if there's any serious competition for Avidemux out there, I certainly can't find it.
Title: Re: x264 Blu Ray Settings
Post by: Jan Gruuthuse on July 29, 2015, 08:00:57 AM
TimW

Can you post (attachment) of your favourite settings?
- load sample video where you would apply these settings. Make your settings. When all settings are made, then from Avidemux Menu: File: Tinypy Project: Save As Project. Could you post his .py file?

And what would be the source type video you apply these settings on?

thanks, Jan
Title: Re: x264 Blu Ray Settings
Post by: TimW on July 29, 2015, 07:02:12 PM
Jan

Hi, see file attached. 

I don't claim these settings are the "best" in any way.  What I did was to try to replicate the settings that I know work with bdrebuilder (as far as I could figure out what they were), and factor in what I could pick up about compulsory blu-ray settings on the web.  Many of the settings on the attached file could be changed and still produce a compliant stream.

What I can say for definite is that the attached settings are producing a stream that will play in my Samsung player with no issues whatsoever.  NeroVideo also thinks the output stream is blu-ray compliant as it will process it without trying to recode it.

Things maybe worth mentioning: 
1. I can't set slices to '4' (Advanced 1 tab allows the the setting but does not seem to save it or use it).  This is the only non-compliant setting as far as I can tell (discounting those that seem to be compliant by default), but as I say it doesn't seem to be affecting playback in any case.  (I suspect that modern will players will play non-strictly compliant streams in many cases anyway so perhaps that's got something to do with it.) 
2. I set "Interlaced" to "Fake Interlaced" and also set the "Generate Fake Interlaced" flag.  Not sure whether both are required.  I was de-interlacing using decomb telecide with no strategy.

The source material was a FTA broadcast transport stream with the following properties:

Format                                   : AVC
Format/Info                            : Advanced Video Codec
Format profile                         : Main@L4
Format settings, CABAC         : Yes
Format settings, ReFrames     : 4 frames
Format settings, GOP              : M=4, N=32
Codec ID                                 : 27
Duration                                 : 2h 2mn
Bit rate                                 : 9 176 Kbps
Width                                    : 1 920 pixels
Height                                   : 1 080 pixels
Display aspect ratio                  : 16:9
Frame rate                               : 25.000 fps
Color space                              : YUV
Chroma subsampling                       : 4:2:0
Bit depth                                : 8 bits
Scan type                                : Interlaced
Scan order                               : Top Field First
Bits/(Pixel*Frame)                    : 0.177
Stream size                              : 7.86 GiB (91%)
Color range                              : Limited
Color primaries                          : BT.709
Transfer characteristics              : BT.709
Matrix coefficients                      : BT.709

(The source stream will 'nearly' play in a blu ray player - but you get nasty frame skipping and juddering.  The output plays fine.)

Hope this helps.  Thanks again.
Title: Re: x264 Blu Ray Settings
Post by: Jan Gruuthuse on July 30, 2015, 05:03:55 AM
Thanks for your settings, see others have interest to ;)