Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a callback event? #2

Closed
jmraker opened this issue Nov 12, 2021 · 3 comments
Closed

Add a callback event? #2

jmraker opened this issue Nov 12, 2021 · 3 comments

Comments

@jmraker
Copy link

jmraker commented Nov 12, 2021

Adding an optional callback/event that passes the 3+ numbers (and maybe the process handle) when needed might be useful for those who want to customize the output to
. Add ANSI colors
. Put the info into a GUI
. Reword/translate something or represent it as ASCII art.
. Remove or re-arrange things

@CrypticSignal
Copy link
Owner

CrypticSignal commented Nov 13, 2021

Just to make sure I understand correctly, you want the run_ffmpeg_show_progress function to accept another argument which is a custom function that you make. So I change my function definition to:

def run_ffmpeg_show_progress(command, ffmpeg_loglevel="info", progress_handler=None)

You create a function that defines what to do with the percentage progress, speed and ETA:

def handle_progress_info(progress, speed, eta):
    # blah blah...

And then you call my function like so:

def run_ffmpeg_show_progress(command, ffmpeg_loglevel="info", progress_handler=handle_progress_info)

I'll add this ability and let you know when the update has been pushed.

@jmraker
Copy link
Author

jmraker commented Nov 13, 2021

Yes, if that's the best python way. I'm not a python expert but I was thinking the parameters could be an object. If you have the need to add more info to it, hopefully if wouldn't automatically break the callback that way.

def handle_progress_info(progress):
    if (progress.percent > 50):
        blah()
    if(progress.eta > 1000 * 60):  # Don't wait more than 1000 hours!
        progress.process.terminate()

@CrypticSignal
Copy link
Owner

Update pushed. Run pip3 install --upgrade better-ffmpeg-progress to test and check out the updated README as the way to use this module has changed: https://github.com/CrypticSignal/better-ffmpeg-progress#readme

Let me know if this new feature works as you want it to.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants