Answers.Body: <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>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-10-31T18:15:06.700Z
Answers.Text: 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...`
Answers.UserDisplayName: Maria
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-02-21T09:33:18.007Z
Answers.Text: @Gyan Can you share a command that only changes the background color to another color. My case doesn't have video scale, title, etc...
Answers.UserDisplayName: Sampath Kumar
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2024-03-12T10:33:38.583Z
Answers.Text: what mean `hue=s=0` work here, thanks
Answers.UserDisplayName: Trương Quốc Khánh
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2024-03-12T19:51:12.510Z
Answers.Text: Set saturation to zero in hue filter.
Answers.UserDisplayName: Gyan
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-10-31T17:54:52.553Z
Answers.LastActivityDate: 2016-10-31T17:54:52.553Z
Answers.UserDisplayName: Gyan
Body: <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>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-10-22T13:01:18.840Z
Comments.Text: 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.
Comments.UserDisplayName: Gyan
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-10-22T13:30:53.820Z
Comments.Text: @Mulvya, Hi , my question updated.
Comments.UserDisplayName: Maria
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-10-22T13:59:05.220Z
Comments.Text: 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
Comments.UserDisplayName: Gyan
Tags: <video><ffmpeg><video-capture>
Title: FFmpeg : How to replace video background color with transparency? (while capturing)
UserDisplayName: Maria
ThreadText: # 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:
  [![enter image description here](https://i.sstatic.net/zAuuX.png)](https://i.sstatic.net/zAuuX.png)
  
  **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.  
  
  ---
  
  