赞
踩
安装
pip install moviepy
1.载入所有mp4结尾的文件,按原始分辨率拼接
from moviepy.editor import concatenate_videoclips, VideoFileClip
import os
path1 = os.getcwd()
data_list = []
for f in os.listdir(path1):
if '.mp4' in f:
print(path1 + '\\' + f)
video1 = VideoFileClip(path1 + '\\' + f)
data_list.append(video1)
# method=‘compose’使得各种编码方式不同的视频也可以进行拼接
final_clip = concatenate_videoclips(data_list, method='compose')
final_clip.write_videofile("new.mp4")
2.将所有视频分辨率调整为最大分辨率
data_dict = {} # 获取所有当前路径mp4文件 for f in os.listdir(path1): if '.mp4' in f: print(path1 + '\\' + f) path2 = path1 + '\\' + f video1 = VideoFileClip(path1 + '\\' + f) # 视频分辨率和路径 data_dict[tuple(video1.size)] = path2 print(list(sorted(data_dict, reverse=True)[0])) # 从大到小排序分辨率取最大 fenbianlv = list(sorted(data_dict, reverse=True)[0]) data_list = [] # 如果分辨率不同则转换分辨率 for d in data_dict: print(data_dict[d]) video2 = VideoFileClip(data_dict[d]) if video2.size != fenbianlv: # 转换分辨率 video2 = VideoFileClip(data_dict[d]).resize(fenbianlv) name1 = data_dict[d] + '.mp4' # 保存 video2.write_videofile(name1) # 重新加载 video2 = VideoFileClip(name1) data_list.append(video2) # method=‘compose’使得各种编码方式不同的视频也可以进行拼接 final_clip = concatenate_videoclips(data_list, method='compose') # 保存 final_clip.write_videofile("new.mp4")
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。