progress event support
See original GitHub issueHi,
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])
Issue Analytics
- State:
- Created 6 years ago
- Reactions:2
- Comments:8
Top GitHub Comments
Hi @Benny739, I have had no response from the repo owner. Nevertheless, you can find an working branch (it’s used on a company) here https://github.com/astroza/ffmpy/tree/progress_support_v2
state object has all what you need
I found the bug, it’s caused by piping and not closing stdin and stderr. In the wait function after the while loop I close stdin and stderr now, and the warning is gone.