Log in

View Full Version : Here's a semi-gradual slowmo function


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

Backwoods
15th December 2005, 02:16
I'm not recieving smooth results from this. I've tried 1440x1080i footage and when the slowmo effect comes in, there is a bouncing back and forth between frames it seems. I've stuck with the default settings too.

Your sample footage looks great though.

Fizick
18th December 2005, 21:12
I missed this topic. (Probably better would be post it to MVtools thread).
Gradual slow-motion? Interesting!
I must think about how it may be implemented as a plugin function.

Backwoods
18th December 2005, 22:33
I would be interested in seeing that.

mg262
18th December 2005, 22:47
I must think about how it may be implemented as a plugin function.How about this: have it take a clip and the name of a script function like

float slowmotion(int n)

that takes as input one frame number and returns a time -- so time 3.5 corresponds to interpolating halfway between frames 3 and 4. Then return interpolated frames as specified by the function.

Gradual slow motion seems like a pretty rarefied-use task... I don't mean to criticise the script, I'm just curious where it is turning up?

Mug Funky
19th December 2005, 11:28
actually, i was just asked if i could do this today...

it gives a nice "matrix-esque" effect of normal time slowing into "bullet time", or just provides a cheaper alternative to a remote-controllable, variable speed camera, which is quite hard to come by.

ShawnFumo
19th December 2005, 16:54
Wow.. people are actually commenting! It was a good experience to comment out my code so I could understand it later, but I'd just about given up hope on interest from others. ;)

Backwoods, if it is bouncing between frames, it is probably that the effect is too long for the in/out points. There's no safeguards in the script currently, so you have to do some calculating ahead of time. See this from the original post:
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.

Let me know if that helps or not. If not, post your script and I'll see if I can figure out what's going on.

mg262, as Mug mentioned, just a fancy pants effect to make things a bit more interesting than a simple cut to slwomo. :)

If your shooting subject can stop moving (and there isn't too much movement in the background), you could use this for a full on ghetto matrix rotation effect. What you could do is have normal movement, then have your subject freeze. Then walk around to another angle and have them resume motion. Then in post, you progressively slow down right until the moment the subject stops. Then you cut to double or triple speed motion along with some deshaking for the "bullet time angle change" and then as they start moving again, you cut back into slowmo which is gradually brought back to normal speed.

Fizick, you're right. I didn't think to post on the MVTools thread.. That would have made too much sense. :) That'd be awesome if it could be made as a plug-in function. As it is, my script is a pretty hack-ish solution.

I guess in a plugin, the best thing would be specifying the final speed and maybe an easing value. Then it interpolates based on the ease (like 0.5 is linear, less than spends more time nearer the old speed, and more spends more time nearer the new speed). Then someone could do a script which splits a video into three parts with normal speed at the start and slower speed at the end, using the plugin for the middle.

Or having optional parameters to specify start and end frames and start and end speeds would be cool to make things easier for people (if that is practical to have in a plugin).. That way you could do gradual slowdown and gradual speedup by only having to cut a clip in half (running the plugin once on each side). Like gradSlow(finalSpeed=0.5, ease=0.5) would be a linear transition from the original speed to half speed over the entire clip. Then gradSlow(startSpeed=0.5, finalSpeed=1, ease=0.75, in=50, out=100) would start at half speed and ease into normal speed starting at frame 50 with transitioning happening quicker toward frame 100, with normal speed until the end.

I just realized that it may be possible to pull this off in a script using MVFlowInter, but I'm not sure I'm capable of figuring that out. It'd certainly be more effecient as a plugin anyway.

I guess to be perfectly smooth, it'd have to somehow treat the clip as having infinite frames and use the original frames almost as keyframes. I'd guess where it'd get tricky is stuff like when it is around .75 of the original speed, so you might grab halfway between two frames and fourth of the way between the next two, and then right on that next frame (except by that time it'd probably be .70 or something so it'd be right before that frame), etc.

If you can pull off something like in a plugin Fizick, it would be epic! :) That'd be the equivilant of a really expensive type of commercial plugin.

Cheers,
Shawn

communist
19th December 2005, 18:41
but I'd just about given up hope on interest from others. ;)

No way. I had read the thread when you originally posted it but just didn have time to test it out (lack of proper material & time) - but your sample looks awesome. Further developement and implentation would just make it better.
I'm always looking out for cool stuff to improve DV footage.

Thanks for the function :)