Log in

View Full Version : custom frame dropping


Dogway
16th July 2010, 13:27
I would like to know how to drop ocasional corrupt frames. I thought of modifying the .txts from multidecimate but it comes to be a huge load of work.

poisondeathray
16th July 2010, 14:24
If you drop frames , wont you start to get A/V sync issues? or is this no audio content ?

Maybe replace frames with adjacent "good" ones? FreezeFrame() ?

Dogway
16th July 2010, 15:32
yes, I always wondered how avisynth looking a so powerful tool couldnt handle sample tasks like this. Im more worried on the visual aspect rather than audio, normally I edit audio to sync with content, although I work a lot with no audio content. thanks for freezeframe it may work, although creating a stutter. Something like Drop(frame=13540) would be really cool.

Guest
16th July 2010, 15:52
It's not a deficiency of Avisynth but rather of your creativity in using it.

Something like Drop(frame=13540) would be really cool. This will drop frames and the audio for them:

Trim(0,a-1) ++ Trim(b+1,0)

It's cumbersome but you can use it to make a Drop() function as you describe (exercise for student). Better to support a range as above than a single frame.

Dogway
16th July 2010, 17:28
Creativity is not the problem, RAM is. You havent discovered anything, only a workaround I dont want to deal with because I suspect it's a performance killer. but thanks for the input, will check anyway.

Guest
16th July 2010, 17:30
Creativity is not the problem, RAM is. You havent discovered anything, only a workaround I dont want to deal with because I suspect it's a performance killer. but thanks for the input, will check anyway. I didn't claim to discover anything. I don't understand your concerns about RAM or performance. Are you seeing imaginary goblins or do you have a basis for that?

And BTW, if you don't care about audio, there is DeleteFrame().

Gavino
16th July 2010, 17:35
Something like Drop(frame=13540) would be really cool.
It's called DeleteFrame (http://avisynth.org/mediawiki/DeleteFrame). ;)
Will even do a list of frames, eg DeleteFrame(3, 9, 21, 42)
It doesn't modify the sound track, so you'll want neuron2's suggestion if you need to preserve audio sync.

Ah, I see neuron2 has addressed that too now.
What was that about 'great minds..."

Dogway
16th July 2010, 17:37
And BTW, if you don't care about audio, there is DeleteFrame(). That is all I was aking for.

PD: just in time, thank you too Gavino!!

Gavino
16th July 2010, 17:40
a workaround I dont want to deal with because I suspect it's a performance killer.
Trim has almost zero hit on performance.

Guest
16th July 2010, 17:48
That is all I was asking for. I suggest that you make a habit of reading the Avisynth documentation before claiming that Avisynth is missing the most basic functionality.

Dogway
16th July 2010, 18:21
I suggest you to dont look down people you dont know.

And...
Reorganize (suggest) the documentation for better searching.

Gavino: I had in mind that triming was keeping in cache (RAM) the range to be joint with other trims, like variables do.

Guest
16th July 2010, 19:44
I suggest you to dont look down people you dont know. Don't make it personal buddy, I'm not looking down on you. It's always a good idea to read documentation before jumping to erroneous conclusions.

The documentation is superbly organized, in my view.

