View Full Version : Starter script to use for SRestore frame blending?
Hello all,
I am a broadcast tech that is relatively new to AviSynth (just did a few of the test scripts), but quite comfortable with cadences and video goblins.
I have a clip that has blended frames in a consistent pattern - 2 blended frames, followed by 4 good ones. So if A were to represent blended frames, and B were to represent good frames, the pattern would be AABBBB, AABBBB throughout the whole thing. The file source is a 29.97 NTSC video, naturally telecined from a 24 fps source.
I have found two threads that seem like they would fit the bill, but I am not sure if these are complete segments of code I could copy and paste to "run" or if they are simply fragments that assumes a level of syntax comprehension I don't (yet) have.
The threads are as follows:
https://forum.doom9.org/showthread.php?t=176301
https://forum.doom9.net/showthread.php?p=1976130
I am really looking for a complete script I could copy/paste in the text file to run through Avisynth "turnkey" to target the blended frames. As I become more comfortable with AviSynth's syntax I can mess with it more, but I am just looking to get started. I would be starting with a short clip of 2-5 minutes to see if it works.
This seemed like a good start (though of course it seems to call other plugins that improve various things.)
ClearAutoloadDirs()
SetFilterMTMode("DEFAULT_MT_MODE", MT_MULTI_INSTANCE)
LoadPlugin("I:\Hybrid\64bit\Avisynth\AVISYN~1\LSMASHSource.dll")
LoadPlugin("I:\Hybrid\64bit\Avisynth\AVISYN~1\RgTools.dll")
LoadPlugin("I:\Hybrid\64bit\Avisynth\AVISYN~1\masktools2.dll")
LoadPlugin("I:\Hybrid\64bit\Avisynth\AVISYN~1\mvtools2.dll")
LoadPlugin("I:\Hybrid\64bit\Avisynth\AVISYN~1\nnedi3.dll")
LoadPlugin("I:\Hybrid\64bit\Avisynth\AVISYN~1\TIVTC.dll")
LoadPlugin("I:\Hybrid\64bit\Avisynth\AVISYN~1\Average.dll")
LoadPlugin("I:\Hybrid\64bit\Avisynth\AVISYN~1\grunt-x64.dll")
LoadPlugin("I:\Hybrid\64bit\Avisynth\AVISYN~1\MedianBlur2.dll")
Import("I:\Hybrid\64bit\Avisynth\avisynthPlugins\mtmodes.avsi")
Import("I:\Hybrid\64bit\Avisynth\avisynthPlugins\QTGMC.avsi")
Import("I:\Hybrid\64bit\Avisynth\avisynthPlugins\Zs_RF_Shared.avsi")
Import("I:\Hybrid\64bit\Avisynth\avisynthPlugins\Srestore.avsi")
# loading source: C:\Users\Selur\Desktop\spots_beg_ufo_sIII1c_amtv_v2_cut.avi
# color sampling YUY2@8, matrix: bt601, scantyp: top field first, luminance scale: limited
LWLibavVideoSource("C:\Users\Selur\Desktop\SPOTS_~1.AVI",cache=false,dr=true,format="YUV422P8", prefer_hw=0)
# current resolution: 720x576
# deinterlacing
AssumeTFF()
QTGMC(Preset="Fast", ediThreads=2)
# removing ghosting
srestore(omode=6)
Preroll(Int(last.FrameRate())) # for consistent preview
# filtering
# adjust color to YV12 (color matrix: Rec601)
ConvertToYV12()
# setting output fps to 23.976fps
AssumeFPS(24000,1001)
# output: color sampling YV16@8, matrix: bt601, scantyp: progressive, luminance scale: limited
return last
Thank you in advance!
Sky
wonkey_monkey
3rd June 2025, 22:36
Hello all,
I am a broadcast tech that is relatively new to AviSynth (just did a few of the test scripts), but quite comfortable with cadences and video goblins.
I have a clip that has blended frames in a consistent pattern - 2 blended frames, followed by 4 good ones.
Frames, or fields? If frames, then you shouldn't be calling QTGMC. And if fields, then there will probably be a better/faster way than deinterlacing it.
Rather than rely on srestore, if you have a completely fixed pattern then you can correct it, possibly more accurately, using Expr or a specialised plugin - that's what I did when I had a similar problem (https://horman.net/doctorwho/specials.php). It depends on the exact nature of the blending. Can you upload a sample, preferably from frame 0?
Lastly, rather than having to use Preroll to avoid seeking errors, I would use BestSource (https://github.com/vapoursynth/bestsource/releases). It guarantees perfect seek accuracy.
Hi, thanks for responding so quickly! I am going by the discrete frames as displayed within Premiere and After Effects. You are right to clarify about fields given 29.97 is technically interlaced.
I can’t really post a frame due to client NDA, but it is absolutely frame blending (ghosting) from a lousy telecine job.
The plan is to deal with the blended frames as they are absolutely consistent in that pattern. The output with the blended frames removed will then be reverse telecined back to 24 (23.976) in the shop with a new pulldown applied so to eliminate cadence issues.
I am also in somewhat of a time crunch - I need to deliver something (even 30 seconds, or a minute or so of footage would be fine) within a few days, so bearing in mind I am a new user I would need an idea of what script I should put in. I will have plenty of time to learn and tweak without the client breathing down my neck at that point and can take the time I need.
Thanks again for your help in advance!
wonkey_monkey
3rd June 2025, 23:10
So there's no interlacing visible in a full frame, whether blended or not? Are the blends exactly 50/50? Can you write out a short table to clarify the blending pattern, e.g.
Frame 0 of blended clip is frame 0 of original (before telecine clip)
Frame 1 is original frame 1
Frame 2 is a blend of original frame 1 and original frame 2
Frame 3 is a blend of original frame 2 and original frame 3
Frame 4 is original frame 3
and so on, for the first 10-15 frames?
And lastly, can you see if the chroma is blended differently from luma?
I can get you that for sure from the test clip.
One thing that will help with respect to chroma is that the show is black and white.
No interlacing visible, no.
From what I can see it is a pretty even 50/50 split.
It seems to follow your chart to the letter, pretty much. We weren't the ones that did the original pulldown so we're working with what is available.
Frame 0 of blended clip is frame 0 of original (before telecine clip)
Frame 1 is original frame 1
Frame 2 is a blend of original frame 1 and original frame 2
Frame 3 is a blend of original frame 2 and original frame 3
Frame 4 is original frame 3
Frame 5 is original frame 4
Frame 6 is original frame 5
Frame 7 is original frame 6
Frame 8 is a blend of (presumably) original frame 7 and original frame 8
Frame 9 is a blend of (presumably) original frame 8 and original frame 9
Frame 10 is original frame 9
Frame 11 is original frame 10
Frame 12 is original frame 11
Frame 14 is original frame 12
Frame 15 is a blend of (presumably) original frame 14 and original frame 15
Frame 16 is a blend of original frame 15 and original frame 16.
However, in the interim, could I theoretically use that Srestore script from above to do a "quick and dirty" that would remove the blended frames in a 30 second clip? Just something to hold the client over while the "proper" way for the longer stuff is applied. They don't know what they're looking at; they just want to see a few seconds of blended frames removed (they don't know much about framerates and whatnot - just how to toggle individual frames.)
wonkey_monkey
4th June 2025, 11:07
Try this:
# <source filter here>
ConvertToY8
a = Trim(0,-1) + last
b = last
c = last.Trim(1, 0)
d = last.Trim(2, 0)
fixes = Expr(a,b,c,d, "y z + x a + 0.5 * -")
Interleave(last, fixes)
SelectEvery(12, 0,2,5,8,10)
ConvertToYV12
It should give a cleaner result than srestore because a) it's not guessing, and b) it's using both blended frames to reconstruct the original.
This looks great, thanks so much! I will try it and report in.
Dumb questions: 1. which plugin (if any) is this script calling (just to ensure I have them installed)
2. For source filter here, which should I put (if any)
3. I presume I must ensure that the test clip starts precisely at a blended frame and if it starts on a good frame then it will offset the sequence so the script applies correctly?
wonkey_monkey
4th June 2025, 18:40
2. That's where you load your clip, e.g. LWLibavVideoSource("<filename>",cache=false,dr=true,prefer_hw=0)
3. The script as written will only work if frames 2 and 3 are the first two blended frames.
Understood. So to clarify, the file must have frame 1 as an unblended frame, with the following 2 frames blended. When I say frame 1 in this case, I am considering it frame 0 - eg, first frame Avisynth sees in the file should be unblended, with the immediate following 2 frames blended, correct?
wonkey_monkey
4th June 2025, 21:02
Frame 0 is always frame 0. The first two frames (frame 0 and frame 1) should be unblended.
Gotcha. So it should begin at frame 0 - the very first frame in the file - with a good frame being frame 0, and a good frame being frame 1. So:
2 good frames
2 blended frames
4 good frames
2 blended frames
4 good frames
2 blended frames
etc.
Is that right? Just want to make 100% sure with the test file I export having the frames in the right place.
wonkey_monkey
5th June 2025, 12:47
That's correct.
Thanks. I think I am doing something wrong, though. I get a red text error that says 'I don't know what Y8 means.' I used the following code:
# D:\AAA-AVISYNTH\TEST\Q_DCM_TEST.mp4
ConvertToY8
a = Trim(0,-1) + last
b = last
c = last.Trim(1, 0)
d = last.Trim(2, 0)
fixes = Expr(a,b,c,d, "y z + x a + 0.5 * -")
Interleave(last, fixes)
SelectEvery(12, 0,2,5,8,10)
ConvertToYV12
I also tried a variant, and it just said it couldn't load my clip in red letters. That was this:
AVISource("D:\AAA-AVISYNTH\TEST\Q_DCM_TEST.mp4")
ConvertToY8
a = Trim(0,-1) + last
b = last
c = last.Trim(1, 0)
d = last.Trim(2, 0)
fixes = Expr(a,b,c,d, "y z + x a + 0.5 * -")
Interleave(last, fixes)
SelectEvery(12, 0,2,5,8,10)
ConvertToYV12
What am I doing wrong? For what it's worth, although the show is in black and white, the original clip is just in normal Rec 709 space:
720 x 486
00;00;30;08, 29.97 fps
48000 Hz - Stereo
Color Space: Rec. 709
wonkey_monkey
5th June 2025, 23:23
# indicates a comment line. The intent was for you to remove the comment line completely and replace it with a call to a source filter. AVISource is a source filter, but only for AVI files. For an .mp4, you can try DirectShowSource, which is a built-in source filter, but a better idea would be to get the BestSource plugin linked above and place the .dll file in C:\Program Files (x86)\AviSynth+\plugins64. Other source filters may not return the correct frames consistently.
It's a 64-bit only plugin so you'll need to make sure you're using a 64-bit program (e.g. 64-bit ffmpeg.exe or VirtualDub2) to read the AVS file.
Understood, thank you. I assume that is why it doesn't understand the Y8 command.
I am literally trying it now. What is the correct syntax to call the source? I apologize, I don't 100% know the right script to call a file per plugin.
e.g.
BestSource("D:\AAA-AVISYNTH\TEST\Q_DCM_TEST.mp4")
ConvertToY8
DirectShowSource("D:\AAA-AVISYNTH\TEST\Q_DCM_TEST.mp4")
ConvertToY8
Thanks again for all your help - I do believe I am close to getting it working. :)
Update: I got it working with DirectShowSource in VirtualDub2. Thanks so much! It doesn't work so well once there is a cut but that is probably just cadence drift. This can easily be rectified by just running an instance on each cut. Problem solved.
I am still trying to figure out how to call the source for BestSource though. I'm looking at forums and tutorials but haven't found the syntax yet.
wonkey_monkey
6th June 2025, 00:41
BSSource("D:\AAA-AVISYNTH\TEST\Q_DCM_TEST.mp4") should work.
https://github.com/vapoursynth/bestsource/
StainlessS
6th June 2025, 08:51
Avisynth Wiki, Script Syntax etc:- [Avisynth.nl]: http://avisynth.nl/index.php/Main_Page
Internal filters are on Main page, under Filters & Utilities:- http://avisynth.nl/index.php/Internal_filters
External filters are on Main page, under Filters & Utilities:- http://avisynth.nl/index.php/External_filters
However those are x86 filters, you need to look further down that (External filters) page for
64-bit filters: Comprehensive list of AviSynth+ 64-bit filters:- http://avisynth.nl/index.php/AviSynth%2B_x64_plugins
But, BestSource() aint yet been added to x64 plugins list.
Sounds good.
The code works brilliantly! Each of these videos are about an hour though, and I have almost 20 of them. My thoughts were, for efficiency's sake, I should run the whole show through SRestore first (which will try to guess the blended frames in the whole file), then use the more accurate script you suggested to individually fix whatever SRestore missed. I will use Premiere to split every individual cut in the video, export those and use the exact code you suggested for the individual clips in cases where SRestore missed.
Some of the cuts occur mid-field, so even though the "2-blended, 4-good" pattern doesn't deviate, as soon as it cuts to another angle, the very exact coding sometimes doesn't "catch". As long as I tell it to do that particular angle up to the cut, it works with 100% accuracy.
I have two questions:
1. What would you recommend as an example script similar to the one you gave me, but for SRestore (so it can scan and "guess" the blended frames overall in the entire video file)
and
2. The code you gave works amazingly with 2 good, 4 blended sequence. Not all the cuts immediately start with precisely 2 good frame though. Is there a way to tell the script to offset by X amount of frames? (Say if one of the frames is a cut.)
BSSource("D:\AAA-AVISYNTH\TEST\Q_DCM_TEST.mp4") should work.
https://github.com/vapoursynth/bestsource/
SKY4
10th June 2025, 16:01
Does anyone have example of a script to do the same thing for SRestore (per last message)? Thanks!
SKY4
12th June 2025, 05:42
Hi, I am still trying to figure out how to do this in SRestore and trying to go through tutorials. I just cannot get this working. If anyone has any insight I would really appreciate it. I’m just looking for a small script to have SRestore guess the blended frames as a starter pass. I am really having a hard time. Thanks!
vBulletin® v3.8.11, Copyright ©2000-2026, vBulletin Solutions Inc.