Using moviepy module i want a callback function to display % audio export.
I have done that changes in module:
a) Call audio.write_audiofile("../disket box/mp3 files/"+title+".mp3",progress_function=self.update_progress_bar_local,verbose=True,logger=None)
(adding progress_function parameter)
b)File Python38\Lib\site-packages\moviepy\audio\AudioClip.py line
def write_audiofile(self, filename, fps=None, nbytes=2, buffersize=2000, codec=None, bitrate=None, ffmpeg_params=None, write_logfile=False, verbose=True, logger='bar',progress_function=None):
c) Same file as b) Line 206 return ffmpeg_audiowrite(self, filename, fps, nbytes, buffersize, codec=codec, bitrate=bitrate, write_logfile=write_logfile, verbose=verbose, ffmpeg_params=ffmpeg_params, logger=logger,progress_function=progress_function)
d) File Python38\Lib\site-packages\moviepy\audio\io\ffmpeg_audiowriter.py lines 144 - end
def ffmpeg_audiowrite(clip, filename, fps, nbytes, buffersize,
codec='libvorbis', bitrate=None,
write_logfile=False, verbose=True,
ffmpeg_params=None, logger='bar',progress_function=None):
"""
A function that wraps the FFMPEG_AudioWriter to write an AudioClip
to a file.
NOTE: verbose is deprecated.
"""
if write_logfile:
logfile = open(filename + ".log", 'w+')
else:
logfile = None
logger = proglog.default_bar_logger(logger)
logger(message="MoviePy - Writing audio in %s" % filename)
writer = FFMPEG_AudioWriter(filename, fps, nbytes, clip.nchannels,
codec=codec, bitrate=bitrate,
logfile=logfile,
ffmpeg_params=ffmpeg_params)
all_chunks = clip.iter_chunks(chunksize=buffersize,
quantize=True,
nbytes=nbytes, fps=fps,
logger=logger)
counter = 0
total_chunks = "?????"
for chunk in all_chunks:
counter = counter + 1
writer.write_frames(chunk)
progress_function(str(counter),str(total_chunks))
writer.close()
if write_logfile:
logfile.close()
logger(message="MoviePy - Done.")
Ok the progress function works but i don't have an idea of how can i calculate total_chunks. I tried len(all_chunks) but it fails, because all_chunks is not a list (it's a generator).
Any advice of how can i calculate total_chunks would be usefull.
Thanks in advance, Chris Pappas
I modified \Python38\Lib\site-packages\moviepy\audio\io\AudioFileClip.py
I added a new method:
Now Python38\Lib\site-packages\moviepy\audio\io\ffmpeg_audiowriter.py looks like:
and total_chunks is same as final counter!!