View Single Post
Old 30th May 2013, 07:01   #1  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 10,980
FrameSel/FrameRep v2.21 - 27 Jul 2021

see post #16 for current docs https://forum.doom9.org/showthread.p...43#post1839843
Code:
	FrameSel/Rep by Stephen Jones, AKA StainlessS @ Doom9

	v2.58, v2.60 x86 and x64 dll's

	Old Version:- FrameSelect(), http://forum.doom9.org/showthread.php?t=164497

	v2.13 - 30 Mar 2015. Recompile v2.6 dll with Avisynth Version 6 Header.
	v2.20 - 20 Apr 2018. Add FrameSel_MakeReDupCmd, and x64. Recompile VS2008.
	v2.21 - 27 July 2021
		Added High Bit Depth metrics [using DDigit 2.0]
		Added PruneIx arg to FrameSel_CmdReWrite.
Short Excerpt from docs (hit D9 meagre 16KB limit AGAIN!!!)
Code:
FrameSel/Rep() Plugins for Avisynth v2.58/v2.6 by StainlessS.

FrameSel() is a simple plugin to select individual frames from a clip.

Can select frames numbers by direct arguments to filter, or in a string, or in a command file.


Video:- All Valid colorspaces

Audio:- Returns NO AUDIO (Does not really make sense for individual frames, although now supports ranges).


FrameSel(Clip, int F1, ... , int Fn, string 'scmd',string 'cmd', bool 'show', bool 'ver',bool "reject",bool "ordered",
            \ bool "debug", int "Extract"=1)

Compulsory args:

        Clip,   No Default, source clip.
                

Optional args:  (at least one of the frame select options must be supplied).

    F1...Fn Un-named. Zero or more frame numbers.

        SCmd,   string, Default= "", Not set.
                Command String, frame numbers supplied in a string.

        Cmd,    string, Default= "", Not set.
                Command file, frame numbers supplied in a file. Use eg "Select.txt" for command file in your script directory.

        Show    bool, Default= false.
                true = Show info. (Requires v2.6 dll if a v2.6 colorspace, except Y8 OK in 2.5 dll).

        Ver     bool, Default=false.
                true = Show version. (Requires v2.6 dll if a v2.6 colorspace, except Y8 OK in 2.5 dll).

        Reject  bool, Default False. If true then selects frames NOT specified rather than specified frames.
                eg if you have a 5 frame clip (0->4) and have commands to select 4,2 and 0, then reject=true would actually
                select frames 1 and 3 instead.
                If reject=true, then orderering occurs no matter whether Ordered is set true or false and the frames are returned
                in sequential order.
                Reject might be of use to view all frames NOT in a frames command set.

        Ordered bool, Default true. No effect if reject is true, where Ordered will ALWAYS be as if set true.
                If true then all selected frames are sequentially ordered and only unique frames are selected
                and returned in sequential order. If Ordered is set false, no frame number ordering is done and eg if
                frames 10,20,30,20,10 were selected in commands, then it would select 5 frames; 10 and 20 and 30 and 20 and 10,
                are returned and in that order. If Ordered is set default true, then for same example it would return 10 and 20
                and 30, in that sequential order.
                So, the purpose of Ordered=true (default), is to remove duplicates and return sequential frames.
                Only change Ordered to false if you are convinced you know what you are doing.

        Debug   bool, Default false. If true sends a little debug info to debugview window during Plugin initialization. (Google DebugView).
        
        Extract Int, Default 1, MUST be ODD, 1 to 11. Error if not default 1 AND neither Ordered nor Reject == True.
                Let us call the UNIQUE resultant frames after Ordered and/or Reject Processing 'Target' frames.
                The number of frames pulled out on either side of Target frame is Extract / 2 (integer divide), so when Extract=3, it will
                extract 1 frame before target, the Target frame, and 1 frame after target, for each and every Target frame.
                This arg allows you to select eg 3 frames for each Target frame, the previous frame, Target frame and next frame.
                May be of use to extract bad frames together with eg 1 frame either side for saving as bitmaps and editing
                in some kind of RotoScope editor to repair bad frames using image from adjacent frames. The edited frames could
                then be re-loaded, middle one selected via SelectEvery(3,1), and then put back into original source clip via FrameRep().
                Another simple use could be when you have a clip where each frame before a scene change is bad, with Ordered=True
                and Extract=3, you pull out 3 frames, a SelectEvery(3,0) would select the frames previous to the bad frames and
                then use Framerep() to replace the bad frames with those previous to them. A SelectEvery(3,2) would select the frames
                after Target frames.
                The total number of frames pulled out of the source clip will be (Extract * number of Target frames).
                Reject is less likely to be of use with Extract, unless frame select commands specify good frames rather than bad,
                where Reject in FrameRep should also be true (same as in FrameSel, as always).
                See FrameRep() for example uses of Extract.
                  