Gavino
16th July 2010, 20:22
Gavino: I had in mind that triming was keeping in cache (RAM) the range to be joint with other trims, like variables do.
It's true that Trim, like all filters (except + and ++), has a cache associated with it to avoid fetching the same frame more than once, but that's no great overhead. Trim doesn't store all the frames in the trimmed range, if that's what you're thinking - Avisynth doesn't work that way. Variables have very little overhead too, as they are just pointers (or simple values).
Reorganize (suggest) the documentation for better searching.
A good place to start when looking for a filter is here (http://avisynth.org/mediawiki/Internal_filters), which is organised by category.
If you already know the filter name, but want more details, a useful alphabetic index is here (http://avisynth.org/mediawiki/Category:Internal_filters).
And of course the documentation installed on your hard disk has similar info.

Dogway
16th July 2010, 20:44
It's not a deficiency of Avisynth but rather of your creativity in using it.

...to make a Drop() function as you describe (exercise for student).
Sorry, if that sounded too personal.

I actually searched on google/doom9: remove/delete/drop frames avisynth, and looked into external filters (I have it on my favourites). I didnt think it was internal, but after almost 1 hour searching, I thought it was easier to just ask (As easy it is for me to reply)

Guest
16th July 2010, 21:23
That's surprising but you're right. A simple search for "avisynth delete frame" does not lead quickly to DeleteFrame(). :confused:

Gavino
17th July 2010, 23:30
This will drop frames and the audio for them:
Trim(0,a-1) ++ Trim(b+1,0)
It's cumbersome ...
A less cumbersome way is simply Loop(0, a, b) (or Loop(0, a, a) for a single frame).
I overlooked this yesterday - still trying to get my brain in gear after the World Cup celebrations. :)
Dogway. ;))

Dogway
18th July 2010, 03:47
@Gavino:

Finally I used Deleteframe, its better for random frames deletion, although I had to install v2.58. I know there are many ways for doing the same, only this came to be the fastest for my purposes. Hope next time somebody finds out this thread when searching for delete frame on avisynth: I wont misslook the internal filters either... : D

Floatingshed
18th July 2010, 23:14
I would find a simple command like "deleteframe" that also removed the audio very useful...

Blue_MiSfit
18th July 2010, 23:30
freezeframe works well for me too, to fix a few consecutive corrupted frames ;)

Gavino
18th July 2010, 23:38
I would find a simple command like "deleteframe" that also removed the audio very useful...
Like I said, you can do this with Loop(0, n, n) to delete both video and audio of frame n.
Or define a wrapper function for it with a name of your choice, eg

function DeleteFrameA(clip c, int frame) {
c.Loop(0, frame, frame)
}

StainlessS
10th June 2014, 20:37
Excuse me digging up this older thread, came across it whilst searching forum and thought I could add something
that could be of use to others that view the thread.

Delete frames, no audio

avisource("d:\avs\flashtest.avi").trim(1000,-10).showframenumber

# Delete list of frames, No Audio returned

# Uncomment one of the below three lines

#FrameSel(3,5,7,reject=true) # delete frames using direct arg frame numbers, return no audio (ranges not supported in direct arg framenos)

#FrameSel(SCmd="3;5;7",reject=true) # delete frames using scmd string of frame numbers, return no audio (';' or Chr(10)=separator, ','=range)

# del.txt = file containing eg "3"+chr(10)+"5"+chr(10)+"7"+chr(10)
#FrameSel(Cmd="del.txt",reject=true) # delete frames using cmd file of newline separated frame numbers, return no audio


Delete frames, Audio processed

avisource("d:\avs\flashtest.avi").trim(1000,-10).showframenumber
# Delete list of frames, Audio trim/splice processed using Prune plugin (with audio fadeout/in to avoid clicks)
# Uncomment one of the below three lines

#FrameSel_CmdReWrite("Prune.txt",3,5,7,reject=true,Prune=True,range=true)# Create Prune delete frames command file using direct args frame numbers

#FrameSel_CmdReWrite("Prune.txt",SCmd="3;5;7",reject=true,Prune=True,range=true)# Create Prune delete frames command file using SCmd string of frame numbers

# del.txt = file containing eg "3"+chr(10)+"5"+chr(10)+"7"+chr(10)
#FrameSel_CmdReWrite("Prune.txt",Cmd="del.txt",reject=true,Prune=True,range=true)# Create Prune delete frames command file using Cmd file of frame numbers

Prune(Cmd="Prune.txt",FadeSplice=True) # And then delete frames, avoid clicks at splices.


FrameSel:- http://forum.doom9.org/showthread.php?t=167971

Prune:- http://forum.doom9.org/showthread.php?t=162446

EDIT: Prune Default Fade duration = 1ms, adjustable to 25ms.

EDIT: Script removed, see next post.

