VideoHelp Forum




+ Reply to Thread
Results 1 to 6 of 6
  1. Member
    Join Date
    Sep 2016
    Location
    Rogers, ar. USA
    Search Comp PM
    Looking for a way to remove blank scenes from vhs tapes recorded to computer. I see that avisynth uses scripts and was wondering if there is a way to tell blank scenes from other scenes? I can do it manually of course but there are many blank scenes involved.
    Quote Quote  
  2. Member
    Join Date
    Aug 2010
    Location
    San Francisco, California
    Search PM
    Define "blank."
    Quote Quote  
  3. You may be able to automate this with AviSynth and its GScript functions. For example:

    https://forum.videohelp.com/threads/344888-Automatically-Delete-Select-Frames
    https://forum.videohelp.com/threads/358891-Automate-Frame-Grabbing-based-on-screen-events

    But what do you mean by "blank" frames? All black? All Blue or some other color? Random garbage?
    Last edited by jagabo; 18th Sep 2016 at 19:08.
    Quote Quote  
  4. Member
    Join Date
    Sep 2016
    Location
    Rogers, ar. USA
    Search Comp PM
    all black scenes
    Quote Quote  
  5. A minor modification of the GScript method should work for black frames:

    Code:
    GScript("""
      function DeleteFrames(clip c, string condition) {
      # DeleteFrames (Gavino, 16 Nov 2011)
      # A generic function that will delete all frames satisfying an arbitrary user-defined condition.
      # The condition can use any of the Avisynth run-time functions such as AverageLuma(), etc, 
      # and/or the variable 'current_frame'.
      # (Note - Since the condition is evaluated inside the function,
      # any variables used (except current_frame) must be global.)
      # Example use (delete duplicate frames):
      #   DeleteFrames("YDifferenceFromPrevious < 0.1 && current_frame > 0")
    
        c    
        fc = FrameCount()
        res = BlankClip(c, length=0)
        current_frame = 0
        
        while (current_frame < fc) {
          while (Eval(condition) && current_frame < fc) {
            current_frame = current_frame+1
          }
          if (current_frame < fc) { # not at end
            start = current_frame # start of wanted section
            while (!Eval(condition) && current_frame < fc) {
              current_frame = current_frame+1
            }
            res = res + Trim(start, start-current_frame)
          }
        }
    
        return res
      }
    """)
    
    Mpeg2Source("samplempg.d2v")
    DeleteFrames("AverageLuma() < 32") # delete frames whose average luma is less than 32
    In theory "black" frames have luma 16. But VHS caps often have bad black levels so you may need to adjust the luma threshold in the last line. 32 worked for my test clip. You can use floating point values like 31.5 there too. If you video wandering black levels you may have problems with this.
    Last edited by jagabo; 19th Sep 2016 at 13:11.
    Quote Quote  
  6. 1. VideoRedo includes a tool to remove commercials. It works by detecting both the brief fade-to-black and also the absence of audio both of which happen when the broadcast switches from program material to commercials. If you own that, you might be able to use if for your purposes.

    2. I have written a number of scripts that are designed to detect blank sections of video and then output the first and last frame of each blank range. I then import this list into my NLE and do the cutting there. I could have easily added the ability to automatically cut the scenes, but I have found that this is a very "dangerous" thing to do because there are all sorts of situations where dark sections of video might still be useful. One simple example is a scene that is indeed all black, but where there is important audio underneath.

    This script will create a file with the frame number of the beginning and end of each blank section. Feel free to modify it to do the actual deletion, although you have been warned ...

    Code:
    #Script to find blank frames
    #John Meyer
    
    #Specify the name and location of the output file
    filename = "e:\output_blank_frames.txt"
    global blankthreshold=25
    
    #Use one of the following to specify the name and location of your video file
    AVISource("E:\myvideo.avi")
    
    #If needed, get rid of the borders, which on analog captures can have all sorts of 
    #black garbage that can affect the averageluma value
    #Crop(16,16,-16,-16)
    
    # Use the following to reduce the number of fields by 50% in order to speed processing
    separatefields.selectodd
    
    i=last
    j=trim(i,1,0) #Previous frame
    
    # Temporarily un-comment next line to display the average luma value on screen to help determine threshold value
    #ScriptClip(i,"Subtitle(String(AverageLuma(i) ))" )
    
    #This line below will output EVERY frame that is below threshold, which results in LOTS of frames
    #Normally you don't do this, but it is included for those who want this capability.
    #WriteFileIf(last, filename,  "(AverageLuma(i)<blankthreshold)", "current_frame+1", append = false)
    
    #This is the line that actually writes the frame number of the FIRST frame that falls below the threshold
    WriteFileIf(last, filename,  "(AverageLuma(i)<blankthreshold)&&AverageLuma(j)>blankthreshold", "current_frame+1", append = false)
    
    #The line below finds the LAST blank frame. 
    WriteFileIf(last, filename,  "(AverageLuma(i)>blankthreshold)&&AverageLuma(j)<blankthreshold", "current_frame+1", append = false)
    Quote Quote  



Similar Threads

Visit our sponsor! Try DVDFab and backup Blu-rays!