Either the direct frame numbers, Command string (SCmd), or command file (Cmd) must be supplied.
*** NOTE ***,  if more than one supplied, the commands in the Command File are processed
first followed by those in the SCmd String, and finally the directly supplied frame numbers, relevant when Ordered=false


NOTE, You can use frame ranges for both command file & command string (not possible for directly supplied frame number args).


The 'Cmd' Command file allows one command per line and can contain comments eg:

#------------- # below contents of a text file.
100       # This is a comment
200       # and so is this
300,400   # This is a frame range, specifies all 101 frames between 300 and 400 inclusive [As Trim(300,400)].
500,-2    # Specifies 2 frames starting at frame 500, ie 500 and 501 [As Trim(500,-2)].
600,0     # Specifies ALL frames from frame 600 to the end of the source clip [As Trim(600,0)].
#-------------
So in a command file, a single number specifies a frame, and a comma(,) separator indicates a frame range.
SPACE's are also now accepted as range separators, and can be used instead of commas as in above example.

The "SCmd" string accepts more than 1 command per line, but MUST be separated by a semi colon (;).
The Semi colon is processed as a sort of soft newline and will terminate a comment, so you CANNOT
have a semi colon in a comment. eg

SCMD = "
       1000  # This is a comment ; 2000 # the 2nd arg is 2000; 3000 # the third arg on a single line.
       4000 ; 5000 ; 6000
       7000,8000 ; 9000,-2 ; 10000,0  # Frames 7000-8000, 2 frames starting at 9000, and frame 10000 to end of clip.
"
So in a command string, a comma(,) specifies a frame range, and a semi colon(;) a new command.
SPACE's are also now accepted as range separators, and can be used instead of commas as in above example.


example commands:

FrameSel(clip, 1,2,3,4,5)                               as Trim(1,1) + Trim(2,2) + Trim(3,3) + Trim(4,4) + Trim(5,5)
FrameSel(clip,"100,110;200,-2;300,0")                   as Trim(100,110) + Trim(200,-2) + Trim(300,0)
FrameSel(clip, 1,2,3,4,5,"100;200;300","Select.txt")
FrameSel(clip, 1,2,3,4,5,"100;200;300")
FrameSel(clip, 1,2,3,4,5,"","Select.txt")
FrameSel(clip,"100;200;300","Select.txt")
FrameSel(clip,"","Select.txt")

--------------------------------------
--------------------------------------
--------------------------------------

FrameRep(Clip c,Clip c2 int F1, ... , int Fn, string 'scmd',string 'cmd', bool 'show', bool 'ver',bool "reject",bool "debug")

Video:- All Valid colorspaces

Audio:- Returns source clip c audio.

Args identical to FrameSel, with exception of the compulsory 2nd clip arg which is a clip of frames to replace into the 1st source clip,
and also does not have an Ordered argument, as it is ALWAYS Ordered, and FrameRep, does not have the Extract arg.

See FrameSel() description for other arguments.

FrameRep() is complimentary to FrameSel, whereas FrameSel extracts frames, FrameRep replaces or reseats them (from the c2 clip) back from
whence they came (into the c clip) and using the EXACT same arguments and commands (whether directly supplied or in string command or
file command). If you wish to extract some frames and later replace back into the source clip, you MUST use the default Ordered=True in
FrameSel or the frames may not be replaced back into the positions they originally came from.

The number of Unique Selected frames in the combined frames commands MUST EQUAL the number of frames in the c2 clip (after taking Reject
into account), or it WILL throw an error, (will not know where to put the remainder or frame shortage). This is the reason you should
use the same frame commands in both FrameSel and FrameRep so that there will be an identical number of unique frames and Ordered
sequential. If Debug is set true, it will show a little info in DebugView (Google), eg number of unique frames in a command set.

# ----------------

EXAMPLES REMOVED, HIT D9 16KB limit AGAIN !!!


--------------------------------------
--------------------------------------
--------------------------------------

FrameSel_CmdReWrite(Clip c,String ofn, int F1, ... , int FN, String "SCmd"="", String "Cmd"="", \
      Bool "Reject"=False, Bool "Ordered"=True, Bool "Debug"=False, Bool "Range"=True, Bool "Space"=False, \
      Bool "Prune"=False, int "PruneIx"=0)

Args identical to FrameSel (up to Debug), with exception of the additional compulsory 2nd String arg which is  
an output filename, and missing 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).

      Space,    bool, Default=False
                False = (Default) Write comma separators in output file for ranges.
                True  = Write SPACE separators in output file  instead of comma for ranges.
      
      Prune,    bool, Default=False
                False = (Default) Write FrameSel style frames or ranges to output file.
                True  = Write Prune style frames or ranges to output file (with a clip index first eg '0,10,20' instead of '10,20').
                Prune supports up to 256 input clips that is the reason it needs a clip index.               
                Prune Supports Audio (whereas FrameSel does not) and also allows you to audio fadein/out at splices.
                This function can only output Prune command files, it cannot read Prune command files.  

      PruneIx,  Int, Default 0. [Added in v2.21]
                Only real use for this is if you want to convert a frames/ranges file to ClipClop format instead of Prune format.
                ClipClop and Prune both support 256 clips, and so both need a clip index to specify clip to use.
                With Prune, you might want to work with a single clip and so default PrunIx of 0, will be what you almost
                certainly want. However, with ClipClop, clip index 0 is the source clip, and to work with only 1 replacement
                clip you will almost certainly want to specifiy a clip index of 1 [replace clip index 0 range with same
                clip index 0 range, would do nothing at all].
                When result is intended for Clipclop, its probably a good idea to use ORDERED=True [the default], although ClipClop
                will order and remove duplicate frames/ranges itself.
                There is no validity check of any kind on the PruneIx, it will even output -ve index.

FrameSel_CmdReWrite, 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, and Ordered, args (as in FrameSel)
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.

The FrameSel_CmdReWrite() function returns the total number of frames written to the output file (including ranges).

This function could have several uses:-
  To combine multiple frame specifying command methods into a single command file, and if Ordered, then remove duplicates. 
  Convert single frame command files to frame range command files, (smaller and perhaps easier to peruse).
  Convert frame range command files to single frame command files, for use in another plugin that expects only frame numbers.
  Convert a Reject=True command set to Reject=False command file, and vice versa.
  Convert a command file of single frames/ranges to reject from a clip, into a Prune command file (Prune does not itself have a
    Reject arg but it does fadein/out audio at splices and can also coalesce single frames into ranges before splicing so that
    it does not fadein/out at every single individually specified frame).
  Perhaps more uses.
  
  *** NOTE ***, if you would normally use Reject=True in FrameSel, and you do a conversion with Reject=True, then the resultant
  command file should be used with Reject=False in FrameSel.   

--------------------------------------

StainlessS.
For audio support with fade in/out see trim/splice plugin Prune().
http://forum.doom9.org/showthread.php?t=162446
For frame range replacement see ClipClop().
http://forum.doom9.org/showthread.php?t=162266

See here for two scripts that allow you to select and delete ranges of frames including audio with fadeout/in at splices.
http://forum.doom9.org/showthread.ph...59#post1683559
See MediaFire or SendSpace in sig
__________________
I sometimes post sober.
StainlessS@MediaFire ::: AND/OR ::: StainlessS@SendSpace

"Some infinities are bigger than other infinities", but how many of them are infinitely bigger ???

Last edited by StainlessS; 27th July 2021 at 21:07. Reason: Update
StainlessS is offline   Reply With Quote