美文网首页
ffmpeg: 视频剪切和拼接

ffmpeg: 视频剪切和拼接

作者: wzNote | 来源:发表于2021-08-21 00:28 被阅读0次
    def cut_and_stitch(input_video, time_list, output_video):
        """
        剪切掉所有time_list里的片段,将其余片段拼接起来
        """
    
        all_cut = []
        filter_cmd = []
        for i, (start, end) in enumerate(time_list):
            filter_cmd.append(
                '[0:v] trim=start={}:end={},setpts=PTS-STARTPTS,format=yuv420p [{}v];'.format(start, end, i))
            filter_cmd.append('[0:a] atrim=start={}:end={},asetpts=PTS-STARTPTS [{}a];'.format(start, end, i))
            all_cut.append('[{}v][{}a]'.format(i, i))
        cmd = "ffmpeg -i {} -filter_complex '{} concat=n={}:v=1:a=1[outv][outa]' -map [outv] -map [outa] -q:v 5 {}".format(
            input_video, ' '.join(filter_cmd) + ''.join(all_cut), len(all_cut), output_video)
        print('cmd:', cmd)
        os.system(cmd)
    

    相关文章

      网友评论

          本文标题:ffmpeg: 视频剪切和拼接

          本文链接:https://www.haomeiwen.com/subject/ymxlpltx.html