Answers.Body: <p>I finally found how to do that in one <code>ffmpeg</code> command, using <code>colorkey</code>:</p>
  <pre><code>ffmpeg  -y -i /dev/video0
             -f lavfi -i color=0x6a6a6a:s=640x480
             -f lavfi -i color=black:s=640x480
             -f lavfi -i color=white:s=640x480
             -filter_complex 'threshold,colorkey=white'
             test.apng
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-12-16T14:26:19.123Z
Answers.LastActivityDate: 2020-12-16T14:26:19.123Z
Answers.UserDisplayName: Amessihel
Body: <p>I created a small video with <code>threshold</code> filter to get black and white pixels (no greyscale):</p>
  <pre><code>ffmpeg -y -i /dev/video0
            -f lavfi -i color=0x606060:s=640x480
            -f lavfi -i color=black:s=640x480 -f lavfi
            -i color=white:s=640x480 -filter_complex threshold
            -c:v libx264 -c:a copy  test.mp4
  </code></pre>
  <p>Then I tried to convert it as a APNG file with white pixels as transparent (<code>chromakey</code> filter).</p>
  <pre><code>ffmpeg -y -i  test.mp4 -f apng -vf chromakey=white test.apng
  </code></pre>
  <p>This command converts all the pixels into transparent (checked with Gimp, it sets alpha of all pixels to 0).</p>
  <p>Why? Also, how can I fix the command to make it work?</p>
  
Tags: <ffmpeg><greenscreen><alpha>
Title: How to convert a black and white video to a APNG file while setting a color as transparent?
UserDisplayName: Amessihel
ThreadText: # How to convert a black and white video to a APNG file while setting a color as transparent?
  
  (Asked by: username_0 on 2020-12-15)
  
  I created a small video with `threshold` filter to get black and white pixels (no greyscale):
  
  ```
  ffmpeg -y -i /dev/video0
            -f lavfi -i color=0x606060:s=640x480
            -f lavfi -i color=black:s=640x480 -f lavfi
            -i color=white:s=640x480 -filter_complex threshold
            -c:v libx264 -c:a copy  test.mp4
  
  ```
  
  Then I tried to convert it as a APNG file with white pixels as transparent (`chromakey` filter).
  
  ```
  ffmpeg -y -i  test.mp4 -f apng -vf chromakey=white test.apng
  
  ```
  
  This command converts all the pixels into transparent (checked with Gimp, it sets alpha of all pixels to 0).
  
  Why? Also, how can I fix the command to make it work?
  
  **Tags:** ffmpeg, greenscreen, alpha
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_0 on 2020-12-16. Score: 1 | Accepted answer
  
  I finally found how to do that in one `ffmpeg` command, using `colorkey`:
  
  ```
  ffmpeg  -y -i /dev/video0
             -f lavfi -i color=0x6a6a6a:s=640x480
             -f lavfi -i color=black:s=640x480
             -f lavfi -i color=white:s=640x480
             -filter_complex 'threshold,colorkey=white'
             test.apng
  
  ```
  
  
  ---
  
  