Skip to content

Commit 2ffdc73

Browse files
committed
-added check_alpha_change()
-build_basic_vf() *checks for 'remove_alpha' output args *fixed bug in scale option check
1 parent 919d6a8 commit 2ffdc73

2 files changed

Lines changed: 25 additions & 3 deletions

File tree

docsrc/options.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,11 @@ up a filtergraph.
138138
:code:`'upscale'` stretches the short side
139139
of the pixels while :code:`'downscale'` compresses the long side.
140140
:code:`'even'` makes sure that the resulting frame size is even (required by some codecs).
141+
* - :code:`remove_alpha`
142+
- bool
143+
- `overlay <https://ffmpeg.org/ffmpeg-filters.html#overlay-1>`__ and `color <https://ffmpeg.org/ffmpeg-filters.html#color-1>`__
144+
- Fill transparent background with :code:`fill_color` color. This filter is automatically
145+
inserted if input :code:`'pix_fmt'` has alpha but not the output.
141146
* - :code:`fill_color`
142147
- str
143148
- n/a

src/ffmpegio/configure.py

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
175184
def 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

Comments
 (0)