How to display converting progress of write_audiofile from moviepy in PyQt5 app?

950 views Asked by At

I want to convert mp4 file to mp3 file using write_audiofile function from moviepy library and display the progress in PyQT5 app using progressbar.

when I use:

mp4audio.write_audiofile(filename, logger="bar")

it shows a progress bar in console, so can I somehow access that progress variable and use it to update my progress bar in PyQt5 app?

I also tried this:

from proglog import ProgressBarLogger
from my_library import my_routine

class MyBarLogger(ProgressBarLogger):

    def callback(self, **changes):
        # Every time the logger is updated, this function is called with
        # the `changes` dictionnary of the form `parameter: new value`.

        for (parameter, new_value) in changes.items():
            print ('Parameter %s is now %s' % (parameter, value))

logger = MyBarLogger()
my_routine(logger=logger)

but it only writes down messages when starts and when ends. Not the progress.

Parameter message is now MoviePy - Writing audio in C:/Users/.../file.mp3
Parameter message is now MoviePy - Done.

Does anyone knows the solution, please?

1

There are 1 answers

0
SamBob On

Doesn't seem to be well documented by proglog but callback of ProgressBarLogger gains access to one time messages, but bars_callback is required for the progress itself:

class MyBarLogger(ProgressBarLogger):
    def callback(self, **changes):
        # Every time the logger message is updated, this function is called with
        # the `changes` dictionary of the form `parameter: new value`.
        for (parameter, value) in changes.items():
            print ('Parameter %s is now %s' % (parameter, value))
    def bars_callback(self, bar, attr, value,old_value=None):
        # Every time the logger progress is updated, this function is called        
        percentage = (value / self.bars[bar]['total']) * 100
        print(bar,attr,percentage)