标签:path1 FFmpeg 批量 echo mp4 Bash path concat result
前言
使用FFmpeg能够很方便的合并同分辨率的视频。很多时候我们可能需要批量化合并视频,此时可以通过编写Bash脚本来实现。
实现
批量合并视频
合并三个文件夹中的视频结果:
result_path1=task1
result_path2=task2
result_path3=task3
concat_path=concat-videos
if [ ! -d "./$concat_path" ]; then
mkdir ./$concat_path
fi
for i in {0..20}
do
echo "process: $i"
ffmpeg -i ./$result_path1/$i/*.mp4 -i ./$result_path2/$i/*.mp4 -i ./$result_path3/$i/*.mp4 -lavfi hstack=3 -y ./$concat_path/concat-video$i.mp4
done
注:hstack为水平合并,vstack为竖直合并。
根据宽高关系合并视频
有时视频是宽大于高,而有时是高大于宽。此时需要根据宽高关系自适应选择hstack或者vstack。
result_path1=task1
result_path2=task2
result_path3=task3
concat_path=concat-videos
if [ ! -d "./$concat_path" ]; then
mkdir ./$concat_path
fi
function getWidth(){
width=( $(ffprobe -v error -show_entries stream=width -of csv=p=0 $1))
echo $width
}
function getHeight(){
height=( $(ffprobe -v error -show_entries stream=height -of csv=p=0 $1))
echo $height
}
for i in {0..20}
do
echo "process: $i"
widthInfo=$(getWidth ./$result_path1/$i/*.mp4)
heightInfo=$(getHeight ./$result_path1/$i/*.mp4)
if [ $widthInfo -gt $heightInfo ]
then
#echo $widthInfo ">" $heightInfo
ffmpeg -i ./$result_path1/$i/*.mp4 -i ./$result_path2/$i/*.mp4 -i ./$result_path3/$i/*.mp4 -qscale 0 -lavfi vstack=3 -y ./$concat_path/concat-$i.mp4
else
#echo $widthInfo "<" $heightInfo
ffmpeg -i ./$result_path1/$i/*.mp4 -i ./$result_path2/$i/*.mp4 -i ./$result_path3/$i/*.mp4 -qscale 0 -lavfi hstack=3 -y ./$concat_path/concat-$i.mp4
fi
done
版权说明
本文为原创文章,独家发布在blog.csdn.net/TracelessLe。未经个人允许不得转载。如需帮助请email至tracelessle@163.com。
参考资料
[1] 【持续更新】FFmpeg常用命令小结_TracelessLe的专栏-CSDN博客_ffmpeg更新命令
[2] Bash语法中的For Loop_TracelessLe的专栏-CSDN博客_bash for loop
[3] Bash语法中的if else_TracelessLe的专栏-CSDN博客
标签:path1,FFmpeg,批量,echo,mp4,Bash,path,concat,result 来源: https://blog.csdn.net/TracelessLe/article/details/122381319
本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享; 2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关; 3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关; 4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除; 5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。