4

I want to capture a window and overlay it on another video.

This is my command:

ffmpeg -i MainVideo.avi 
-f gdigrab -framerate 25 -video_size 300x200 -i title="MyWindow" 
-filter_complex "[0]setpts=PTS-STARTPTS[b];[b][1:v]overlay=(main_w-overlay_w):main_h-overlay_h[v]"
-map "[v]" -c:v libx264 -r 25  out.mp4

background of my window is black.

How can I replace this black color with transparency?

is this possible by ffmpeg? (I think it is possible by chromakey/colorkey filters but I'm not sure, and I don't know how to use those filters)

Thanks.

UPDATE:

Suppose this is a frame of video that I want: enter image description here

3
  • GDIgrab supplies RGB feed so colorkey can work here, but if you share a sample frame of the grab, then I can see if a more effective alt method is possible.
    – Gyan
    Commented Oct 22, 2016 at 13:01
  • @Mulvya, Hi , my question updated.
    – Maria
    Commented Oct 22, 2016 at 13:30
  • See here. But insert format=yuv444p filter before the geq and instead of 16, you may have to use a value of 0 or near 0
    – Gyan
    Commented Oct 22, 2016 at 13:59

1 Answer 1

3

GDIgrab supplies a RGB feed so the colorkey filter can work here.

Try

ffmpeg -i 1.mp4 -f gdigrab -framerate 25 -video_size 300x200 -i title="MyWindow"
-filter_complex
"[1]split[m][a];
 [a]format=yuv444p,geq='if(gt(lum(X,Y),0),255,0)',hue=s=0[al];
 [m][al]alphamerge[ovr];
 [0][ovr]overlay=(main_w-overlay_w):main_h-overlay_h[v]"
-map "[v]" -c:v libx264 -r 25 out.mp4

You may have to use a value of near 0, if 0 doesn't capture all the transparent area.

4
  • Thank you so much! , it works for me with 16 instead of 0. ( ...(X,Y),16),255,0... instead of ...(X,Y),0),255,0...
    – Maria
    Commented Oct 31, 2016 at 18:15
  • 1
    @Gyan Can you share a command that only changes the background color to another color. My case doesn't have video scale, title, etc... Commented Feb 21, 2019 at 9:33
  • what mean hue=s=0 work here, thanks Commented Mar 12 at 10:33
  • Set saturation to zero in hue filter.
    – Gyan
    Commented Mar 12 at 19:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.