OT: AviSynth Retime/Velocity + DeInt Combined?

fausseplanete wrote on 1/5/2012, 12:51 AM
There are AviSynth scripts for deinterlacing and for retiming (fps) and/or velocity (e.g. faux-slomo) but are there any that combine the two processes (deint + retime/velocity) into a single operation? In principle, each requires motion estimation, which eats CPU time etc., so it would be good if that was only done once then shared by both processes.

Comments

NickHope wrote on 1/5/2012, 8:05 AM
Here's how you might deinterlace and do slomo with QTGMC and MVtools2, lifted from a script I'm currently using a lot. The MVtools vectors created by QTGMC get re-used. There are 3 separate optional slomo lines in this script. Just use one of them and delete the others or comment them out with a #. You can of course adjust the ml value from the value of 100. I would try some extreme values to see what effect that has. 100 seems to work for me. More QTGMC help here. MVTools2 help here.

QTGMC( SubPel=2 )
super = MSuper(levels=1, pel=2)
#MFlowFps(super, QTGMC_bVec1, QTGMC_fVec1, num=60000, den=1001) #50% speed @ 29.97p output or 100% @ 59.94p
#MFlowFps(super, QTGMC_bVec1, QTGMC_fVec1, num=120000, den=1001, ml=100) #25% speed @ 29.97p output or 50% @ 59.94p
MFlowFps(super, QTGMC_bVec1, QTGMC_fVec1, num=73260, den=1001, ml=100) #num=60000/playback rate for 59.94p
fausseplanete wrote on 1/5/2012, 5:39 PM
Thanks a lot Nick, I'm definitely going to get into these and spread the word, especially to someone I know with a Canon 7D and maths/code flair (I have no such flair, more creative, but usually manage somehow).

David
fausseplanete wrote on 1/6/2012, 11:18 AM
Nick,

I managed to make your script work fine, thanks. It runs OK though it is a lot slower than my "stupid" (TDeint+MVTools2) script, at 1.0 fps as compared to 2.4 fps.

For reference, the script I ran was as follows. Its goal (whether or not I customized it correctly) is to take 1080i50 and generate 1080p100.


SetMTmode(mode=2, threads=2)

source = AVISource("EndPan 001.avi").KillAudio().assumetff().ConvertToYV12
final= Retime(source).assumefps(100.00, false).ConvertToRGB(matrix="Rec709", interlaced=false)
return final

function Retime(clip thisclip)
{
QTGMC(thisclip, SubPel=2 )
super = MSuper(levels=1, pel=2)
MFlowFps(super, QTGMC_bVec1, QTGMC_fVec1, num=100, den=1, ml=100)
}


Incidentally I'm running it on [MacBook Pro > Boot Camp > Windows 7], where the MacBook is Code 2 Duo.

Because it's so (necessarily) slow, and only one core's worth appeared to be executing (actually 60% cpu), I tried multi-threading. I installed everything right I think, because it still performs the basic function ok, but there is no sign of the extra core kicking-in. Script is described below. Any tips?

To install multithreading, I followed the instructions at As advised at http://forum.doom9.org/showthread.php?t=156028, including the SEt-2.6 version of AviSynth and the modded plugin-pack for QTGMC.

At the start of your script I added
SetMTmode(mode=1, threads=2) 


That worked OK from within AvsP (my preferred AviSynth script editor) but when I tried opening the [.avs] file in VirtualDub, the latter crashed. Changing the mode to 2 fixed that, then it played OK in VirtualDub. But no extra CPU effort seen - it was still only around 60% i.e. just over one core's worth.

Any thoughts (Nick or anybody)?
fausseplanete wrote on 1/6/2012, 11:35 AM
By putting
Preset="Medium"
in QTGMC, speed went up to 2.4 fps, same as my stupid script's speed. Default Preset is apparently "Slower", which is two notches down in speed.

Info on this was found at http://forum.doom9.org/showthread.php?t=156028

No idea yet how quality at that speed will compare to that from my stupid script.

Still only one core's-worth happening though.
NickHope wrote on 1/6/2012, 11:51 AM
I think you need SetMTmode 3. Also you can try adding and varying the edithreads setting in QTGMC. On my quad core Q6600 I have a script something like this:

