View Full Version : ChangeSpeed(): Fast motion...
joshbm
18th August 2004, 03:55
Right now I was wondering how I could take a video and speed up the video without changing the FPS on the video. The trick is I want something like so:
ChangeSpeed(orig_percent, change_percent, frames)
orig_percent: This is the original percent for the video.
default: 100%
change_percent: This is the percent to change to from the orig_percent value.
default: 200%
frames: Number of frames.
default: number of frames in clip.
Here is an example:
ChangeSpeed(orig_percent=100,change_percent=400,frames=560)
What that would do is within 560 frames it would create a motion transition from 100% to 400% so what in reality it would do is take a video and make it faster gradually to 400%.
I am not talking about immediately to 400%, making the entire video 400%, but starting at frame 1 with orig_percent (100 in this case) and increasing it until frame 560 at change_percent (400 percent in this case). Everything beyond 560 would be 400% as well. If frames was not specified then it would simply take the entire length of the clip to gradually increase to 400% speed.
That would be perfect. I do not need a deinterlacer built into it, because I am using bobmatcher as well as dgbob as an overlay at 30% opacity. So I'm good with that and I am pleased with the results. Which brings me to 60p or 30p using Decimate(2).
If someone could help me find or code something like this, that would be awesome!
Thanks!
- joshbm
joshbm
18th August 2004, 04:39
I believe this is my start on the script:
function ChangeSpeed(clip a, int orig_percent, int change_percent, int frames)
{
frames = default(frames,a.framecount)
orig_percent = default(orig_percent,100)
change_percent = default(change_percent,200)
# Etc... Script in developement still
}
scharfis_brain
18th August 2004, 05:02
look at the Function, I posted there : http://forum.doom9.org/showthread.php?s=&threadid=78808&highlight=changespeed%2A
joshbm
18th August 2004, 07:53
Okay great! That's a great start, except now I want to gradually slow down/speed up the video.
I have modified my script to fit yours:
function ChangeSpeed(clip a, float "orig_percent", float "change_percent", int "frames", int "mode")
{
frames = default(frames,a.framecount)
orig_percent = default(orig_percent,100)
change_percent = default(change_percent,200)
ord = getparity(a) ? 1 : 0
orig_framerate = framerate(a)
percent_change = (change_percent>orig_percent) ? (change_percent/orig_percent) : (orig_percent/change_percent)
new_framerate = (change_percent>orig_percent) ? (orig_framerate/percent_change) : (orig_framerate*percent_change)
newmode = (percent_change<1) ? 2 : 0
mode = default(mode,newmode)
#debug
#Subtitle(String(var))
#process the video
clipa=a.ConverttoYUY2
clipa=(mode == 0) ? clipa.changefps(new_framerate) : (mode == 1) ? clipa.convertfps(new_framerate) : clipa.converttoyv12.mvconvertfps(fps=new_framerate).converttoyuy2
clipa=clipa.assumefps(orig_framerate,true)
return clipa
}
All I need now is to like I said find out how to start at 100% and gradually increase to 400%.
Thanks
- joshbm
joshbm
18th August 2004, 07:58
Any ideas?
Wilbert
18th August 2004, 09:52
This should be possible with Animate
http://www.avisynth.org/Animate
# changespeed(1, 0, 8) # at 100%
# changespeed(0.25, 0, 8) # at 400%
clip = ...
Animate(0, 149, "changespeed", clip, 1, 0, 8, clip, 0.25, 0, 8)
didn't try it though.
scharfis_brain
18th August 2004, 15:33
hm.. no time now, but wilberts idea seems to be a good start, but it will not work, caus it will destroy the interlacing.
I'll test the later.
sh0dan
18th August 2004, 17:45
I think you are playing with fire here. ;)
In principle this shouldn't be possible, since there is no way to assure you get the correct framecount - or at best the correct frames.
AFAICT there is no way to do a gradual slowdown/speedup in AviSynth. I think a plugin would have to be written, for you yo do this.
joshbm
18th August 2004, 18:03
I have already deinterlaced the source to from 60i to 60p. So I have no problems with screwing up interlacing.
scharfis_brain
18th August 2004, 18:19
hehe, indeed, it IS fire.
a short test like this, will show:
a=last
animate(1,200,"changefps",a,3,a,30)
sh0dan
18th August 2004, 18:23
Originally posted by scharfis_brain
hehe, indeed, it IS fire.
Funny effect, though ;)
joshbm
18th August 2004, 20:27
So it does work then? changefps?
Well how could I incorporate it with your script? Thanks!
scharfis_brain
19th August 2004, 05:08
just try that line, and see yourself
Didée
19th August 2004, 07:40
Originally posted by sh0dan
In principle this shouldn't be possible, since there is no way to assure you get the correct framecount - or at best the correct frames.
AFAICT there is no way to do a gradual slowdown/speedup in AviSynth. I think a plugin would have to be written, for you yo do this.
For sure a plugin would be the best solution, no doubt.
But what about using SelectEvery() inside of ScriptClip() & Co.? There, one could call SelectEvery() with per-frame-variable parameters, based on current frame number.
BTW, the audio could be rather easily processed to stay in-synch through CoolEdit, as it offers the possibility to do sliding pitch/speed changes.
This should be possible to do. (However I won't do it - I'm preparing a trip to POV-Ray land :) )
- Didée
joshbm
19th August 2004, 15:37
Thanks guys for all of your replies! Out of this I have created 2 functions (which I wanted to combine both, but they happen to be separate):
function ChangeSpeed(clip a, float "percent", int "mode", float "fps", float "frames", float "seconds")
{
a.AssumeFrameBased()
percent=default(percent,0)
fps=default(fps,framerate(a))
seconds=default(seconds,0)
frames=default(frames,a.framecount)
ord=getparity(a) ? 1 : 0
fpsdiv=framerate(a)/1./fps
defpercent=(1./fpsdiv)*100
getframes=(seconds==0) ? frames*fpsdiv : seconds*framerate(a)
percent=(percent==0) ? (a.framecount/1./getframes)*100 : percent
percent=(percent==0) ? defpercent : Abs(percent)
original_percent=percent
percent=float(percent*fpsdiv)
percent_change=(percent/100.)
new_framerate=(framerate(a)/1./percent_change)
newmode=(percent_change<1) ? 2 : 0
mode=default(mode,newmode)
clipa=a.ConverttoYUY2(interlaced=false)
clipa=(round(percent)!=100) ? (mode == 0) ? clipa.changefps(new_framerate) : (mode == 1) ? clipa.convertfps(new_framerate) : clipa.converttoyv12(interlaced=false).mvconvertfps(fps=new_framerate).converttoyuy2(interlaced=false) : clipa
clipa=clipa.assumefps(framerate(a)/1./fpsdiv)
return clipa
}
function AnimateSpeed(clip a, float "orig_percent", float "change_percent", float "fps", float "start_frame",float "end_frame")
{
a.AssumeFrameBased()
orig_percent=default(orig_percent,100)
fps=default(fps,framerate(a))
start_frame=default(start_frame,framecount(a))
end_frame=default(end_frame,1)
fpsdiv=framerate(a)/1./fps
defpercent=(1./fpsdiv)*100
change_percent=default(change_percent,defpercent)
change_percent=change_percent*fpsdiv
orig_percent=orig_percent*fpsdiv
framerate1=(framerate(a)/1./(orig_percent/100.))
framerate2=(framerate(a)/1./(change_percent/100.))
return animate(end_frame,start_frame,"changefps",a,framerate1,a,framerate2).assumefps(framerate(a)/1./fpsdiv)
}
ChangeSpeed
percent: The speed of the clip in percent.
default: Checks if frames and seconds are present, if neither are present then it auto-detects based on "fps" (see animate speed "change_percent").
mode: Method for slowing down or speeding up. 0=changefps, 1=convertfps, 2=mvconvertfps
default: auto-detect-- best method
fps: Desired frames per second.
default: Input (clip a) framerate.
frames: Instead of entering percent or seconds, you can enter a desired amount of frames, which will result in the video slowing down or speeding up to accomodate this value.
default: Checks if seconds are present, if none are present 0
seconds: Instead of entering percent or frames, you can enter a desired amount of seconds, which will result in the video slowing down or speeding up to accomodate this value.
default: 0
Example:
ChangeSpeed(percent=20,fps=23.976)
#It would slow the clip down 20% and convert to 23.976 fps.
AnimateSpeed
orig_percent: The starting percent.
default: 100
change_percent: The ending percent.
default: Auto-detects to framerate. Ex. If framerate input is 60p and the "fps" is set to 24p, this value is 40% (24/60).
fps: The desired frames per second.
default: Input (clip a) framerate.
start_frame: Start at frame number "start_frame".
default: 1
end_frame: End at frame number "end_frame".
default: Total frames in input clip (framecount).
Example:
AnimateSpeed(orig_percent=100,change_percent=20,fps=23.976)
#The clip would start at 100% and gradually slow to 20%, and converted to 23.976 fps.
Whew... Those are the two functions I have been working on. I was hoping I could use mvconvertfps with AnimateSpeed, but this will have to do for now.
Thanks all!
- joshbm
vBulletin® v3.8.11, Copyright ©2000-2026, vBulletin Solutions Inc.