View Full Version : Automatic left-right pan script?
zambelli
8th April 2007, 10:01
Would it be possible to write an Avisynth script that automatically pans across a widescreen clip at fixed intervals?
Let's say I have a video that's 560x240 in resolution. I want to show only a 320x240 window of the video at all times, but I don't want the window to be static. I want it be interesting and simulate how a camera man might pan from left to right and back, occasionally cutting directly to a specific window. There'd be a pattern to the panning, of course. Perhaps something like:
Center (pan to) Right
Right (pan to) Center
Center (pan to) Left
Left (cut to) Right
Right (pan to) Left
Left (cut to) Center
And then repeat the whole sequence over and over again, with, for example, fixed 20 second intervals between each action.
I know how to make a pan with Animate() and Crop(), but I don't know how I'd go about scripting a series of actions like that in something resembling a "while" loop. Any ideas? Or am I asking too much from Avisynth's scripting engine?
Mug Funky
9th April 2007, 08:05
i'd say it'd be doable with the resizers and frameevaluate/scriptclip.
if this is for panscanning, i had an idea of abusing depan to track important objects around the frame, but never got round to scripting it, so i don't know if it'd give watchable results.
zambelli
9th April 2007, 09:41
i'd say it'd be doable with the resizers and frameevaluate/scriptclip.
if this is for panscanning, i had an idea of abusing depan to track important objects around the frame, but never got round to scripting it, so i don't know if it'd give watchable results.
It's not really for pan-n-scanning movies. I have a concert footage video that I'd like to upload to YouTube, but because YouTube restricts everything to 320x240, I'm having a hard time making the video look good by scaling it down to 320x240 (everyone looks like ants). So I got this idea to zoom in on the central part of the video and only show a 320x240 window at all times. However, I don't want to go through the whole thing in Premiere and edit the pan in-out points manually. I was hoping I could write an Avisynth script that'd essentially automatically pan left-center-right and vice versa for the duration of the video and just create a slightly more exciting video than if it were just static. I'm not looking for perfection. If we had while-do loops in Avisynth, the pseudoscript might look something like this:
counter = 0
while (currentframe < end) do
{
Pan(Center, Right, counter, counter+300)
counter += 600
Pan(Right, Center, counter, counter+300)
counter += 600
Pan(Center, Left, counter, counter+300)
counter += 600
Cut(Left, Right, counter, counter+300)
counter += 600
Pan(Right, Left, counter, counter+450)
counter += 600
Pan(Left, Center, counter, counter+300)
}
Mug Funky
10th April 2007, 03:56
i'm not having much fun interpreting that pseudocode, but i think scriptclip will work for you.
you'll need to use a resize with (subpixel) cropping, and use something like "(current_frame % 600) > 300? panleft : panright". or something similar. a nested if inside a scriptclip should be enough, but it'll look ugly (remember you can triple-quote the scriptclip line and use \ for new lines to make things nicer to look at).
gzarkadas
11th April 2007, 22:02
@zambelli,
ScriptClip (as Mug Funky suggests) plus a number stream that oscilates between [-1..1] for the desired frame interval is all that needed.
If a large number of frames is specified in the textfile for conditional reader, longer than any clip to be processed, then the same text file can cover all clips to be processed.
Below is a script I use for such situations (window dimensions are hard-coded) and a sample pan_x.txt file:
AviSource(...)
# x, y factor: [-1..1] -> move until window hits the clip's end; use |x or y| > 1 to go off-sight;
global x_factor = 0.0
global y_factor = 0.0
ScriptClip(last, """
x = Round(x_factor * (last.Width - 320) / 2.0)
y = Round(y_factor * (last.Height - 240) / 2.0)
Overlay(last.BlankClip(), last, x, y, mode="blend", opacity=1.0, ignore_conditional=true)
""")
Exist("pan_x.txt") ? ConditionalReader("pan_x.txt", "x_factor") : last
Exist("pan_y.txt") ? ConditionalReader("pan_y.txt", "y_factor") : last
Crop((last.Width - 320) / 2, (last.Height - 240) / 2, 320, 240)
type float
default 0
I 0 200 0 1
I 200 400 1 0
I 400 600 0 -1
I 600 800 -1 0
I 800 1000 0 1
I 1000 1200 1 0
I 1200 1400 0 -1
I 1400 1600 -1 0
Hope you find it useful :) .
zambelli
13th April 2007, 05:55
@gzarkadas: You're a life saver! This looks like it might be exactly what I'm looking for. Thank you!
vBulletin® v3.8.11, Copyright ©2000-2026, vBulletin Solutions Inc.