View Full Version : Command-line utility to Autodetect Aspect Ratio
ScootyPuffJr
8th August 2008, 10:23
I've spent several hours looking for a command-line utility that can report to me the true aspect ratio of a DVD (not just 16x9, but the actual 1.78, 2.35, etc... ratio) so that I can crop and convert properly in a batch environment, but haven't had any luck. Has anyone seen a tool that can do this, or a tool that can analyze the VOB and report the margins that need to be cropped?
Could anyone whose written another front-end tell me how you have done this?
Thanks!
-spj
smok3
8th August 2008, 10:39
a. there is avisynth plugin autocrop that may be helpfull?
b. mplayer seems to have some border detection options?
simplified example:
b1. cropdetect
mplayer -ss 30 VTS_06_1.VOB -vf cropdetect -frames 50 > UglyCropInfo.txt
b2. then you would need to parse the text file to find
Movie-Aspect is 1.33:1 - prescaling to correct movie aspect.
and
[CROP] Crop area: X: 4..710 Y: 71..501 (-vf crop=704:416:6:80).
b3. then you would need to mod16 the cropping results and calculate the resizing or anamorfic flag.
c. describe how that tool would work and what it should return?
(It will never end up as good as manual-labor imho)
ScootyPuffJr
8th August 2008, 17:18
I has seen the AviSynth plugin, but couldn't figure out how to get either any kind of usable stdout output out of it. I'm still faily new to all the tools, so it probably does it, i just hadn't figured out how. I was so focused on doing it manaully I should probably investigate and see if they have an autocrop/autoresize combo that I could just specify the target output AR and size for, through you say manual will probably be the best anyway.
I currently have my resizing calculations and avs script generation all figured out in vbscript, so I can handle 1.78, 1.85, 2.35, 2.40, etc..., as I've set up the templates. I just need to figure out what the source format is to feed to that template (right now I manually view it and select the template). I can get the size and general aspect ratio from DGIndex, so I'm really just tring to figure out how much of the frame borders are black so I can select the right template. At this point I'll take anything I can find, and I won't be too picky, but what I would love to see is something that either reports the real (simple) ratio, or the black borders on all sides of the frame. The black border detection would almost be better because then I could feed that info into something like aspect2 and not have to do all the manaul resizing and cropping calculations my self.
I'll give the mplayer example a try, it may be ugly but it looks like it may be what I'm looking for.
I'm trying to write a front-end that will allow easy conversion to iPod/iPhone/AppleTV. I would definately prefer do do as much manaully as I can, but a couple of friends want it as automatic as possible - MeGUI, Gordian Knot, etc... are all too complicated for them, they aren't 'computer' people :)
I should probabily post samples of the command-lines some time and let people pick them apart - I'm sure they need some improvement, though I guess I am failry happy with the video that is produced.
Thanks smok3
smok3
8th August 2008, 19:40
mplayer should report the real DAR of the VOB and cropdetection is black borders, so i guess that is all you need for the input to next faze.
what is aspect2 and what input info it takes? example?
ScootyPuffJr
8th August 2008, 23:51
Aspect.zip is a command-line utility at doom9.org/ (http://www.doom9.org/) to figure out the cropping and resizing paramaters when encoding video.
Program: aspect v1.1
Author: Eric A. Welsh <ewelsh@ccb.wustl.edu>
Usage: aspect.exe x_orig y_orig ratio cl cr ct cb [mx my] [amx amy] [prmx prmy]
Examples: aspect.exe 720 480 1.8180 2 2 59 63 16 16 <RGB space>
aspect.exe 720 480 1.8180 2 2 59 63 16 16 2 2 <YV12, progressive>
aspect.exe 720 480 1.8180 2 2 59 63 16 16 1 1 1 2 <old VDub Lanczos>
x_orig/y_orig = original input resolution
ratio = target aspect ratio
cl/cr/ct/cb = crop left/right/top/bottom needed to remove black borders
mx/my = mods for final X/Y resolutions (default 16/16)
amx/amy = alignment mods for X/Y (color space dependant):
RGB: 1/1 (this is the default)
YUY2: 2/1 (progressive), 2/2 (interlaced)
YV12: 2/2 (progressive), 2/4 (interlaced)
prmx/prmy = pre-resize mods for X/Y (default 1/1)
ONLY used when an alignment mod == 1
old Lanczos resize VDub plugin requires Y to be mod 2
I haven't played with it much yet, but it looks to have promise. Aspect 2.0 (http://aspect.fre3.com/index.html) is a different GUI utility by another author that lets you preview a screen image and select the borders to create an AVS script for encoding. I haven't played with that much either, and may just keep doing the calculations myself if I can easily autodetect the areas that need cropping.
From what I've seen people tend to resize first, then crop? is that a fair statement? or am I better off to crop then resize, or doesn't it really matter?
ScootyPuffJr
9th August 2008, 03:34
smok3,
These 3 lines give me exactly what I need ...
Movie-Aspect is 1.78:1 - prescaling to correct movie aspect.
VO: [directx] 720x480 => 854x480 Planar YV12
[CROP] Crop area: X: 0..719 Y: 57..419 (-vf crop=720:352:0:64).
MPlayer even does the 16x16 block calculations for you if you want.
I had never really looked at MPlayer before because I was outputting to Apple devices, so I just used quicktime to view. It's a fantastic tool.
Thanks for your help!
-spj
smok3
10th August 2008, 11:21
ScootyPuffJr: cool, i guess if you need square pixels then it is mostly done. It is probably 'better' to crop->resize, since you have more precision for cropping and then later there is less to scale-down (at least for progressive sources).
vBulletin® v3.8.5, Copyright ©2000-2012, Jelsoft Enterprises Ltd.