Answers.Body: <p>Output by MP4 defaults to the H.264 codec for the video. H.264 does not support alpha.</p>
  
  <p>You can output to <code>.mov</code> with a video codec <code>-c:v</code> of <code>png</code> or <code>qtrle</code>. There are others but they have restrictions on resolution and framerate.</p>
  
  <p>You can't use the overlay filter as it doesn't output to a pixel format with alpha. So, just the chromakey filter, and no color source.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-06-05T04:04:10.873Z
Answers.Text: Thanks. So something like this? 'ffmpeg -f lavfi -i color=c=#00000000:s=606x1080 -i  input.mp4 -c: png  -filter_complex "[1:v]chromakey=0x70de77:0.1:0.2[out]" -map "[out]"  output.mov'
Answers.UserDisplayName: Bob Woodley
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-06-05T04:16:47.523Z
Answers.Text: `ffmpeg -i input.mp4 -vf "chromakey=0x70de77:0.1:0.2" -c copy -c:v png output.mov`
Answers.UserDisplayName: Gyan
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-06-07T04:33:06.707Z
Answers.Text: That indeed works -thanks! But the .mov file is a huge! 2 min of video which is 58MB as mp4 turns into 15GB of mov. And then I need to display it on the web, and it seems only webm will handle alpha channel video in a browser. And that is multiples larger. (Can't give an exact figure because I haven't got it to complete yet!).
Answers.UserDisplayName: Bob Woodley
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-06-07T04:44:07.097Z
Answers.Text: VP8 shouldn't be multiples larger. Somewhat, yes. PNG or QTRLE will be much larger; they are intra-frame lossless codecs. QTRLE employ very basic compression. PNG is better.
Answers.UserDisplayName: Gyan
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-06-08T02:39:54.390Z
Answers.Text: Tried various permutations. keep getting "Transparency encoding with auto_alt_ref does not work" and "maybe incorrect parameters such as bit_rate, rate, width or height". This was one thing I tried that gave those errors: 'ffmpeg -i input.mp4 -vf "chromakey=0x70de77:0.1:0.2" -c copy -c:v libvpx -b:v 1M output.webm'
Answers.UserDisplayName: Bob Woodley
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-06-08T03:32:18.233Z
Answers.Text: Ah, I see from an answer you gave elsewhere that I need to add the '-auto-alt-ref 0'  option, then i get a nice small transparent video. thanks for all your help.
Answers.UserDisplayName: Bob Woodley
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-06-28T11:15:25.203Z
Answers.Text: What's the final command?
Answers.UserDisplayName: chovy
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-05-14T05:58:27.757Z
Answers.LastActivityDate: 2017-05-14T06:19:12.167Z
Answers.LastEditDate: 2017-05-14T06:19:12.167Z
Answers.UserDisplayName: Gyan
Body: <p>ffmpeg does a very good job of getting rid of a green screen, with a command like this:</p>
  
  <pre><code>ffmpeg -f lavfi -i color=c=black:s=606x1080 
         -i input.mp4  
         -filter_complex 
              "[1:v]chromakey=0x70de77:0.1:0.2[ckout];
              [0:v][ckout]overlay[out]" 
         -map "[out]"  output.mp4
  </code></pre>
  
  <p>but it replaces the green screen with solid black, whereas I would like it replaced with a transparent background, alpha = 0.</p>
  
  <p>I tried setting the color to <code>#00000000</code> (8 zeroes indicating a zero alpha), but that still resulted in a black background.</p>
  
  <p>Strangely, when I set the color to say red, it gives a red tint to many unfiltered areas.</p>
  
  <p>So I would like a transparent background, but I'm also curious what the color option is doing.</p>
  
Tags: <ffmpeg>
Title: green screen to transparent with ffmpeg
UserDisplayName: Bob Woodley
ThreadText: # green screen to transparent with ffmpeg
  
  (Asked by: username_0 on 2017-05-14)
  
  ffmpeg does a very good job of getting rid of a green screen, with a command like this:
  
  ```
  ffmpeg -f lavfi -i color=c=black:s=606x1080 
         -i input.mp4  
         -filter_complex 
              "[1:v]chromakey=0x70de77:0.1:0.2[ckout];
              [0:v][ckout]overlay[out]" 
         -map "[out]"  output.mp4
  
  ```
  
  but it replaces the green screen with solid black, whereas I would like it replaced with a transparent background, alpha = 0.
  
  I tried setting the color to `#00000000` (8 zeroes indicating a zero alpha), but that still resulted in a black background.
  
  Strangely, when I set the color to say red, it gives a red tint to many unfiltered areas.
  
  So I would like a transparent background, but I'm also curious what the color option is doing.
  
  **Tags:** ffmpeg
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2017-05-14. Score: 4 | Accepted answer
  
  Output by MP4 defaults to the H.264 codec for the video. H.264 does not support alpha.
  
  You can output to `.mov` with a video codec `-c:v` of `png` or `qtrle`. There are others but they have restrictions on resolution and framerate.
  
  You can't use the overlay filter as it doesn't output to a pixel format with alpha. So, just the chromakey filter, and no color source.
  
  > **Comments:**
  > **username_0**: Thanks. So something like this? 'ffmpeg -f lavfi -i color=c=#00000000:s=606x1080 -i  input.mp4 -c: png  -filter_complex "[1:v]chromakey=0x70de77:0.1:0.2[out]" -map "[out]"  output.mov'  
  > **username_1**: `ffmpeg -i input.mp4 -vf "chromakey=0x70de77:0.1:0.2" -c copy -c:v png output.mov`  
  > **username_0**: That indeed works -thanks! But the .mov file is a huge! 2 min of video which is 58MB as mp4 turns into 15GB of mov. And then I need to display it on the web, and it seems only webm will handle alpha channel video in a browser. And that is multiples larger. (Can't give an exact figure because I haven't got it to complete yet!).  
  > **username_1**: VP8 shouldn't be multiples larger. Somewhat, yes. PNG or QTRLE will be much larger; they are intra-frame lossless codecs. QTRLE employ very basic compression. PNG is better.  
  > **username_0**: Tried various permutations. keep getting "Transparency encoding with auto_alt_ref does not work" and "maybe incorrect parameters such as bit_rate, rate, width or height". This was one thing I tried that gave those errors: 'ffmpeg -i input.mp4 -vf "chromakey=0x70de77:0.1:0.2" -c copy -c:v libvpx -b:v 1M output.webm'  
  > **username_0**: Ah, I see from an answer you gave elsewhere that I need to add the '-auto-alt-ref 0'  option, then i get a nice small transparent video. thanks for all your help.  
  > **username_2**: What's the final command?  
  
  ---
  
  