Log in

View Full Version : Can I remove duplicates before applying filters and then add them back after?


attackworld
19th December 2021, 09:38
Hello, I was looking into newer AI upscaling filters. And in general they can be quite slow.

I was wondering if there exists a way to do something like this

Dedup()
Upscale()
UndoDedupWithNewFrames()

In this case UndoDedupWithNewFrames will add back the removed frames using the filtered versions, so even the dups will be upscaled.

Doing this would result in a CFR file in the end, unlike just using DeDup by itself which will make it VFR. And I think there would be a speedup in terms of processing?

Or is there no downsides to VFR that I should be doing this??

hello_hello
19th December 2021, 17:30
I haven't used AI upscaling but I've never had a problem with VFR video. Most of my VFR encodes have been hybrid video though (combinations of 23.976fps and 29.97fps rather than more random Dedup frame rates).

There's a few plugins that'll take a timecodes file and output a CFR.
This sort of thing.

Dedup()
Upscale()
CFRPlugin("Deduptimes.txt", FPSNum=24000, FPSDen=1001)

http://avisynth.nl/index.php/TimecodeFPS
http://avisynth.nl/index.php/VFRtoCFR
http://avisynth.nl/index.php/VfrToCfr

StainlessS
19th December 2021, 18:52
FrameSel:- https://forum.doom9.org/showthread.php?t=167971

Post #4 of 4.

4) FrameSel_MakeReDupCmd

FrameSel_MakeReDupCmd(Clip c,String ofn, int F1, ... , int FN, String "SCmd"="", String "Cmd"="", \
Bool "Reject"=False, Bool "Debug"=False, Bool "Range"=True, Bool "Comments"=False)

FrameSel_MakeReDupCmd(), a function to take a duplicates frames command file and convert it to a FrameSel command file to
replace duplicates in source clip with duplicates that are identical to the predecessor frame of the first duplicate.
You could eg pull out non duplicates using FrameSel (with Reject=True), and do some kind of processing on those frames,
and then re-create duplicates but with identical duplicates using the processed clip as source for the newly inserted
identical duplicates. Motion Compensated processing would likely work better with duplicates removed first.
Identical Duplicates may be of some use in creating VFR (Variable Frame Rate) encodes, or in better compression where
many duplicates present.
The Reject arg provides you with the option of using a non dupe frames list rather that a dupe frames list and achieve
identical results, see later example.

Args identical to FrameSel (up to Reject), with exception of the additional compulsory 2nd String arg which is
an output filename, and missing Ordered (is always ordered), Ver and Show and Extract args.
See FrameSel() description for other arguments.

ofn, String, Compulsory.
Output file name. It is advised to use a different name to the Cmd file, although there is nothing to stop you
overwriting an original Cmd file if you like a little gamble.(Output file only written after fully read in and
all Ordering, Rejecting etc already processed. Only likely error would be during file writing eg eject floppy disk).

Range, bool, Default=True
False = Write individual frame numbers only, to output file.
True = (Default) Write comma separated Frame Ranges to output file (only where adjacent frames).

Comments, Bool, default False.
If true, then write additional descriptive comments to output file, else no comments written.

FrameSel_MakeReDupCmd, takes either Frame numbers as direct arguments, or in the SCmd string, or in the Cmd file (at least one must
be specified). If more than one command method is used, will process Cmd file first, then SCmd string second and lastly
directly supplied frame numbers. The command frames will be acted upon via the Reject arg (as in FrameSel, and here Ordered is ALWAYS
implied) and then re-written to the output command file. Any comments in SCmd string or Cmd file will not be written to the output
command file, where arg Comments=True, comments are auto generated to help decipher the output.

The FrameSel_MakeReDupCmd() function returns the total number of duplicate frames written to the output file.

