import os
import ffmpeg
from moviepy.editor import VideoFileClip
from moviepy.editor import concatenate_videoclips
from shutil import copy
# 设置环境变量
os.environ['path'] = os.environ.get('path') + ';C:\\tools'
# 获取视频的时长
def video_EX(fullPath):
isSP = str(ffmpeg.probe(fullPath)).find("rotate")
video = VideoFileClip(fullPath)
# 获取视频的时长
times = int(video.duration)
# 文件名称
fileName = os.path.basename(video.filename)
# 最终处理完成的视频地址
final = "final/" + fileName
# 判断该视频是否是横批时长超过一分钟
# if (isSP == -1 and times > 60):
# 先对时长进行处理 剪辑然后写出文件
cut1 = video.subclip(5, times)
finalClip = concatenate_videoclips([cut1])
finalClip.write_videofile("bak/" + fileName)
cut1 = video.subclip(5, times)
finalClip = concatenate_videoclips([cut1])
bakUrl = "bak/" + fileName
finalClip.write_videofile("bak/" + fileName)
# 对视频采用FFMPEG加水印
ffmpegCmd = "ffmpeg -t 10 -i " + bakUrl + " -filter_complex \"[0:v]crop=w=200:h=100:x=500:y=0,boxblur=luma_radius=25:luma_power=2[boxblur];[0:v][boxblur]overlay=500:0[vout]\" -map \"[vout]\" -map 0:a -c:v libx264 -crf 28 -preset veryfast -c:a copy -movflags +faststart " + final + " -y"
# 执行水印命令处理操作
os.system(ffmpegCmd)
# else:
# # 直接移动到该目录当中去
# copy(fullPath, final)
if __name__ == '__main__':
video_EX("video/video.mp4")
网友评论