问答

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

作者:admin 2021-07-22 我要评论

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

在说正事之前,我要推荐一个福利:你还在原价购买阿里云、腾讯云、华为云服务器吗?那太亏啦!来这里,新购、升级、续费都打折,能够为您省60%的钱呢!2核4G企业级云服务器低至69元/年,点击进去看看吧>>>)

为什么程序在运行几秒后视频写入速度变得特别慢。
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()

版权声明:本文转载自网络,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。本站转载出于传播更多优秀技术知识之目的,如有侵权请联系QQ/微信:153890879删除

相关文章
  • 用Python的moviepy剪视频,为什么视频

    用Python的moviepy剪视频,为什么视频

  • vue element点击创建table表格和标签

    vue element点击创建table表格和标签

  • 微信公众号开发,当我修改微信昵称和头

    微信公众号开发,当我修改微信昵称和头

  • vue+element-ui table表格内存溢出,有

    vue+element-ui table表格内存溢出,有

腾讯云代理商
海外云服务器