使用ffmpeg从mp4文件转换后如何获得具有透明背景填充的动画webp文件?
How to get animated webp file with transparent background padding after converting from mp4 file with ffmpeg?
我需要将 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
对于带 alpha 通道的文件的转换,也将编解码器更改为 libwebp_anim,以便在绘制新帧时清除之前的帧。
这是最终命令的样子:
ffmpeg -i input.mov -c:v libwebp_anim -filter:v fps=fps=20 -lossless 1 \
-loop 0 -preset default -an -vsync 0 -vf \
"scale=512:512:force_original_aspect_ratio=decrease,format=rgba,pad=512:512:-1:-1:color=#00000000" \
output.webp
我需要将 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
对于带 alpha 通道的文件的转换,也将编解码器更改为 libwebp_anim,以便在绘制新帧时清除之前的帧。 这是最终命令的样子:
ffmpeg -i input.mov -c:v libwebp_anim -filter:v fps=fps=20 -lossless 1 \
-loop 0 -preset default -an -vsync 0 -vf \
"scale=512:512:force_original_aspect_ratio=decrease,format=rgba,pad=512:512:-1:-1:color=#00000000" \
output.webp