VideoHelp Forum
+ Reply to Thread
Results 1 to 19 of 19
Thread
  1. Member
    Join Date
    Jul 2024
    Location
    Vancouver
    Search Comp PM
    I'm using ReplaceFramesMC to fix a few frames with scratches and black streaks, but I can't figure out how to script it for more than 2 instances at a time. If I have 2 lines of ReplaceFramesMC(), it fixes both, but if I have 3 of them, it only fixes 2. I haven't tried more than 3. But in my video, I have about 20 or so frames out of the 2 hour timeline, and I don't really want to export after 2 fixes, then reopen for the next 2, then the next 2, and so on.

    Here's my script:

    Code:
    video=AVISource("F:\Tape 1\Tape 1.avi")
    ReplaceFramesMC(video, 163465, 1)
    ReplaceFramesMC(video, 163479, 1)
    ReplaceFramesMC(video, 176731, 1)
    
    function ReplaceFramesMC(clip Source, int N, int X)
    {
     # N is number of the 1st frame in Source that needs replacing. 
     # X is total number of frames to replace
     #e.g. RX(101, 5) would replace 101,102,103,104,105 , by using 100 and 106 as reference points for mflowfps interpolation
     
    start=Source.trim(N-1,-1) #one good frame before, used for interpolation reference point
    end=Source.trim(N+X,-1) #one good frame after, used for interpolation reference point
     
    start+end
    AssumeFPS(1) #temporarily FPS=1 to use mflowfps
      
    super = MSuper()
    backward_vec = MAnalyse(super, isb = true)
    forward_vec = MAnalyse(super, isb = false)
    MFlowFps(super, backward_vec, forward_vec, blend=false, num=X+1, den=1) #num=X+1
    AssumeFPS(FrameRate(Source)) #return back to normal source framerate for joining
    Trim(1, framecount-1) #trim ends, leaving replacement frames
      
    Source.trim(0,-N) ++ last ++ Source.trim(N+X+1,0)
    }
    How do I go about configuring it for more than 2 at a time?

    Thanks.
    Quote Quote  
  2. Member
    Join Date
    Jul 2024
    Location
    Vancouver
    Search Comp PM
    Oh well, I was hoping someone had a suggestion, but I guess not. I guess I could just create a bunch of scripts, one for each section to be fixed, then add to a master script that add them all, splicing their outputs into the timeline, exporting it all in one run.
    Quote Quote  
  3. The instructions are right there in the source. ReplaceFramesMC(123, 3) will replace 3 consecutive frames, 123, 124, and 125, with motion interpolated between frames 122 and 126. Note that the longer the string of frames you replace the greater the chance of artifacts.
    Quote Quote  
  4. If you're referring to separate instances of frame ranges, call the video , and use implied "last" to keep all the changes. Otherwise only the last line is processed. The first two instances of ReplaceFramesMC are not used in your script, the changes are not cumulative because you have video=something

    Code:
    video=AVISource("F:\Tape 1\Tape 1.avi")
    
    video
    ReplaceFramesMC(163465, 1)
    ReplaceFramesMC(163479, 1)
    ReplaceFramesMC(176731, 1)
    .
    .
    .
    Or

    Code:
    AVISource("F:\Tape 1\Tape 1.avi")
    
    ReplaceFramesMC(163465, 1)
    ReplaceFramesMC(163479, 1)
    ReplaceFramesMC(176731, 1)
    .
    .
    .
    Quote Quote  
  5. Member
    Join Date
    Jul 2024
    Location
    Vancouver
    Search Comp PM
    Originally Posted by jagabo View Post
    The instructions are right there in the source. ReplaceFramesMC(123, 3) will replace 3 consecutive frames, 123, 124, and 125, with motion interpolated between frames 122 and 126. Note that the longer the string of frames you replace the greater the chance of artifacts.
    Thanks jagabo, but as I said in my original post, I'm trying to script it to work with single frames, at multiple points in the video, not a section with multiple frames within a single stretch.
    Quote Quote  
  6. Member
    Join Date
    Jul 2024
    Location
    Vancouver
    Search Comp PM
    Originally Posted by poisondeathray View Post
    If you're referring to separate instances of frame ranges, call the video , and use implied "last" to keep all the changes. Otherwise only the last line is processed. The first two instances of ReplaceFramesMC are not used in your script, the changes are not cumulative because you have video=something

    Code:
    video=AVISource("F:\Tape 1\Tape 1.avi")
    
    video
    ReplaceFramesMC(163465, 1)
    ReplaceFramesMC(163479, 1)
    ReplaceFramesMC(176731, 1)
    .
    .
    .
    Or

    Code:
    AVISource("F:\Tape 1\Tape 1.avi")
    
    ReplaceFramesMC(163465, 1)
    ReplaceFramesMC(163479, 1)
    ReplaceFramesMC(176731, 1)
    .
    .
    .
    Thanks. I "thought" it had processed 1 and 2 when specifying 2 instances, then 1 and 3 when specifying 3 instances, but I guess I was trippin'. I had already tried the 2nd suggestion without 'video' added, and it errored out saying invalid argument to ReplaceFrameMC. That was actually the first way I wrote it, until seeing that 'video' was in the brackets along with the frame number. But, your first suggestion works like a charm...

    Code:
    video=AVISource("F:\Tape 1\Tape 1.avi")
    
    video
    ReplaceFramesMC(163465, 1)
    ReplaceFramesMC(163479, 1)
    ReplaceFramesMC(176731, 1)
    That makes life so much easier. Thank you very much!
    Quote Quote  
  7. Originally Posted by bmichaelb View Post
    Originally Posted by jagabo View Post
    The instructions are right there in the source. ReplaceFramesMC(123, 3) will replace 3 consecutive frames, 123, 124, and 125, with motion interpolated between frames 122 and 126. Note that the longer the string of frames you replace the greater the chance of artifacts.
    Thanks jagabo, but as I said in my original post, I'm trying to script it to work with single frames, at multiple points in the video, not a section with multiple frames within a single stretch.
    Sorry, I guess I misread the post. I see poisondeathray gave the code for that. I've replaced many dozens of individual frames within a video that way. You can have the function default to replacing a single frame if the X argument isn't supplied: just set the default X value to 1 at the start of the function.

    Code:
    video=AVISource("F:\Tape 1\Tape 1.avi")
    ReplaceFramesMC(video, 163465, 1)
    ReplaceFramesMC(video, 163479, 1)
    ReplaceFramesMC(video, 176731, 1)
    
    function ReplaceFramesMC(clip Source, int N, int X)
    {
     # N is number of the 1st frame in Source that needs replacing. 
     # X is total number of frames to replace
     #e.g. RX(101, 5) would replace 101,102,103,104,105 , by using 100 and 106 as reference points for mflowfps interpolation
    
     X = Default(X, 1)
    
    start=Source.trim(N-1,-1) #one good frame before, used for interpolation reference point
    end=Source.trim(N+X,-1) #one good frame after, used for interpolation reference point
     
    start+end
    AssumeFPS(1) #temporarily FPS=1 to use mflowfps
      
    super = MSuper()
    backward_vec = MAnalyse(super, isb = true)
    forward_vec = MAnalyse(super, isb = false)
    MFlowFps(super, backward_vec, forward_vec, blend=false, num=X+1, den=1) #num=X+1
    AssumeFPS(FrameRate(Source)) #return back to normal source framerate for joining
    Trim(1, framecount-1) #trim ends, leaving replacement frames
      
    Source.trim(0,-N) ++ last ++ Source.trim(N+X+1,0)
    Then you can use:

    Code:
    ReplaceFramesMC(123)
    That will save you a little typing.
    Quote Quote  
  8. Member
    Join Date
    Jul 2024
    Location
    Vancouver
    Search Comp PM
    Originally Posted by jagabo View Post
    Originally Posted by bmichaelb View Post
    Originally Posted by jagabo View Post
    The instructions are right there in the source. ReplaceFramesMC(123, 3) will replace 3 consecutive frames, 123, 124, and 125, with motion interpolated between frames 122 and 126. Note that the longer the string of frames you replace the greater the chance of artifacts.
    Thanks jagabo, but as I said in my original post, I'm trying to script it to work with single frames, at multiple points in the video, not a section with multiple frames within a single stretch.
    Sorry, I guess I misread the post. I see poisondeathray gave the code for that. I've replaced many dozens of individual frames within a video that way. You can have the function default to replacing a single frame if the X argument isn't supplied: just set the default X value to 1 at the start of the function.

    Code:
    video=AVISource("F:\Tape 1\Tape 1.avi")
    ReplaceFramesMC(video, 163465, 1)
    ReplaceFramesMC(video, 163479, 1)
    ReplaceFramesMC(video, 176731, 1)
    
    function ReplaceFramesMC(clip Source, int N, int X)
    {
     # N is number of the 1st frame in Source that needs replacing. 
     # X is total number of frames to replace
     #e.g. RX(101, 5) would replace 101,102,103,104,105 , by using 100 and 106 as reference points for mflowfps interpolation
    
     X = Default(X, 1)
    
    start=Source.trim(N-1,-1) #one good frame before, used for interpolation reference point
    end=Source.trim(N+X,-1) #one good frame after, used for interpolation reference point
     
    start+end
    AssumeFPS(1) #temporarily FPS=1 to use mflowfps
      
    super = MSuper()
    backward_vec = MAnalyse(super, isb = true)
    forward_vec = MAnalyse(super, isb = false)
    MFlowFps(super, backward_vec, forward_vec, blend=false, num=X+1, den=1) #num=X+1
    AssumeFPS(FrameRate(Source)) #return back to normal source framerate for joining
    Trim(1, framecount-1) #trim ends, leaving replacement frames
      
    Source.trim(0,-N) ++ last ++ Source.trim(N+X+1,0)
    Then you can use:

    Code:
    ReplaceFramesMC(123)
    That will save you a little typing.
    Wow... now that's cool. I can write batch file in Windows, and shell scripts in linux, but my knowledge is limited and self-taught. That little bit of info you gave will definitely make things so much easier.

    It's definitely only for a single frame at a time though... multiple frames create too many artifacts. But in a situation where a scratch crosses 3 frames, I found that unfolding the fields side-by-side revealed that the scratch starts in the top field in the first frame, then ends in the bottom field in the 3rd frame, but in both fields in the middle frame. So using johnmeyer's "Replace Bad Field With Motion Estimated Field from Good Field.avs", I run it 2 times... once for odd fields, then once for even fields, then splice out the first and 3rd frames with the newly created good frames, leaving me with the single frame to be replaced. That's now handled by ReplaceFramesMC. Done deal.
    Quote Quote  
  9. Member
    Join Date
    Aug 2018
    Location
    Wrocław
    Search PM
    Originally Posted by bmichaelb View Post
    ...
    I will add that it is better to use RIFE for these purposes. I have never had good results with the method you use.
    Quote Quote  
  10. Yes, RIFE is usually better. Here's a simple function that creates a clip where every frame is interpolated from the two frames around it. Then ReplaceFramesSimple() is used to replace frames within the original video with frames taken from the interpolated video.

    Code:
    ########################################################
    #
    # Replace every frame with a frame motion interpolated
    # from the frame before and after it.  No original
    # frames left.
    #
    ########################################################
    
    function InterpolateAllRIFE(clip c)
    {
        c.z_ConvertFormat(pixel_type="RGBPS", colorspace_op="709:709:709:l=>rgb:709:709:f")
        e = SelectEven().RIFE(gpu_thread=1, model=4).SelectOdd()
        o = SelectOdd().RIFE(gpu_thread=1, model=4).SelectOdd()
        Interleave(e,o)
        Loop(2,0,0)
        z_ConvertFormat(pixel_type=c.pixeltype, colorspace_op="rgb:709:709:f=>709:709:709:l")
    }
    
    ########################################################
    
    
    LWLibavVideoSource("video.ext") 
    
    interp = InterpolateAllRIFE()
    
    ReplaceFramesSimple(interp, Mappings="500 505 509 515") # list of frames to be replaced with interpolated frames
    The listed frames are replaced with RIFE interpolated frames. You can change the RIFE model to whatever works best for your video.

    Note this works only for single bad frames. If there are more than one in a sequence the interpolated frames will include some of the junk from the bad frames.
    Last edited by jagabo; 23rd Aug 2024 at 17:15.
    Quote Quote  
  11. Member
    Join Date
    Jul 2024
    Location
    Vancouver
    Search Comp PM
    Originally Posted by rgr View Post
    Originally Posted by bmichaelb View Post
    ...
    I will add that it is better to use RIFE for these purposes. I have never had good results with the method you use.
    Thank you. I've never heard of RIFE until just now. I'll have to check it out.
    Quote Quote  
  12. Member
    Join Date
    Jul 2024
    Location
    Vancouver
    Search Comp PM
    Originally Posted by jagabo View Post
    Yes, RIFE is usually better. Here's a simple function that creates a clip where every frame is interpolated from the two frames around it. Then ReplaceFramesSimple() is used to replace frames within the original video with frames taken from the interpolated video.

    Code:
    ########################################################
    #
    # Replace every frame with a frame motion interpolated
    # from the frame before and after it.  No original
    # frames left.
    #
    ########################################################
    
    function InterpolateAllRIFE(clip c)
    {
        c.z_ConvertFormat(pixel_type="RGBPS", colorspace_op="709:709:709:l=>rgb:709:709:f")
        e = SelectEven().RIFE(gpu_thread=1, model=4).SelectOdd()
        o = SelectOdd().RIFE(gpu_thread=1, model=4).SelectOdd()
        Interleave(e,o)
        Loop(2,0,0)
        z_ConvertFormat(pixel_type=c.pixeltype, colorspace_op="rgb:709:709:f=>709:709:709:l")
    }
    
    ########################################################
    
    
    LWLibavVideoSource("video.ext") 
    
    interp = InterpolateAllRIFE()
    
    ReplaceFramesSimple(interp, Mappings="500 505 509 515") # list of frames to be replaced with interpolated frames
    The listed frames are replaced with RIFE interpolated frames. You can change the RIFE model to whatever works best for your video.

    Note this works only for single bad frames. If there are more than one in a sequence the interpolated frames will include some of the junk from the bad frames.
    Thank you jagabo, I'll play with this tomorrow. Although ReplaceFramesMC does what I want, I'll give this a try as well.

    Working on a tape last night, making 5 captures to run through Median. But while lining the clips up, 1 of the captures had a duplicate that was actually an inserted extra frame. I didn't know at the time it was extra, so proceeded to run RemoveFramesMC on it. The clip didn't didn't line up properly. Upon closer inspection, I realized it was an extra frame. Instead of 86, 87, 88, it was 86, 87, 87, 88. So after interpolating the frame, it became 86, 87, 87.5, 88. It took me close to an hour to figure out it was an extra frame. Doh!
    Quote Quote  
  13. Member
    Join Date
    Jul 2024
    Location
    Vancouver
    Search Comp PM
    Is RIFE only available for AviSynth+? It errors out with regular Avisynth 2.6. "Script error: there is no function named "z_ConvertFormat". Is it possible to have both AviSynth+ and non-+ versions installed?
    Quote Quote  
  14. Do you have this installed? http://avisynth.nl/index.php/Avsresize

    2.6 and + cannot be installed at the same time unless you have one in 32 bit, the other in 64 bit. Although someone wrote a utility that allows you to easily switch between the two.

    I'm not sure if RIFE requires +. It does require you download a bunch of models and put them in a folder called "models" in the plugins folder.
    Quote Quote  
  15. Member
    Join Date
    Jul 2024
    Location
    Vancouver
    Search Comp PM
    Originally Posted by jagabo View Post
    Do you have this installed? http://avisynth.nl/index.php/Avsresize

    2.6 and + cannot be installed at the same time unless you have one in 32 bit, the other in 64 bit. Although someone wrote a utility that allows you to easily switch between the two.

    I'm not sure if RIFE requires +. It does require you download a bunch of models and put them in a folder called "models" in the plugins folder.
    Thanks jagabo. I didn't have it, but I do now. It's still complaining about no z_ConvertFormat. I even installed the VisualC++ package. The requirements listed on the RIFE page only says AviSynth+, so I guess regular AviSynth isn't going to work. I guess I'll look into an x64 install, then use VirtualDub2 to run it. Now that I have AviSynth regular all set up with the filters I need, I don't want to mess with it.

    Code:
    Requirements
    Vulkan compatible device
    [x64]: AviSynth+ r3682 or greater (AviSynth+ 3.7.3 (test 6, r3935 can be downloaded from here)
    Microsoft VisualC++ Redistributable Package 2022 (can be downloaded from here)
    Supported color formats: RGBPS
    models must be located in the same folder as RIFE.
    Quote Quote  
  16. I didn't realize you don't have AviSynth+. And 64 bit is highly recommended. 32 bit AviSynth and 64 bit AviSynth+ can both be installed on the same Windows64 system. I highly recommend you use 64 bit AviSynth+. All the new development is happening there. Of course, you'll have to find 64 bit versions of all the 32 bit dll files you're using now.
    Quote Quote  
  17. Here's aversion of InterpolateAll() that uses InterFrame (another frame rate doubler):

    https://www.spirton.com/uploads/InterFrame/InterFrame2.html

    Code:
    # replace every frame with a motion interpolated frame (between the frame before and the frame after)
    
    function InterpolateAll(clip c)
    {
        e = SelectEven(c).InterFrame(FrameDouble=true, cores=4).SelectOdd()
        o = SelectOdd(c).InterFrame(FrameDouble=true, cores=4).SelectOdd()
        Interleave(e,o)
        Loop(2,0,0)
    }
    You can also use adapt that to use any other frame rate doubler.
    Quote Quote  
  18. Member
    Join Date
    Jul 2024
    Location
    Vancouver
    Search Comp PM
    Originally Posted by jagabo View Post
    I didn't realize you don't have AviSynth+. And 64 bit is highly recommended. 32 bit AviSynth and 64 bit AviSynth+ can both be installed on the same Windows64 system. I highly recommend you use 64 bit AviSynth+. All the new development is happening there. Of course, you'll have to find 64 bit versions of all the 32 bit dll files you're using now.
    Thanks jagabo. I'll probably set it up on my capture pc, fix any duplicates there before exporting to my editing/gaming pc. Makes things easier.
    Quote Quote  
  19. Member
    Join Date
    Jul 2024
    Location
    Vancouver
    Search Comp PM
    Originally Posted by jagabo View Post
    Here's aversion of InterpolateAll() that uses InterFrame (another frame rate doubler):

    https://www.spirton.com/uploads/InterFrame/InterFrame2.html

    Code:
    # replace every frame with a motion interpolated frame (between the frame before and the frame after)
    
    function InterpolateAll(clip c)
    {
        e = SelectEven(c).InterFrame(FrameDouble=true, cores=4).SelectOdd()
        o = SelectOdd(c).InterFrame(FrameDouble=true, cores=4).SelectOdd()
        Interleave(e,o)
        Loop(2,0,0)
    }
    You can also use adapt that to use any other frame rate doubler.
    Thanks again. Cheers.
    Quote Quote  



Similar Threads

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