使用 moviepy 模块,我想要一个回调函数来显示 % 音频导出。
我已经在模块中进行了更改:
a) 调用audio.write_audiofile("../disket box/mp3 files/"+title+".mp3",progress_function=self.update_progress_bar_local,verbose=True,logger=None)
(添加progress_function参数)
b)文件Python38\Lib\site-packages\moviepy\audio\AudioClip.py行
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) 与 b) 第 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) 文件 Python38\Lib\site-packages\moviepy\audio\io\ffmpeg_audiowriter.py 第 144 行 - 结束
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)
好的,进度函数可以工作,但我不知道如何计算total_chunks。我尝试了 len(all_chunks) 但失败了,因为 all_chunks 不是列表(它是生成器)。
任何关于如何计算total_chunks的建议都会很有用。
阿晨1998
相关分类