diff --git a/ffcompress b/ffcompress index 914fad9..cab5628 100644 --- a/ffcompress +++ b/ffcompress @@ -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 @@ -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" @@ -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