diff --git a/scritps/vidcompress b/scritps/vidcompress index c1f6fb5..513ccd5 100755 --- a/scritps/vidcompress +++ b/scritps/vidcompress @@ -1,11 +1,13 @@ #!/bin/sh +# TODO: Add hardware acceleration support +# TODO: More consistently find a way to delete ffmpeg log files usage() { - printf '%b\n' "${0##*/} -i [OPTIONS]" \ - "\noptions:" \ - "\t-c CODEC - video codec to use (default: libx264)" \ - "\t-h - display this message" \ - "\t-o FILE - output file (default: out.ext)" \ - "\t-p PRESET - encoding preset to use (default: veryslow)" \ + printf '%b\n' "${0##*/} -i [OPTIONS]" \ + "\noptions:" \ + "\t-c CODEC - video codec to use (default: libx264)" \ + "\t-h - display this message" \ + "\t-o FILE - output file (default: out.ext)" \ + "\t-p PRESET - encoding preset to use" \ "\t-t FILE_SIZE - file size to target in MiB (default: 50)" } @@ -47,18 +49,18 @@ ext="${VIDCOMP_INPUT_FILE##.*}" : "${VIDCOMP_CODEC:=libx264}" : "${VIDCOMP_TARGET_SIZE:=50}" -: "${VIDCOMP_PRESET:=veryslow}" a_bitrate="$(ffprobe -v error -select_streams a:0 -show_entries stream=bit_rate -of default=noprint_wrappers=1:nokey=1 \ "${VIDCOMP_INPUT_FILE}")" secs="$(ffprobe -v error -show_entries format=duration -of default=noprint_wrappers=1:nokey=1 "${VIDCOMP_INPUT_FILE}")" bitrate="$(fend floor \("${VIDCOMP_TARGET_SIZE} * 8388.608 / ${secs}" - \("${a_bitrate}" / 1000\)\))" -ffmpeg -hide_banner -loglevel warning \ - -i "${VIDCOMP_INPUT_FILE}" -c:v "${VIDCOMP_CODEC}" -b:v "${bitrate}k" -preset "${VIDCOMP_PRESET}" -pass 1 \ + +ffmpeg -hide_banner -loglevel info \ + -i "${VIDCOMP_INPUT_FILE}" -c:v "${VIDCOMP_CODEC}" -b:v "${bitrate}k" \ + ${VIDCOMP_PRESET:+"-preset" "$VIDCOMP_PRESET"} -pass 1 \ -an -f null -y /dev/null && \ -ffmpeg -hide_banner -loglevel warning \ - -i "${VIDCOMP_INPUT_FILE}" -c:v "${VIDCOMP_CODEC}" -b:v "${bitrate}k" -preset "${VIDCOMP_PRESET}" -pass 2 \ +ffmpeg -hide_banner -loglevel info \ + -i "${VIDCOMP_INPUT_FILE}" -c:v "${VIDCOMP_CODEC}" -b:v "${bitrate}k" \ + ${VIDCOMP_PRESET:+"-preset" "$VIDCOMP_PRESET"} -pass 2 \ -c:a copy "${VIDCOMP_OUTPUT_FILE}" - -rm ffmpeg2pass*.log*