VideoHelp Forum
+ Reply to Thread
Results 1 to 11 of 11
Thread
  1. I've been reading like every post about Trim() I could find on Google and duration of images etc, and can't find one single example (nor make one myself that work).

    I got this code that takes an image, removes the background so it becomes transparent, and places it on a video, it's all perfect. My problem is, I don't want it to last from the first frame to the last, I want to be able to control what frame it begins and ends on, and I've not yet found out how. Anyone of you know?

    a1=DirectShowSource("f:\Video.avi")
    a2=ImageReader("f:\Logo.png")
    a3=ImageReader("f:\Logo.png",pixel_type="RGB32").S howAlpha(pixel_type="RGB32")
    Overlay(a1,a2,mask=a3,x=50,y=50)

    Thanks in advance.
    Quote Quote  
  2. See if this works:

    a1=DirectShowSource("f:\Video.avi")
    a2=ImageReader("f:\Logo.png")
    a3=ImageReader("f:\Logo.png",pixel_type="RGB32").S howAlpha(pixel_type="RGB32")
    a4=Overlay(a1,a2,mask=a3,x=50,y=50)
    ReplaceFramesSimple(a1,a4,Mappings="[1000 2000] [5000 6000]")#the frames where you want to use it


    ReplaceFramesSimple is part of stickboy's RemapFrames filter which can be found here:

    http://www.avisynth.nl/users/stickboy/
    Quote Quote  
  3. Another way is to use Trim() to break your video into sections. Then apply the logo t one section. Then append the two (or more) sections:

    Code:
    DirectShowSource("f:\Video.avi")
    a2=ImageReader("f:\Logo.png")
    a3=ImageReader("f:\Logo.png",pixel_type="RGB32").S  howAlpha(pixel_type="RGB32")
    
    part1=Trim(0,999).Overlay(last,a2,mask=a3,x=50,y=50) # first 1000 frames with overlay
    part2=Trim(1000,0) # the rest without
    
    part1+part2
    Quote Quote  
  4. Thanks guys, much appreciated. Will try them out later when I get the time. If I don't return, they worked
    Quote Quote  
  5. I used manobo's code as Jagabo's didn't work, just threw errors which I couldn't fix. It complained on the overlay row, might be the "last" thingy it didn't get, donno.

    Anyway, I modded my code and included an image sequence, it plays perfectly. My problem is it starts playing from frame 0 in the movie, so when I later want it to display, like at frame 1000, I just get a still of the last frame in the sequence.

    For example:

    I set it to display the image sequence at frame 1000 to 1060 (60 frames long), at frame 1000 to 1060 it just shows the last frame. But from 0-999 there is no image ofc, which is how it should be.

    So, seems like it starts playing at frame 0, even if it's not displayed yet, and only shows the last frame if displayed any later than frame 60. But well, if it was displayed at frame 58, it would just play 2 frames anyway.

    So, how can I make it start playing where I want?


    a1=DirectShowSource("h:\movie.avi")
    a2 = ImageSource("h:\logo%04d.png", start=1, end=60, fps=2, pixel_type="RGB32")
    a3 = ImageSource("h:\logo%04d.png", start=1, end=60, fps=2, pixel_type="RGB32").ShowAlpha(pixel_type="RGB32")
    a4=Overlay(a1,a2,mask=a3,x=0,y=0)
    ReplaceFramesSimple(a1,a4,Mappings="[0 60]")# it plays from frame 0-60 and disappears, which is perfect, but I want it to start playing from i.e. frame 1000 ([1000 1060] = last frame only for 60 frames).
    Quote Quote  
  6. Originally Posted by Genex9 View Post
    Jagabo's didn't work, just threw errors which I couldn't fix. It complained on the overlay row, might be the "last" thingy it didn't get, donno.
    Sorry. I didn't test the script. Just remove the "last" argument from the Overlay call:

    Code:
    DirectShowSource("h:\movie.avi")
    a2=ImageReader("Logo.png")
    a3=ImageReader("Logo.png",pixel_type="RGB32").ShowAlpha(pixel_type="RGB32")
    
    part1=Trim(0,999).Overlay(a2,mask=a3,x=50,y=50) # first 1000 frames with overlay
    part2=Trim(1000,0) # the rest without
    
    part1+part2
    Originally Posted by Genex9 View Post
    My problem is it starts playing from frame 0 in the movie, so when I later want it to display, like at frame 1000, I just get a still of the last frame in the sequence.
    You can use Loop() to increase the length (repeat the sequence over and over again) of the overlay and alpha channel animations.
    Quote Quote  
  7. Originally Posted by jagabo View Post
    You can use Loop() to increase the length (repeat the sequence over and over again) of the overlay and alpha channel animations.
    I'm aware of Loop(), but can't use that as it will just make the animation to play from a random frame. I mean, by the time I want the animation to play, it could be in the middle of the animation and start playing half way into the animation. I need the animation (image sequence) to play from the start (logo0001.png). Only way to use Loop() would be if I checked how many times it has looped up to the point I wanna play, like, after it has looped 60 times, it will start again at frame 1000 if it started from frame 0, but I have no control of on what frame it needs to start playing, it's random from movie to movie, so I really need it to start playing from logo0001.png at the frame of my movie frame of my choice.
    Quote Quote  
  8. Originally Posted by Genex9 View Post
    I need the animation (image sequence) to play from the start (logo0001.png). Only way to use Loop() would be if I checked how many times it has looped up to the point I wanna play, like, after it has looped 60 times, it will start again at frame 1000 if it started from frame 0, but I have no control of on what frame it needs to start playing, it's random from movie to movie, so I really need it to start playing from logo0001.png at the frame of my movie frame of my choice.
    You can use Loop to duplicate the first frame as many times as needed to sync it to where you want the overlay to start. For example, if you want the logo overlay to start with frame 0 at frame 1000 of the video, duplicate the first frame 1000 times. Then loop the 60 frame sequence as many times as necessary for the duration of the overlay. Put this in a function and you can easily call anywhere you need it.
    Quote Quote  
  9. Member
    Join Date: Sep 2007
    Location: Canada
    Search Comp PM
    1) Use AVISource() for AVI because DirectShowSource() isn't necessary frame accurate, prone to other issues like inadvertent directshow filters which you haven't disabled


    2) I'm assuming your overlay image sequence is animated, not static single frame ? It makes it slightly more difficult

    If it was a static single frame overlay, that you only want to overlay on certain frames - you could just overlay the entire video and swap between (overlayed version) vs. (original version) using trim() or replaceframesimple or similar plugins . (ie. don't trim the image sequence ; make it match the entire length of the video)



    One problem is your numbering isn't correct

    Your image sequence goes from 01-60 or 60 frames

    The replacement goes from 1000-1060 or 61 frames

    Avisynth normally starts numbering at zero

    So in this example, the overlay from 01-60 is overlayed onto original frames 1001-1060 . You can adjust the timing but they have to match the same number of frames

    Code:
    a1=AVISource("h:\movie.avi")
    a2=ImageSource("h:\logo%04d.png", start=1, end=60, fps=2, pixel_type="RGB32")
    a3=Overlay(a1.trim(1001,1060),a2,mask=a2.ShowAlpha(),x=0,y=0)
    
    a1.trim(0,1000) ++ a3 ++ a1.trim(1061,0)
    So If you wanted to overlay from 1000-1059, shift the times by 1

    Code:
    a1=AVISource("h:\movie.avi")
    a2=ImageSource("h:\logo%04d.png", start=1, end=60, fps=2, pixel_type="RGB32")
    a3=Overlay(a1.trim(1000,1059),a2,mask=a2.ShowAlpha(),x=0,y=0)
    
    a1.trim(0,999) ++ a3 ++ a1.trim(1060,0)
    Last edited by poisondeathray; 23rd Jan 2014 at 10:52.
    Quote Quote  
  10. Originally Posted by jagabo View Post
    You can use Loop to duplicate the first frame as many times as needed to sync it to where you want the overlay to start. For example, if you want the logo overlay to start with frame 0 at frame 1000 of the video, duplicate the first frame 1000 times. Then loop the 60 frame sequence as many times as necessary for the duration of the overlay. Put this in a function and you can easily call anywhere you need it.
    I don't have the skill to do that , and wouldn't that still mean like I said earlier, that looping 60 frames till the point I wanna play it could mean I couldn't play it at the exact frame I wanted, only every 60 frames, like I could start it at frame 180, as it needed to loop 3 times before that, but what if frame 150 or 200, then it would be in the middle of the image sequence, but maybe that's not what you meant, and what you explained actually means to play it exactly from whatever frame I want. I'm not clever enough to understand I guess Anyway, got it to work as I want it with poisondeathray's example, so thanks anyway for your time and help

    Originally Posted by poisondeathray View Post
    Code:
    a1=AVISource("h:\movie.avi") 
    a2=ImageSource("h:\logo%04d.png", start=1, end=60, fps=2, pixel_type="RGB32") 
    a3=Overlay(a1.trim(1001,1060),a2,mask=a2.ShowAlpha(),x=0,y=0)  
    
    a1.trim(0,1000) ++ a3 ++ a1.trim(1061,0)
    I can't use AVISource as it doesn't play the movies properly. With it, every second frame is black, and every second frame with an image is randomly jumping around between frames anywhere between current frame and 1000+, also the image sequence is played twice on top of each other with delay so I see two etc. But when I switched back to DirectShowSource, it all played perfectly Have had this problem for years, always had to use DirectShowSource. I remember at one time, my movies only showed green with AVISource. Anyway, DirectShowSource has never failed me and I've encoded a loooooot of movies , I care about pixel perfectly quality, proper aspect ratio and frame rate, I'm very sensitive to anything that isn't perfect. I usually do my stuff in Virtual Dub, and not much scripting in avs, just the basic loading of movie, set size or whatever and drop it in megui or whatever I use. I do longplays, you can see some of them here: LINK (movies older than 2 years aren't that good on youtube, they need to be downloaded from the website. Only downloading the original files = proper quality and frame rate), and here: LINK (a fav as I like the music in the intro, cool for an Amiga game: LINK)

    So now I can play the image sequence from frame 0 of the animation from any frame in the movie I want , thank you both very much for your help.
    Quote Quote  
  11. Originally Posted by Genex9 View Post
    Originally Posted by jagabo View Post
    You can use Loop to duplicate the first frame as many times as needed to sync it to where you want the overlay to start. For example, if you want the logo overlay to start with frame 0 at frame 1000 of the video, duplicate the first frame 1000 times. Then loop the 60 frame sequence as many times as necessary for the duration of the overlay. Put this in a function and you can easily call anywhere you need it.
    I don't have the skill to do that , and wouldn't that still mean like I said earlier, that looping 60 frames till the point I wanna play it could mean I couldn't play it at the exact frame I wanted, only every 60 frames
    No, it would do exactly what you want.
    Quote Quote  



Similar Threads