我需要将 mp4 视频 (1280×720) 转换为 webp 文件 (512x512),以便生成的 webp 文件保持纵横比并完全包含在 512x512 中,顶部和底部未覆盖的区域应该是透明的。
我尝试了以下 ffmpeg 命令:
ffmpeg -i sample.mp4
-vcodec libwebp -filter:v fps=fps=20 -lossless 1 -loop 0 -preset default -an -vsync 0 -vf
scale=512:512:force_original_aspect_ratio=decrease,pad=512:512:-1:-1:color=#00000000 sample.webp
在上面的命令中请注意pad=512:512:-1:-1:color=#00000000
我给了 alpha 值 00 但它只输出黑色。
我也引用了这个网站https://ffmpeg.org/ffmpeg-utils.html#color-syntax它说
It can be the name of a color as defined below (case insensitive match) or a [0x|#]RRGGBB[AA] sequence, possibly followed by @ and a string representing the alpha component. The alpha component may be a string composed of "0x" followed by a hexadecimal number or a decimal number between 0.0 and 1.0, which represents the opacity value (‘0x00’ or ‘0.0’ means completely transparent, ‘0xff’ or ‘1.0’ completely opaque). If the alpha component is not specified then ‘0xff’ is assumed.
我尝试了 color=0x000000@0x00
和 color=0x000000@0.0
但结果是不透明的黑色。
最佳答案
我只是在 pad format=rgba,pad
之前缺少格式过滤器
关于video - 使用ffmpeg从mp4文件转换后如何获得具有透明背景填充的动画webp文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66144707/