@@ -172,12 +172,22 @@ def finalize_video_read_opts(
172172 return dtype , shape , r
173173
174174
175+ def check_alpha_change (args , dir = None , ifile = 0 , ofile = 0 ):
176+ # check removal of alpha channel
177+ inopts = args ["inputs" ][ifile ][1 ]
178+ outopts = args ["outputs" ][ofile ][1 ]
179+ if inopts is None or outopts is None :
180+ return None if dir is None else False # indeterminable
181+ return utils .alpha_change (inopts .get ("pix_fmt" , None ), outopts .get ("pix_fmt" , None ))
182+
183+
175184def build_basic_vf (args , remove_alpha = None , ofile = 0 , force = False ):
176185 """convert basic VF options to vf option
177186
178187 :param args: FFmpeg dict
179188 :type args: dict
180189 :param remove_alpha: True to add overlay filter to add a background color, defaults to None
190+ : This argument would be ignored if `'remove_alpha'` key is defined in `'args'`.
181191 :type remove_alpha: bool, optional
182192 :param ofile: output file id, defaults to 0
183193 :type ofile: int, optional
@@ -193,7 +203,14 @@ def build_basic_vf(args, remove_alpha=None, ofile=0, force=False):
193203 # extract the options
194204 fopts = {
195205 name : outopts .pop (name )
196- for name in ("fill_color" , "crop" , "flip" , "transpose" , "square_pixels" )
206+ for name in (
207+ "fill_color" ,
208+ "crop" ,
209+ "flip" ,
210+ "transpose" ,
211+ "square_pixels" ,
212+ "remove_alpha" ,
213+ )
197214 if name in outopts
198215 }
199216
@@ -207,7 +224,7 @@ def build_basic_vf(args, remove_alpha=None, ofile=0, force=False):
207224 except :
208225 pass
209226 try :
210- do_scale = len (scale ) > 2 or [ scale [0 ] <= 0 or scale [1 ] <= 0 ]
227+ do_scale = len (scale ) > 2 or ( scale [0 ] <= 0 or scale [1 ] <= 0 )
211228 except :
212229 do_scale = False
213230
@@ -217,7 +234,7 @@ def build_basic_vf(args, remove_alpha=None, ofile=0, force=False):
217234 fopts ["scale" ] = scale
218235 del outopts ["s" ]
219236
220- if remove_alpha :
237+ if remove_alpha and "remove_alpha" not in fopts :
221238 fopts ["remove_alpha" ] = True
222239
223240 bvf = video_basic_filter (** fopts )
0 commit comments