剪切
用 -ss 和 -t 选项, 从第 30 秒开始,向后截取 10 秒的视频,并保存:
ffmpeg -i input.wmv -ss 00:00:30.0 -c copy -t 00:00:10.0 output.wmv
ffmpeg -i input.wmv -ss 30 -c copy -t 10 output.wmv
也可以用 -ss 和 -to 选项, 从第 30 秒截取到第 40 秒:
ffmpeg -i input.wmv -ss 30 -c copy -to 40 output.wmv
旋转
如果不想重新编码视频并且播放器可以处理旋转元数据,则可以使用ffmpeg更改元数据中的旋转:
ffmpeg -i input.m4v -metadata:s:v rotate="90" -codec copy output.m4v
拼接
先把 mp4 封装成 ts 格式,之后 ts 直接拼接,最后在转化为 mp4。
ffmpeg -i video1.mp4 -vcodec copy -acodec copy -vbsf h264_mp4toannexb 1.ts
ffmpeg -i video2.mp4 -vcodec copy -acodec copy -vbsf h264_mp4toannexb 2.ts
ffmpeg -i "concat:1.ts|2.ts" -c copy -bsf:a aac_adtstoasc -movflags +faststart output.mp4
转换为Gif
- 将视频 MP4 转化为 GIF
ffmpeg -i test.mp4 test.gif
- 将视频中的一部分转换为GIF
// 从视频中第3秒开始,截取时长为3秒的片段转化为 gif
ffmpeg -t 3 -ss 00:00:03 -i test.mp4 test-clip.gif