Skip to content

Commit

Permalink
Update ffcompress
Browse files Browse the repository at this point in the history
  • Loading branch information
antunnitraj authored Sep 21, 2022
1 parent 99cbeab commit f975520
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions ffcompress
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#!/usr/bin/env bash

EXT="mp4"
SIZE=8
while getopts i:o:s: OPTION; do
while getopts i:o:s:n:e: OPTION; do
case $OPTION in
i)
INPUT=$OPTARG
Expand All @@ -13,14 +14,25 @@ while getopts i:o:s: OPTION; do
s)
SIZE=$OPTARG
;;
n)
NAME=$OPTARG
;;
e)
EXT=$OPTARG
;;
\?)
echo "script usage: ffcompress [-i input] [-o output] [-s size in mb]" >&2
echo "script usage: ffcompress [-i input] [-o output] [-s size in mb] [-n exported video name] [-e exported video extension]" >&2
exit 1
;;
esac
done

filename=$(basename "$INPUT")
outputname="${OUTPUT}/${filename%.*}-${SIZE}mb.${filename#*.}"

if [ "$NAME" != "" ]; then
outputname="${OUTPUT}/${NAME}-${SIZE}mb.${EXT}"
fi

if test -f "$INPUT" && test -d "$OUTPUT"; then
echo "[+] File exists! Launching ffmpeg compress script"
Expand All @@ -30,8 +42,8 @@ if test -f "$INPUT" && test -d "$OUTPUT"; then
total_bitrate=$(( $target_size / $length_round_up ))
audio_bitrate=$(( 128 * 1000 ))
video_bitrate=$(( $total_bitrate - $audio_bitrate ))
ffmpeg -i "$INPUT" -b:v $video_bitrate -maxrate:v $video_bitrate -bufsize:v $(( $target_size / 20 )) -b:a $audio_bitrate "${OUTPUT}/${filename%.*}-${SIZE}mb.${filename#*.}"
ffmpeg -i "$INPUT" -b:v $video_bitrate -maxrate:v $video_bitrate -bufsize:v $(( $target_size / 20 )) -b:a $audio_bitrate "$outputname"
else
echo "script usage: ffcompress [-i input video] [-o output directory] [-s size in MB]" >&2
echo "script usage: ffcompress [-i input] [-o output] [-s size in mb] [-n exported video name] [-e exported video extension]" >&2
exit 1
fi

0 comments on commit f975520

Please sign in to comment.