1

I am trying to use the -vf format="gray" in ffmpeg-python and I can't seem to get the syntax right. From what I have seen, ffmpeg-python has a set of filter_name options you can use, and then there is also the option to use .filter_() to just put in the ffmpeg commands directly in.

I have tried using both and seem to get the same error, where ffmpeg-python wants me to declare a filter_name and from what I am seeing in the documentation, format=gray doesn't fall under any of the filter_name options.

If I take this approach, it works:

(
        ffmpeg.input(img_seq_template, framerate=framerate, **input_options)
        .filter("format", "gray")
        .output(filename=output_path, **output_options)
        .run(overwrite_output=True)
   )

However, I want to also use a dictionary in the filter(), which then requires me to put in a filter_name. The goal would be to have something like below working:

filter_options = {'format' : 'gray'}

(
        ffmpeg.input(img_seq_template, framerate=framerate, **input_options)
        .filter(filter_name = "some_filter_name", **filter_options)
        .output(filename=output_path, **output_options)
        .run(overwrite_output=True)
    )

Any ideas on what I could put into the filter_name to get this running would be amazing! All suggestions welcome, thanks so much!

  • Not familiar with the package, but you should be able to use `output_options = {'pix_fmt':'gray'}` to get the same effect (unless you have more to your filter graph. Also, you can use `.compile()` instead of `.run()` to print the ffmpeg command. – kesh Aug 22 '22 at 18:16
  • Try: `filter("format", pix_fmts="gray")`. When using command line, we don't have to explicitly specify `format=pix_fmts=gray`, and we may skip `pix_fmts` and use `format=gray`. The name of the parameter is `pix_fmts`. We can get the names using "help" in shell command `ffmpeg -h filter=format`. – Rotem Aug 22 '22 at 18:34
  • `format` is not a filter option; it is the filter name. So, `.filter(filter_name = "format", **filter_options)` – Gyan Aug 23 '22 at 04:00
  • See my [following answer](https://stackoverflow.com/a/73455879/4926757) for more detailed explanation regarding the syntax `filter("format", pix_fmts="gray")`. – Rotem Aug 23 '22 at 09:05
  • Do you have a command-line version of ffmpeg for what you are trying to achieve? – kyrlon Dec 21 '22 at 22:05

0 Answers0