StainlessS
11th June 2014, 23:41
Update of EDIT to previous post.

RejectRanges, Script function to delete ranges from clip, together with audio.

Function RejectRanges(clip c,String "SCmd",String "Cmd",Bool "TrimAudio",Float "FadeMS") {
# RejectRanges() by StainlessS. Required:- FrameSel, Prune, RT_Stats
# Wrapper to delete frames/ranges along with audio, can supply frames/ranges in SCmd string And/Or Cmd file.
# The wrapper makes for easier usage of Prune() which supports up to 256 input clips, but requires a clip index,
# eg '3, 100,200' would specify clip 3, range 100 to 200. The wrapper does away with the necessity for the clip index as we
# are only using a single clip here. Prune also does not have a 'reject' arg to delete specified frames rather than select them,
# this wrapper also converts a list of frames to delete into a list of frames to select so that we can use Prune and its audio
# capability.
#
# SCmd: Frames/Ranges specified in String (Frames/Ranges either Chr(10) or ';' separated, infix ',' specifies range, eg 'start,end').
# Cmd: Frames/Ranges specified in file (one frame/range per line, comments also allowed, see FrameSel for Further info).
# TrimAudio:
# True(default), deletes audio belonging to deleted frames
# False, returns original audio, probably out of sync.
# FadeMS: (default 1.0 millisec). Linear Audio Fade duration at splices when TrimAudio==true, 0 = dont fade (might result in audio 'clicks/cracks').
c
TrimAudio=Default(TrimAudio,True) # default true trims audio, false returns original audio (audiodubbed, as Framesel returns no audio)
FadeMS=Float(Default(FadeMS,1.0)) # 1 millisecond linear fadeout/fadein at splices
PruneCmd = (TrimAudio) ? "~Prune_"+RT_LocalTimeString+".txt" : ""
(!TrimAudio)
\ ? FrameSel(Last,scmd=SCmd,cmd=Cmd,reject=true)
\ : FrameSel_CmdReWrite(Last,PruneCmd,scmd=SCmd,cmd=Cmd,reject=true,Prune=True,range=true)
(TrimAudio) ? Prune(Last,Cmd=PruneCmd,FadeIn=True,FadeSplice=True,FadeOut=True,Fade=FadeMS) : NOP
# If TrimAudio==true then delete Prune temp file, Else restore original Audio to the now audio-less clip
(TrimAudio)
\ ? RT_FileDelete(PruneCmd)
\ : (c.HasAudio) ? AudioDub(c) : NOP
Return Last
}


Client script for RejectRanges

avisource("d:\avs\flashtest.avi").trim(1000,-20).showframenumber # 20 frames

SCMD=""" # This is a comment
1 # delete frame 1
9 # delete frame 9
11,15 # delete range 11 to 15
"""

# del.txt = file containing eg "3"+chr(10)+"5"+chr(10)+"7"+chr(10)
RejectRanges(scmd=SCMD,cmd="del.txt") # Delete frames 1 & 9, 11 to 15, and frames in del.txt 3 and 5 and 7, trim audio 1 ms fade
#RejectRanges(scmd="1;9;11,15",cmd="del.txt") # Exactly the same as above




SelectRanges, Script function to select ranges from clip, together with audio.

