Log in

View Full Version : MeGUI Aspect Ratio Problem


Teppic
19th July 2008, 06:41
Hi folks,

I have encoded a movie using MeGUI but the aspect ratio is wrong (the movie looks stretched vertically). These are the steps I followed:

Copied movie (Memento) to hard drive using DVD Decrypter
Opened MeGUI and created a D2V file with the D2V Creator tool (demuxed all audio tracks)
Used the AviSynth Script Creator tool to create a script with Clever Anamorphic Encoding (Overcrop to Mod16) turned on, some basic cropping, progressive source type, and a medium noise filter.
After selecting the audio track, used the Autoencoder tool to set the filename and location and the chapters.


I checked the log file and noticed the following in the second line of the standard error stream for the job:
x264 [warning]: cannot create valid sample aspect ratio

I have used this process in the past without any problems so I am not sure where I am going wrong. I am currently using MeGUI 0.3.0.1015.

Any help would be greatly appreciated.

Cheers,
Brad

Octo-puss
19th July 2008, 09:24
I noticed this on most of my movies. What I do is simply add "--sar 64:45" (that's 16:9 PAL /all the DVDs I have are that way) in the MeGUI's x264 config page, custom parameters. Problem solved. For me at least.

Teppic
19th July 2008, 09:47
Fantastic, worked like a charm!

Thanks for your help Octo-puss, much appreciated.

:thanks:

Sharktooth
19th July 2008, 11:05
it depends on the source. some DVDs have wrong AR signaling and manual intevention is needed.

Teppic
20th July 2008, 01:47
Hi Sharktooth, thanks for your reply.

Is there a way to determine if the signalling is wrong before starting the encode, or is it easier to simply append --sar 64:45 to the command line for all PAL wide-screen DVDs as Octo-Puss suggested?

saint-francis
20th July 2008, 01:56
or is it easier to simply append --sar 64:45 to the command line for all PAL wide-screen DVDs as Octo-Puss suggested?

That won't work in many cases. Many movies don't have a 16:9 AR. If it's off the best thing to do would be to look on IMDB or Amazon or some DVD etailer And see what the DAR of the movie is. Then calculate the AR to signal in the command line manually.

Sharktooth
20th July 2008, 03:15
saint-francis told you the right solution.

jmnk
20th July 2008, 06:16
or is it easier to simply append --sar 64:45 to the command line for all PAL wide-screen DVDs as Octo-Puss suggested?
That won't work in many cases. Many movies don't have a 16:9 AR. If it's off the best thing to do would be to look on IMDB or Amazon or some DVD etailer And see what the DAR of the movie is. Then calculate the AR to signal in the command line manually.
Could you provide an example of where this method would not work? I agree that a lot of movies do not have 16:9 display aspect ratio - when you crop out black bars. But that is the beauty of pixel aspect ratio, it does not care about that. Since I'm in NTSC land let's discuss NTSC DVD. I would use sar=32:27 for all my DVD encodings that need to be displayed at 16:9 ratio. Let's say I have a DVD with for-TV made show (like 24). It is exactly 16:9 display aspect ratio. The signal outputted from DVD player is exactly 720x480 with no black bars. I encode, apply sar=32:27 and my final encode should be played by any decent (ratio observing) player at 720x32:27=~853 by 480 which is exactly what I would see if I were to play DVD.
Now I have DVD with movie shot with display aspect ratio 2.35:1 like Terminator2. The signal outputted from DVD player is exactly 720x480 but there are black bars now, about 58 pixels on top and bottom. What I see when playing DVD is again ~853 by 480 but since 116 pixels are just black bars the movie image is actually 853 by 480-116 which is 853 by 364, which is 2.343:1. Due to rounding it is not exatly 2.35:1 but if noone can spot the difference.
So when I encode I crop 58 pixels on top and bottom and apply sar=32:27 again (just like I did with TV show DVD). I'm going to get 720by364 movie flagged with 32:37 ratio which is going to play at 720x32:27=~853 by 364 - which is exactly what I wanted.
Any other DVD with aspect ratios in between will work out just fine without me ever checking IMDB.
If you see that DVD has some black bars on the side than it follows the 704x480 standard and than you use sar=40:33 instead of 32:27. But again - no need to check IMDB.
For 4:3 display aspect ratio movies one is better off just resizing to 640x480 (for NTSC) and encode with aspect ratio 1:1. With any movie.
(for now let's not discuss 16:9 movies inside 4:3 - like Running Man).
Anyway, what would be a case where this method does not work?

Sharktooth
20th July 2008, 16:12
k, i've encountered the AR problem making a backup of Hellboy.
i think we can fix it, however, signaling the AR with MP4Box remuxing the streams to a new .MP4 file did work without much problems at least in my case.

chainring
21st July 2008, 02:02
k, i've encountered the AR problem making a backup of Hellboy.
i think we can fix it, however, signaling the AR with MP4Box remuxing the streams to a new .MP4 file did work without much problems at least in my case.

And here I thought I've been going crazy! This bug, or whatever it's considered, has plagued me for a while now. I'm doing all NTSC stuff ripped from DVD, and always do an overcrop to mod16 while signaling it to be anamorphic.

I just did a test with Hellboy since Sharktooth mentioned it, and got the same results.

Process:
- Rip to single IFO with DVD Decrypter and AnyDVD
- Create .d2v from within meGUI
- AviSynth script creator

Load .d2v
Overcrop to mod16
Autocrop and inspect. Adjust as necessary
Have meGUI analyze for interlace, etc...
Save the newly created .avs

- enqueue and encode

With that process, it's a crapshoot whether or not the aspect ratio will be correct; some are, some are not.

Here's the commandline for the above process:
--crf 20.0 --level 3 --ref 3 --mixed-refs --no-fast-pskip --bframes 3 --b-pyramid --b-rdo --bime --weightb --subme 7 --no-chroma-me --trellis 2 --partitions p8x8,b8x8,i8x8 --8x8dct --me umh --threads 3 --thread-input --progress --no-dct-decimate --no-psnr --no-ssim --output "output" "input"CODE]

Note: I used skystrife's 915 modified with psyRDO 0.5 for this test.

Using Hellboy as an example, I decided to try a method suggested here (http://forum.doom9.org/showthread.php?p=1058927#post1058927) by Brother John.

I still go through the process above, including letting meGUI figure out the crop and overcrop to mod16. Where I change it is; once the .avs is saved, I'll manually edit it and cut out the signalling section, but keeping the mod16 overcrop.

From this:
[CODE]# Set DAR in encoder to 37 : 20. The following line is for automatic signalling
global MeGUI_darx = 37
global MeGUI_dary = 20
DGDecode_mpeg2source("hellboy.demuxed.d2v",info=3)
ColorMatrix(hints=true)
#deinterlace
crop( 8, 6, -8, -10)

#resize
#denoise


To this:
DGDecode_mpeg2source("hellboy.demuxed.d2v",info=3)
ColorMatrix(hints=true)
#deinterlace
crop( 8, 6, -8, -10)

#resize
#denoise


To get an idea of the correct DAR, I played the original VOB with VLC, took a snapshot, then cropped black bars and any funky areas.
Original snapshot: 853x480
Cropped snapshot: 850x467

I then tested multiple encodes while varying "--sar x:x" on the custom command line option.

Results:
Signaling in .avs (37:20) - 704x464
--sar 40:33 - 852x464 (MPEG-4 PAR for NTSC 16:9)
--sar 32:27 - 833x464 (generic PAR for NTSC 16:9)
--sar 251:214 - 824x464 (process taken from here (http://forum.doom9.org/showthread.php?p=1034465#post1034465))

Commandline used to signal --sar for x264:
--crf 20.0 --level 3 --ref 3 --mixed-refs --no-fast-pskip --bframes 3 --b-pyramid --b-rdo --bime --weightb --subme 7 --no-chroma-me --trellis 2 --partitions p8x8,b8x8,i8x8 --8x8dct --me umh --threads 3 --thread-input --progress --no-dct-decimate --no-psnr --no-ssim --output "output" "input" --sar 32:27

Sharktooth
21st July 2008, 02:09
my hellboy is PAL so there are differencies from the NTSC verision for sure.

the correct final AR, in my case was 360:187 overcropping to mod 16 and the resulting res after crop was 720x544. playback res 1046x544.

ZombiePimp
21st July 2008, 02:21
There is definitely a bug with anamorphic encoding in the 0.3.x versions of meGUI. I restored version 0.2.6.1048 from backups and all of these aspect ratio problems went away.

Sharktooth
21st July 2008, 02:22
i know, im investigating it.

ZombiePimp
21st July 2008, 02:25
Thanks, Sharktooth :)

jmnk
21st July 2008, 05:50
...
To get an idea of the correct DAR, I played the original VOB with VLC, took a snapshot, then cropped black bars and any funky areas.
Original snapshot: 853x480
Cropped snapshot: 850x467

I then tested multiple encodes while varying "--sar x:x" on the custom command line option.

Results:
Signaling in .avs (37:20) - 704x464
--sar 40:33 - 852x464 (MPEG-4 PAR for NTSC 16:9)
--sar 32:27 - 833x464 (generic PAR for NTSC 16:9)
--sar 251:214 - 824x464 (process taken from here (http://forum.doom9.org/showthread.php?p=1034465#post1034465))

Commandline used to signal --sar for x264:
--crf 20.0 --level 3 --ref 3 --mixed-refs --no-fast-pskip --bframes 3 --b-pyramid --b-rdo --bime --weightb --subme 7 --no-chroma-me --trellis 2 --partitions p8x8,b8x8,i8x8 --8x8dct --me umh --threads 3 --thread-input --progress --no-dct-decimate --no-psnr --no-ssim --output "output" "input" --sar 32:27

so after all of this - is your encoded movie OK? Because if I were you I would use --sar=40:33 since that would give you the display aspect ratio almost identical to what your cropped DVD is. I'm not sure why you picked 32:27. And I definitely do not get why anyone would use --sar=251:214. I've read the thread you have referenced and to me all of that is not needed if you never resize (and only possibly crop).
As far as MEGUI - I always do crop only, I do not even do overcrop to mod16 since x264 will encode non-mod16 size anyway. I comment out MeGui global MeGui_darx and global MeGui_dary since I do not like the way MeGUI does conversion between these DAR values and SAR values that are ultimately fed into x264. Most of the time you get custom sar values while if you do encoding from DVD source you really need only 3 (for NTSC, and 3 for PAL): 32:27 or 40:30 or 1:1 (for 4:3 aspect ratio - you should resize to 640x480 and set sar=1:1) - so I provide that as custom command line parameter.
Also, at least in some not so recent versions MeGUI, if I comment out global MeGui_dary and MeGui_darx and provide sar as custom parameter, the command line has two --sar values: one is set to 1:1 (I'm assuming that's what MeGui assumes when you comment out MeGui_dary and MeGui_darx, and the other that comes from custom command line. I have not seen it to be a problem since apparently the sar from custom parameters comes last and it overwrites the sar coming from MeGUI itself - but it is a small annoyance.

saint-francis
21st July 2008, 06:00
Yeah I just used CAE for an experiment and it plain didn't work. It didn't work on two movies in a row.

@jmnk: There are certainly movies with odd AR's. What if the movie is 2.4:1? Or how about this (http://www.imdb.com/title/tt0021884/)one? I've never seen that AR before. It never hurts to be cautious when signaling the DAR.

jmnk
21st July 2008, 08:18
@jmnk: There are certainly movies with odd AR's. What if the movie is 2.4:1? Or how about this (http://www.imdb.com/title/tt0021884/)one? I've never seen that AR before. It never hurts to be cautious when signaling the DAR.
a movie with 2.4:1 display aspect ratio is going to be encoded on DVD as 720x480 (assuming it is NTSC) with black bars on top and bottom of about 52 pixels each. When displayed by DVD player it is going to look as (when considering image only and not counting black bars) 853x356. So when you encode you crop out black bars which leaves you with 720x356 and signal sar=32:27. Which on playback will give you 720x32:27=853x356. Exactly what you want.
a movie with 1.37 display aspect ratio is going to be encoded on DVD as 720x480 (assuming it is NTSC) with black bars on the sides of about 31 pixels each and flagged for DVD player as 1:1. This is indeed odd resolution since it is less than 16:9 but more than 4:3. When displayed by DVD player it is going to look as (when considering image only and not counting black bars) 658x480 with bars on the side. There's no reason to encode 720x480. So you resize to 658x480 and apply sar=1:1. Done.
I do not need to look at IMDB. Really, this math works every time.
MeGUI, I think for historical reasons/misconceptions tries to calculate proper DAR (that's where these globals in avs script come from) and than recalculate that into SAR since x264 supports SAR only. That is a bit more than necessary in my opinion. But it is a great software.

Irakli
21st July 2008, 10:02
I think "jmnk" is right. Pixel Aspect Ratio (--sar command in x264) is just a ratio of pixel width to pixel height, Since cropping does not alter that ratio, the Pixel Aspect Ratio remains unchanged after cropping. Here (http://forum.doom9.org/showthread.php?p=1058927#post1058927) are standard Pixel Aspect Ratios used in DVDs.

Best wishes,
Irakli

Sharktooth
21st July 2008, 12:41
ok, after a deep investigation, i found the problem happens when OVERCROPPING to MOD16 but not when RESIZING to MOD16.
So, to have a correct AR in the encode you can follow this steps:
1- In the avs creator open the .d2v as usual
2- Check "Clever anamorphic encoding" and "Resize to MOD 16"
3- Check "Crop" and eventually autocrop (or manually remove the black bars)
4- Ensure the orizontal res in the resize field is correct (720 is the full res for DVDs) - the vertical res should be automatically chosen.
5- Proceed with filters as needed (i generally use lanczos as default resizer... but use whatever you like more).]
6- Save the script.

Going this way the AR will be ALWAYS correct.

cbarroso
21st July 2008, 16:05
Hi Sharktooth,

I did all the steps and got a wrong ratio. Here is the avs:

# Set DAR in encoder to 29 : 12. The following line is for automatic signalling
global MeGUI_darx = 29
global MeGUI_dary = 12
DGDecode_mpeg2source("G:\Temp\01.d2v")
#deinterlace
crop( 0, 58, 0, -60)

LanczosResize(720,368) # Lanczos (Sharp)
#denoise


And here the resullt:

Video: MPEG4 Video (H264) 720x368 (178950801:268432903) 23.98fps

Sharktooth
21st July 2008, 16:11
weird it never failed here even with hellboy.

chainring
21st July 2008, 16:58
so after all of this - is your encoded movie OK? Because if I were you I would use --sar=40:33 since that would give you the display aspect ratio almost identical to what your cropped DVD is. I'm not sure why you picked 32:27. And I definitely do not get why anyone would use --sar=251:214. I've read the thread you have referenced and to me all of that is not needed if you never resize (and only possibly crop).
As far as MEGUI - I always do crop only, I do not even do overcrop to mod16 since x264 will encode non-mod16 size anyway. I comment out MeGui global MeGui_darx and global MeGui_dary since I do not like the way MeGUI does conversion between these DAR values and SAR values that are ultimately fed into x264. Most of the time you get custom sar values while if you do encoding from DVD source you really need only 3 (for NTSC, and 3 for PAL): 32:27 or 40:30 or 1:1 (for 4:3 aspect ratio - you should resize to 640x480 and set sar=1:1) - so I provide that as custom command line parameter.
Also, at least in some not so recent versions MeGUI, if I comment out global MeGui_dary and MeGui_darx and provide sar as custom parameter, the command line has two --sar values: one is set to 1:1 (I'm assuming that's what MeGui assumes when you comment out MeGui_dary and MeGui_darx, and the other that comes from custom command line. I have not seen it to be a problem since apparently the sar from custom parameters comes last and it overwrites the sar coming from MeGUI itself - but it is a small annoyance.
All of that was a test of the different PAR values possible, and mentioned in Brother John's post I linked to previously. In the end, what got it right on the money was "--sar 40:33", at least for Hellboy and Much Ado About Nothing (another I tried and was having problems with).

ZombiePimp
21st July 2008, 19:15
ok, after a deep investigation, i found the problem happens when OVERCROPPING to MOD16 but not when RESIZING to MOD16.
So, to have a correct AR in the encode you can follow this steps:
1- In the avs creator open the .d2v as usual
2- Check "Clever anamorphic encoding" and "Resize to MOD 16"
3- Check "Crop" and eventually autocrop (or manually remove the black bars)
4- Ensure the orizontal res in the resize field is correct (720 is the full res for DVDs) - the vertical res should be automatically chosen.
5- Proceed with filters as needed (i generally use lanczos as default resizer... but use whatever you like more).]
6- Save the script.

Going this way the AR will be ALWAYS correct.

I've always used "Resize to MOD 16" and had these aspect ratio issues.

Brother John
21st July 2008, 22:25
For everyone struggling with the math: Checking PAR and DAR for resized anamorphic encodings isn't that difficult. You only need to do:

resized_height cropped_width
new_par = table_par * -------------- * -------------
cropped_height resized_width

With the example from cbarroso's last posting, assuming it was 16:9 (anamorphic) NTSC and using generic PAR:

32 368 720 5888
-- * --- * --- = ----
27 362 720 4887

That means the correct PAR signalling for x264 is --sar 5888:4887 (might not be completely cancelled, I was lazy). Same story for MPEG-4 or ITU PAR, just different numbers.

And to go from there to the proper playback display AR:
resized_width
DAR = -------------- * new_par
resized_height

Kurtnoise
14th October 2008, 08:21
ok guys,

1st attempt (http://www.mediafire.com/?zgddyidmwiq) to fix this bug in megui. Please test and report back...

:thanks:

LeXXuz
14th October 2008, 08:58
Will test it as soon as my current work job is done. :)

EDIT: Can't download it. Always getting a timeout. :(

Kurtnoise
14th October 2008, 09:57
mirror (http://kurtnoise.free.fr/index.php?dir=MeGUI/&file=MeGUI_20081014.zip)...

LeXXuz
14th October 2008, 10:27
Okay here we go. Looks ok so far. The sar is now fixed to 1459:1000 for most sources. Here's a part of my log:


[Warning] Log
-[Information] Versions
--[NoImage] MeGUI Version : 0.3.0.3003
--[NoImage] OS : Microsoft Windows XP Professional SP3 (5.1.196608.2600)
--[NoImage] Framework used : 2.0 SP1 (2.0.50727.3053)

-[Warning] Log for job4 (video, )
--[Information] [14.10.2008 11:01:45] Started handling job
--[Information] [14.10.2008 11:01:45] Preprocessing
---[NoImage] avis [info]: 704x544 @ 25.00 fps (154755 frames)
---[NoImage] x264 [info]: using SAR=1459/1000
---[NoImage] x264 [info]: using cpu capabilities: MMX2 SSE2Fast SSSE3 Cache64
---[NoImage] mp4 [info]: initial delay 2 (scale 25)
--[Information] [14.10.2008 11:02:03] Job completed
--[Information] [14.10.2008 11:02:03] Current job was aborted

-[Warning] Log for job5 (video, )
---[NoImage] avis [info]: 688x432 @ 25.00 fps (155372 frames)
---[NoImage] x264 [info]: using SAR=1459/1000
---[NoImage] x264 [info]: using cpu capabilities: MMX2 SSE2Fast SSSE3 Cache64
---[NoImage] mp4 [info]: initial delay 2 (scale 25)
--[Information] [14.10.2008 11:03:16] Job completed
--[Information] [14.10.2008 11:03:16] Current job was aborted

-[Warning] Log for job6 (video, )
---[NoImage] avis [info]: 704x432 @ 25.00 fps (151512 frames)
---[NoImage] x264 [info]: using SAR=1459/1000
---[NoImage] x264 [info]: using cpu capabilities: MMX2 SSE2Fast SSSE3 Cache64
---[NoImage] mp4 [info]: initial delay 2 (scale 25)
--[Information] [14.10.2008 11:03:43] Job completed
--[Information] [14.10.2008 11:03:43] Current job was aborted

-[Warning] Log for job7 (video, )
---[NoImage] avis [info]: 704x560 @ 25.00 fps (138156 frames)
---[NoImage] x264 [info]: using SAR=184/125
---[NoImage] x264 [info]: using cpu capabilities: MMX2 SSE2Fast SSSE3 Cache64
---[NoImage] mp4 [info]: initial delay 2 (scale 25)
--[Information] [14.10.2008 11:04:14] Job completed
--[Information] [14.10.2008 11:04:14] Current job was aborted

-[Warning] Log for job8 (video, )
---[NoImage] avis [info]: 704x432 @ 25.00 fps (123412 frames)
---[NoImage] x264 [info]: using SAR=1459/1000
---[NoImage] x264 [info]: using cpu capabilities: MMX2 SSE2Fast SSSE3 Cache64
---[NoImage] mp4 [info]: initial delay 2 (scale 25)
--[Information] [14.10.2008 11:04:50] Job completed
--[Information] [14.10.2008 11:04:50] Current job was aborted

-[Warning] Log for job9 (video, )
---[NoImage] avis [info]: 704x416 @ 25.00 fps (129923 frames)
---[NoImage] x264 [info]: using SAR=1459/1000
---[NoImage] x264 [info]: using cpu capabilities: MMX2 SSE2Fast SSSE3 Cache64
---[NoImage] mp4 [info]: initial delay 2 (scale 25)
--[Information] [14.10.2008 11:05:17] Job completed
--[Information] [14.10.2008 11:05:17] Current job was aborted

-[Warning] Log for job10 (video, )
---[NoImage] avis [info]: 704x432 @ 25.00 fps (141052 frames)
---[NoImage] x264 [info]: using SAR=1459/1000
---[NoImage] x264 [info]: using cpu capabilities: MMX2 SSE2Fast SSSE3 Cache64
---[NoImage] mp4 [info]: initial delay 2 (scale 25)
--[Information] [14.10.2008 11:05:46] Job completed
--[Information] [14.10.2008 11:05:46] Current job was aborted

-[Warning] Log for job11 (video, )
---[NoImage] avis [info]: 704x416 @ 25.00 fps (152215 frames)
---[NoImage] x264 [info]: using SAR=1459/1000
---[NoImage] x264 [info]: using cpu capabilities: MMX2 SSE2Fast SSSE3 Cache64
---[NoImage] mp4 [info]: initial delay 2 (scale 25)
--[Information] [14.10.2008 11:06:11] Job completed
--[Information] [14.10.2008 11:06:11] Current job was aborted


I don't need to finish the encodes, because I do know for sure that they'll work with these values. (Done it dozens of times manually so far. :D)

I guess the ar-error will be negligible using this fixed 1.459 sar setting. From my notes the par varies between 1.4582 to 1.4594 depending on how the source was cropped. This would be an aberration of just one pixel in width, two at the most. :)

Kurtnoise
14th October 2008, 10:34
question : despite the rounding value, does it look correct when you play them ?

LeXXuz
14th October 2008, 10:54
question : despite the rounding value, does it look correct when you play them ?

I made about 10 encodes with a fixed 1.4585 a couple of days ago, because I was tired of writing down the calculated par-values. They all looked ok. :)

Kurtnoise
14th October 2008, 16:01
if some other people can test please...that would be great (to have a "stable" version before the new incomings).

Jawed
14th October 2008, 18:54
Here are my test results, using the following Avisynth scripts as my test clip:

global MeGUI_darx = 2361
global MeGUI_dary = 1000
blankclip(length=100,width=704,height=424,pixel_type="YV12",fps=25)

result: SAR 711:500, i.e. 1.422, correct to 4 significant digits

global MeGUI_darx = 2362
global MeGUI_dary = 1000
blankclip(length=100,width=704,height=424,pixel_type="YV12",fps=25)

result: SAR 1423:1000, i.e. 1.423, correct to 4 significant digits

global MeGUI_darx = 2363
global MeGUI_dary = 1000
blankclip(length=100,width=704,height=424,pixel_type="YV12",fps=25)

result: SAR 1423:1000, i.e. 1.423, correct to 4 significant digits

Thank you very much that appears to be working correctly :)

Jawed

Kurtnoise
14th October 2008, 22:04
not bad for a 1st attempt, isn't it ?...;)

thanks for the tests.

albatros44
29th November 2008, 22:10
ok, after a deep investigation, i found the problem happens when OVERCROPPING to MOD16 but not when RESIZING to MOD16.
So, to have a correct AR in the encode you can follow this steps:
1- In the avs creator open the .d2v as usual
2- Check "Clever anamorphic encoding" and "Resize to MOD 16"
3- Check "Crop" and eventually autocrop (or manually remove the black bars)
4- Ensure the orizontal res in the resize field is correct (720 is the full res for DVDs) - the vertical res should be automatically chosen.
5- Proceed with filters as needed (i generally use lanczos as default resizer... but use whatever you like more).]
6- Save the script.

Going this way the AR will be ALWAYS correct.

thanks