View Full Version : Aspect Ratio Encoding Question
Mikel
5th September 2008, 10:03
Hi there
I have been encoding my DVDs over the last year. X264 is really perfect for that. Recently (I cannot recall exactly
when), I have the problem that the aspect ratio of the encoded mp4 file is not displayed correctly. I am not sure this belongs in here, if it's an encoder problem or not.
I also did some searching but I have not really found a similar question here in the forum.
I use MEGUI as GUI for X264.
Here is what I do:
- Create D2v File
- Create AVS script with following setting: I always do anamorphic encoding, cropping without resize, encode non mod 16.
- load avs script in MEGUI, the AR is displayed correctly when I select to do so.
- after encoding when I open the mp4-file in MPC, aspect ratio is not displayed correctly
- I mux mp4 and ac3 files into mkv
- Playing mkv also does not show correct AR, testing on Hardware player also the same
- Remux mkv file, manually setting the AR in the options i calculated from the Avi-Script file
So, if I manually set the AR in the mkv-options before muxing, it is displayed correctly when playing both on hardware / software player.
Is this normal? I think to remember that some months ago, I never had to manually set the AR before muxing the mkv.
So do I have to set the PAR somewhere when encoding?
Any feedback here is welcome.
Thanks.
Mikel
talen9
5th September 2008, 12:12
It seems like the already known MeGUI AR bug (http://forum.doom9.org/showthread.php?t=140066) .. I'm not sure if it has already been fixed, but be sure to have the latest version of MeGUI :)
Anyway, muxing with explicit indication of DAR, as you already did, fixes it, so you already have found the workaround, have you? :)
Mikel
5th September 2008, 12:26
It seems like the already known MeGUI AR bug (http://forum.doom9.org/showthread.php?t=140066) .. I'm not sure if it has already been fixed, but be sure to have the latest version of MeGUI :)
Anyway, muxing with explicit indication of DAR, as you already did, fixes it, so you already have found the workaround, have you? :)
Hey, thanks for that information... if this is a bug, it will be hopefully fixed, in the meantime, I will manually set it in the muxing.
It's just not as smooth if I need to do that :/
Best, Mikel
saint-francis
5th September 2008, 13:26
If you know the proper DAR you can set it manually in the MeGUI custom cmd options in the x264 configuration dialog before encoding.
kemuri-_9
5th September 2008, 15:15
since i personally don't use megui (big CLI user) I use the --sar x:y parameter to manually set the sample/pixel aspect ratio
i.e.
i usually do 720x480 DVD encodes with an end DAR of 16:9,
480 * (16/9) / 720 = 32:27
this is the SAR to use.
for 704x480 16:9 encodes, it would be
480 * (16/9) / 704 = 40:33
Mikel
5th September 2008, 15:52
Hi
Thanks for those additional feedbacks. I am kind of surprised that MEguid does not do this automatically.
All the information I think is in the avs-file?
The solution with the mkv-file muxing works also nice both for hardware and software players.
This just prevents me from using the one click encoder solution in MEgui.
The reason why I brought it up was because I thought I did something wrong either with encoding or with MEgui.
As it looks like, the problem is with MEgui.
Cheers
Mikel
wyti
5th September 2008, 16:00
All the information I think is in the avs-file?
No they aren't avisynth only frameserv frames pixels by pixels ignoring AR
Sharktooth
5th September 2008, 16:02
megui uses custom variables to store AR in the avisynth script... however, no, avisynth has no idea of what AR is...
and btw megui does calculate the AR automatically, there's just a bug that sometimes screws the AR.
Mikel
6th September 2008, 09:57
It is true that Avisynth does not know about AR.
Still, MEgui creates the following portion in the script:
global MeGUI_darx = 154
global MeGUI_dary = 61
What does MeGUI do with this?
Just did another encode, playing the mp4 gives me the impression that those lines are just there as info?
The mp4 file played with the wrong AR.
Again, when I remux and set the AR in MKVmerge as 154/61, it displays correctly.
Here is the commandline MEGui produced:
C:\Programme\megui\x264.exe" --crf 18.0 --ref 3 --mixed-refs --no-fast-pskip --bframes 16 --b-pyramid --b-rdo --bime --weightb --direct auto --filter 1,1 --subme 6 --trellis 2 --partitions p8x8,b8x8,i4x4,i8x8 --8x8dct --me umh --threads auto --thread-input --sar 6415219761047:4398046514504 --progress --no-psnr --no-ssim --output "c:\movie.mp4" "c:\movie.avs"
Cheers, Mikel
kemuri-_9
6th September 2008, 15:55
--sar 6415219761047:4398046514504
there's what MeGUI did for the AR, and that is honestly really messed up...
what was the resolution of your script?
though x264 accepts 32bit numbers on the command line for the SAR, it reduces them all to 16bit (65535 max)
so giving higher numbers is relatively pointless
Sharktooth
6th September 2008, 16:03
It is true that Avisynth does not know about AR.
Still, MEgui creates the following portion in the script:
global MeGUI_darx = 154
global MeGUI_dary = 61
What does MeGUI do with this?
Just did another encode, playing the mp4 gives me the impression that those lines are just there as info?
The mp4 file played with the wrong AR.
Again, when I remux and set the AR in MKVmerge as 154/61, it displays correctly.
Here is the commandline MEGui produced:
C:\Programme\megui\x264.exe" --crf 18.0 --ref 3 --mixed-refs --no-fast-pskip --bframes 16 --b-pyramid --b-rdo --bime --weightb --direct auto --filter 1,1 --subme 6 --trellis 2 --partitions p8x8,b8x8,i4x4,i8x8 --8x8dct --me umh --threads auto --thread-input --sar 6415219761047:4398046514504 --progress --no-psnr --no-ssim --output "c:\movie.mp4" "c:\movie.avs"
Cheers, Mikel
Megui stores the AR in the avs for later use... As i said there is a bug in megui so those values are not respected.
kemuri-_9
6th September 2008, 16:25
how is megui even calculating the SAR from the DAR?
i just dl'ed megui and tried telling it to encode a 704x480 video as 16:9,
it calculated the SAR as
341620328351:274877960443 ~ 1.2428
when it should of just been 40:33 ~ 1.2121
if you're using the decimal representation of the DAR i could see this generating from horribly awry rounding and decimal->fraction conversion.
it would be easier (and more accurate) to maintain everything in ints:
SAR X = DAR X * Height
SAR Y = DAR Y * Width
and using gcd reduction to reduce them down
Sharktooth
6th September 2008, 16:35
check the avs script. are the values in MeGUI_darx and MeGUI_dary correct?
kemuri-_9
6th September 2008, 16:52
i checked the script after the encode and there was no alteration to it for the adding of those values.
so i'm wondering where it put them....
guess it's a good thing i don't regularly use meGUI, seems overcomplicated for a CLI guy like me.
edit:
checked the xml for the job and it has
<DAR>
<ar>1.822784</ar>
</DAR>
so you are using decimals... ouch.
Sharktooth
6th September 2008, 16:53
did you create the script in the avisynth script creator tool?
btw there is a bug that was introduced some time ago in the AR calculation so, if it borks, it's useless to try keeping doing the things right... until we fix it...
kemuri-_9
6th September 2008, 17:04
did you create the script in the avisynth script creator tool?
what? that's really cumbersome, it doesn't even allow selection of other .avs files...
at least allow importing of other avs scripts into the tool so it can do w/e it wants to a new .avs and keep the original intact.
so.... the answer is 'nope'....
oh as a side note, meGUI even dared to tell me that avs wasn't installed when it is. looks like the detection needs to be fixed to check the SysWOW64 folder on win x64 boxes.
Sharktooth
6th September 2008, 17:14
it does... stop telling lies if you dont know what you're doing. i already told you the AR feature is buggy and it have to be fixed.
it's useless you continue playing with it... just add your AR with the --sar option to the encoder commandline (using custom commandline settings in the encoder preset config window) and you're done (it will override the wrong value passed to the encoder by megui). if you dont know how to do it :readguid: and look at the wiki.
the detection is done by looking for a registry entry, and, AFAIK it was updated for 64bit OSES. what version of avisynth have you installed?
Sharc
6th September 2008, 17:16
Actually the sar 6415219761047:4398046514504 is very exactly the ITU-R BT.601 sar of 512:351 for a PAL 16:9 DVD, just represented by insane large numbers. Assuming your original is a PAL 16:9 DVD you could overwrite these number with 512:351, or very closely approximated by 16:11, and the movie should playback correctly.
I am not very familiar with MeGUI, but I would assume that it calculated these insane huge numbers. I suspect that encoders/players may not handle such large numbers properly, either they truncate to max 255 or perhaps may do improper downscaling. So I would just overwrite such large sar numbers in the cli with 16:11.
kemuri-_9
6th September 2008, 17:18
2.5.8.3 (CVS)
if it looks for the plugin autoload directory entry, that would fail since i have it removed since avs crashes with over 50 loaded plugins when i have more than that available for use.
Sharktooth
6th September 2008, 17:20
beta and CVS versions are not supported.
kemuri-_9
6th September 2008, 17:24
well that's a shame, it actually encoded from it perfectly fine:
I just ignored the 'Do you want me to install it for you?' message and it worked fine. so *shrugs*
Sharktooth
6th September 2008, 17:46
well, we'll add support for 2.5.8 when becomes stable.
G_M_C
27th September 2008, 12:58
Just a short question, cause I'm not sure I've done this right;
When i need to make a 576i for on a BD9 that has to play on a stand-alone; Am i right that i have to set SAR in x264 (meGUI) to 576:405 ? Cause i don't know for sure if that works on my player ...
SeeMoreDigital
27th September 2008, 14:13
Am i right that i have to set SAR in x264 (meGUI) to 576:405 ? Cause i don't know for sure if that works on my player ...Just to let you know, an SAR of 576:405 can be simplified to 64:45 ;)
kemuri-_9
27th September 2008, 15:57
Just to let you know, an SAR of 576:405 can be simplified to 64:45 ;)
x264 will reduce SAR ratios itself, so you don't have to (enabling laziness)
G_M_C
27th September 2008, 20:47
Thx, the last time i had to simplify fractions is a long time ago; It seems i have forgotten how to do so. But ive put the 64/45 in now :)
mistatofa
6th October 2008, 05:39
As a matter of interest, if I have already processed the movie and still have the .avs file, can I just open the .mkv (containing x264 mp4 + aac) with mkvmerge GUI, adjust the display width/height to the settings in the .avs file (43 x 23) and re-mux? I've tried it and it looks pretty good but just wanted to know if it's getting me the exact correct ratios before I go through a bunch of them.
Looks like this bug only came about since around July - all my rips before then are bang on for display height / width but since then I get odd stuff like 1786547568 x -1841127680.
Just so ya know, I'm not complaining here - this software is just awesome, and the movies ripped in x264/aac are much nicer and smaller than the old divx/ac3 jobs so thanks a bunch for all your hard work!
vBulletin® v3.8.11, Copyright ©2000-2026, vBulletin Solutions Inc.