简体   繁体   English

将填充颜色添加到 none 或 alpha 0,在使用 ffmpeg-python 时返回渲染视频中的绿色背景

[英]Add the fillcolor to none or alpha 0, return the green background in the rendered video while using ffmpeg-python

I am using ffmpeg-python (the wrapper for ffmpeg written in python) Below is the sample code mentioned.我正在使用ffmpeg-python(用python编写的ffmpeg的包装器)下面是提到的示例代码。

                     inp.filter_multi_output('split')[k]
                        .filter_('rotate', a=rotation, fillcolor='#00FF0000',  ow=f"rotw({rotation})", oh=f"roth({rotation})")
                        .filter_('scale', width=(i['width'] * Factors().factors['w_factor']), height=(i['height'] * Factors().factors['h_factor'])).filter('setsar', '1/1')
                        .setpts(f"PTS-STARTPTS+{i['showtime']}/TB")

Transparent background in rotate filter旋转滤镜中的透明背景

Use fillcolor=none .使用fillcolor=none From the rotate filter documentation :旋转过滤器文档

fillcolor , c填充c色, fillcolor
Set the color used to fill the output area not covered by the rotated image.设置用于填充旋转图像未覆盖的 output 区域的颜色。 If the special value none is selected then no background is printed.如果选择了特殊值none ,则不打印背景。 Default value is black .默认值为black

Green output绿色 output

If the background is green then either your output does not support alpha and/or the input had no alpha channel before giving it to the rotate filter.如果背景为绿色,则您的 output 不支持 alpha 和/或输入在将其提供给旋转过滤器之前没有 alpha 通道。 If the latter is the case use the format filter to add an alpha channel before the rotate filter.如果是后者,请使用格式过滤器在旋转过滤器之前添加一个 Alpha 通道。 Simplified ffmpeg example:简化ffmpeg示例:

ffmpeg -i input.jpg -vf "format=rgba,rotate=PI/6:fillcolor=none" output.png

See ffmpeg -pix_fmts for a list of pixel formats accepted by the format filter.有关格式过滤器接受的像素格式列表,请参阅ffmpeg -pix_fmts Choose one with a in the name, such as rgba or yuva420p .选择一个名称中带有a的,例如rgbayuva420p

                   inp.filter_multi_output('split')[k]
                       .filter_('scale', width=(i['width'] * Factors().factors['w_factor']), height=(i['height'] * Factors().factors['h_factor'])).filter('setsar', '1/1')
                        .filter_('rotate', a=rotation, fillcolor='#00FF0000',  ow=f"rotw({rotation})", oh=f"roth({rotation})")
                        .setpts(f"PTS-STARTPTS+{i['showtime']}/TB")

Just Apply the scaling before the rotation and the problem will be resolved.只需在旋转之前应用缩放,问题就会得到解决。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM