Log in

View Full Version : Bumping up performance for my timelapse scripts


tsk1979
14th November 2022, 09:07
Hello
I create timelapse videos by stiching together still images. Since most of these frames are 30s each, hours of shooting will give me few seconds of video. I use fastdoubler function which a very helpful user here gave me. The problem I see with my script when used in virtualub2 with latest avisynth is that I just get 1 FPS with my intel i5 8600K desktop whcih has 32GB of RAM.


What could I do better to get atleast 4-5 FPS?

I am encoding ffmpeg x265, but pretty much most encoders give me this time.
I am attaching the "perf" tab. My CPU usage is 20-30%

18244

LoadPlugin("D:\Program Files\avisynth64plugins\mvtools2.dll")

#.ConvertToRGB24()

#Blank for intro
titleblank=blankclip(length=72,fps=24,height=2160,width=3840).KillAudio().ConvertToYUY2()
blank=blankclip(length=24,fps=24,height=2160,width=3840).KillAudio().ConvertToYUY2()
#Saggitarious rising
a1=FastDoubler(Imagesource(".....\images\a-%d.jpg", 1, 276, 12).ConvertToYUY2()).Lanczos4Resize(3840,2160)
#Mount Shasta tracking mount
a2=FastDoubler(Imagesource(".....\xyz-%d.jpg", 1, 124, 12).ConvertToYUY2()).Lanczos4Resize(3840,2160)
#Austin Nevada long milky way timelapse with tent
a3=...
a4=...
...
a10
Dissolve(titleblank,a1,a2,a3,a4,a5_1,a5_2,a6,a7,a8,a9,a10,10)
#
function FastDoubler(clip C)
{
C # Last=C
super=MSuper(pel=2, hpad=0, vpad=0, rfilter=4)
MBlockFps(super,
\ MRecalculate(super,
\ MRecalculate(super,
\ MAnalyse(super,
\ blksize=16, search=3, searchparam=2,
\ plevel=0, badrange=(-24), isb=true),
\ blksize=8, searchparam=0, search=3),
\ blksize=4, searchparam=0, search=3),
\ MRecalculate(super,
\ MRecalculate(super,
\ MAnalyse(super,
\ blksize=16, search=3, searchparam=2,
\ plevel=0, badrange=(-24), isb=false),
\ blksize=8, searchparam=0, search=3),
\ blksize=4, searchparam=0, search=3),
\ num=FramerateNumerator*2, den=FramerateDenominator, mode=2)
return Last
}

VoodooFX
14th November 2022, 09:58
Read this thread on image posting: https://forum.doom9.org/showthread.php?t=183538

Can you share ~10 images from a1 and a2? You can upload to https://wetransfer.com

tsk1979
14th November 2022, 17:05
Read this thread on image posting: https://forum.doom9.org/showthread.php?t=183538

Can you share ~10 images from a1 and a2? You can upload to https://wetransfer.com

I uploaded images to my smugmug gallery. Originals can be downloaded
https://tanveer.smugmug.com/Other/temp/Doom9-test-images/n-RsKdHT/

johnmeyer
14th November 2022, 17:05
For faster script performance with MVTools2, read these forums to learn how to use multi-threading. Depending on your computer and your script, it should give you a 3-5 times speed increase.

I don't know what version of AVISynth you are using, but it might be as easy as adding:
Prefetch(4)on the line immediately after your Dissolve statement. "4" indicates the number of threads you want to use. For stability (multi-thread sometimes crashes), start with a number that is half the number of cores in your computer.

VoodooFX
14th November 2022, 21:26
This runs twice faster than your script:


titleblank=blankclip(length=72,fps=24,height=2160,width=3840, pixel_type="YV12").KillAudio()
# crop(0,0,0,-1) for a1 because height of images is odd number
a1=Imagesource("...\a1\a-%d.jpg", 1, 10, 12).crop(0,0,0,-1).ConvertToYV12().Lanczos4Resize(3840,2160).InterFrame(Preset="Faster", Cores=1, FrameDouble=true)
a2=Imagesource("...\a2\a-%d.jpg", 1, 10, 12).ConvertToYV12().Lanczos4Resize(3840,2160).InterFrame(Preset="Faster", Cores=1, FrameDouble=true)
Dissolve(titleblank,a1,a2,10)
Prefetch(4)


