PDA

View Full Version : video clip with translucent image background


jingke2000
30th July 2008, 21:27
Hi All,

I'm new to Avisynth. Now I've got a question: how can I overlay video onto an image with translucent background(e.g., png with alpha channel)?

talen9
30th July 2008, 21:33
Are you sure you don't want to do the opposite? Image onto video?

Have a look here (http://avisynth.org/mediawiki/Internal_filters#Overlay_and_Mask_filters), anyway :)

jingke2000
30th July 2008, 22:20
No, I don't want the opposite. What I want to do is to put video (small resolution) on top of a larger image (with alpha channel). Then encode the output avi into h.264 for steaming. Acutally, I don't know what would happen to the original alpha value after codec at the client side. Just want to get some ideas from you guys.

talen9
30th July 2008, 23:10
I have to admit I don't know very much about the subject but .. did you have a look at the page I linked and at AviSynth documentation in general?

Anyway, I think you can't overlay a video on top of an image; you might have more success if you overlay it over another video (which, incidentally, may very well be a sequence of all identical frames all representing your starting image ... think about 2D - 3D, that is ;) ),

Wilbert
30th July 2008, 23:18
Anyway, I think you can't overlay a video on top of an image
Sure you can. Load your image with pixel_type="RGB32". Use Loop() such that the length is the same as your clip. Use ShowAlpha() to get the alpha channel of the image-clip and use that as mask in Overlay.

kakomu
30th July 2008, 23:28
If the image is supposed to be the bottom layer and it's transparent, what do you expect to see through the image?

talen9
31st July 2008, 00:20
Sure you can. Load your image with pixel_type="RGB32". Use Loop() such that the length is the same as your clip. Use ShowAlpha() to get the alpha channel of the image-clip and use that as mask in Overlay.

Well, that (even if more technically expressed :p) is exactly what I said: the way you're treating the image, it's no more an image (2D object), but a sequence of identical images (3D Object) :)

jingke2000
31st July 2008, 04:20
Thanks for the suggestions.

To answer Kakomu's question, here's my whole situation:
I have a background video playing all the time. I need to dynamically load a few video clips on top of that controlled by user inteface. The UI will need to cover the whole screen. But the video clips cover only a small portion of the screen. Another requirement is some logos should be displayed together with video when certain events happen.
Anyway, please let me know if you have better ways to do it. I would greatly appreciate it.

NerdWithNoLife
31st July 2008, 05:21
Sounds like you have lots of things going on there! This could get complicated in a hurry with AviSynth, but here are some principles I've learned. First, here's how to put a logo over a video clip:

1) Design a transparent PNG the same size as the video clip with the logo placed wherever you want. To put it all together:
Video=AviSource("video.avi").ConvertToRGB32()
Logo=ImageSource("logo.png",pixel_type="RGB32").Loop().AssumeFPS(Video)
Video=Layer(Video,Logo,"add",255)
Video
And I'm guessing you want to do sort of a picture in picture on top of the UI? You'll want to deinterlace the video first if necessary, then:
Video=AviSource("video.avi").BicubicResize(320,240).ConvertToRGB32() #or whatever size you want
Slug=BlankClip(Video)
UI=ImageSource("UI.png",pixel_type="RGB32").AssumeFPS(Video).Loop()
UI=Layer(Slug,UI,"add",255) #This gives the image the same amount of frames as the video
Overlay(UI,Video,x=0, y=0) #x and y control the offset (positioning) of the video being overlayed.
I hope that steers you in the right direction.

stickboy
1st August 2008, 05:15
No, I don't want the opposite. What I want to do is to put video (small resolution) on top of a larger image (with alpha channel).It sounds to me like you want the video to have the alpha channel, not the image.

As kakomu said, it's pointless if the background image has transparency; the transparent areas won't have anything to show.

jingke2000
4th August 2008, 17:22
To NerdWithNoLife: What you suggested is exactly what I want. I'm writing some scripts following yours. Thanks a lot for the help!

The reason why I need translucent (0 - 100%) image background is I need to overlay the whole thing onto another background external video which would be out of my control in the field.