Function SelectRanges(clip c,String "SCmd",String "Cmd",Bool "TrimAudio",Float "FadeMS",Bool "Ordered") {
# SelectRanges() by StainlessS. Required:- FrameSel, Prune, RT_Stats
# Wrapper to Select frames/ranges along with audio, can supply frames/ranges in SCmd string And/Or Cmd file.
# The wrapper makes for easier usage of Prune() which supports up to 256 input clips, but requires a clip index,
# eg '3, 100,200' would specify clip 3, range 100 to 200. The wrapper does away with the necessity for the clip index as we
# are only using a single clip here.
#
# SCmd: Frames/Ranges specified in String (Frames/Ranges either Chr(10) or ';' separated, infix ',' specifies range, eg 'start,end').
# Cmd: Frames/Ranges specified in file (one frame/range per line, comments allowed, see FrameSel for Further info).
# *** NOTE ***, If both Cmd and SCmd supplied AND Ordered == False, then will process Cmd file and then SCmd string afterwards, ie
# Will select ranges in Cmd file and in order specified (rather than auto ordering ranges) and then append ranges specified in
# SCmd string (and in order specified).
# TrimAudio:
# True(default), selects audio belonging to selected frames/ranges
# False, returns original audio, probably out of sync (maybe totally out of whack if Ordered == false and selected ranges out of order).
# FadeMS: (default 1.0 millisec). Linear Audio Fade duration at splices when TrimAudio==true, 0 = dont fade (might result in audio 'clicks/cracks').
# Ordered:
# True(default), all frames/ranges are returned in sequencial order. Any frame specified more than once will return only 1 instance.
# False, All frames/Ranges are returned in specified order, Cmd processed first and then SCmd. Frames/ranges specified more than once
# will return multiple instances. Allows out-of-order trimming of clip, eg re-sequencing of scenes in movie.
#
# Does not make much sense to select individual frames with audio, best used with ranges.
# Will coalesce individually selected adjacent frames/ranges before any Fade, ie only audio fade where sensible to do so.
# TrimAudio==false with non Ordered selection will result in completely out of sync audio.
c
TrimAudio=Default(TrimAudio,True) # default true trims audio, false returns original audio (audiodubbed, as Framesel returns no audio)
FadeMS=Float(Default(FadeMS,1.0)) # 1 millisecond linear fadeout/fadein at splices
Ordered=Default(Ordered,True) # True (default) frames/ranges will be Ordered and selected only once even if specified more than once.
# False, frames/ranges returned in specified order, Cmd processed 1st and then SCmd.
PruneCmd = (TrimAudio) ? "~Prune_"+RT_LocalTimeString+".txt" : ""
(!TrimAudio)
\ ? FrameSel(Last,scmd=SCmd,cmd=Cmd,Ordered=Ordered)
\ : FrameSel_CmdReWrite(Last,PruneCmd,scmd=SCmd,cmd=Cmd,Ordered=Ordered,Prune=True,range=true)
(TrimAudio) ? Prune(Last,Cmd=PruneCmd,FadeIn=True,FadeSplice=True,FadeOut=True,Fade=FadeMS) : NOP
# If TrimAudio==true then delete Prune temp file, Else restore original Audio to the now audio-less clip
(TrimAudio)
\ ? RT_FileDelete(PruneCmd)
\ : (c.HasAudio) ? AudioDub(c) : NOP
Return Last
}



Client script for SelectRanges

avisource("d:\avs\flashtest.avi").trim(1000,-20).showframenumber # 20 frames

SCMD=""" # This is a comment
1,3 # Select Range 1 to 3
9,11 # Select Range 9 to 11
14,15 # Select Range 14 to 15
2,5 # Select Range 2 to 5, If Ordered==True then already previously selected 1st range above (1,3) extended to 1,5
"""

ORDERED=True
SelectRanges(scmd=SCMD,Ordered=ORDERED) # Select SCmd ranges, trim audio 1 ms fade.
#SelectRanges(scmd="1,3;9,11;14,15;2,5",Ordered=ORDERED) # Exactly the same as above


EDITED: Added FadeIn and FadeOut to Prune calls. (fade at beginning and end of resultant clip [same duration as FadeMS default 1ms]).

EDIT: Short thread on clicks and cracks in audio when trimming:- http://forum.doom9.org/showthread.php?p=1534803#post1534803

See FrameSel() for full range specifications in SCmd string and Cmd file eg '4,-10' as Trim(4,-10), 10 frames starting at frame 4.
http://forum.doom9.org/showthread.php?t=167971

EDIT: Added 'Last' to FrameSel_CmdReWrite calls, make explicit that it requires a clip (otherwise might be baffling how it converts reject
commands into select commands, Last only used to access FrameCount so we know what to reject).