View Full Version : Scripting problem : video -> slide show video (1 second intervals)
Bob Wya
15th May 2006, 15:01
Hi all,
I've been trying write a functon to a create a 1 second of duplicate frames for a single frame for every second of a video clip. So basically I want to change the clip to appear to be 1FPS!!
However being a complete newbie to Avisynth scripting I have hit a brick wall...
Here is my current script function:
function VIDEO_STILLS(clip c)
{
return (c.framecount >= c.framerate) ? Loop(c, c.framerate, 0, 0)+VIDEO_STILLS(Trim(c, c.framerate, 0)) : Loop(c, c.framecount, 0, 0)
}
It currently complains about invalid arguments to function 'Loop'.
Can anyone help me out with a way to do this that works!!
Bob Wya :confused:
....
Fr=FrameRate()
AssumeFPS(1.0)
DuplicateFrame(0)
ChangeFPS(Fr)
Trim(Round(Fr/2.0), 0)The DuplicateFrame and Trim are to compensate for the Roundin calculation inside ChangeFPS
Bob Wya
15th May 2006, 17:06
Ah!!
That is so elegant!! :thanks:
BTW can you do recursive functions in Avisynth?
Anyone have idea why my little script wasn't working?? Its really so that I can learn from my mistakes. It looks fine to me and the error message are a bit vague...
Cheers for the quick help!!
B. Wya
stickboy
16th May 2006, 03:22
BTW can you do recursive functions in Avisynth?Yes, and AviSynth depends on it since it doesn't provide looping constructs as part of the language.
Anyone have idea why my little script wasn't working?? Its really so that I can learn from my mistakes. It looks fine to me and the error message are a bit vague...The error message says you passed invalid arguments to Loop, and that's exactly what you did. You passed a floating-point value (c.FrameRate()) where it expects an int.
@Stickboy, Damn, Snap! :o
The FrameRate function returns a Float. Loop expects an Int for that argument. You would need to use Int/Floor/Round/Ceil in this context to convert it to an Int.
Yes, Avisynth scripts can have recursion, but remember the script is fully resolved at compile time to a fixed Video/Audio processing graph. There are some devious functions like Animate and ScriptClip that can cause a recompile of a script segment on a per frame request basis.
Generally you should strive to think about processing whole clip segments rather than single frames.
Another option for your 1 FPS would be to use# Repeat each frame 30 times
SelectEvery(1, 0,0,0, 0,0,0, 0,0,0, 0,0,0, 0,0,0,
\ 0,0,0, 0,0,0, 0,0,0, 0,0,0, 0,0,0)Generally functions that multiply the number of frames should occur at the end of your script. Functions that number crunch on frames should where frames are the most reduced and unique (usually the middle). Functions that discard data (Crop, Select..., Decimate, PullDown, etc) should be near the begining of your script. This will minimise the amount of CPU need to render your clip. Eg...
ConvertToYUY2()
AssumeFPS(1.0)
ChangeFPS(25.0)is almost 25 times faster than...
AssumeFPS(1.0)
ChangeFPS(25.0)
ConvertToYUY2()In the first example each source frame is converted once to YUY2 format and that same frame is subsequently returned 25 times. In the second example each frame is converted 25 times.
Bob Wya
17th May 2006, 11:21
Hi
Thanks to IanB I got it working!!
It did almost work straight away but I got a video file that was 25x too long at first...
So I changed the script to:
ChangeFPS(1.0)
<processing>
DuplicateFrame(0)
ChangeFPS(Fr)
Trim(Round(Fr/2.0), 0)
Don't worry Ian I had already worked out the short cut with the processing :-) As I am using VagueDenoiser a lot I am always looking for a shortcut... and I did do a C.S. degree :cool:
Thanks for the advice about the type problem. So I if I corrected that problem with a type conversion would that function work?? (Naturally it would be very inefficient for processing purposes...)
Thanks guys :thanks:
B. Wya
vBulletin® v3.8.5, Copyright ©2000-2012, Jelsoft Enterprises Ltd.