我正在编写一个脚本来使用ffmpeg
压缩视频文件并尝试创建一个until
循环,直到copression ratio
超过1.5
这是代码:
for f in "$@"; do
BASE=${f%.*}
filesize_compressed=$(stat --format=%s "${BASE}_${suffix}.mp4")
filesize_original=$(stat --format=%s "${BASE}.mp4")
filesize_compressed_mb=$(echo "scale=2; ${filesize_compressed} / 1024 / 1024" | bc)
filesize_original_mb=$(echo "scale=2; ${filesize_original} / 1024 / 1024" | bc)
echo -e "Compressed file size: "$(basename "${BASE}_${suffix}.mp4")" ${filesize_compressed_mb} MB"
echo -e "Original file size: "$(basename "${BASE}.mp4")" ${filesize_original_mb} MB"
compression_ratio=$(echo "scale=2; ${filesize_original} / ${filesize_compressed}" | bc)
echo -e "Compression ratio: ${compression_ratio}"
if (( $(echo "${compression_ratio} < 1.5" | bc) )); then
until (( $(echo "${compression_ratio} > 1.49" | bc) )); do
echo -e "Trying ffmpeg compression with CRF: "$(("${crf}"++))""
echo -e "Deleting "${BASE}_${suffix}.mp4""
rm -f "${BASE}_${suffix}.mp4"
ffmpeg -i "${f}" -y -f mp4 -c:a "${ca}" -b:a "${ba}" -c:v "${cv}" -crf "$(("${crf}"++))" -preset "${preset}" -map_metadata 0 "${f%.*}_${suffix}.mp4"
done
fi
done
基本上我想:
ratio
ratio
&lt; 1.5
${crf}
(恒定速率因子)并再次压缩until
此比率超过1.5
由于某些原因,如果我运行脚本,它会在每次迭代时向CRF添加2而不是1,并且脚本永远不会退出重新压缩。 我错过了一些重要的东西吗?