ShawnFumo
3rd December 2005, 22:52
This a function for creating slow motion using a bit of gradual ease in and out. It currently just works for footage which starts interlaced and will become progressive after. One of the functions is based on scharfis_brain's interlaced slow motion function "changespeed".
First, to get the bad news out of the way. My function currently has a lot of limitations imposed on it. It isn't REALLY gradual. It works by splitting a clip into seven sections with a base speed and three additional speeds, to make the transition less jarrring. I felt this gave enough options without being too complex, but you can only do so much with it. This is why the function is called "step7slow" right now.
It also currently just works for normal speed and slower, not for speeding up a clip. Lastly, it works just with multiples of slowness (x2 slower, x3, x4, etc... no x1.5 times slower).
Usually you'd start with "initspd" being 1 to give normal speed for most of the clip. "transpda" and "transpdb" are the two transition speeds. "slowspd" is your slowest speed that you want for the focus of the effect.
"in" and "out" set the frames where you go from initspd to the other speeds. Keep in mind that this is based on the original clip's frame numbers, so even if you put initspd to be 2, it'll still happen in the same place of the footage.
"preview" if set to true will switch leakkernalbob to bob and mvflowfps2 to changefps. This is just to help if your computer is too slow to preview correctly (even if it is fast, the smoothness might not be quite right until you write out your final file, and that's even with no other filters).
"buffera" and "bufferb" control how long the two transition speeds last in frames. It works like the above in that it is length based on the original video. This means that if you select 6 frames for a transition at a slowmo of 3, it'll be 18 frames in the resulting video. Usually it is fine to use the same number for both transitions, because buffera will have less frames in the end, giving a more exponential increase in slowmo.
The main thing to be careful of is the relationship of the in/out and the two buffers. Let's say you have a video and you set the in point to 30 and the out point to 50 (20 frames of effect). If you set both buffers to 5, that gives you 10 frames of transition on the start and 10 at the end. That gives you no frames left for your final slow motion! In that case you'd need to lower the buffers or make the in/out points further apart. If your video is jumping all around at the transition points, you need to make sure you have enough frames allocated for everything.
"thresh" is for the threshold of the bobber. I'd try to set this as low as you can (maybe even 0), because any kind of combing that is left (and maybe even borders between the two sides of the thresh?) can create very bad artifacts in slower speeds. But experiment to your own taste.
"debug" just sticks on a subtitle showing you the speed at any given time to help you nudge your settings around a bit.
The function is especially good for something that suddenly starts and stops moving. Sudden motion will tend to mess up the interpolation at slower speeds but the x2 is using a bobber and so mostly immune to that at lower thresholds. 3x and higher is more dangerous since it is making up new frames from scratch. So you can set transpda to 2, have that part happen during the initial acceleration of your subject, and have your slowest speed once movement is relatively constant. That way you may be able to capture the entire motion without many artifacts.
Lastly, I'm still a newbie at stuff like mvtools and I made this for one kind of footage, so you may need to tweak the mvflowfps2 settings. What I have there is straight out of the docs. ;)
Here's an example of the function in use (see example1_xvid.avi on my site):
output = step7slow(myclip, in=58, out=88,
\initspd=1, transpda=2, transpdb=4, slowspd=8,
\buffa=6, buffb=6, thresh=0, debug=true)
This is a fairly smooth effect. Can change transpdb to 3 instead of 4 to make the 8 more noticable as super-slowmo if you'd like.. :)
30 frames from the original used in the effect (58 to 88).
24 for the transition (6+6+6+6) and 6 left for the slowest motion inbetween.
In the actual output, this becomes:
12 (6x2), 24 (6x4), 48 (6x8), 24, 12. So a total of 120 frames.
Here are the functions:
function step7slow(clip base, bool "preview", int "in", int "out",
\ int "initspd", int "transpda", int "transpdb", int "slowspd",
\ int "buffa", int "buffb", int "thresh", bool "debug") {
prv = default(preview, false)
dbg = default(debug, false)
in = default(in, 0)
out = default(out, 0)
initspd = default(initspd, 1)
transpda = default(transpda, 2)
transpdb = default(transpdb, 3)
slowspd = default(slowspd, 4)
inc1 = round(default(buffa, 6))
inc2 = inc1+round(default(buffb, 6))
thresh = default(thresh, 0)
clipa = changespeed(base, 0, in, initspd, thresh, prv, dbg)
clipb = nofirst(changespeed(base, in, in+inc1, transpda, thresh, prv, dbg))
clipc = nofirst(changespeed(base, in+inc1, in+inc2, transpdb, thresh, prv, dbg))
clipd = nofirst(changespeed(base, in+inc2, out-inc2, slowspd, thresh, prv, dbg))
clipe = nofirst(changespeed(base, out-inc2, out-inc1, transpdb, thresh, prv, dbg))
clipf = nofirst(changespeed(base, out-inc1, out, transpda, thresh, prv, dbg))
clipg = nofirst(changespeed(base, out, 0, initspd, thresh, prv, dbg))
return clipa+clipb+clipc+clipd+clipe+clipf+clipg
}
function nofirst(clip base) {
return trim(base, 1, 0)
}
function changespeed(clip base, int in, int out, int factor, int thresh, bool prv, bool debug)
{
in = in*factor
out = out*factor
frate = round(base.framerate)
base = prv?Bob(base) : LeakKernelBob(base, 0, threshold=thresh)
base = assumefps(base, frate)
# compensate for bob doubling
factoradj = factor/2.0
# speed label currently tied to previewing
base = debug ? base.subtitle(string(factor)+"x SlowMo") : base
backward_vec = prv?nop(): base.MVAnalyse(isb = true, truemotion=true, pel=2, idx=1)
forward_vec = prv?nop(): base.MVAnalyse(isb = false, truemotion=true, pel=2, idx=1)
cropped = prv?nop(): base.crop(4,4,-4,-4)
backward_vec2 = prv?nop(): cropped.MVAnalyse(isb = true, truemotion=true, pel=2, idx=2)
forward_vec2 = prv?nop(): cropped.MVAnalyse(isb = false, truemotion=true, pel=2, idx=2)
newfps = round(frate*factoradj)
base = prv? changefps(base, newfps) :
\MVFlowFps2(base, backward_vec,forward_vec,backward_vec2,forward_vec2,num=newfps,idx=1,idx2=2)
base = assumefps(base, frate)
base = trim(base, in, out)
return base
}
You can grab the function and an example here:
http://www.yoyoing.com/shawn/videofiles/avisynth
I still need to go through the code and document it a bit more, but this should basically work right now. The example file is 1pass xvid at 3k bitrate. Check it out and tell me what you think!
Shawn
First, to get the bad news out of the way. My function currently has a lot of limitations imposed on it. It isn't REALLY gradual. It works by splitting a clip into seven sections with a base speed and three additional speeds, to make the transition less jarrring. I felt this gave enough options without being too complex, but you can only do so much with it. This is why the function is called "step7slow" right now.
It also currently just works for normal speed and slower, not for speeding up a clip. Lastly, it works just with multiples of slowness (x2 slower, x3, x4, etc... no x1.5 times slower).
Usually you'd start with "initspd" being 1 to give normal speed for most of the clip. "transpda" and "transpdb" are the two transition speeds. "slowspd" is your slowest speed that you want for the focus of the effect.
"in" and "out" set the frames where you go from initspd to the other speeds. Keep in mind that this is based on the original clip's frame numbers, so even if you put initspd to be 2, it'll still happen in the same place of the footage.
"preview" if set to true will switch leakkernalbob to bob and mvflowfps2 to changefps. This is just to help if your computer is too slow to preview correctly (even if it is fast, the smoothness might not be quite right until you write out your final file, and that's even with no other filters).
"buffera" and "bufferb" control how long the two transition speeds last in frames. It works like the above in that it is length based on the original video. This means that if you select 6 frames for a transition at a slowmo of 3, it'll be 18 frames in the resulting video. Usually it is fine to use the same number for both transitions, because buffera will have less frames in the end, giving a more exponential increase in slowmo.
The main thing to be careful of is the relationship of the in/out and the two buffers. Let's say you have a video and you set the in point to 30 and the out point to 50 (20 frames of effect). If you set both buffers to 5, that gives you 10 frames of transition on the start and 10 at the end. That gives you no frames left for your final slow motion! In that case you'd need to lower the buffers or make the in/out points further apart. If your video is jumping all around at the transition points, you need to make sure you have enough frames allocated for everything.
"thresh" is for the threshold of the bobber. I'd try to set this as low as you can (maybe even 0), because any kind of combing that is left (and maybe even borders between the two sides of the thresh?) can create very bad artifacts in slower speeds. But experiment to your own taste.
"debug" just sticks on a subtitle showing you the speed at any given time to help you nudge your settings around a bit.
The function is especially good for something that suddenly starts and stops moving. Sudden motion will tend to mess up the interpolation at slower speeds but the x2 is using a bobber and so mostly immune to that at lower thresholds. 3x and higher is more dangerous since it is making up new frames from scratch. So you can set transpda to 2, have that part happen during the initial acceleration of your subject, and have your slowest speed once movement is relatively constant. That way you may be able to capture the entire motion without many artifacts.
Lastly, I'm still a newbie at stuff like mvtools and I made this for one kind of footage, so you may need to tweak the mvflowfps2 settings. What I have there is straight out of the docs. ;)
Here's an example of the function in use (see example1_xvid.avi on my site):
output = step7slow(myclip, in=58, out=88,
\initspd=1, transpda=2, transpdb=4, slowspd=8,
\buffa=6, buffb=6, thresh=0, debug=true)
This is a fairly smooth effect. Can change transpdb to 3 instead of 4 to make the 8 more noticable as super-slowmo if you'd like.. :)
30 frames from the original used in the effect (58 to 88).
24 for the transition (6+6+6+6) and 6 left for the slowest motion inbetween.
In the actual output, this becomes:
12 (6x2), 24 (6x4), 48 (6x8), 24, 12. So a total of 120 frames.
Here are the functions:
function step7slow(clip base, bool "preview", int "in", int "out",
\ int "initspd", int "transpda", int "transpdb", int "slowspd",
\ int "buffa", int "buffb", int "thresh", bool "debug") {
prv = default(preview, false)
dbg = default(debug, false)
in = default(in, 0)
out = default(out, 0)
initspd = default(initspd, 1)
transpda = default(transpda, 2)
transpdb = default(transpdb, 3)
slowspd = default(slowspd, 4)
inc1 = round(default(buffa, 6))
inc2 = inc1+round(default(buffb, 6))
thresh = default(thresh, 0)
clipa = changespeed(base, 0, in, initspd, thresh, prv, dbg)
clipb = nofirst(changespeed(base, in, in+inc1, transpda, thresh, prv, dbg))
clipc = nofirst(changespeed(base, in+inc1, in+inc2, transpdb, thresh, prv, dbg))
clipd = nofirst(changespeed(base, in+inc2, out-inc2, slowspd, thresh, prv, dbg))
clipe = nofirst(changespeed(base, out-inc2, out-inc1, transpdb, thresh, prv, dbg))
clipf = nofirst(changespeed(base, out-inc1, out, transpda, thresh, prv, dbg))
clipg = nofirst(changespeed(base, out, 0, initspd, thresh, prv, dbg))
return clipa+clipb+clipc+clipd+clipe+clipf+clipg
}
function nofirst(clip base) {
return trim(base, 1, 0)
}
function changespeed(clip base, int in, int out, int factor, int thresh, bool prv, bool debug)
{
in = in*factor
out = out*factor
frate = round(base.framerate)
base = prv?Bob(base) : LeakKernelBob(base, 0, threshold=thresh)
base = assumefps(base, frate)
# compensate for bob doubling
factoradj = factor/2.0
# speed label currently tied to previewing
base = debug ? base.subtitle(string(factor)+"x SlowMo") : base
backward_vec = prv?nop(): base.MVAnalyse(isb = true, truemotion=true, pel=2, idx=1)
forward_vec = prv?nop(): base.MVAnalyse(isb = false, truemotion=true, pel=2, idx=1)
cropped = prv?nop(): base.crop(4,4,-4,-4)
backward_vec2 = prv?nop(): cropped.MVAnalyse(isb = true, truemotion=true, pel=2, idx=2)
forward_vec2 = prv?nop(): cropped.MVAnalyse(isb = false, truemotion=true, pel=2, idx=2)
newfps = round(frate*factoradj)
base = prv? changefps(base, newfps) :
\MVFlowFps2(base, backward_vec,forward_vec,backward_vec2,forward_vec2,num=newfps,idx=1,idx2=2)
base = assumefps(base, frate)
base = trim(base, in, out)
return base
}
You can grab the function and an example here:
http://www.yoyoing.com/shawn/videofiles/avisynth
I still need to go through the code and document it a bit more, but this should basically work right now. The example file is 1pass xvid at 3k bitrate. Check it out and tell me what you think!
Shawn