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)



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

  • 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 Oct 22 '16 at 13:01
  • @Mulvya, Hi , my question updated. – Mitra M Oct 22 '16 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 Oct 22 '16 at 13:59

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


ffmpeg -i 1.mp4 -f gdigrab -framerate 25 -video_size 300x200 -i title="MyWindow"
-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.

  • 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... – Mitra M Oct 31 '16 at 18:15
  • @Gyan Can you share a command that only changes the background color to another color. My case doesn't have video scale, title, etc... – Sampath Kumar Feb 21 at 9:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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