<p>GDIgrab supplies a RGB feed so the colorkey filter can work here.</p>

<p>Try</p>

<pre><code>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
</code></pre>

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

CC BY-SA 3.0
2016-10-31T18:15:06.700Z
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
CC BY-SA 4.0
2019-02-21T09:33:18.007Z
@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
CC BY-SA 4.0
2024-03-12T10:33:38.583Z
what mean `hue=s=0` work here, thanks
Trương Quốc Khánh
CC BY-SA 4.0
2024-03-12T19:51:12.510Z
Set saturation to zero in hue filter.
Gyan
CC BY-SA 3.0
2016-10-31T17:54:52.553Z
2016-10-31T17:54:52.553Z
Gyan
<p>I want to capture a window and overlay it on another video.</p>

<p>This is my command:</p>

<pre><code>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
</code></pre>

<p>background of my window is black.</p>

<p>How can I replace this black color with transparency?</p>

<p>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)</p>

<p>Thanks.</p>

<p><strong>UPDATE:</strong></p>

<p>Suppose this is a frame of video that I want:
<a href="https://i.sstatic.net/zAuuX.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/zAuuX.png" alt="enter image description here"></a></p>

CC BY-SA 3.0
2016-10-22T13:01:18.840Z
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
CC BY-SA 3.0
2016-10-22T13:30:53.820Z
@Mulvya, Hi , my question updated.
Maria
CC BY-SA 3.0
2016-10-22T13:59:05.220Z
See [here](http://stackoverflow.com/q/38578363/5726027). 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
<video><ffmpeg><video-capture>
FFmpeg : How to replace video background color with transparency? (while capturing)
Maria
# FFmpeg : How to replace video background color with transparency? (while capturing)

(Asked by: username_0 on 2016-10-22)

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:

**Tags:** video, ffmpeg, video-capture

> **Comments:**
> **username_1**: 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.  
> **username_0**: @Mulvya, Hi , my question updated.  
> **username_1**: See [here](http://stackoverflow.com/q/38578363/5726027). But insert `format=yuv444p` filter before the `geq` and instead of `16`, you may have to use a value of 0 or near 0  

---

## 1 answers

### Answer by username_1 on 2016-10-31. Score: 3 | Accepted answer

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.

> **Comments:**
> **username_0**: 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...`  
> **username_2**: @username_1 Can you share a command that only changes the background color to another color. My case doesn't have video scale, title, etc...  
> **username_3**: what mean `hue=s=0` work here, thanks  
> **username_1**: Set saturation to zero in hue filter.  

---

