VideoHelp Forum
+ Reply to Thread
Results 1 to 13 of 13
Thread
  1. The Avisynth wiki gives this example of how to use DeleteFrame:
    Code:
    DeleteFrame(3, 9, 21, 42) # delete frames 3, 9, 21 and 42
    Just what I need for an old film with a single splicemark frame at each scene change. But when looking at the preview of my script the splice marks were still there despite the fact that the framecount had gone down by the number of frames I wanted cut. So, to see what was happening, I scripted
    Code:
    trim(5000,5005).deleteframe(5002,5004)
    It returned a four frame clip comprising frames 5000-5003. The two final frames were cut.

    What am I doing wrong? Thanks
    Quote Quote  
  2. In your example, the trim command makes the frame numbers no longer valid. There are new frame numbers after the Trim(), namely 0,1,2,3,4,5 , corresponding to 5000 to 5005. Any subsequent DeleteFrame call out of the new framenumber range (now 0 to 5) will now just delete frames from the end. So you would expect 5004,5005 to be deleted .


    Use a frame accurate source filter

    Post your script
    Quote Quote  
  3. I do a lot of film work and often have to fix splices. While I generally find it easier to do this within Vegas, using Vegas scripts I have written to delete a frame, or replace it with a duplicate of the next or previous frame, I did write an AVISynth script to replace a bad frame at a scene change. Since splice marks always happen at a scene change (even if the splice was to repair broken film, because this usually creates a big enough jump to create a scene change), you may find this useful (or maybe you won't)

    Code:
    #Script to replace frames at scene changes
    
    global scenethreshold=15
    
    source=AVISource("E:\fs.avi").killaudio().convertTOYV12()
    
    # Temporarily un-comment next line to display the average luma value on screen to help determine threshold value
    #ScriptClip(source,"Subtitle(String(YDifferenceToNext(source) ))" )
    
    fixed = ConditionalFilter(source, trim(source,1,0), source, "YDifferenceToNext()>scenethreshold", "greaterthan", "0")
    
    return fixed
    Quote Quote  
  4. Thanks, poison, I understand DeleteFrame now. Seems counterintuitive, in my view, though. Much easier, surely, to specify the rogue frames with their original numbers. What do you mean by a frame accurate source filter? (I get my frame numbers from the .showframenumber command.)

    Thanks, John. I tried various ways of using your script but without success. How should I apply it to this, my standard way of scripting:
    Code:
    LoadPlugin("D:\MeGUI 2944 32bit\tools\lsmash\LSMASHSource.dll")
    a=LWLibavVideoSource("D:\movie.avi")
    b=LWLibavaudioSource("D:\movie.avi")
    audiodub(a,b)
    trim(5149,68345)
    Thanks again, gents.
    Quote Quote  
  5. Originally Posted by pooksahib View Post
    Thanks, poison, I understand DeleteFrame now. Seems counterintuitive, in my view, though. Much easier, surely, to specify the rogue frames with their original numbers.
    Delete the frames referencing the original numbers first, then use trim referencing the new numbers

    What do you mean by a frame accurate source filter? (I get my frame numbers from the .showframenumber command.)
    Basically not DirectShowSource - because the frames can get mixed up. LWLibavVideoSource is (mostly) frame accurate
    Quote Quote  
  6. Originally Posted by poisondeathray View Post
    Delete the frames referencing the original numbers first
    But by what method? That's what I was hoping to do with DeleteFrame (instead of the laborious trim(50,1000)++trim(1002,4444) etc).
    Originally Posted by poisondeathray View Post
    then use trim referencing the new numbers
    I'm thinking this would not be necessary if I'd already deleted the bad frames...!
    Quote Quote  
  7. Originally Posted by pooksahib View Post
    Originally Posted by poisondeathray View Post
    Delete the frames referencing the original numbers first
    But by what method? That's what I was hoping to do with DeleteFrame (instead of the laborious trim(50,1000)++trim(1002,4444) etc).
    Using DeleteFrame

    Do this exercise and step through the frames

    Code:
    BlankClip()
    ShowFramenumber()
    DeleteFrame(3, 9, 21, 42) # delete frames 3, 9, 21 and 42
    Frames 3,9,32, 42 are deleted

    Why do you need Trim at all ?
    Quote Quote  
  8. Thanks, poison, but I've just had a eureka moment. I use MeGUI and if the entire movie is selected then finding the bad frames is difficult due to lack of space in the small preview screen. So I select a few scenes at a time making it easier to find the frames to delete. With my first go at using DeleteFrame I assumed it would delete the original frame number but you put me right on that. But - eureka moment - I can still use DeleteFrame by using the position number rather than the frame number.
    Image Attached Thumbnails Click image for larger version

Name:	zdf.jpg
Views:	3
Size:	23.9 KB
ID:	82896  

    Last edited by pooksahib; 18th Oct 2024 at 01:37.
    Quote Quote  
  9. When you use Trim, it becomes a new clip, with new framenumbers. Another way is to use ShowFrameNumber again . You can position the 2nd instance somewhere else e.g. ShowFramenumber(x=60, y=60) . Or change the color. When you're done, you can comment out all the ShowFrameNumber entries
    Quote Quote  
  10. Nice, hadn't thought of that. Thanks.
    While happy enough with DeleteFrame now (happier if it worked the way I think it should!) I'd still be interested to see how johnmeyer's script works. Can't get it to run at all...
    Quote Quote  
  11. Originally Posted by pooksahib View Post
    I'd still be interested to see how johnmeyer's script works. Can't get it to run at all...
    If you can't get it to run at all, I don't know what to tell you. It only uses basic AVISynth calls, so you don't need to worry about plugins and dependencies, and it should work with any AVISynth version.

    Just to make sure it does really work (it is something I wrote decades ago), I used some 16 fps film from the early 1930s and fed it to the script. It replaced the first frame after each scene change with the frame after that frame (i.e., the 2nd frame after the scene change).

    You obviously need to modify the script so it points to your video file (i.e. you have to replace "fs.avi").

    I made a few slight changes as I did the test (like increasing the scene detection threshold), so here is the slightly revised script. Nothing I did with these small changes should make it suddenly work, if you weren't able to get it to work before, but it did make it work more reliably on my test movie.

    Code:
    #Script to replace first frame after scene change with the 2nd frame after the scene change.
    #You will then have two identical frames after each scene change, something which usually is not noticeable.
    
    global scenethreshold=25
    
    source=AVISource("E:\fs.avi").killaudio().convertTOYV12()
    
    #Temporarily un-comment next line to display the average luma value on screen to help determine threshold value
    #ScriptClip(source,"Subtitle(String(YDifferenceFromPrevious(source) ))" )
    
    fixed = ConditionalFilter(source,  trim(source,1,0), source, "YDifferenceFromPrevious()>scenethreshold", "greaterthan", "0")
    
    #Uncomment the next line to see what is actually happening (i.e., before/after)
    #and also comment out the return line
    
    #stackhorizontal (source,fixed)
    
    return fixed
    Last edited by johnmeyer; 18th Oct 2024 at 16:56. Reason: added more comments to script
    Quote Quote  
  12. P.S. Just before I closed down AVISynth, I tried a clip which still had all the splices intact. The script actually did a lousy job on this. It is no fault of the script but instead shows the reason why, as I mentioned in my first post, I always do my editing in Vegas, using the Vegas scripts I created. The problem is that film splices are really messy and they almost always screw up at least two frames, and sometimes more, depending on how much glue was used, or the length of the tape, if it it was a tape splice. Thus, getting rid of just one bad frame is not enough, and you may actually create a bigger mess.

    You would be well advised to do the editing in your NLE.

    So, when I edit film, I use a scene detection script which gives me the frame numbers for all the scene changes. I import this into Vegas and create markers at each scene change. I can then go immediately to each scene change and use a Vegas script to cut 1, 2, or 3 frames at a push of a single button. It is a little tedious, but even when editing several hours of film, it usually only takes 10-15 minutes.

    With this workflow I can also get rid of the "flash frames" you get at most scene changes because the spinning shutter in film cameras takes 1-2 frames to get up to speed. This causes the first several frames at each scene change to be over-exposed.
    Quote Quote  
  13. Ah, got it, thanks. Although I had to change "source=AVISource" to "source=LWLibavVideoSource". I've not encountered AVISource before, perhaps it needs a plugin that I don't have...
    But the luma values showed up (don't know how to interpret them!) and the before/after worked (although every frame was identical). Running 'return fixed' (with scenethreshold at 25 the first time and 5 the second) did nothing at all - all splice marks intact and no sign of newly inserted duplicate frames. Doesn't matter though, I'm working well enough with DeleteFrame. Many thanks for your time.
    Code:
    LoadPlugin("D:\Free\MeGUI 2944 32bit\tools\lsmash\LSMASHSource.dll")
    global scenethreshold=5
    source=LWLibavVideoSource("D:\movie.avi").killaudio().convertTOYV12()
    
    #Temporarily un-comment next line to display the average luma value on screen to help determine threshold value
    #ScriptClip(source,"Subtitle(String(YDifferenceFromPrevious(source) ))" )
    
    fixed = ConditionalFilter(source,  trim(a,1,0), source, "YDifferenceFromPrevious()>scenethreshold", "greaterthan", "0")
    
    #Uncomment the next line to see what is actually happening (i.e., before/after)
    #and also comment out the return line
    
    #stackhorizontal (source,fixed)
    
    return fixed
    Quote Quote  



Similar Threads

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