剪切视频
通过 ffmpeg 去剪切视频,使用以下命令:
1
| ffmpeg -ss [00:00:00] -t [00:00:30] -i [test.mp4] -vcodec copy -acodec copy [output.mp4]
|
-ss:该参数指定从源视频的剪切起始点
–t:该参数指定需要截取多长时间
–i:该参数指定要剪切的源视频
output.mp4: 最终生成的视频文件名称
示例:
1 2 3 4 5
| ffmpeg -ss 00:00:00 -t 00:00:16 -i 球机修正.mp4 -vcodec copy -acodec copy 1.mp4
ffmpeg -ss 00:01:12 -t 00:01:35 -i 球机修正.mp4 -vcodec copy -acodec copy 2.mp4
|
合并视频
前置操作
需要将你要合并的视频以以下格式写到一个 txt 文件中:
比如我有 3 个文件需要合并,那么该 txt 的内容便是:
1 2 3
| file '1.mp4' file '2.mp4' file '3.mp4'
|
写个脚本可以将这些视频都输出到文件中:
1 2 3 4 5 6 7 8 9 10
| #!/bin/bash
if [ ! -f filelist.txt ]; then touch filelist.txt fi
for file in $(ls /home/yunzhou/videos | grep mp4$) do echo "file '$file'" >> filelist.txt done
|
然后使用合并命令:
1
| ffmpeg -f concat -i filelist.txt -c copy result.mp4
|
-i 参数后面跟的就是包含要合并视频的 txt 文件,result.mp4 就是最终生成文件的视频文件。