View Full Version : IF statements in Avisynth syntax
Zhelkus
21st July 2008, 04:28
I'm using MeGUI to encode video files to my 6thG iPod (Classic). In some cases, the video might be in widescreen format, in which case I apply some borders relative to the video's height. And in some cases, the audio might be AC3, for which Avisource() can't process it and I have to force Directshowsource or use Audiodub in conjunction with directshowsource for the audio.
This is my default script profile:
<input>
<deinterlace>
autocrop(0)
spline36resize(640,480)
<denoise>
unfilter(-5,-5)
convolution3d("moviehq")
I might be missing a few good filters but this is simply something to encode iPod ready videos and I'm mostly interested in speed :) .
In cases where the height/width ratio of the source video isn't 0.75 I insert this line after the crop:
addborders(0,round(width*.75 - height*1.25),0,round(width*0.75 - height*1.25))
How do I write up an If Then statement to make the addborders() automatic? I read the help file :readguid: but didn't understand it because there weren't enough examples... can't make do without examples :p
mikeytown2
21st July 2008, 05:04
If you want a more general solution to your problem (maintaining aspect ratio), you could give ZoomBox() (http://forum.doom9.org/showthread.php?p=1111789#post1111789) a try.
But to answer your question i would do something like this
float(height())/width() == 0.75 ? last : addborders(....)
Check out the code examples at the bottom of this page
http://avisynth.org/mediawiki/Operators
Gavino
21st July 2008, 05:11
The conditional (http://avisynth.org/mediawiki/Operators) operator is modelled on the C language and takes the form condition ? then-part : else-partSo you would writeheight*4 != width*3 ? addborders(0,round(width*.75 - height*1.25),0,round(width*0.75 - height*1.25)) : last
Note that the 'else' part is compulsory so you need to put 'last' in there.
EDIT: Ah, I see mikeytown2 just beat me to it.
Zhelkus
21st July 2008, 05:15
I'll go give it a try. Thanks guys.
Zhelkus
21st July 2008, 05:59
One more question: is there a function that checks if the script outputs audio? This is regarding the AC3 & Avisource() problem in my first post...:thanks:
RsVolcom
21st July 2008, 06:04
Did you already see this:
http://forum.doom9.org/showthread.php?t=131095
?
Sorry if it's irrelevant.
Zhelkus
21st July 2008, 07:01
Just finished reading it. Interesting breakthrough. Like you pointed out, I'm not sure it's relevant to the subject of my request... but if I'm wrong please make it clear to me because I've been using AviSynth for a long time but I can handle so little of what it can do. I can understand the idea and purpose of many functions but not the clockwork of them. If you have any idea on how to help me with this, then please do. I appreciate any incoming aid.
squid_80
21st July 2008, 07:19
If you install ac3acm avisource should be able to handle ac3.
RsVolcom
21st July 2008, 07:25
Just try it!
Its really easy and fast...just one command line...run it on your file and see if it works! I use it on all my iPod encodes mainly to add chapters, but I also never have aspect ratio issues, even when switching from widescreen to 4:3 content.
Gavino
21st July 2008, 11:51
One more question: is there a function that checks if the script outputs audio? This is regarding the AC3 & Avisource() problem in my first post.
Try something like this:file = "C:\mysource.avi"
try {
AviSource(file)
HasAudio ? last : AudioDub(DirectShowSource(file, video=false))
}
catch (err) {
DirectShowSource(file)
}
Zhelkus
28th July 2008, 02:23
Just realized the iPod had a built-in "don't zoom in" feature if the video's width was longer than the height... but not if the height is longer than the width, in which case it stretches. So, this still came in handy. Thanks a lot guys.
vBulletin® v3.8.5, Copyright ©2000-2012, Jelsoft Enterprises Ltd.