从更长的视频中选择的几秒钟生成新的视频

时间:2018-06-27 17:43:49

标签: python-3.x video ffmpeg

我尝试生成一个10分钟原始视频文件.mp4的较短版本,该文件仅包含原始文件的四个10s子剪辑(即,从10秒到20秒;从197秒到207秒;从393秒到403秒;从570秒到580秒)。到目前为止,我只能生成4个同时复制视频和音频的新文件:

ffmpeg -i videofile.mp4 -vcodec copy -acodec copy -ss 10 -to 20 videofile1.mp4 -vcodec copy -acodec copy -ss 197 -to 207 videofile2.mp4 -vcodec copy -acodec copy -ss 393 -to 403 videofile3.mp4 -vcodec copy -acodec copy -ss 570 -to 580 videofile4.mp4

但是,在连接这4个子剪辑以生成所需的40秒out_videofile.mp4时,我遇到了很大的麻烦。我发现在ffmpeg中使用“选择”命令的this替代方法使我省去了“失败”的串联过程。到目前为止,我有:

ffmpeg -i videofile.mp4 -vf "select='between(t,10,20)+between(t,197,207)+between(t,393,403)+between(t,570,580)',setpts=N/FRAME_RATE/TB" -af "aselect='between(t,10,20)+between(t,197,207)+between(t,393,403)+between(t,570,580)" out_videofile.mp4

我猜这最后一个代码应该给我我想要的40年代out_videofile.mp4。但是,它给了我一个“ SyntaxError:无效的语法”。知道我哪里出问题了吗?

仍然感谢您的时间。

1 个答案:

答案 0 :(得分:2)

您遗漏了一个结束语,但缺少一个用于平滑音频时间戳记的过滤器。

使用

ffmpeg -i videofile.mp4 -vf "select='between(t,10,20)+between(t,197,207)+between(t,393,403)+between(t,570,580)',setpts=N/FRAME_RATE/TB" -af "aselect='between(t,10,20)+between(t,197,207)+between(t,393,403)+between(t,570,580)',asetpts=N/SR/TB" out_videofile.mp4
相关问题