-
-
Save r17x/41f76e92f377c13697704923a54bd246 to your computer and use it in GitHub Desktop.
Revisions
-
trvswgnr revised this gist
Aug 22, 2024 . 1 changed file with 0 additions and 6 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -22,12 +22,6 @@ get_filepath_without_extension() { echo "${1%."$ext"}" } if [ $# -ne 1 ]; then echo "ERROR: input file is required" print_usage -
trvswgnr revised this gist
Aug 22, 2024 . 1 changed file with 12 additions and 8 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -24,7 +24,7 @@ get_filepath_without_extension() { # Check if ffmpeg is installed if ! command -v ffmpeg >/dev/null 2>&1; then echo "ERROR: ffmpeg is not installed. Please install it and try again" exit 1 fi @@ -49,10 +49,15 @@ acodec="aac" format_opt="" case $input_file_ext in mp4) vcodec="libx264" acodec="aac" ;; mov) vcodec="libx264" acodec="aac" format_opt="-f mov" ;; webm) vcodec="libvpx-vp9" acodec="libopus" @@ -72,13 +77,12 @@ avi|flv) ;; esac echo "compressing video. this could take a while..." if ffmpeg -i "$input_file" -c:v $vcodec -crf 23 -preset medium -c:a $acodec $format_opt "$output_file"; then echo "compression completed successfully" echo "output file: $output_file" else echo "ERROR: compression failed" exit 1 fi -
trvswgnr revised this gist
Aug 22, 2024 . 1 changed file with 23 additions and 11 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -2,7 +2,7 @@ print_usage() { echo "usage: compress_video <input_file>" echo "supported formats: mp4, webm, mkv, mov, avi, flv" } get_extension() { @@ -22,6 +22,12 @@ get_filepath_without_extension() { echo "${1%."$ext"}" } # Check if ffmpeg is installed if ! command -v ffmpeg >/dev/null 2>&1; then echo "ERROR: ffmpeg is not installed. Please install it and try again." exit 1 fi if [ $# -ne 1 ]; then echo "ERROR: input file is required" print_usage @@ -37,8 +43,13 @@ fi input_file_ext="$(get_extension "$input_file")" output_file="$(get_filepath_without_extension "$input_file")_compressed.$input_file_ext" # Default to libx264 and aac for unknown formats vcodec="libx264" acodec="aac" format_opt="" case $input_file_ext in mp4|mov) vcodec="libx264" acodec="aac" ;; @@ -50,23 +61,24 @@ mkv) vcodec="libx265" acodec="libopus" ;; avi|flv) vcodec="libx264" acodec="aac" format_opt="-f mp4" output_file="$(get_filepath_without_extension "$input_file")_compressed.mp4" ;; *) echo "WARNING: unsupported video format - trying with default codecs" ;; esac cmd="ffmpeg -i \"$input_file\" -c:v $vcodec -crf 23 -preset medium -c:a $acodec $format_opt \"$output_file\"" echo "Compressing video. This may take a while..." if eval "$cmd"; then echo "Compression completed successfully" echo "Output file: $output_file" else echo "ERROR: Compression failed" exit 1 fi -
trvswgnr created this gist
Aug 22, 2024 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,72 @@ #!/bin/sh print_usage() { echo "usage: compress_video <input_file>" echo "supported formats: mp4, webm, mkv, mov" } get_extension() { f="${1##*/}" case "$f" in .*) get_extension "${f#.}" && return 0 ;; esac case "$f" in .*.*) echo "${f#.}" ;; *.*) echo "${f#*.}" ;; *) return 0 ;; esac } get_filepath_without_extension() { ext=$(get_extension "$1") echo "${1%."$ext"}" } if [ $# -ne 1 ]; then echo "ERROR: input file is required" print_usage exit 1 fi input_file="$1" if [ ! -f "$input_file" ]; then echo "ERROR: input file '$input_file' does not exist" exit 1 fi input_file_ext="$(get_extension "$input_file")" output_file="$(get_filepath_without_extension "$input_file")_compressed.$input_file_ext" case $input_file_ext in mp4) vcodec="libx264" acodec="aac" ;; webm) vcodec="libvpx-vp9" acodec="libopus" ;; mkv) vcodec="libx265" acodec="libopus" ;; mov) vcodec="libx264" acodec="aac" format_opt="-f mov" ;; *) echo "ERROR: unsupported video format" exit 1 ;; esac cmd="ffmpeg -i $input_file -c:v $vcodec -crf 28 -c:a $acodec $format_opt $output_file" if $cmd; then echo "compression completed successfully" echo "output file: $output_file" else echo "ERROR: compression failed" exit 1 fi