SetMemoryMax(768)
SetMTMode(3, 4)

AviSource("E:\night\fs.avi")
AssumeBFF()

SetMTMode(2)

ConvertToYUY2(interlaced=true, matrix="Rec601")

QTGMC( Preset="Slower", SubPel=2, EdiThreads=2 )
super = MSuper(levels=1, pel=2)
MFlowFps(super, QTGMC_bVec1, QTGMC_fVec1, num=73260, den=1001, ml=100) #num=60000/playback rate

AssumeFPS(59.94)


There are faster modes to QTGMC if you need more speed. "Faster" works well for HD footage.

If you can't get that working then my best advice is to be brave and ask on that doom9 thread. The author -vit- is very helpful and will often put people right on other inconsistencies in their scripts without being asked.
fausseplanete wrote on 1/6/2012, 12:35 PM
Thanks Nick, I'm having a play with those settings and so far eked it up to 2.8 fps and 70% CPU, and Vegas still reads and uses the result just fine. I'll go visit the Wizard Temple as you suggest.

David
fausseplanete wrote on 1/6/2012, 2:07 PM
Yeehah!
Finally it's 100% CPU !

With this, "Slow" gives 2.1fps, "Fast" gives greater than 2.8fps.
Before this fix I claimed 2.8fps but really that was the max, average was more like 2.7. Now with 100% CPU it does 2.8fps average, more like 3fps maximum). Job done.

The magic fix:
All it lacked was a Distributor() (note the capital "D") function-call at the end of the script. I discovered that from example code at http://forum.doom9.org/showthread.php?t=156028, the post of 23rd January 2011 by "aegisofrime". No need to awaken the wizards just yet, I'll save that for later...

In case it helps anyone else, and for reference, the complete script that achieves 100% CPU for my system looks like the following.

SetMTmode(mode=3, threads=2)

AVISource("EndPan 001.avi").KillAudio().assumetff().ConvertToYV12

SetMTMode(mode=2)

QTGMC(SubPel=2, Preset="Fast")
super = MSuper(levels=1, pel=2)
MFlowFps(super, QTGMC_bVec1, QTGMC_fVec1, num=100, den=1, ml=100)

assumefps(100.00, false).ConvertToRGB(matrix="Rec709", interlaced=false)

Distributor()


Also it works inside a function definition, e.g. as follows:

SetMTmode(mode=3, threads=2)

source = AVISource("EndPan 001.avi").KillAudio().assumetff().ConvertToYV12

SetMTMode(mode=2)

final= DeintRetime(source).assumefps(100.00, false).ConvertToRGB(matrix="Rec709", interlaced=false)

return final


function DeintRetime(clip thisclip)
{
SetMTMode(mode=2)
QTGMC(thisclip, SubPel=2, Preset="Fast")
super = MSuper(levels=1, pel=2)
MFlowFps(super, QTGMC_bVec1, QTGMC_fVec1, num=100, den=1, ml=100)
Distributor()
}


Recap:The Purpose:

And finally to recap, what these scripts both achieve is to take 1080i50 footage and generate 1080p100 (with some degree of enhancement (denoise & edge) thrown in behind the scenes). Reason: to allow Vegas to produce a smoother result when slowing the velocity (e.g. by control-drag of event-edge or velocity-envelope (which in my case I am ramping-down progressively slower down to static over time).

It should also be useful to derive 30p footage from 25fps (25p or 50i), because 25fps is best for UK mains (traditional artificial lighting etc.) and 30fps is better for display on most computers nowadays, since they refresh at a 60Hz, which is a multiple of 30 but not 25.
fausseplanete wrote on 1/6/2012, 2:14 PM
...though it ("Distributor()") is not always to be used:

Whether or not to call Distributor() depends on how the client (encoder, player, etc) calls Avisynth. If it uses the VfW interface or if is MT-aware, you will end up calling it twice, creating twice as many threads.
(From http://forum.doom9.org/showthread.php?t=156028, post of 23rd January 2011 by "Gavino")

The client I was using was VirtualDub, 1.9.11, 32-bit.