linux里使用ffmpeg 无损剪切 拼接视频程序
发布时间:2022-06-15 22:45:27 所属栏目:教程 来源:互联网
导读:ffmpeg是一款视频处理工具了,我们可以在系统中安装之后利用ffmpeg命令进行视频的处理了,下面就一起来看看吧. 其实借助 ffmpeg 我们就可以在不进行视频重编码的情况下完成此类任务. 剪切代码如下: ffmpeg -i input.mp4 -ss **START_TIME** -t **STOP_TIME** -
ffmpeg是一款视频处理工具了,我们可以在系统中安装之后利用ffmpeg命令进行视频的处理了,下面就一起来看看吧. 其实借助 ffmpeg 我们就可以在不进行视频重编码的情况下完成此类任务. 剪切代码如下: ffmpeg -i input.mp4 -ss **START_TIME** -t **STOP_TIME** -acodec copy -vcodec copy output.mp4 其中 START_TIME/STOP_TIME 的格式可以写成两种格式: 以秒为单位计数: 80 时:分:秒: 00:01:20 拼接: 拼接的情况稍微复杂些,我们需要将需要拼接的视频文件按以下格式保存在一个列表 list.txt 中,代码如下: file '/path/to/file1' file '/path/to/file2' file '/path/to/file3' 相应的命令为如下代码: ffmpeg -f concat -i **list.txt** -c copy output.mp4 由于不需要重编码,这两条命令几乎是即时完成的,方便起见,我写了一个脚本来简化操作,放在 github 上,请自取,代码如下: #!/bin/bash #cut/join videos using ffmpeg without quality loss if [ -z $1 ] || [ -z $2 ]; then echo "Usage:$0 c[ut] seconds <File>" echo " eg. $0 c 10 80 example.mp4" echo " eg. $0 c 00:00:10 00:01:20 example.mp4" echo "Usage:$0 j[oin] <FileType>" echo " eg. $0 j avi" exit fi case "$1" in c) echo "cuttig video..." fileName=$(echo $4 | cut -f 1 -d '.') fileType=$(echo $4 | cut -f 2 -d '.') ffmpeg -i $4 -ss $2 -t $3 -acodec copy -vcodec copy $fileName-$2-$3.$fileType ;; j) echo "joinning videos..." rm temp_list.txt for f in ./*.$2; do echo "file '$f'" >> temp_list.txt; done printf "file '%s'\n" ./*.$2 > temp_list.txt ffmpeg -f concat -i temp_list.txt -c copy output.$2 rm temp_list.txt //phpfensi.com ;; *) echo "wrong arguments" ;; esac exit 。 (编辑:广西网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
站长推荐