VideoHelp Forum
+ Reply to Thread
Results 1 to 21 of 21
Thread
  1. Hi

    I am currently trying to overlay one video onto another. After this, I want to trim a certain part of it so it starts playing at a certain point, and trimming a certain point at the end of it so it doesn't interfere with the rest of the video.

    Here is my script:

    som=AviSource("SOM.avi").converttorgb32
    replay=AVISource("COURSE.avi")

    transparent=resetmask(som).colorkeymask($FB0010, 94)

    Overlay(replay, som, mask=ShowAlpha(transparent), x=1097, y=619, mode="blend", opacity=1)

    Alternatively, I purposely have transparency in there because I am making a part of the overlaid video transparent. I tried adding trim in many different places to no avail.

    In short, I'll give you the context on what I want to achieve:

    The overlaid video actually is a portion of a different part of the original video, placed at a certain spot on the video, so in theory this means both videos are in sync. I want to trim a part of the beginning of the overlaid video so it starts at a certain point in bot the overlaid video and in the video itself, as well as ending in the same way.

    I am sorry if this is kind of vague. Any help is deeply appreciated, thank you.
    Quote Quote  
  2. Member
    Join Date
    Jul 2009
    Location
    Spain
    Search Comp PM
    I'm not sure I totally understand your question, but if what you want is for the overlay to appear only for a certain range of frames, say frames 200-500, you would do this:

    ...
    ov = Overlay(replay, som, ...)
    replay.Trim(0,199) ++ ov.Trim(200,500) ++ replay.Trim(501,0)

    This gives the overlay 'in sync' with the original.
    If, alternatively, you want the overlay to appear on a different frame to the original, you would have to Trim either replay or som in the Overlay parameters too.
    Quote Quote  
  3. I modified my overlaid video a bit and that did the trick. Thanks a lot

    Final script looks like this:

    som=AviSource("SOM.avi").converttorgb32
    replay=AVISource("COURSE.avi")

    transparent=resetmask(som).colorkeymask($FB0010, 94)

    ov = Overlay(replay, som, mask=ShowAlpha(transparent), x=1097, y=619, mode="blend", opacity=1)

    replay.Trim(0,205) ++ ov.Trim(206,3793) ++ replay.Trim(3794,0)

    Hopefully if someone has the same problem they can look at this thread and see how I fixed my problem. Thanks again.
    Quote Quote  
  4. I have a different issue now but I didn't want to make another topic just for it.

    I am trying to overlay a picture in my video, but when I open my script in Virtualdub, I get these weird artifacts where some pixels are acting as though they are meant to be transparent. (The picture is actually meshed with my overlaid video and I have it so I disable the color to make it transparent) The desired effect works but there are still pixels acting as though they should be disabled when they shouldn't. I'll show you the example:

    http://i282.photobucket.com/albums/kk277/NMeade94/8d85deeb.png

    If you can't see so well, just zoom in on the image, and you see it on the "k" of "km/h" and the right side of the "h", I'll show you a zoomed in image on what the overlaid image looks like:

    http://i282.photobucket.com/albums/kk277/NMeade94/a034eaad.png

    As you can see, apart from the screenshot of the script in Virtualdub, the second picture clearly shows that those pixels aren't the red that should be disabled (in fact, you see it in the top middle portion of it).

    Could this be the result of importing the image wrong when I am originally combining it with my overlaid video? This is what the script originally looks like when I create the overlaid video:

    v1 = DirectShowSource("C:\Users\Nicholas\My Videos\pr\begin.ts").Crop(24, 12, -14, -14).Sharpen(0.35).Lanczos4Resize(640, 360).Sharpen(0.35).Tweak(sat=1.1) ++ DirectShowSource("C:\Users\Nicholas\My Videos\pr\som.ts").Crop(24, 12, -14, -14).Sharpen(0.35).Lanczos4Resize(640, 360).Sharpen(0.35).Tweak(sat=1.1)
    v2 = ImageReader("C:\Users\Nicholas\Desktop\Unused Documents\transparent s-o-m\kmh5.png", pixel_type="RGB32")
    v3 = Overlay (v1, v2, x = 547, y = 48)
    return v3

    Anything horribly wrong with that? I have a feeling it will lie in the way that I am importing the image...
    Quote Quote  
  5. Member
    Join Date
    Jul 2009
    Location
    Spain
    Search Comp PM
    Are you trying to use the alpha channel of your image to get transparency?
    If so, you need to use
    v3 = Overlay (v1, v2, mask=ShowAlpha(v2), x = 547, y = 48)
    Quote Quote  
  6. Thanks for the response Gavino.

    Yeah I am pretty sure I am trying to use the alpha channel for transparency since it's going for the video above it as well (the numbers).

    I tried changing the script to what you had and it still has those artifacts. :/ Maybe there is a different way/method to get the transparency right?
    Quote Quote  
  7. Member
    Join Date
    Jul 2009
    Location
    Spain
    Search Comp PM
    If adding mask=ShowAlpha(...) makes no difference, that suggests something wrong with the transparency data in your input image, since without it Overlay ignores transparency altogether.

    But another possible source of artifacts is chroma subsampling.
    Try adding output="RGB32" to the Overlay command and see if it make a difference.
    Of course, that won't be much help if your final destination requires YV12 (eg xvid or H.264), but at least it might confirm where the problem lies.
    Quote Quote  
  8. Good point, I use xvid to save my videos when I am ready.

    I put the "output="RGB32" in the script as you said, and as expected, it is still the same. I don't understand why it happens if the problem lies in xvid when it is not even used yet?

    If this makes any difference, when I put the image and the overlaid video together, I don't save it with xvid, I save it uncompressed.
    Quote Quote  
  9. Member
    Join Date
    Jul 2009
    Location
    Spain
    Search Comp PM
    Originally Posted by NMeade View Post
    I put the "output="RGB32" in the script as you said, and as expected, it is still the same. I don't understand why it happens if the problem lies in xvid when it is not even used yet?
    It's not that the problem lies in xvid as such. I wanted to see if outputting as RGB32 would remove the artifacts, in order to determine if they were caused by chroma subsampling. But as Xvid requires YV12 (4:2:0 chroma subsampled), this would not have been a solution for you anyway, as you would have had to convert it back to YV12 eventually.

    Anyway, it seems this is not the source of the problem, so attention switches back to your image used to overlay.
    How are you producing it?
    Could you post it here (or to some upload site), exactly as is?
    Quote Quote  
  10. Original from a friend:

    http://i282.photobucket.com/albums/kk277/NMeade94/97c766cc.png

    I then delete everything I don't need and drag what I need to the top left in paint, then save it.
    Quote Quote  
  11. Member
    Join Date
    Jul 2009
    Location
    Spain
    Search Comp PM
    That image has no transparency at all - it is completely opaque.
    I thought the script you showed at post #4 was what you used to overlay the "km/h" image.
    Or is that the script used to produce the base image?

    So maybe you have missed out some details of your script.
    On a hunch, I tried overlaying the "km/h" image using the chroma key mask from your very first post:
    colorkeymask($FB0010, 94)
    and it produced exactly the effects you are complaining about. Aha!

    The problem is the 'tolerance' you have set for the mask (94) is too big - any pixels with a red value between 158 and 255 (ie differing by less than 94 from 251, or hex FB) will be made transparent.
    The solution is to use a smaller tolerance - the default 10 will work.
    Since your background color is pure red, you can use
    ColorKeyMask($FF0000)
    Quote Quote  
  12. The script I posted up there referring to my image wasn't implying that it was just purely going over my video, sorry if you thought otherwise.

    The red behind the image is purposely put there. I combine both my image and the overlayed video together to form one video, I save it uncompressed, then I overlay that over my actual video. Since the video I am merging with the image also has a red background, it is practical to have both the same color so the colorkeymask can disable the color with no problems.

    The max tolerance for the video itself being merged with the image is 94, anything below that and the transparency won't be there anymore. If I put it at let's say 75, some of the red around the whole thing is still there. I'll show you an example:

    tolerance 75 http://i282.photobucket.com/albums/kk277/NMeade94/8e4bbec7.png

    Maybe that's a bad example, it wasn't as obvious as 10, but the artifacts are still there anyway, I'll show you 10:

    tolerance 10 http://i282.photobucket.com/albums/kk277/NMeade94/64309923.png

    So I guess I am limited on what I can do if the max tolerance for the video being merged with the image is 94 while that is affecting the image itself.

    I am pretty sure I've tried overlaying the image itself on the video where I want it, but I would constantly get an error because I used colorkeymask twice and I guess you can't do that.

    This sounds more complicated than it needs to be lol
    Quote Quote  
  13. Member
    Join Date
    Jul 2009
    Location
    Spain
    Search Comp PM
    If I understand what you are trying to do, you have a base video and you want to overlay two separate things on top. One of those things requires a tolerance of 94 on the red value, but the other (the "km/h" image) needs a smaller tolerance.

    Can't you overlay each separately, each with its own colorkeymask and appropriate tolerance?
    There is no problem using ColorKeyMask more than once (either on different videos or the same one).

    If you do it all in one script, you don't need to save an uncompressed intermediate file.
    Quote Quote  
  14. You are exactly right on what I am trying to do.

    If you could show me how I can fix that script around to use the colorkeymask twice correctly, that would be a great help.

    I prefer to uncompress the other video though because I have to cut some parts out of each one and I think I could just do it in a script all together but it might be longer than just uncompressing. If you have a method you are welcome to show me though.
    Quote Quote  
  15. Member
    Join Date
    Jul 2009
    Location
    Spain
    Search Comp PM
    In outline, and assuming overlay clips are (or have been converted to) RGB32:

    base = ... #base video
    ov1 = ... # first overlay
    mask1 = ov1.ResetMask().ColorKeyMask($FB0010, 94)
    ov2 = ... # 2nd overlay ("km/h")
    mask2 = ov2.ResetMask().ColorKeyMask($FF0000)

    Overlay(base, ov1, mask=ShowAlpha(mask1), x=1097, y=619)
    Overlay(ov2, mask=ShowAlpha(mask2), x=547, y=48)
    Quote Quote  
  16. That worked, thanks.

    My only problem is trimming now. Here is how I have my script:

    base = AVISource("COURSE.avi")
    ov1 = AVISource("SOM.avi").converttorgb32
    mask1 = ov1.resetmask().colorkeymask($FB0010, 94)
    ov2 = ImageSource("kmh.png").converttorgb32
    mask2 = ov2.resetmask().colorkeymask($FF0000, 50)

    Overlay(base, ov1, mask=ShowAlpha(mask1), x= 547, y=300)
    Overlay(ov2, mask=ShowAlpha(mask2), x=560, y=324)

    base.Trim(0,205) ++ ov1.Trim(206,3555) ++ ov2.Trim(206,3555) ++ base.Trim(3556, 0)

    I couldn't just use "$FF0000" for mask2 though, because I would always get an error with the colorkeymask, so I had to assign it a tolerance for it to work.

    I am trying to have both the ov1 and ov2 enter and go away at the same time, but when I try to open the script like this in Virtualdub, I get this:

    Splice: one source has audio and one source doesn't (not allowed)

    Is there a way around this?
    Quote Quote  
  17. Member
    Join Date
    Jul 2009
    Location
    Spain
    Search Comp PM
    Originally Posted by NMeade View Post
    I couldn't just use "$FF0000" for mask2 though, because I would always get an error with the colorkeymask, so I had to assign it a tolerance for it to work.
    I guess you are using version 2.57?
    It had a bug where the tolerance could not be left out, even though the docs say it defaults to 10.
    From v2.58 on, the bug has been fixed.

    I am trying to have both the ov1 and ov2 enter and go away at the same time, but when I try to open the script like this in Virtualdub, I get this:
    Splice: one source has audio and one source doesn't (not allowed)
    That's because you are splicing the wrong things.
    After the two Overlay commands, the result of the combined overlays is left in the special variable last.
    So what you want is:
    base.Trim(0,205) ++ last.Trim(206,3555) ++ base.Trim(3556, 0)
    Quote Quote  
  18. Sorry for bringing up an old topic (again)...

    That end of the script you had in your last post solved it when I tried it Gavino, thanks a bunch.

    Just a simple problem I have now: in the video (or any) when the overlayed things come in, the video goes to a greenish-distorted hue like these:

    Frame before it appears:

    http://i282.photobucket.com/albums/kk277/NMeade94/57b0b9e3.png

    Frame when it appears:

    http://i282.photobucket.com/albums/kk277/NMeade94/3a7d46ad.png

    Anything I can change in my script to prevent this from happening?
    Quote Quote  
  19. Member
    Join Date
    Jul 2009
    Location
    Spain
    Search Comp PM
    Originally Posted by NMeade View Post
    in the video (or any) when the overlayed things come in, the video goes to a greenish-distorted hue
    Is your base clip (course.avi) RGB?
    Overlay works internally in YUV, so RGB clips get converted to YUV on the way in and back to RGB on the way out.
    Unfortunately, there is a rounding bug in the conversion which causes loss of color accuracy, more obvious when you have repeated overlays like here. This bug is fixed in the latest 2.6.0 alpha version.

    If this is the problem, a solution would be to use Layer instead of Overlay.
    The script would then become:

    base = AVISource("COURSE.avi").converttorgb32
    ov1 = AVISource("SOM.avi").converttorgb32
    ov1 = ov1.resetmask().colorkeymask($FB0010, 94)
    ov2 = ImageSource("kmh.png").converttorgb32
    ov2 = ov2.resetmask().colorkeymask($FF0000, 50)

    Layer(base, ov1, x= 547, y=300)
    Layer(ov2, x=560, y=324)


    base.Trim(0,205) ++ last.Trim(206,3555) ++ base.Trim(3556, 0)

    In fact, if working entirely in RGB, Layer is preferable to Overlay anyway (faster, simpler use of alpha layer, higher quality).
    Quote Quote  
  20. Yup, that solved it

    Again thank you for all your help, I don't think I should be having any issues anymore.
    Quote Quote  
  21. Hello everybody,
    I'll try to explain my problem in English, I hope it works.

    I use StaxRip to cut and convert recorded files from TV to mkv on my PC. StaxRip works with AviSynth. Now I want to cut a movie with StaxRip and I want the different parts to be overlayed.

    If I edit a movie in StaxRip, the program makes an avs File like this:

    LoadPlugin("C:\Program Files\StaxRip\Applications\AviSynth plugins\ffms2\ffms2.dll")
    LoadCPlugin("C:\Program Files\StaxRip\Applications\AviSynth plugins\Yadif\yadif.dll")
    FFVideoSource("C:\Users\Name\Folder\Folder\Folder\ Folder\Movie\Movie.mp4", cachefile="C:\Users\Name\Folder\Folder\Folder\Fold er\Movie\Movie temp files\Movie.ffindex")
    AssumeFPS(25.000)
    Crop(0,0, -Width % 8,-Height % 8)
    ConvertToYV12()
    Yadif()
    Crop(0,46,-0,-50)
    Trim(16228,17632) + Trim(19900,22840) + Trim(24948,25576) + Trim(26648,27180)


    How can I instruct StaxRip to overlay the different "trim parts"? For example the last 100 frames of the first part with the first 100 frames of the second part and so on.

    If anybody knows a way to instruct StaxRip, it would be great. But after reading a lot of websites I think I have to do it by editing the avs file. I read about an overlay filter in AviSynth but I don't know how to use. I'm just a newbie in editing with StaxRip and AviSynth.

    So, please tell me how to write the overlay filter into the avs script. And after editing the script, can I go on with StaxRip to cut and merge the movie parts or do I have to use another program like VirtualDubMod?

    Hope for help and thanx!
    Quote Quote  



Similar Threads

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