Skip to content

progress event support #23

@astroza

Description

@astroza

Hi,

I was working on a transcoding platform and I found your module to wrapping ffmpeg. I'm interested to make improvements that would be useful to everyone involved in this niche.

I'm planning to replace Popen.communicate call to achieve the goals:

  • Make ffmpy efficient in memory usage
  • Give it progress reporting support

Popen.communicate() is inefficient because of stdout and stderr buffering. Let's see some cases:

Use case 1:

you want to send transcoded data over network as fast as available. If communicate() is used, you must to accumulate the entire transcoded movie on a memory buffer to send it.

Use case 2:

you want to know the transcoding state (output size, time, bitrate) in real time. If communicate() is used, you can't do it because this method is consuming the stderr pipe

I have a experimental branch with a on_progress callback implemented here:
https://github.com/astroza/ffmpy/tree/progress_support

An usage example is:

def on_progress(state):
        print state.time

ff = ffmpy.FFmpeg(
        global_options="-hide_banner -nostdin -y -stats",
        inputs={local_input_path: None},
        outputs={local_output_path: None},
        on_progress=on_progress
)
ff.run(stderr=subprocess.PIPE)

Now I'm working to make it backwards compatible. The branch break your API

UPDATE

https://github.com/astroza/ffmpy/tree/progress_support_v2 keeps backward compatibility

Usage:

def on_progress(state):
        print state.time

ff = ffmpy.FFmpeg(
        global_options="-hide_banner -nostdin -y -stats",
        inputs={local_input_path: None},
        outputs={local_output_path: None}
)
print(ff.run(on_progress=on_progress)[1])

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions