I've made a modified version of Ali Ent.
That's helpful if you only want the percentage change for each second instead of every decimal change.
I'm also only printing it when MoviePy is exporting the video
if 'Writing video' in self.last_message:
That was really helpful as I only want to update the front-end messages when this happens. Here is the code:
class MyBarLogger(ProgressBarLogger):
def __init__(self):
super().__init__()
self.last_message = ''
self.previous_percentage = 0
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))
self.last_message = value
def bars_callback(self, bar, attr, value,old_value=None):
# Every time the logger progress is updated, this function is called
if 'Writing video' in self.last_message:
percentage = (value / self.bars[bar]['total']) * 100
if percentage > 0 and percentage < 100:
if int(percentage) != self.previous_percentage:
self.previous_percentage = int(percentage)
print(self.previous_percentage)
logger = MyBarLogger()
video.write_videofile('name.mp4', logger=logger)