1、moviepy,提供开始和结束时间截取视频并保存。有些播放器音频解码有问题
from moviepy.editor import *
def clip(filename, start = 0, end = None):
tmp_name = filename.split('.')
new_filename = tmp_name[0] + '_clip.' + tmp_name[1]
video = VideoFileClip(filename)
try:
result = video.subclip(start, end)
result.write_videofile(new_filename)
video.reader.close()
return new_filename
except:
traceback.print_exc()
return None
2、python+ffmpeg剪切视频
from moviepy.editor import VideoFileClip
JIE_QU = 'ffmpeg -ss %s -t %s -accurate_seek -i %s -codec copy -avoid_negative_ts 1 %s'
def clip(filename, start = 0, end = None):
tmp_name = filename.split('.')
new_filename = tmp_name[0] + '_clip.' + tmp_name[1]
video = VideoFileClip(filename)
try:
if end < 0: end = video.duration + end
command = JIE_QU % (start, end, filename, new_filename)
os.system(command)
return new_filename
except:
traceback.print_exc()
return None
参考:
https://blog.csdn.net/matrix_laboratory/article/details/53157383 ffmpeg视频精准剪切
http://blog.csdn.net/summermaoz/article/details/56058056 python+ffmpeg截取视频段
https://baijiahao.baidu.com/s?id=1561527904480690&wfr=spider&for=pc 使用Python对视频的简单截取
http://blog.csdn.net/xlianglei/article/details/68925377 win10 + anaconda +moviepy + mayavi + ffmpeg
http://blog.csdn.net/myboyliu2007/article/details/53928746 通过python安装ffmpge
http://www.cppblog.com/socketref/archive/2014/04/14/206584.html python中利用ctype包装ffmpeg
http://zulko.github.io/moviepy/examples/examples.html examples
https://blog.csdn.net/dszgf5717/article/details/80873538 centos安装ffmpeg