View Full Version : Apply filter to only 1 frame
Bluedraft
4th November 2023, 00:05
Hi,
Any idea how can I apply an avisynth filter to only one frame? (ie, frame no 2290)
Thanks in advance for any help
kedautinh12
4th November 2023, 00:12
You can use this
http://avisynth.nl/index.php/Trim
Bluedraft
4th November 2023, 00:40
Thanks for reply kedautinh12, I imagine something like this
tcFile = "%temp_file%_timestamps.txt" # timestamps file path
Exist(tcFile) ? FFVideoSource("%source_file%", cachefile="%source_temp_file%.ffindex", timecodes=tcFile) : FFVideoSource("%source_file%", cachefile="%source_temp_file%.ffindex")
Import("C:\StaxRip-v2.28.0-x64\Apps\Plugins\AVS\Spotless\Spotless.avsi")
Spotless()
clip1 = trim(0,22919)
clip2 = trim (22920,22921).Spotless()
clip3 = trim(22922,153144)
clip1 + clip2 + clip3
It's right? I mean, in this way the filter will be applied only to the frame 22920?
kedautinh12
4th November 2023, 00:59
Cause avs count from frame 0 so frame 22920 means 22919-22920 and if you use Spotless() only from frame to frame, you can't put Spotless() in the above trim filter. Correct script:
tcFile = "%temp_file%_timestamps.txt" # timestamps file path
Exist(tcFile) ? FFVideoSource("%source_file%", cachefile="%source_temp_file%.ffindex", timecodes=tcFile) : FFVideoSource("%source_file%", cachefile="%source_temp_file%.ffindex")
Import("C:\StaxRip-v2.28.0-x64\Apps\Plugins\AVS\Spotless\Spotless.avsi")
clip1 = trim(0,22918)
clip2 = trim (22919,22920).Spotless()
clip3 = trim(22921,0)
clip1 ++ clip2 ++ clip3
Bluedraft
4th November 2023, 01:07
Wonderful, thank you very much kedautinh12!
StainlessS
4th November 2023, 01:15
clip2 = trim (22919,22920).Spotless()
Above is 2 frames not 1. [also, Spotless temporal filter on only 2 frames is not a good idea]
It's right? I mean, in this way the filter will be applied only to the frame 22920?
# other lead stuff, with src in special Last clip
FIX = 22920 # Frame to fix
SpotClip = Last.SpotLess() # SpotLess on Single trimmed frame would not do anything of use (Temporal filter acting on a single frame is pointless)
clip1 = trim(0,FIX-1) # start to FIX - 1
clip2 = SpotClip.trim(FIX, -1) # -1 is -ve framecount, ie -1 means 1 frame only
clip3 = trim(FIX+1,0) # FIX + 1 to End of clip
clip1 ++ clip2 ++ clip3
coolgit
4th November 2023, 15:36
Just do what i always do for 1 frame.
I.e fix frame 10 then spotless needs frame 9 to 11.
trim(9,11).spotless()
That's all folks.
Rob105
4th November 2023, 16:26
Use AnimateRange() (https://avisynthplus.readthedocs.io/en/latest/avisynthdoc/corefilters/animate.html#applyrange) its exactly what you need
StainlessS
4th November 2023, 17:12
trim(9,11).spotless()
But eg trim(9,11).spotless(RadT=2) would not work well.
Use AnimateRange() its exactly what you need
Not good for single frame only, much 'heavier' (slow) on filtering, and for no particular reason.
For a single frame only, Trim probably best. [For Lots of single frames or ranges, ClipClop() best]
# other lead stuff, with src in special Last clip
FIX = 22920 # Frame to fix
RADT=2
SpotClip = Last.SpotLess(RadT=RADT) # SpotLess on Single trimmed frame would not do anything of use (Temporal filter acting on a single frame is pointless)
clip1 = trim(0,FIX-1) # start to FIX - 1
clip2 = SpotClip.trim(FIX, -1) # -1 is -ve framecount, ie -1 means 1 frame only
clip3 = trim(FIX+1,0) # FIX + 1 to End of clip
clip1 ++ clip2 ++ clip3
EDIT: @ Rob105, perhaps you meant ApplyRange rather than AnimateRange,
ApplyRange
ApplyRange is a special case of Animate where start_args = end_args. It can be used to apply a certain filter only on a certain range of frames of a clip. Like Animate, this filter will not handle a changing soundtrack or different output frame sizes.
In cases where a large number of ranges need processing, calling ApplyRange many times may cause resource issues. An alternative is found here: ConditionalReader: ApplyRange replacement.
Syntax and Parameters
ApplyRange (clip, int start_frame, int end_frame, string filtername, var args)
clip
Source clip, sent to filter filtername.
start_frame, end_frame
Frames outside the range start_frame to end_frame are passed through untouched.
Frames inside the range start_frame to end_frame (inclusive) are processed by filter filtername with arguments args. If start_frame==end_frame, only one frame is processed.
filtername
Name of any filter or function accessible to your script.
args
List of arguments to filtername. Unlike Animate, args can't contain a clip.
As with Animate, if you use a clip as the first argument to ApplyRange, that clip shouldn't be included here.
ApplyRange Examples
ver = Version()
return ver.ApplyRange(0, 149, "Crop", 158, 0, 64, 32)
# gives an error since cannot have different frame sizes within a clip
Version()
ApplyRange(100, 149, "Blur", 1.0) # Blur only frames 100-149
AviSource("test.avi").BicubicResize(320,240)
ApplyRange(0, 48, "Subtitle", "Hello, World!", 25, 130, 0, 99999, "Arial", 48)
# is the same as:
clip = AviSource("test.avi").BicubicResize(320,240)
ApplyRange(clip, 0, 48 "Subtitle", "Hello, World!", 25, 130, 0, 99999, "Arial", 48)
# since the frame range can be provided to Subtitle itself, this is the same as:
AviSource("test.avi").BicubicResize(320,240)
Subtitle("Hello, World!", 25, 130, 0, 48, "Arial", 48)
EDIT: Actually, I'm not sure if ApplyRange() could properley be used for Spotless(),
does ApplyRange trim before applying spotless then trim/splice, or, apply spotless to copy of entire clip and then trim and splice.
coolgit
4th November 2023, 19:47
Radt=2 is unnecessary. Radt=1 works fine and default.
Stainless... did you have any problems using utvideo in vdub? Sometimes when i use it and merge the files it would fail. Something to do with merging direct copy file and processed file. With ffv1 it works.
StainlessS
4th November 2023, 19:57
Radt=2 is unnecessary. Radt=1 works fine and default.
I was meaning the general method is better, for Spotless or whatever other filter was required.
did you have any problems using utvideo in vdub? Sometimes when i use it and merge the files it would fail. Something to do with merging direct copy file and processed file. With ffv1 it works.
I'm not sure what you mean there, I've never had any problems with UtVideo (that I can remember), and certainly not with the new April 2023 version.
(cos I've only used it twice)
EDIT: I have not used Vdub/Vdub2 much for editing AVI files, for a long time (mostly just saving AVI from AVS).
EDIT: I do use VD2 script editor a lot for editing avs files. (I use PsPad text editor, with F9 to launch VDub2 x64 opening the pspad script).
hello_hello
5th November 2023, 10:42
For temporal filters I tend to do it this way.
clip1 = last
clip2 = clip1.Spotless()
clip1.trim(0,22919) ++ \
clip2.trim (22920,22921) ++ \
clip1.trim (22922,0)
One of the resident Avisynth experts will probably be able to correct me if I'm wrong, but I believe that if Spotless needs to reference frames outside the Trim range in order to do it's thing, the above method should allow it to do so, and it shouldn't be necessary to include frames in the Trim range that don't need filtering.
Edit: Or this should achieve the same thing. It's just not as tidy or easy to edit when there's lots of Trims and/or different filtering in a script.
clip1 = last
clip1.trim(0,22919) ++ \
clip1.Spotless().trim(22920,22921) ++ \
clip1.trim (22922,0)
StainlessS
5th November 2023, 10:55
trim(22920,22921)
Yes but that is two frames.
I believe if Spotless needs to reference frames outside the Trim range in order to do it's thing
Again yes. [so must trim AFTER spotless, not before]
hello_hello
5th November 2023, 11:02
Yes but that is two frames.
In my defense, I simply copied and pasted the Trim ranges already being used. :)
StainlessS
5th November 2023, 11:33
I forgive you.
[to err is human, to forgive devine]
Frank62
5th November 2023, 12:47
Saves my day. :D
vBulletin® v3.8.11, Copyright ©2000-2026, vBulletin Solutions Inc.