VideoHelp Forum




+ Reply to Thread
Results 1 to 14 of 14
  1. Hello.

    Is there a way to loop through frames in a clip in an AviSynth script? Like a "For" or "While" loop structure, but in AVS? If there's no way to loop like this, is there any other way to loop through frames?
    Quote Quote  
  2. Thanks mate! I'll try GScript!
    Quote Quote  
  3. If you don't need to loop infinitely you can just add the clip several times.

    WhateverSource()
    return(last+last+last+last+last...)
    Quote Quote  
  4. Member
    Join Date
    Jul 2009
    Location
    Spain
    Search Comp PM
    Originally Posted by jagabo View Post
    If you don't need to loop infinitely you can just add the clip several times.

    WhateverSource()
    return(last+last+last+last+last...)
    If you just want to repeat a clip (or part of a clip), you can use the Loop function:
    WhateverSource()
    Loop(5)

    To repeat a series of script statements, use the 'for' or 'while' loop in GScript.
    Quote Quote  
  5. Originally Posted by Gavino View Post
    If you just want to repeat a clip (or part of a clip), you can use the Loop function:
    WhateverSource()
    Loop(5)
    Haha! Missed that. Ah and -1 means (nearly) infinite (10^32?).
    Quote Quote  
  6. Member
    Join Date
    Jul 2009
    Location
    Spain
    Search Comp PM
    Originally Posted by jagabo View Post
    Ah and -1 means (nearly) infinite (10^32?).
    -1 (the default) actually gives 10^7 output frames (which is over 100 hours at 25 fps).
    Quote Quote  
  7. Anonymous344
    Guest
    I'm sorry to bump an old thread, but I have a related question. Can one make multiple calls to Loop()?

    Code:
    x=whateversource()
    edit= \
    x.Trim(0,40000).Loop(10,25000,25000) ++\
    x.Trim(40000,80000) ++\
    x.Trim(80000,90000).Loop(10,88000,88000)
    return edit
    The first call to Loop() does what I want it to do. The second seems to do nothing.
    Quote Quote  
  8. Code:
    x.Trim(80000,90000).Loop(10,88000,88000)
    The output of Trim(80000,90000) is a new 10001 frame clip with frames numbered 0 to 10000 (not the original frame numbers). So you can't loop() frame 88000. You want to Loop(10,8000,8000) -- assuming that was your intent.
    Last edited by jagabo; 25th Apr 2014 at 07:17.
    Quote Quote  
  9. Anonymous344
    Guest
    Oh, I understand now! Thanks.

    Could I insert Loop() earlier to achieve the same effect?
    Code:
    x=whateversource()
    edit= \
    x.Trim(0,40000).Loop(10,25000,25000).Loop(10,88000,88000) ++\
    x.Trim(40000,80000) ++\
    x.Trim(80000,90000)
    return edit
    I suppose I could also loop before trimming.

    Code:
    x=whateversource()
    edit= \
    x.Trim(0,40000).Loop(10,25000,25000) ++\
    x.Trim(40000,80000) ++\
    x.Loop(10,88000,88000).Trim(80000,90000)
    return edit
    Quote Quote  
  10. Originally Posted by Richard1485 View Post
    Oh, I understand now! Thanks.

    Could I insert Loop() earlier to achieve the same effect?
    Code:
    x.Trim(0,40000).Loop(10,25000,25000).Loop(10,88000,88000) ++\
    This will have a similar problem. The output of the Trim() is a 40001 frame video. So you can't Loop() frame 88000. Further, the output of the first Loop() has 9 extra frames, so even if your second Loop() was within the trimmed video, you would need to account for the extra 9 frames.

    Originally Posted by Richard1485 View Post
    I suppose I could also loop before trimming.

    Code:
    x=whateversource()
    edit= \
    x.Trim(0,40000).Loop(10,25000,25000) ++\
    x.Trim(40000,80000) ++\
    x.Loop(10,88000,88000).Trim(80000,90000)
    return edit
    That will work. Except you need to account for the extra 10 frames you added with the Loop(). Ie, as written, you are losing 9 frames at the end of the original video.
    Last edited by jagabo; 25th Apr 2014 at 08:08.
    Quote Quote  
  11. Anonymous344
    Guest
    Originally Posted by jagabo View Post
    This will have a similar problem. The output of the Trim() is a 40001 frame video. So you can't Loop() frame 88000.
    I really should have thought of that...

    Further, the output of the first Loop() has 10 extra frames, so even if your second Loop() was within the trimmed video, you would need to account for the extra 10 frames...

    ...That will work. Except you need to account for the extra 10 frames you added with the Loop(). Ie, as written, you are losing 10 frames at the end of the original video.
    That all make sense. I'll have to change the way I think about the frame numbers because I keep thinking of them in terms of the original video, rather than the looped/edited video. It's a problem I have come across in the past when writing scripts with multiple calls to DeleteFrame() and DuplicateFrame(). Thanks again.
    Quote Quote  
  12. Originally Posted by Richard1485 View Post
    It's a problem I have come across in the past when writing scripts with multiple calls to DeleteFrame() and DuplicateFrame(). Thanks again.
    Yes, it's easiest to work from last to first in those circumstances. Ie, if you know you want to delete frames 10, 20 and 30 from the original video:

    Code:
    DeleteFrame(30)
    DeleteFrame(20)
    DeleteFrame(10)
    is much easier than:

    Code:
    DeleteFrame(10)
    DeleteFrame(19)
    DeleteFrame(28)
    Quote Quote  
  13. Anonymous344
    Guest
    That's a good idea. I guess it would work with the situations I come across, in which my script is more like this.

    Code:
    WhateverSource()
    DeleteFrame()
    DuplicateFrame()
    DeleteFrame()
    DuplicateFrame()
    DeleteFrame()
    I usually obviate the confusion by using Trim() instead.

    Code:
    x=WhateverSource() \
    .ShowFrameNumber(scroll=true)
    edit= \
    x.Trim(0,1000) ++\
    x.Trim(1002,2000) ++ \
    x.Trim(2000,1000) ++ \
    return edit
    This gets rid of 1001 and duplicates 2000. Obviously, it's a simple example: my scripts are often long. The advantage to me is that ShowFrameNumber() is applied to the original video, so I can see which frames are being added or omitted when scrolling through the video. I'm sure I'll figure out a way to adopt a similar approach when using Loop().
    Quote Quote  



Similar Threads

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