diff --git a/.config/lf/lfrc b/.config/lf/lfrc index fb43a051..7cbd2cd4 100644 --- a/.config/lf/lfrc +++ b/.config/lf/lfrc @@ -91,6 +91,52 @@ cmd delete ${{ [ $ans = "y" ] && rm -rf -- $fx }} +cmd compressvideo ${{ + clear; + set -f; + + converted_filenames=""; #notify-send variable + converted_files_count=0; #notify-send variable + + echo "Compression Rate? (default: 31, maximum: 50)"; + read -N 2 compressionRate; + + #If not a number (e.g. empty), give default 31 value + if ! [[ $compressionRate =~ ^[0-5][0-9]$ ]]; then + compressionRate="31"; + fi + + for pickedFilepath in $fx; do + #could instead use ffprobe but would get more complicated as the filetype suffix becomes unknown + case $pickedFilepath in + *.mp4) + tempFilepath=$(echo "$pickedFilepath" | sed 's|.mp4|(CONVERTING).mp4|'); + mv -f "$pickedFilepath" "$tempFilepath"; + + ffmpeg -i "$tempFilepath" -vcodec libx265 -crf "$compressionRate" "$pickedFilepath"; + rm -f -- "$tempFilepath"; + ;; + *.webm | *.mkv) + newFilepath=$(echo "$pickedFilepath" | sed 's/\(.webm\|.mkv\)/.mp4/'); + ffmpeg -i "$pickedFilepath" -vcodec libx265 -crf "$compressionRate" "$newFilepath"; + rm -f -- "$pickedFilepath"; + ;; + *) + continue 1;; + esac + + ((converted_files_count=converted_files_count+1)); + converted_filenames="$converted_filenames"$'\n'"$pickedFilepath"; + + done + + #Notify the user of the results + if [[ $converted_files_count -gt 0 ]]; then + converted_filenames=$(echo "$converted_filenames" | sed 's|.*\/||'); + notify-send "Compressed Videos($converted_files_count):" "$converted_filenames"; + fi; +}} + cmd moveto ${{ clear; tput cup $(($(tput lines)/3)); tput bold set -f @@ -177,5 +223,7 @@ map unselect +map compressvideo + # Source Bookmarks source "~/.config/lf/shortcutrc"