You can lower x265 preset to make it faster [probably].

tsk1979
15th November 2022, 00:52
Thanks.
Prefetch made me go to 3.5fps from 1.5fps!

Question about "FrameDouble=true"

This does the same thing as my special function (mvtools2 function) does?

VoodooFX
15th November 2022, 00:57
his does the same thing as my special function (mvtools2 function) does?
Yes .

johnmeyer
15th November 2022, 02:37
Thanks.
Prefetch made me go to 3.5fps from 1.5fps!Do you know how many cores your computer has (you can find out with Windows Task Manager). You can try using a number larger than 4 as the argument to Prefetch(). Just don't enter a number that is larger than your number of cores.

You should also read the documentation for multi-threading:

http://avisynth.nl/index.php/SetFilterMTMode

Note that you can "tune" the multi-threading for the particular plugins and, once you have figured that out, you can save all the settings in your autoload folder, as described in the link above.

It's been a long time since I did any work on this, but I think these are the correct MT modes for MVTools2:

SetFilterMTMode("MDegrain2", MT_MULTI_INSTANCE)
SetFilterMTMode("MSuper", MT_MULTI_INSTANCE)
SetFilterMTMode("MAnalyse", MT_MULTI_INSTANCE)
SetFilterMTMode("MFlowFps", MT_MULTI_INSTANCE)
SetFilterMTMode("MRecalculate", MT_MULTI_INSTANCE)

I don't know if this will further increase the script speed, but doing this, plus playing around with Prefetch may give you some additional performance. Your slightly better than 2X speed improvement is obviously a big deal, but I would have expected 3x or even 4x. Having said that, MVTools2 may not be the biggest bottleneck and the other DLLs may not work with multi-threading (although you should look to see if you can search and find the SetFilterMTMode settings for the other DLLs).

Reel.Deel
15th November 2022, 03:17
It's been a long time since I did any work on this, but I think these are the correct MT modes for MVTools2:

Pinterf's MVTools2 is self registering so there's no need to define the MT modes yourself. They just get ignored if you do set them, unless you force a mode. Internally all MVTools2 filters self register as MT_MULTI_INSTANCE except MAnalyse when temporal is set to true or outfile is used, in that case it self registers as MT_SERIALIZED.

johnmeyer
15th November 2022, 03:34
OK, listen to Reel.Deel because he knows more than I do. Also, I am a Luddite and am probably using a version of AVISynth that was written when people like me were still using paper tape and punch cards.

kedautinh12
15th November 2022, 03:56
Yes, Reel.Deel is library of avs :D

tsk1979
15th November 2022, 06:20
This runs twice faster than your script:


titleblank=blankclip(length=72,fps=24,height=2160,width=3840, pixel_type="YV12").KillAudio()
# crop(0,0,0,-1) for a1 because height of images is odd number
a1=Imagesource("...\a1\a-%d.jpg", 1, 10, 12).crop(0,0,0,-1).ConvertToYV12().Lanczos4Resize(3840,2160).InterFrame(Preset="Faster", Cores=1, FrameDouble=true)
a2=Imagesource("...\a2\a-%d.jpg", 1, 10, 12).ConvertToYV12().Lanczos4Resize(3840,2160).InterFrame(Preset="Faster", Cores=1, FrameDouble=true)
Dissolve(titleblank,a1,a2,10)
Prefetch(4)


You can lower x265 preset to make it faster [probably].


Hi
I downloaded the plugins and tried running with this new function InterFrame


18245

My script header

LoadPlugin("D:\Program Files\avisynth64plugins\mvtools2.dll")
LoadPlugin("D:\Program Files\avisynth64plugins\svpflow1_64.dll")
LoadPlugin("D:\Program Files\avisynth64plugins\svpflow2_64.dll")
PluginPathInterFrame = "D:\Program Files\avisynth64plugins\InterFrame-2.8.2\"
Import(PluginPathInterFrame+"InterFrame2.avsi")

tsk1979
15th November 2022, 06:48
Okay I could fix this by replacing the commented line with uncommented line in the function

