I'm converting a PNG to JPG. The transparent background turns black by default. I need it to be white.
What is the FFmpeg command to set the alpha channel to a color?
I think it has something to do with the alphamerge and alphaextract Filters.
ffmpeg -i image.png -qscale:v 2 image.jpg
This replaces white with transparency when converting to png:
-vf chromakey=white
You can use the geq filter.
ffmpeg -i in.png -vf format=yuva444p,geq='if(lte(alpha(X,Y),16),255,p(X,Y))':'if(lte(alpha(X,Y),16),128,p(X,Y))':'if(lte(alpha(X,Y),16),128,p(X,Y))' out.jpg
If your alpha is a pure black and white image, change 16 to 1.
Related
I'm trying to pad the GIF source to a square thumbnail and the extended area should be transparent.
(image source: https://store.steampowered.com/app/2113680/The_Dot/)
To achieve the goal, I used the following command:
ffmpeg -i ./test/source.gif -filter_complex "[0]scale=255:144[s1];[s1]pad=256:256:0:-56:blue[s2];[s2]split[s3][s4];[s3]palettegen=reserve_transparent=on:transparency_color=blue[p];[s4][p]paletteuse[s5]" -map [s5] -loop 0 ./test/output.gif -y
[0]scale=255:144[s1] First I scale down the image.
[s1]pad=256:256:0:-56:blue[s2] Then pad the image with an uncommon background color: blue
[s2]split[s3][s4] And I split to two streams. One for palettegen and another for paletteuse.
[s3]palettegen=reserve_transparent=on:transparency_color=blue[p] Generate the color palette that indicates blue as the transparency_color
[s4][p]paletteuse[s5] Use the new color palette for output. The padded image with blue background color should be treated as a transparent background.
But the output animated GIF still has a visible blue background color no matter if I put the paletteuse at first or in the end.
Related posts:
Making GIFs with ffmpeg: what does "transparency_color" do?
How do I resize an animated GIF and keep transparency?
Transparency is gone while resizing (scaling) gif using ffmpeg
overlay on transparent background:
ffmpeg -i 74bRi.gif -filter_complex "
color=s=256x256:d=100,format=argb,colorchannelmixer=aa=0.0[b];
[0]scale=255:144[f];
[b][f]overlay=(W-w)/2:(H-h)/2:shortest=1,split[s1][s2];
[s1]palettegen[p];
[s2][p]paletteuse
" -loop 0 output.gif
pad using transparent color ffffff00
ffmpeg -i 74bRi.gif -filter_complex "
[0]scale=255:144,pad=256:256:0:-1:ffffff00,split[s1][s2];
[s1]palettegen[p];
[s2][p]paletteuse
" -loop 0 out.gif
Below command works fine to stack two png file with alpha channel left and right, The output png file will keep the alpha channel as well.
ffmpeg -i a.png -i b.png -filter_complex hstack=inputs=2 output.png
I wish replace alpha channel with white color (no need alpha channel), which parameter should I use?
You can try this filter:
color=c=white[b];\
hstack=inputs=2[f];\
[b][f]scale2ref[b1][f1];\
[b1][f1]overlay
also set -pix_fmt rgb24 output option
I'm converting a PNG to JPG. The transparent background turns black by default. I need it to be white.
What is the FFmpeg command to set the alpha channel to a color?
I think it has something to do with the alphamerge and alphaextract Filters.
ffmpeg -i image.png -qscale:v 2 image.jpg
This replaces white with transparency when converting to png:
-vf chromakey=white
You can use the geq filter.
ffmpeg -i in.png -vf format=yuva444p,geq='if(lte(alpha(X,Y),16),255,p(X,Y))':'if(lte(alpha(X,Y),16),128,p(X,Y))':'if(lte(alpha(X,Y),16),128,p(X,Y))' out.jpg
If your alpha is a pure black and white image, change 16 to 1.
How to convert a video to black and white using ffmpeg?
Desaturate
Use the hue filter if you want to desaturate:
ffmpeg -i input -vf hue=s=0 output
This is like using Colors → Saturation in the GIMP.
Grayscale
Use the format filter if you want to convert to grayscale format:
ffmpeg -i input -vf format=gray output
This is like using Image → Mode → Grayscale in the GIMP.
Threshold
See FFmpeg convert video to Black & White with threshold?
This is like using Colors → Threshold in the GIMP.
The monochrome filter can do the trick:
ffmpeg -i input.mp4 -vf monochrome output.mp4
I generate a video from png images using
ffmpeg -i visualization/%d.png -c:v libx264 -vf "scale=500:trunc(ow/a/2)*2" -pix_fmt yuv420p z.mov
and if images have transparencies, they become black. Can I somehow make them white?
Before running ffmpeg, use ImageMagick to "flatten" each PNG against white.
mogrify -background white -flatten visualization/*.png