PDA

View Full Version : interlaced slow motion


HighInBC
27th June 2004, 23:44
Ok I am trying to make a routine that takes DV footage and makes a slow-motion scene without damaging the interlacing... this is what I have made:

function interlaced_speed_change (clip clip, float speed)
{
o_fps = Framerate(clip)
n_fps = o_fps / speed
clip = clip.SeparateFields
odd = clip.SelectOdd.ConvertFPS(n_fps)
evn = clip.SelectEven.ConvertFPS(n_fps)
master = Interleave(evn,odd).AssumeFPS(o_fps).Weave().DoubleWeave.SelectOdd().Info
return master
}

and it is called like so: interlaced_speed_change(Trim(bulk,2142,2277),.333)

for approx 1/3 speed.

This is all fine and well, but this strangeness happens with avisynth when it gets past frame 46, it crashes.. says: caught in access violation at 0x01336990, attempting to read from.......

this happens no matter which portion of the video I put into the routine. and it happens when I seek past frame 46 using a media player, vdub, or even the Trim command in avisynth... Also if I return 'evn' or return 'odd' then I get the entire clip, not jsut to 46... soo I assume it has somthing to do with the 'master=' line, which worked perfectly in my interlaced_dissolve clip.

am I making a fundemental error? or have I invoked an avisynth strangeness?

I do need to do slow motion without damaging interlacing, so if anyone knows a better way than this routine please tell me.

scharfis_brain
28th June 2004, 00:10
(2 instances changefps() and fieldseparated video does not work for unknow reasons... I've gotten such weirdness in past, too)

this is much easier to achieve with a full framerate deinterlacer (bobber) like kerneldeint.

my script to do so:

loadplugin("C:\x\kerneldeint140.dll")
loadplugin("C:\x\mvtools.dll") #be sure to get mvtools 0.9.2.2

function changespeed(clip a, float factor, int mode, int th)
{

ord = getparity(a) ? 1 : 0
f=a.kerneldeint(order=ord, sharp=false, twoway=false, threshold=th)
e=a.separatefields.trim(1,0).weave.kerneldeint(order=1-ord, sharp=false, twoway=false, threshold=th)
interleave(f,e).assumeframebased
converttoyuy2()

(mode == 0) ? changefps(framerate*factor) : (mode == 1) ? convertfps(framerate*factor) : converttoyv12().mvconvertfps(fps=framerate*factor).converttoyuy2()
assumefps(a.framerate*2,true)
separatefields()
(ord==0) ? selectevery(4,0,3) : selectevery(4,1,2)
weave()

}

avisource("doom9.avi")
assumebff()

changespeed(1.0, 0, 8)

changespeed(1.0, 0 ,8) does nothing (exept wasting CPU cycles)

changespeed(1.5, 0, 8) slows down 1.5 times, using frame duplication

changespeed(1.5, 1, 8) slows down 1.5 times, using weighted frame blending

changespeed(1.5, 2, 8) slows down 1.5 times, using motion compensated frame interpolation (motion will stay smooth)

changespeed(0.5, 0, 8) speeds up 2 times

the last number (here 8) sets up the deinterlacing threshold.
lowering it will reduce combing (motion) artifacts, rasing it will lower flickering artifacts.

HighInBC
28th June 2004, 01:50
you rock, thank you... nice to know my theary was corret and it was just an avisynth strangness... this should be fixxed as the events leading up the error can be very common.

HighInBC
28th June 2004, 03:57
wow, that is a tricky script... good thing I use alot of (a ? b : c) in my perl scripting or I would not be able to grasp it...

as it is, it looks nice, and I can grasp it, and it seems as tho it would work in all sorts of strange situations. did you develop the routine after reading my question, or did you have it before?

scharfis_brain
28th June 2004, 07:31
I've done this kiind of speedup/slowdown earlier but it wasn't built into an AVS function.

I've just written down it out of my head within some minutes...
Tested it a little bit, and now you have the ultimative speed-changer for AVS :)

HighInBC
28th June 2004, 22:54
where do I get 'mvtools.dll version 0.9.2.2'?

scharfis_brain
7th July 2004, 12:10
Get it here: http://jourdan.madism.org/~manao/