Example:
# Script to test identical results if commands specified as either duplicates or non duplicates.
# Duplicates are synthesized as Blank Frames and will be replaced with duplicate of frame prior to first blank/dupe.
# Req ClipClop, RT_Stats, FrameSel plugins.
#######
CB=ColorBars.KillAudio.Trim(0,-20).ShowFrameNumber # 20 frames
BK=Last.BlankClip
#
CCDupeFrames=""" # ClipClop Duplicate Frame Numbers for creating test clip
1 3,5
1 9,11
1 15,17
"""
FSDupeFrames=""" # FrameSel Duplicate Frame Numbers (MUST NOT INLCUDE 0)
3,5
9,11
15,17
"""
#
CCNonDupeFrames=""" # ClipClop Non Duplicates Frame Numbers for creating test clip
1 0,2
1 6,8
1 12,14
1 18,19
"""
FSNonDupeFrames=""" # FrameSel Non Duplicates (MUST INCLUDE FRAME 0)
0,2
6,8
12,14
18,19
"""
####### CONFIG #####
AreDupes=True # If True then SCmd=list of duplicates, else list of non duplicates (SHOULD GET SAME RESULT)
####################
CCSCmd = (AreDupes) ? CCDupeFrames : CCNonDupeFrames
SCmd = (AreDupes) ? FSDupeFrames : FSNonDupeFrames
ORG = (AreDupes) ? ClipClop(CB,BK,scmd=CCSCmd) : ClipClop(BK,CB,scmd=CCSCmd)
#Return ORG
#######
ReDupFrames = "ReDupFrames.txt" # FrameSel command to re-assemble clip after processing. (created by FrameSel_MakeReDupCmd).
ReDupFrames = RT_GetFullPathName(ReDupFrames)
# Select Non Dupes Only for processing (Ordered always implied if Reject)
PreProc = Org.FrameSel(SCmd=SCmd,Reject=AreDupes,Ordered=True) # MUST be Ordered, Ordered=True, for when Reject=False
Processed = PreProc.McDegrainSharp(Frames=3) # Whatever Processing of non dupes
# Make Cmd file to recreate dups from processed predecessor (Reject=False if SCmd file specifies duplicates. else true if is non dupes)
FrameSel_MakeReDupCmd(ORG,ReDupFrames,Scmd=SCmd,Reject=!AreDupes,Debug=True,Range=True,Comments=True)
ReDupped=Processed.FrameSel(Cmd=ReDupFrames,Ordered=False) # Recreate Dups. (duplicates so cannot be Ordered)
#######
#return ReDupped
StackVertical(ORG,ReDupped)
#AudioDubEx(Last,ORG) # Restore audio
Return Last

Result for above script in ReDupFrames.txt command file.
Numbers in comments are output frame numbers, those prefixed by a 'D' are duplicates.
Below shows why you need in line ReDupped=Processed.FrameSel(Cmd=ReDupFrames,Ordered=False), Ordered=False, as we have
at beginning of file frames 0,2 ;2;2;2, so must not be ordered.
>>>>>>>>>>>>
0 ,2 # 0,2 [Len=3]
2 # D 3 # These are duplicates
2 # D 4
2 # D 5
3 ,5 # 6,8 [Len=3]
5 # D 9
5 # D 10
5 # D 11
6 ,8 # 12,14 [Len=3]
8 # D 15
8 # D 16
8 # D 17
9 ,10 # 18,19 [Len=2]
<<<<<<<<<<<<<





And the dll's prototype as script function:- https://forum.doom9.org/showthread.php?p=1832814#post1832814

you'll need some kind of dupes frames file creator.

attackworld
22nd December 2021, 18:05
I haven't used AI upscaling but I've never had a problem with VFR video. Most of my VFR encodes have been hybrid video though (combinations of 23.976fps and 29.97fps rather than more random Dedup frame rates).

There's a few plugins that'll take a timecodes file and output a CFR.
This sort of thing.

Dedup()
Upscale()
CFRPlugin("Deduptimes.txt", FPSNum=24000, FPSDen=1001)

http://avisynth.nl/index.php/TimecodeFPS
http://avisynth.nl/index.php/VFRtoCFR
http://avisynth.nl/index.php/VfrToCfr

Thank you, this worked.

I had to use the VFRtoCFR by Aktan for it to work. For some reason the one by joyje gave me a video that ended off early.

Also, I managed to get a substantial speed boost of about 2x for anime. However it seems useless in filmed videos.