kkroening / ffmpeg-python

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

-filter_complex too long cause cmd prompt crush #161

Open gj94gj94ao4 opened 5 years ago

gj94gj94ao4 commented 5 years ago

I create some code to split and concat with my scenes like below

    for scene in scenes:
        start = scene.get_startat()
        duration = scene.get_interval()
        v_clip_stream = ffmpeg.trim(
            stream, start=start, duration=duration)
        v_clip_stream = ffmpeg.setpts(v_clip_stream, 'PTS-STARTPTS')
        a_clip_stream = ffmpeg.filter_(
            stream, 'atrim', start=start, duration=duration)
        a_clip_stream = ffmpeg.filter_(
            a_clip_stream, 'asetpts', 'PTS-STARTPTS')

        video_streams.append(v_clip_stream)
        audio_streams.append(a_clip_stream)
    v_stream = ffmpeg.concat(
        *video_streams, n=len(video_streams), v=1, a=0)
    a_stream = ffmpeg.concat(
        *audio_streams, n=len(audio_streams), v=0, a=1)
    stream = ffmpeg.output(v_stream, a_stream, outputfile)

and when my scenes goes too many system return

FileNotFoundError: [WinError 206] 檔名或副檔名太長。

And i found ffmpeg has -filter_complex_script is there any way to use that?

sorry for my poor English. :P

kkroening commented 5 years ago

I'm converting this to a feature request / enhancement.

filter_complex_script is not yet supported but could be implemented at some point.

(PRs are welcome)

kkroening commented 5 years ago

I think it would be something like

stream.run(script_filename='some_script_file')

.. or ..

stream.run(use_script_tmpfile=True)

.. the latter of which automatically determines a temporary script filename and then deletes it when the processing is complete.

But this functionality does not exist yet.

AFAICT, if your command line arguments are getting too long then this is basically what's needed in order to get around the issue.

However, you may still run into issues with command line arguments being too long if you have a lot of input files, because the input filenames probably have to encoded on the command-line either way, even when using filter_complex_scriptfile.

But it'd be good to get support for filter_complex_scriptfile at some point anyways.

desbma commented 4 years ago

On Linux with huge filter chains, I managed to hit the argument length and get this error: OSError: [Errno 7] Argument list too long: 'ffmpeg'

I tried bumping the stack size with: resource.setrlimit(resource.RLIMIT_STACK, (resource.RLIM_INFINITY, resource.RLIM_INFINITY)) but it did not change anything.

I worked around this by getting the ffmpeg command with ffmpeg.compile(..., writing the filter chain to a temporary file, and then modifying the ffmpeg command to use -filter_complex_script and reference the file.

utdemir commented 2 years ago

However, you may still run into issues with command line arguments being too long if you have a lot of input files, because the input filenames probably have to encoded on the command-line either way, even when using filter_complex_scriptfile.

Would using the movie filter a good solution here? https://ffmpeg.org/ffmpeg-filters.html#movie-1

I haven't tried it, but it seems like we can define input sources within the filter graph, sidestepping the issue entirely.