1. 剪切:
./ffmpeg -ss 00:00:06 -t 00:00:12 -i input.mp4 -vcodec copy -acodec copy output.mp4
意思是从截取从6秒开始,时长为12秒的视频,格式不变,
输入为input.mp4
输出为output.mp4
-vcodec copy -acodec copy : 编码格式不变
2. 合并:
mp4的合并最好是先转成无损质量的ts,再合并(如果直接合并,会有些小bug)
./ffmpeg -i 1.mp4 -vcodec copy -acodec copy -vbsf h264_mp4toannexb 1.ts
./ffmpeg -i 2.mp4 -vcodec copy -acodec copy -vbsf h264_mp4toannexb 2.ts
./ffmpeg -i "concat:1.ts|2.ts" -acodec copy -vcodec copy -absf aac_adtstoasc output.mp4
还有就是关于-s选项的解释:
‘-ss position (input/output)’
When used as an input option (before -i), seeks in this input file to position. When used as an output option (before an output filename), decodes but discards input until the timestamps reach position. This is slower, but more accurate.
position may be either in seconds or in hh:mm:ss[.xxx] form.
意思就是如果要把-ss作为输入选项的话要放在-i之前,当做输出选项的话放在输出文件之前。我们这是要截取一段视频,应该当做输入选项,所以-ss要在-i之前才有效,不然会花费很长一段时间来寻找-ss。
3. 批处理(python脚本实现)
主要是实现用自动化工具,将视频切割成比如2分钟的很多小视频文件;
事情的由来是我看到一个youtube的视频不错,因为墙的原因不能分享,但是原文件比较大(有200多M)不能发微信(限定是20M以内),所以造了这个轮子;
1.png
# coding=gb2312
import string
import