# Put it together
# smooth_video = SVSmoothFps(Input, Super, Vectors, SmoothString, url="www.svp-team.com", mt=Cores)
smooth_video = SVSmoothFps(Input, Super, Vectors, SmoothString, mt=Cores )

VoodooFX
15th November 2022, 07:07
I downloaded the plugins and tried running with this new function InterFrame

Did you read this post about the image posting: https://forum.doom9.org/showthread.php?p=1978394#post1978394 ?

tsk1979
15th November 2022, 07:18
Did you read this post about the image posting: https://forum.doom9.org/showthread.php?p=1978394#post1978394 ?

Yes, but I have a smugmug account and so uploaded there. It all works for me now. I did a Prefetch(6)
since I have a 6 core processor.

I now start at around 6-7FPS but midway it drops to about 2.5-3fps and is variable

See screen grab
18246

Total 6295 frames took 1500 seconds i.e about 4.2FPS. Significantly better than my 1.5 FPS earlier.

Thanks I guess this is the best I can do, and its not too bad (faster than WYSIWYG editors like blender)

I am wondering if some encoding software can use GPU acceleration and make it even faster!

kedautinh12
15th November 2022, 08:13
And after read, you still post images here and wating for moderator approval forever?? :D

tsk1979
15th November 2022, 08:55
And after read, you still post images here and wating for moderator approval forever?? :D

Oh, my bad. :p I thought everyone was talking about samples. I realized that on this forum I need to upload images and then share

https://i.postimg.cc/nMXyfqqh/Capture.jpg (https://postimg.cc/nMXyfqqh)

DTL
15th November 2022, 11:33
For better analyse performance but with possible quality degradation you can remove 2 MRecalculate calls and use single MAnalyse with blocksize=8. As for hardware acceleration if you use Win10 or later and compatible with DX12 ME accelerator you can try post 2.7.45 builds of mvtools2 with MAnalyse optSearchOption 5 or 6.

Boulder
15th November 2022, 13:04
I'd probably do the MAnalyse+MRecalculate as it is, but since it's 4K, it might make sense to change the blocksizes to 32, 16 and finally 8 instead of 16, 8 and 4.

poisondeathray
15th November 2022, 16:09
I am wondering if some encoding software can use GPU acceleration and make it even faster!

That would only help if encoding was the bottleneck in the process. If you script is slow, a 10x faster encoder won't help

If you have a compatible NVidia card (pascal or newer), look at NVencC for h.265 encoding. Fast and decent quality

VoodooFX
15th November 2022, 16:42
For me SVPflow works faster and produces better results than MVtools2.

It all works for me now. I did a Prefetch(6) since I have a 6 core processor.

Total 6295 frames took 1500 seconds i.e about 4.2FPS. Significantly better than my 1.5 FPS earlier.


Too high Prefetch can hurt speed, I would use 4 or 5 on 6 cores CPU.

You can try InterFrame(Preset="Faster", Cores=1, FrameDouble=true, GPU=true) maybe GPU processing would give some boost.

Btw, what you have selected in VDub2 under Video ["Fast Recompress" should be selected there]?

DTL
16th November 2022, 10:11
badrange=(-24) - may be also slow enough. Depending on relative amount of bad MVs. Default of +24 UMH search may be visibly faster.

tsk1979
17th November 2022, 07:55
Thanks, I will keep these tips in mind.

The full video is now up
https://www.youtube.com/watch?v=SDIOAEiuBz8

StainlessS
17th November 2022, 12:52
Nice dark skies you got there, we dont see nuttin' like that over London :(

anton_foy
19th November 2022, 13:38
For me SVPflow works faster and produces better results than MVtools2.



Too high Prefetch can hurt speed, I would use 4 or 5 on 6 cores CPU.

You can try InterFrame(Preset="Faster", Cores=1, FrameDouble=true, GPU=true) maybe GPU processing would give some boost.

Btw, what you have selected in VDub2 under Video ["Fast Recompress" should be selected there]?

Can you share your SVP-script please?
My experience with SVP and fastdegrain script did not give almost any performance or speed boost and it does not want to process chroma.

VoodooFX
20th November 2022, 05:15
Can you share your SVP-script please?
You've quoted it, look inside InterFrame:

InterFrame(Preset="Faster", Cores=1, FrameDouble=true)