VideoHelp Forum
+ Reply to Thread
Results 1 to 22 of 22
Thread
  1. I want to sync 2 video, but one has some blank/black frames in the middle for a pause, while the other just jumps to the next part of the episode.

    I want to add solid black frames in to fill it in with silence to match up with the other source.

    If this is possible, how would I do this with avisynth, whats the script command?
    Quote Quote  
  2. As a function:

    Code:
    function InsertBlank(clip v, int position, int duration)
    {
        # position and duration are frame numbers
        blank = BlankClip(v, length=duration) # create black clip with same properties as existing clip
        v.Trim(0,position-1) ++ blank ++ v.Trim(position,0)
    }
    Call with

    Code:
    named_clip = WhateverSourceWithAudio()
    named_clip = InsertBlank(named_clip, 10000, 50) # insert 50 blank frames at frame 10000
    Quote Quote  
  3. Video Restorer lordsmurf's Avatar
    Join Date
    Jun 2003
    Location
    dFAQ.us/lordsmurf
    Search Comp PM
    This is easier to do visually in an NLE like Premiere.
    I have a project in Premiere right now, with this issue, and a few others.
    Want my help? Ask here! (not via PM!)
    FAQs: Best Blank DiscsBest TBCsBest VCRs for captureRestore VHS
    Quote Quote  
  4. Thanks Jagabo!

    Before I saw your reply, I also came up with the idea to copy black frames from other parts of the episode with trim and place them where I needed in the video. It seems to work for what I was looking for.
    Quote Quote  
  5. Originally Posted by killerteengohan View Post
    Thanks Jagabo!

    Before I saw your reply, I also came up with the idea to copy black frames from other parts of the episode with trim and place them where I needed in the video. It seems to work for what I was looking for.
    Or, if the video doesn't have any black frames, you can make black frames from existing frames by adjusting levels, gain, offset, etc. For example ColorYUV(gain_y=-256, off_y=16, cont_u=-256, cont_v=-256) will create a pure (limited range) black clip.
    Quote Quote  
  6. Another way to insert a delay into a clip is to use Loop to repeat a frame (or a sequence of frames) multiple times. For example:

    Code:
    Loop(51, 1000, 1000)
    will display frames 1000 through 1000 (ie, just frame 1000) a total of 51 times, the original 1 plus 50 copies. Note that the audio is also repeated so this can be annoying.
    Quote Quote  
  7. Originally Posted by lordsmurf View Post
    This is easier to do visually in an NLE like Premiere.
    That's using an elephant gun on a mouse as it's a trivial exercise in AviSynth. VDub serves as the visual and script confirmation. jagabo has already shown several ways to do it. Me, I'd do it like so:


    A=Trim(Last,0,1000)###1000=last frame before black frame insertion
    B=BlankClip(Last,Length=10)###Insert 10 black frames with same characteristics (including silent audio) as rest of video
    C=Trim(Last,1001,0)### resume video after insertion of black frames
    A++B++C###AlignedSplice
    Last edited by manono; 2nd Jun 2019 at 14:10.
    Quote Quote  
  8. Now, supposing I take that black frame, open it in paint, and add a title. How do I add this to the beginning of a clip, and make it last for a few seconds before the video begins?
    Quote Quote  
  9. Here's one way:

    AssumeFPS(23.976)
    Title=ImageSource("Title.bmp",End=99,fps=23.976).C onvertToYV12()
    Title+Last


    You might not need the AssumeFPS line, depending on your framerate, but you'll probably need to set one in the ImageSource line. The default is 24fps. Figure out how many frames for your length at your framerate. This adds 100 frames (Avisynth counting begins with zero) at 23.976fps or just over 4 seconds of title. This doesn't include the audio. If you need silent audio, read up on ImageSource on the AviSynth site. As they both have to be in the same colorspace to join, I added the ConvertTo command.
    Quote Quote  
  10. Assuming the main video is already loaded as "last", YV12, no audio, and the image is already the right dimensions:
    Code:
    title = ImageSource("filename.ext",  start=0, end=int(last.framerate*3.00), fps=last.framerate).ConvertToYV12() # note: 3 seconds
    title+last
    Quote Quote  
  11. Originally Posted by jagabo View Post
    Another way to insert a delay into a clip is to use Loop to repeat a frame (or a sequence of frames) multiple times. For example:

    Code:
    Loop(51, 1000, 1000)
    will display frames 1000 through 1000 (ie, just frame 1000) a total of 51 times, the original 1 plus 50 copies. Note that the audio is also repeated so this can be annoying.
    I never heard of or knew about that before. That is a nice new thing to learn about. Thanks! It can actually save me some time when I don't feel like counting frames.
    Quote Quote  
  12. Originally Posted by manono View Post
    Here's one way:

    AssumeFPS(23.976)
    Title=ImageSource("Title.bmp",End=99,fps=23.976).C onvertToYV12()
    Title+Last

    Can you accomplish the same thing by using your insertblank function + adding a hardcoded subtitle, without having to create an image file?
    Quote Quote  
  13. Originally Posted by Christina View Post
    Originally Posted by manono View Post
    Here's one way:

    AssumeFPS(23.976)
    Title=ImageSource("Title.bmp",End=99,fps=23.976).C onvertToYV12()
    Title+Last

    Can you accomplish the same thing by using your insertblank function + adding a hardcoded subtitle, without having to create an image file?
    Just add a Subtitle() to the blank clip.

    Code:
    function InsertBlank(clip v, int position, int duration)
    {
        # position and duration are frame numbers
        blank = BlankClip(v, length=duration) # create black clip with same properties as existing clip
        blank = blank.Subtitle("This is a subtitle.") # add font, size, x and y positions as desired
        v.Trim(0,position-1) ++ blank ++ v.Trim(position,0)
    }
    Quote Quote  
  14. Originally Posted by jagabo View Post

    Just add a Subtitle() to the blank clip.

    Code:
    function InsertBlank(clip v, int position, int duration)
    {
        # position and duration are frame numbers
        blank = BlankClip(v, length=duration) # create black clip with same properties as existing clip
        blank = blank.Subtitle("This is a subtitle.") # add font, size, x and y positions as desired
        v.Trim(0,position-1) ++ blank ++ v.Trim(position,0)
    }
    Ahh, thanks! I'm totally new to this and just starting to experiment to see what is possible. I think I was making it more complicated than it needs to be since I wanted to add in front of video. So I think I would only need:

    Code:
    video = Avisource("movie.avi")
    blank = BlankClip(video, length=200) # create black clip (200 frames) with same properties as existing clip
    blank = blank.Subtitle("This is a subtitle.") # add font, size, x and y positions as desired
    blank+video
    Right? (PS. I don't really understand "blank.Subtitle" vs Subtitle() ) Also, are these subtitles hardcoded into the video?

    Can you/how would you add FadeIn and FadeOut to both "blank" (so the subtitle would fade in and out) and "video"?

    Also, how would you get multiple lines of subtitles using this format?

    I'm trying to read through the Wiki articles but it's a lot to take in all at once

    Ultimately I'm wondering if I can do simple titling and fading on my videos right in AviSynth (without being an actual "subtitle" that you can turn off). The title would have to be several lines to fit in what I want.. like what the event is, and the date, possibly the location, etc.

    Other than fades and titles, I think the only other processing I would need in most cases is masking, QTGMC and conversion to x264 so if I can avoid using an external editor, that would be great. It's just a lot to wrap your head around when starting out, but so far I like it!
    Quote Quote  
  15. Originally Posted by Christina View Post
    Code:
    video = Avisource("movie.avi")
    blank = BlankClip(video, length=200) # create black clip (200 frames) with same properties as existing clip
    blank = blank.Subtitle("This is a subtitle.") # add font, size, x and y positions as desired
    blank+video
    Right? (PS. I don't really understand "blank.Subtitle" vs Subtitle() )
    subtitle() requires a video to refer to, otherwise which video are you referring to ? In this case the video being subtitled is "blank", but it could have been video1, video99, xyz, myvideo, etc...

    If you did not use variable names, avisynth uses "implied last"

    Code:
    BlankClip(length=200)
    Subtitle("This is a subtitle.")
    This would also work to subtitle the BlankClip , because the clip being referred to is "last"

    Also, are these subtitles hardcoded into the video?
    yes

    Can you/how would you add FadeIn and FadeOut to both "blank" (so the subtitle would fade in and out) and "video"?
    FadeIO for (Fade In/Out)
    http://avisynth.nl/index.php/Fade

    eg. 10 frame fade in/out
    Code:
    blank.fadeio(10)+video.fadeio(10)

    Also, how would you get multiple lines of subtitles using this format?
    lsp=1 line spacing parameter (or greater than 1 if you want to adjust spacing) , with "\n" as the line break character
    eg.
    Code:
    subtitle("first line \nsecond line", lsp=1)
    http://avisynth.nl/index.php/Subtitle
    Quote Quote  
  16. Originally Posted by poisondeathray View Post
    ...
    !!!

    Thank you! Worked perfectly. I get it now. I didn't know about "last" and I read those pages already that you linked but knowing the syntax and how it all goes together to do what you want it to do is tricky when you are just looking at basic isolated examples. Really appreciate both of your help here.

    I'm so excited right now!
    Quote Quote  
  17. Originally Posted by Christina View Post
    Code:
    video = Avisource("movie.avi")
    blank = BlankClip(video, length=200) # create black clip (200 frames) with same properties as existing clip
    blank = blank.Subtitle("This is a subtitle.") # add font, size, x and y positions as desired
    blank+video
    Right?
    Yes, that will work.

    Originally Posted by Christina View Post
    (PS. I don't really understand "blank.Subtitle" vs Subtitle() ) Also, are these subtitles hardcoded into the video?
    Most AviSynth filters take a clip as an input and produce a clip as an output. If you don't supply a name for those clips the name "last" is assumed. So a call like:

    Code:
    Subtitle("This is a subtitle.")
    is the same as:

    Code:
    last = Subtitle(last, "This is a subtitle.")
    the "pipe" character "." pipes the output of the thing on the left to the thing on the right. So the above is the same as

    Code:
    last = last.Subtitle("This is a subtitle.")
    If you didn't specify "blank.Subtitle(...)" in your script above, AviSynth would have assumed you meant "last" and would fail because last has not been defined yet in the script.

    Originally Posted by Christina View Post
    Can you/how would you add FadeIn and FadeOut to both "blank" (so the subtitle would fade in and out) and "video"?
    Use Fade filters: http://avisynth.nl/index.php/Fade
    Code:
    blank = blank.Subtitle("This is a subtitle.").FadeIO0(10) # fade in (over 10 frames at the start) and out (over 10 frames at the end).
    Originally Posted by Christina View Post
    Also, how would you get multiple lines of subtitles using this format?
    You can embed new lines in the subtitle text and include the line spacing parameter, lsp:

    Code:
    blank = blank.Subtitle("This is a subtitle.\nThis is the second line.", lsp=10).FadeIO0(10) # fade in (over 10 frames at the start) and out (over 10 frames at the end).

    Originally Posted by Christina View Post
    the only other processing I would need in most cases is masking
    See Overlay().

    Originally Posted by Christina View Post
    QTGMC
    A pain get set up the first time because there are so many dependencies, versions, etc. But once you have everything it's pretty easy to use.

    Originally Posted by Christina View Post
    and conversion to x264
    Use any encoder that supports AvISynth scripts as input. x264 cli, ffmpeg...
    Quote Quote  
  18. Originally Posted by jagabo View Post
    ...
    Thank you!!! It's all starting to make a lot more sense now and I feel like the programmer I never was.

    Here's what I have so far and it's working out great. I will easily be able to re-use this script and change the text for each video.

    Code:
    video = Avisource("movie.avi")
    blank = BlankClip(video, length=200) # create black clip (200 frames) with same properties as existing clip
    blank = blank.Subtitle("Text line 1 \n" + \
                                    "Text line 2 \n" + \
                                    "Text line 3", \
                                    lsp=10, font="georgia", size=48, text_color=$FFFFFF, x=-1, y=200) # add font, size, x and y positions as desired
    blank.fadeio(20)+video.fadeio(20)
    Very pleased for day 1 of AviSynth! I just got everything installed and working last night, including QTGMC and all its dependencies. I will look into Overlay (thanks) and getting the rest of this script done. If I run into any other issues with that I will start a new thread.

    For converting, the way I know how to do it so far is creating a .bat with the ffmpeg command inside and then executing the .bat. I haven't actually tried it with x264 yet though (only ProRes) so that is the next thing I need to look into with all the available parameters, and see what the best way is.

    Thanks again.
    Quote Quote  
  19. Here's an example batch file for ffmpeg:

    Code:
    "G:\program files\ffmpeg64\bin\ffmpeg.exe" ^
        -i %1 ^
        -c:v libx264 -preset slow -crf 18 -g 50 ^
        -profile:v high -level:v 4.2 -colorspace bt709 -color_range tv ^
        -acodec ac3 ^
        "%~dpn1.avc.mkv"
    pause
    Example x264 cli bat file (video encoding only, no audio):

    Code:
    start /b /low "x264" "g:\program files\x264\x264-64bit.exe" --preset=slow --crf=18 --keyint=50 --sar=1:1 --colormatrix=bt709 --stitchable --output "%~1.mkv" "%~1"
    pause
    Change the path to the exe files to where they are installed on your computer. You can drag/drop an AVS script onto either of those batch file to encode. If you put them in your SendTo folder you can right click on an AviSynth script and select Send To -> Batchname.bat -- where BatchName is whatever you name the batch files.
    Quote Quote  
  20. Originally Posted by jagabo View Post
    "%~dpn1.avc.mkv"
    And is it as simple as changing avc.mkv to avc.mp4 for mp4 container?

    Originally Posted by jagabo View Post
    You can drag/drop an AVS script onto either of those batch file to encode.
    That’s pretty cool. I didn’t know that either. Can you select multiple files and drag and drop them on the batch at the same time to do more than one?

    Also I assume if I use my AVS script to create a intermediate file in say, ProRes format, that I could also just drag and drop the ProRes .mov onto the batch file as well and it would work just fine too?

    Thanks. This helps a lot!
    Quote Quote  
  21. Originally Posted by Christina View Post
    Originally Posted by jagabo View Post
    "%~dpn1.avc.mkv"
    And is it as simple as changing avc.mkv to avc.mp4 for mp4 container?
    Yes

    Also I assume if I use my AVS script to create a intermediate file in say, ProRes format, that I could also just drag and drop the ProRes .mov onto the batch file as well and it would work just fine too?
    Yes ; the "%1" is a wildcard for any input

    But there is generation loss (albeit only a small amount if you're using HQ or 4444XQ) from using the prores file as the intermediate. Using the avs directly would result in less quality loss
    Quote Quote  
  22. Originally Posted by Christina View Post
    Originally Posted by jagabo View Post
    "%~dpn1.avc.mkv"
    And is it as simple as changing avc.mkv to avc.mp4 for mp4 container?
    Yes.


    Originally Posted by Christina View Post
    Originally Posted by jagabo View Post
    You can drag/drop an AVS script onto either of those batch file to encode.
    That’s pretty cool. I didn’t know that either. Can you select multiple files and drag and drop them on the batch at the same time to do more than one?
    Not as written. But you don't have to wait for one to finish before starting another so you can encode multiple files at once. You just have to drag/drop them individually.

    Originally Posted by Christina View Post
    Also I assume if I use my AVS script to create a intermediate file in say, ProRes format, that I could also just drag and drop the ProRes .mov onto the batch file as well and it would work just fine too?
    Yes, as long as the programs have a ProRes decoder built in (most x264 and ffmpeg builds do).
    Quote Quote  



Similar Threads

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