Valky
24th January 2005, 14:22
Originally posted by scharfis_brain
(2 instances changefps() and fieldseparated video does not work for unknow reasons... I've gotten such weirdness in past, too)

this is much easier to achieve with a full framerate deinterlacer (bobber) like kerneldeint.

my script to do so:

loadplugin("C:\x\kerneldeint140.dll")
loadplugin("C:\x\mvtools.dll") #be sure to get mvtools 0.9.2.2

function changespeed(clip a, float factor, int mode, int th)
{

ord = getparity(a) ? 1 : 0
f=a.kerneldeint(order=ord, sharp=false, twoway=false, threshold=th)
e=a.separatefields.trim(1,0).weave.kerneldeint(order=1-ord, sharp=false, twoway=false, threshold=th)
interleave(f,e).assumeframebased
converttoyuy2()

(mode == 0) ? changefps(framerate*factor) : (mode == 1) ? convertfps(framerate*factor) : converttoyv12().mvconvertfps(fps=framerate*factor).converttoyuy2()
assumefps(a.framerate*2,true)
separatefields()
(ord==0) ? selectevery(4,0,3) : selectevery(4,1,2)
weave()

}

avisource("doom9.avi")
assumebff()

changespeed(1.0, 0, 8)

changespeed(1.0, 0 ,8) does nothing (exept wasting CPU cycles)

changespeed(1.5, 0, 8) slows down 1.5 times, using frame duplication

changespeed(1.5, 1, 8) slows down 1.5 times, using weighted frame blending

changespeed(1.5, 2, 8) slows down 1.5 times, using motion compensated frame interpolation (motion will stay smooth)

changespeed(0.5, 0, 8) speeds up 2 times

the last number (here 8) sets up the deinterlacing threshold.
lowering it will reduce combing (motion) artifacts, rasing it will lower flickering artifacts.

Thank you very much for this script. Just what I was looking for and newbie like me understands your guide for settings.
I was wondering how can I use this on particular frames (how to use trim function ie frames 900-1025) and how does this affect on audio?
Also I noticed that VD didn't load my audio in avs-script when using avisource so I have to search somewhere how to add that too (my content is dv-type1).

Btw, video looked like interlaced. I thought that this script produces de-interlaced video?

HighInBC
24th January 2005, 16:16
To affect just some frames

clip.Trim(900,1025),ChangeSpeed(....)

This will return just those clips changed in speeds, then use the ++ operator to join the sections you did not want changed.

To change the speed of audio without pitch distortions use the timestretch command:

put "sound = a.TimeStretch(tempo=((1/factor)*100))"
at the beggining, and:

"AudioDub(sound)"
at the end.

Valky
24th January 2005, 17:24
Originally posted by HighInBC
To affect just some frames

clip.Trim(900,1025),ChangeSpeed(....)

This will return just those clips changed in speeds, then use the ++ operator to join the sections you did not want changed.

To change the speed of audio without pitch distortions use the timestretch command:

put "sound = a.TimeStretch(tempo=((1/factor)*100))"
at the beggining, and:

"AudioDub(sound)"
at the end.

This audio-thing went straight over my head.
I dont know avisynth well enough to know what you
are trying to say, but thanks for trying :)

At least I got the video working like I wanted using this script (without audio...):

avisource("e:\dv\testi.avi")
a=trim(0,965)
b=trim(965,1025).assumebff().changespeed(3.0, 0, 8)
c=trim(1026,1556)
d=a+b+c
return(d)

Now if I only could insert original audio to the part a and c and mute it in slow motion part or at least slow it in that part so that I get the audio in my final video.

Tio
16th September 2005, 07:43
Q1 - scharfis_brain's "changespeed" function works well except when attempting to uses mode "2" (motion compensated frame interpolation). I am assuming this is due to my using MaskTools_1.5.1.0. Does it no longer include the required "mvconvertfps"?

While on the subject of the "changespeed" function...anyone see a reason why "KernelDeint" could not be replaced with "LeakKernelDeint"? Just don't want to be unpleasantly surprised.

Q2 - Valky! How did you get that script to allow a segmented slow-motion request? My attempts keep failing. I was also advised that mixed framerates are illegal in an avs script.

Regards,
Tio

foxyshadis
16th September 2005, 09:38
Tio -
1. mvtools and masktools are entirely different filters. You can find both on that page.
1a. The simple API this function uses is fully compatible with Leak's.
2. changespeed does not change the fps, it inserts or removes frames as necessary, but more intelligently than my earlier lame suggestion. ;p

Thanks for digging this up, I should save that script.

Edit: You might need to use one of the old versions, since later versions changed a lot of the internals. In particular, 0.9.5 was current when this thread was hot.

Tio
16th September 2005, 11:34
@foxyshadis
Thanks for tagging along and setting me on the straight and narrow again regarding the items listed above. ;-)

Me thinks the frustration factor blinded me to the fact I was looking at two completely different filters. I can verify though that the latest "mvtools" is different from the one suggested by scharifs_brain and will not work with the "changespeed" function. The earlier one is 5kb larger so I am guessing that functionality may have been removed.

I might also add that now being able to use that mode has stunned me. The output looks great but getting there is a trial of patience. I usually encode HD material at 6fps but using mode 2 on this function/filter I get 3spf (seconds per frame)! Thankfully I am only encoding 3 seconds of slo-motion.

Appreciate all your input!

Tio
17th September 2005, 07:46
Reference: 1088i to XviD/AVI 1280x720 via AVISynth/V'Dub for PC playback.

I'm having some trouble implementing motion compensation (mode=2) in the "changespeed" function/filter. It introduces major combing artifacts no matter what deinterlacing threshold value (0-8) I use. Mode=0 and mode=1 work fine and I can effect a noticable change varying the deinterlacing threshold in conjunction with them.

My 1088i source is processed through DGIndex with field operation in forced film mode. I also processed one without forced film and then added telecide.decimate to my avs. Both produce the combing artifacts noted above.

Suggestions appreciated. If more info is required please let me know. ;-)

Thanks