kkroening / ffmpeg-python

Python bindings for FFmpeg - with complex filtering support
Apache License 2.0
10.01k stars 887 forks source link

How to add arbitrary arguments at the beginning? + Bug found in examples/README.md #608

Open ShakedDovrat opened 3 years ago

ShakedDovrat commented 3 years ago

I want to add the "-re" flag at the beginning of the command (i.e. as an input parameter). I cannot pass it to the input function as it is not in the format of -<param_name> <param_value> (i.e. it's a flag w/o a value).

I came across this issue https://github.com/kkroening/ffmpeg-python/issues/30 which says I should use global_args. But it does not allow to add flags at the beginning of the command, As I get AttributeError: 'FilterableStream' object has no attribute 'global_args' when trying ffmpeg.input(file_path).global_args("-re").

This led me to examples/README.md, where I saw global_args("-re") being used on the output. FFmpeg ignores this flag when used on the output, which means the example under "Stream from a local video to HTTP server" has a bug in it, and also means I was unsuccesful to add this flag.

I kindly ask for you help. Thank you.

kyrlon commented 2 years ago

This seems to be a reoccurring bug with the global_args() parameter, but every instance that I have seen and personally attempted with it, it has not worked as proclaimed and I am not aware (or searched) to see if there is an active PR to fix this bug. Here in a previous issue, I put the parameter -rethat I wanted at the beginning after input with the value of None:

process = (
    ffmpeg
    .input("input.mp4", re=None)
    .output(
        server_url, 
        codec = "copy", # use same codecs of the original video
        listen=1, # enables HTTP server
        f=video_format)
    .run()
)
ShakedDovrat commented 2 years ago

@kyrlon Works like a charm, thank you! I tried .input("input.mp4", re="") but didn't think to try None instead of ""...

frankiedrake commented 2 years ago

This should really be notices in documentation...