Skip to content

Instantly share code, notes, and snippets.

@21zz
Created January 10, 2024 11:16
Show Gist options
  • Save 21zz/25c2e2fa8ff40509b380d2336a53ff06 to your computer and use it in GitHub Desktop.
Save 21zz/25c2e2fa8ff40509b380d2336a53ff06 to your computer and use it in GitHub Desktop.
#!/bin/bash
if [ "$#" -ne 1 ];
then
echo "Usage:"
echo " 25mb /path/to/video.mp4"
exit 1
fi
video="$1"
filename=$(basename -- "$video")
filename="${filename%.*}"
# magic
kb=$(python -c "import math; print(math.floor(191700/math.ceil($(ffprobe -v error -show_entries format=duration -of default=noprint_wrappers=1:nokey=1 "$video"))));")
ffmpeg -y -i "$video" -c:v libx264 -b:v "${kb}k" -pass 1 -f mp4 /dev/null
ffmpeg -i "$video" -c:v libx264 -b:v "${kb}k" -pass 2 "${filename}_new.mp4"
printf "\n\nsaved to %s_new.mp4" "$filename"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment