How to Convert PNG Transparent Background to JPG White Background?

核能气质少年 提交于 2021-02-04 21:18:09

问题


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

回答1:


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.



来源:https://stackoverflow.com/questions/41346323/how-to-convert-png-transparent-background-to-jpg-white-background

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!