moviepy,ffmpeg截取视频

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

bug:

https://www.youtube.com/watch?v=3Md9MkOLYL4 

https://stackoverflow.com/questions/43966523/getting-oserror-winerror-6-the-handle-is-invalid-in-videofileclip-function

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值