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

advance use for api #19

Closed
erfantkerfan opened this issue Jun 9, 2020 · 5 comments
Closed

advance use for api #19

erfantkerfan opened this issue Jun 9, 2020 · 5 comments

Comments

@erfantkerfan
Copy link

Hi
I want to send a progress bar percent and time estimation to my frontend app.
is it possible to get that in another python app and send it via socket to the frontend app?
could you demonstrate how?

@althonos
Copy link
Owner

althonos commented Aug 15, 2020

Hi @erfantkerfan

I changed the signature of ffpb.main so that you can pass it a tqdm.tqdm subclass. With this, you should be able to write a custom subclass that interacts with your frontend.

@modbender
Copy link

Could you give an example of for extracting only the progress number?

@erfantkerfan
Copy link
Author

I don't have the time to explain it fully but I used something like this

command = "ffprobe -v error -hide_banner -show_entries format=duration -of default=noprint_wrappers=1:nokey=1 -i \"" + str(
         self.file_name) + "\""
         ffprobe_process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.STDOUT,
                                        universal_newlines=True, shell=True)
         out, err = ffprobe_process.communicate()
         reg = re.search('\d*\.\d*', str(err) + str(out))

above command to get the total time

thread = threading.Thread(target=self.start_convert,
                                   args=(self.file_name, modified_file_name_hq, modified_file_name_240p))
thread.start()
         while thread.is_alive():
             self.progress_hq['value'] = parse_seconds(self.ffmpeg_time_hq) / self.total_duration * 100
             self.progress_240p['value'] = parse_seconds(self.ffmpeg_time_240p) / self.total_duration * 100
             self.root.update()

and used to above command to update the tkinnter interface

@althonos
Copy link
Owner

althonos commented Aug 31, 2020

To use a custom tqdm.tqdm subclass:

class ProgressBar(tqdm.tqdm):
    def update(self, n):
        super().update(n)
        # now put here whatever code you need to update your 
        # GUI or whatever

        # self.n is the current progress
        # self.total is the total

ffpb.main(["-i", "input.mp4", "output.mkv", tqdm=ProgressBar)

@pablofiumara
Copy link

I needed to add self to make that work. Final code:

import tqdm
class ProgressBar(tqdm.tqdm):
    def update(self, n):
        super().update(n)
        print(self.n)
        print(self.total)

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

No branches or pull requests

4 participants