簡體   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

我正在使用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")

旋轉濾鏡中的透明背景

使用fillcolor=none 旋轉過濾器文檔

填充c色, fillcolor
設置用於填充旋轉圖像未覆蓋的 output 區域的顏色。 如果選擇了特殊值none ,則不打印背景。 默認值為black

綠色 output

如果背景為綠色,則您的 output 不支持 alpha 和/或輸入在將其提供給旋轉過濾器之前沒有 alpha 通道。 如果是后者,請使用格式過濾器在旋轉過濾器之前添加一個 Alpha 通道。 簡化ffmpeg示例:

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

有關格式過濾器接受的像素格式列表,請參閱ffmpeg -pix_fmts 選擇一個名稱中帶有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")

只需在旋轉之前應用縮放,問題就會得到解決。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM