如何找到所有视频文件,并且持续时间处于特定间隔内。
例如,查找持续时间在20到40分钟之间的所有视频文件。
以下脚本将为您完成这项工作。假定视频在目录中(并非整个系统中)。
该脚本还假定您已avprobe
安装,它是的一部分avconv
。如果有语法,则应与ffprobe
(的一部分ffmpeg
)使用相同的语法。如果来自的输出ffprobe
不同,则需要编辑脚本。
持续时间以秒为单位,但是需要-保存进行计算。
#!/bin/sh
# NOTE: Assumes you have avprobe installed and the full path
# to it is /usr/bin/avprobe - if not, edit.
# Where are the videos?
MASTER="/home/tigger/Videos"
# Duration min in seconds (1200 = 20min)
DUR_MIN="1200"
# Duration max in seconds (2400 = 40min)
DUR_MAX="2400"
# Get a list of files
LIST=`find "$MASTER" -type f`
# In case of a space in file names, split on return
IFS_ORIG=$IFS
IFS="
"
valid="\nList of videos with duration between $DUR_MIN and $DUR_MAX seconds"
# Loop over the file list and probe each file.
for v in $LIST
do
printf "Checking ${v}\n"
dur=`/usr/bin/avprobe -v error -show_format_entry duration "${v}"`
if [ -n $dur ]
then
# Convert the float to int
dur=${dur%.*}
if [ $dur -ge $DUR_MIN -a $dur -le $DUR_MAX ]
then
valid="${valid}\n$v"
fi
fi
done
printf "${valid}\n"
exit
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句