用Python的moviepy剪视频,为什么视频的写入速度非常慢?

为什么程序在运行几秒后视频写入速度变得特别慢。
jjzzz.png
下面是全部代码了

from moviepy.editor import VideoFileClip
from moviepy.editor import CompositeVideoClip
from moviepy.editor import concatenate_videoclips

import xlrd

#文件路径
path = ".\\sources\\{}"
word_art_path = path.format("art{}.mov")
source_path = path.format("{}.mp4")
op_path = path.format("op.mp4")
ed_path = path.format("ed.mp4")
logo_path = path.format("logo.png")
result_path = ".\\results\\{}.mp4"

def fun1(sources, logo_size, logo_top_distance, logo_right_distance, art_one, art_two, art_four, art_five):
#加logo、花字
    import moviepy.editor as mp

    clip = VideoFileClip(sources)
    clip1 = VideoFileClip(word_art_path.format(1), has_mask=True)
    clip2 = VideoFileClip(word_art_path.format(2), has_mask=True)
    clip3 = VideoFileClip(word_art_path.format(3), has_mask=True)
    clip4 = VideoFileClip(word_art_path.format(4), has_mask=True)
    clip5 = VideoFileClip(word_art_path.format(5), has_mask=True)
    logo = (mp.ImageClip(logo_path)
            .set_duration(clip.duration)  # 水印持续时间
            .resize(height = logo_size)  # 水印的高度,会等比缩放
            .margin(right = logo_top_distance, top = logo_right_distance, opacity=0)  # 水印边距和透明度
            .set_pos(("right","top")))  # 水印的位置
    video = CompositeVideoClip([
                            clip, #在第0秒开始
                            clip1.set_start(art_one),
                            clip2.set_start(art_two),
                            clip3.set_start(clip.duration / 2),
                            clip4.set_start(clip.duration - art_four),
                            clip5.set_start(clip.duration - art_five)
                            ])
    result = mp.CompositeVideoClip([video, logo])
    return result

def fun2(vid, opname, edname, outputname):  #加片头片尾
    video1 = VideoFileClip(opname)
    video2 = VideoFileClip(edname)
    result = concatenate_videoclips([video1, vid, video2])
    result.write_videofile(outputname, codec="libx264", bitrate="10000000")
    result.close

def main():
    data = xlrd.open_workbook('vidinfo.xlsx')  #Excel文件名 
    table = data.sheet_by_name('vid')       #Excel表
    start_num = int(table.cell(0,0).value)  #开始集数
    end_num = int(table.cell(0,1).value)    #终止集数
    #logo参数读取
    logo_size = int(table.cell(0,2).value)
    logo_top_distance = int(table.cell(0,3).value)
    logo_right_distance = int(table.cell(0,4).value)
    #花字参数读取
    art_one = int(table.cell(0,5).value)    
    art_two = int(table.cell(0,6).value)    
    art_four = int(table.cell(0,7).value)   
    art_five = int(table.cell(0,8).value)   
    while start_num <= end_num:
        sources = source_path.format(start_num)
        mask_vid = fun1(sources, logo_size, logo_top_distance, logo_right_distance, art_one, art_two, art_four, art_five)
        fun2(mask_vid, op_path, ed_path, result_path.format(start_num))
        start_num += 1

if __name__ == '__main__':
    main()
阅读 5k
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题