jui*_*yah 5 bash ffmpeg shell-script
我正在使用这个 bash 脚本从视频生成缩略图:
#!/bin/bash
source_dir="."
output_dir="/output"
input_file_types=(avi wmv flv mkv mpg mp4)
output_file_type="jpg"
r1=$(( ( RANDOM % 10 ) + 5 ))
convert() {
echo "" | ffmpeg -ss 00:"r1":05 -y -i "$1" -an -f image2 -vframes 1 "$output_dir/$2"
}
for input_file_type in "${input_file_types[@]}"
do
find "$source_dir" -name "*.$input_file_type" -print0 | while IFS= read -r -d $'\0' in_file
do
echo "Processing…"
echo ">Input $in_file"
# Replace the file type
out_file=$(echo "$in_file" | sed "s/\(.*\.\)$input_file_type/\1$output_file_type/g")
# The above can be shortened to
# out_file="${in_file%.$input_file_type}.$output_file_type"
echo ">Output $out_file"
# Convert the file
convert "$in_file" "$out_file"
if [ $? != 0 ]
then
echo "$in_file had problems" >> handbrake-errors.log
fi
echo ">Finished $out_file\n\n"
done
done
echo "DONE CONVERTING FILES"
Run Code Online (Sandbox Code Playgroud)
我想要的是计算总视频时间并从随机视频时间生成缩略图。
mediainfo myvideo.mp4 | grep Duration
Duration : 5mn 7s
Duration : 5mn 7s
Duration : 5mn 7s
Run Code Online (Sandbox Code Playgroud)
我如何集成grep Duration
到上面的 bash 脚本中,以便根据总视频时间获得随机时间的缩略图?
尝试以秒为单位获取持续时间,因为这将使一切变得更容易:
您的转换函数最终可能是:
convert() {
# Get duration in milliseconds, then convert to seconds
duration=$(($(mediainfo --Inform="General;%Duration%" "${in_file}" ) / 1000 ))
# Calculate random time
random_time=$(date -u -d @$(shuf -i 0-${duration} -n 1) +"%T")
# Take screenshot
ffmpeg -ss ${random_time} -i "$in_file" -vframes 1 -q:v 2 "$output_dir/$output_file"
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
2549 次 |
最近记录: |