python根据时间段拆分视频并且合并(高效快速)

# coding=utf-8
__author__ = 'Administrator'

import time
from moviepy.editor import VideoFileClip, concatenate_videoclips

"""
def print_time():
    now = time.time()
    r = time.strftime("%Y-%m-%d %H:%M:%S",time.localtime(now))
    print(r)

path1 =r'D:/1/biaoqing/video.mp4'
path2 =r'D:/1/biaoqing/video_0002.mp4'
desc_path=r"D:/1/biaoqing/my_concatenation.mp4"
print_time()
clip1 =VideoFileClip(path1).subclip(11,15)
print_time()
clip2 =VideoFileClip(path2)
print_time()
# 结合剪辑,你甚至能够完全自动化剪辑拼接视频的操作
# clip2 =VideoFileClip("myvideo2.mp4").subclip(50,60)
final_clip = concatenate_videoclips([clip1,clip2])
print_time()
# final_clip = concatenate_videoclips([clip1,clip2,clip3])
final_clip.write_videofile(desc_path)
print_time()
"""
def combine_list_video(time_list, source_path, out_path):

    clip_list = []
    for i in time_list:
        clip = VideoFileClip(source_path).subclip(i[0], i[1])
        clip_list.append(clip)
    # clip1 = VideoFileClip(path1)
    # clip2 = VideoFileClip(path2)
    # 结合剪辑,你甚至能够完全自动化剪辑拼接视频的操作
    # clip2 =VideoFileClip("myvideo2.mp4").subclip(50,60)

    final_clip = concatenate_videoclips(clip_list)
    # final_clip = concatenate_videoclips([clip1,clip2,clip3])
    final_clip.write_videofile(out_path)


if __name__ == '__main__':
    source_path = r'D:/1/biaoqing/video.mp4'
    out_file = r'D:/1/biaoqing/result.mp4'
    # time_list=[(1260,1275),(1140,1320)]
    # time_list=[(1850,1870),(1790,1997)]
    time_list=[(0,16),(37,45),(66,71)]
    combine_list_video(time_list,source_path,out_file)




你可能感兴趣的:(Python,python,windows,开发语言)