Following is a simple ffmpeg command line for encoding an input video into a AV1 output with CRF 30:
ffmpeg -i input.mkv -c:v libsvtav1 -crf 30 output.mkv
Converting that command line into the syntax of ffmpeg-python is pretty straight-forward:
(
ffmpeg
.input('input.mkv')
.output('output.mkv', vcodec='libsvtav1', crf=30)
.run()
)
However, what happens if we want to specify the fast-decode option? In ffmpeg that would mean extending our command line to include -svtav1-params fast-decode=1
, i.e.:
ffmpeg -i input.mkv -c:v libsvtav1 -crf 30 -svtav1-params fast-decode=1 output.mkv
How do we specify the same thing in ffmpeg-python? Adding svtav1-params='fast-decode=1'
into the output arguments results in invalid Python code since variables are not allowed to have dash in the name:
(
ffmpeg
.input('input.mkv')
.output('output.mkv', vcodec='libsvtav1', crf=30, svtav1-params='fast-decode=1')
.run()
)
# Error: Expected parameter name
Replacing the dash with an underscore in the name makes ffmpeg-python read it literally which doesn't translate into a valid ffmpeg command line.
How is it possible to specify fast-decode and other svtav1-params
specific arguments in ffmpeg-python?
According to the documentation,
you can use the **
syntax to pass additional arguments for Special option names like this
(
ffmpeg
.input('input.mkv')
.output('output.mkv', vcodec='libsvtav1', crf=30, **{'svtav1-params': 'fast-decode=1'})
.run()
)