<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>

CC BY-SA 4.0
2020-12-16T14:26:19.123Z
2020-12-16T14:26:19.123Z
Amessihel
<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>

<ffmpeg><greenscreen><alpha>
How to convert a black and white video to a APNG file while setting a color as transparent?
Amessihel
# 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


---

