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.
I am trying to make video from images. First i create images with imagemagick (simple version):
convert -background transparent -size 1280x720 -gravity center
caption:'text' 0.png
then ffmpeg(simple version):
ffmpeg -framerate 0.5 -i 0.png debug.mp4
and this is what happens: http://prntscr.com/qy5i08 do you see the difference? Image and video resolution is the same 1280x720
I used another png image not created with imagemagick and there is no difference. Why is that?
The issue was -background transparent
When using background black than the quality is normal.
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