Created
November 4, 2022 12:12
-
-
Save goose-ws/2bf4c3da224045c9de71ebc0b0610ebd to your computer and use it in GitHub Desktop.
Usage is: ./tiny-video.bash "/path/to/input/file.mkv" "/path/to/output/file.mp4"
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
target_size=$(( 6 * 1000 * 1000 * 8 )) # 6MB | |
length="$(ffprobe -v error -show_entries format=duration -of default=noprint_wrappers=1:nokey=1 "${1}")" | |
length_round_up=$(( ${length%.*} + 1 )) | |
total_bitrate=$(( ${target_size} / ${length_round_up} )) | |
audio_bitrate=$(( 10 * 1000 )) # 80k bit rate | |
video_bitrate=$(( $total_bitrate - $audio_bitrate )) | |
ffmpeg-bar -i "${1}" -b:v ${video_bitrate} -maxrate:v ${video_bitrate} -bufsize:v $(( ${target_size} / 20 )) -b:a ${audio_bitrate} -ac 1 -vf scale=-1:144 "${2}" | |
ffmpeg-bar -i "${2}" -map_metadata -1 -c:v copy -c:a copy -fflags +bitexact -flags:v +bitexact -flags:a +bitexact "${2%.mp4}-2.mp4" | |
mv "${2%.mp4}-2.mp4" "${2}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment