View Single Post
Old 27th February 2014, 04:31   #5  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 10,980
New version, v2.11, see 1st post.

Code:
	v2.10 - 23 Feb 2014 :
		Fixed All Frames Rejected bug (zero length return clip), best throw an error.
		Implemented Unique_Sort(), much faster in unlikely event that frames are in random order (when Ordered or Reject) .
		Added function FrameSel_CmdReWrite();
	v2.11 - 27 Feb 2014 : 
		Fixed, v2.5 dll only worked with YV12 or Y8 (EDIT: FrameRep, when Show or Ver), (throw error) oops.
		Added Extract arg to FrameSel().
FrameSel Extract Arg
Code:
       Extract Int, Default 1, MUST be ODD, 1 or 3 or 5 or 7. 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.
Here, Examples removed from 1st post due to draconian D9 16KB limit in Usage forum
Code:
Here, Example to do some simple editing on selected frames, try changing REJECT to True.

Colorbars.Trim(0,-10).ShowFrameNumber()                            # 10 frames
sCmd="2;5;6"                                                       # Frames in SCmd string
REJECT=False                                                       # False=modify SCmd frames : True=modify frames NOT in SCmd
SELECTED=FrameSel(scmd=sCMD,ordered=TRUE,reject=REJECT,debug=true) # We are going to use FrameRep, must use ORDERED=True (OR REJECT=True)
SELECTED=Invert(SELECTED)                                          # Do some editing
FrameRep(Last,SELECTED,scmd=sCMD,reject=REJECT,debug=true)         # Put edited frames back into original Last clip (audio from Last)
return Last

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

Example use when NOT selecting/replacing in exact same position:
  Lets say you have a clip with a bad frame before each scene change and you want to replace these bad frames with the frame immediately
before it.

    C=Colorbars().Trim(0,-50).ShowFrameNumber()                    # 50 frames (0 -> 49)
    BADFRAMES = "10;20;30;40"                                      # 4 bad frames in source clip
    PREBAD    = " 9;19;29;39"                                      # 4 frames immediately before bad frames
    REPAIR=FrameSel(C,scmd=PREBAD)                                 # Get the 4 frames we will duplicate
    Return FrameRep(C,REPAIR,scmd=BADFRAMES)                       # fix bad frames with REPAIR clip from PREBAD frames

Will produce a duplicate at frames 10, 20, 30, and 40 in source clip.

When used as above you must ensure that eg BADFRAMES and PREBAD have the same number of unique frames and sequential or results
may not be as expected (ie use Ordered).

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

Same Example again using Extract arg:-

    C=Colorbars().Trim(0,-50).ShowFrameNumber()                     # 50 frames (0 -> 49)
    BADFRAMES = "10;20;30;40"                                       # 4 bad frames in source clip
    EXTRACT=FrameSel(C,scmd=BADFRAMES,ordered=True,extract=3)       # Extract Previous, Target and Next frames for each Target frame
    REPAIR=EXTRACT.SelectEvery(3,0)                                 # Select each frame previous to Target bad frames, 1st of each triplet
    #REPAIR=REPAIR.Invert()                                         # So we can easily see repaired frames
    Return FrameRep(C,REPAIR,scmd=BADFRAMES)                        # Fix bad frames with REPAIR clip using exact same BADFRAMES spec.

# ----------------
Example scripts to show use with a paint program for manual frame repair.

    # Extract Script
    C=Colorbars().Trim(0,-50).ShowFrameNumber.ConvertToRGB24        # 50 frames (0 -> 49), RGB24
    BADFRAMES = "10;20;30;40"                                       # 4 bad frames in source clip
    EDITCLIP=FrameSel(C,scmd=BADFRAMES,ordered=True)                # Extract BAD frames
    EDITCLIP.ImageWriter(file="Pic%06d.bmp",type="bmp",info=true)   # Write bitmaps to edit 
    return Last
    # Need to play all way through for ImageWriter to work properly.

    # Here, EDIT bad frames in paint program 

    # Replace Script, after editing
    C=Colorbars().Trim(0,-50).ShowFrameNumber.ConvertToRGB24        # 50 frames (0 -> 49), RGB24
    BADFRAMES = "10;20;30;40"                                       # 4 bad frames in source clip
    END = 3                                                         # unique_bad_frames - 1 (number of frames in BADFRAMES-1)
    REPAIRED=ImageReader(file="Pic%06d.bmp",end=END)
    #REPAIRED=REPAIRED.Invert()                                     # Hilite repaired frames, easier to see
    Return FrameRep(C,REPAIRED,scmd=BADFRAMES,show=true)            # Fix bad frames with REPAIRED clip using exact same BADFRAMES spec.
    # NOTE, you need to tell ImageReader the last frame number to read,
    # the default for End is 1000, so imagereader will read in 4 frames (0 to 3) and 997 duplicates,
    # FrameRep would throw an error as it does not know what to do with the unwanted 997 duplicate frames that were 'helpfully' appended.
    # The 1st script, ImageWriter(Info=True) arg, shows the FrameNumber and name for each frame, and the number shown on the last frame
    # can be assigned to END in 2nd script, shows eg "Frame 3 written to: D:\Pic000003.bmp".
    # The Last frame number shown by Info=True, will be correct even if BADFRAMES list (in eg string or command file) has duplicates
    # as they will be sorted and only unique frames delivered by FrameSel when Ordered=True is used, eg 
    #  BADFRAMES="40;30;20;10;20;30;40", if used in 1st script FrameSel will select exactly the same frames as BADFRAMES="10;20;30;40",
    # ie 4 frames and in sequential order (Ordered=True). 

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

Example scripts to show use with a paint/rotoscope program that can read in bad frames together with previous and next frames,
  and manually fix frames using image data from previous or next frames to repair damage.
    # Extract Script
    C=Colorbars().Trim(0,-50).ShowFrameNumber.ConvertToRGB24        # 50 frames (0 -> 49), RGB24
    BADFRAMES = "10;20;30;40"                                       # 4 bad frames in source clip
    EDITCLIP=FrameSel(C,scmd=BADFRAMES,ordered=True,extract=3)      # Extract Previous, Target and Next frames for each BAD frame
    EDITCLIP.ImageWriter(file="Pic%06d.bmp",type="bmp",info=true)   # Write bitmaps to edit 
    return Last

    # Here, EDIT in Triple frame paint/rotoscope editing program 

    # Replace Script, after editing triplets
    C=Colorbars().Trim(0,-50).ShowFrameNumber.ConvertToRGB24        # 50 frames (0 -> 49), RGB24
    END = 11                                                        # unique_bad_frames * Extract - 1
    BADFRAMES = "10;20;30;40"                                       # 4 bad frames in source clip
    EDITCLIP=ImageReader(file="Pic%06d.bmp",end=END)
    REPAIRED=EDITCLIP.SelectEvery(3,1)                              # Select repaired BAD frames, 2nd of each triplet
    #REPAIRED=REPAIRED.Invert()                                     # Hilite repaired frames, easier to see
    Return FrameRep(C,REPAIRED,scmd=BADFRAMES,show=true)            # Fix bad frames with REPAIRED clip using exact same BADFRAMES spec.
EDIT:
Extract now fully implements support for original intent, as in previous post link.

What we need now is a Windows progger to write a RotoScope type frame editor that supports import of previous,
Target, and next frames, as either a clip or a bunch of frame triplets (for Copy/Rub-Through From Adjacent Frame, or Interpolated
From Adjacent Frames, or maybe even quintuplets or septets for motion predicted frames/pixels).
__________________
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; 12th June 2014 at 22:36.
StainlessS is offline   Reply With Quote