Compress Video Updates, Attempt To Customize Cinnamon (#42)
* Using $1 does not work well with options. * Add timestamp to compressed file. Format code. * Add a wildcard catch for getopts. * Add a usage line to the usage. * Add m, v, and x options. Refactor a few areas. * Add missing options to usage. * Change verbose to be V so that video-bitrate stays v. * Set the same values as GNOME for Cinnamon DE. * Add note on what the change really did to Cinnamon. * Enhancements to multiple options. * Process the files/folders in a recognizable order. * Update comment, no longer using a hard-coded codec.
This commit is contained in:
parent
b47183af76
commit
84844715a6
@ -9,78 +9,123 @@ if [[ $DIR == '.' ]]; then
|
|||||||
fi
|
fi
|
||||||
echo "Running $DIR/$PROG"
|
echo "Running $DIR/$PROG"
|
||||||
|
|
||||||
## Functions
|
## Functions ##
|
||||||
|
|
||||||
function usage {
|
function usage {
|
||||||
|
echo "Usage: $PROG [-i file/folder] [-v bitrate] [-a bitrate] [-c vcodec] [-r] [-f] [-m] [-V] [-x] [-h]"
|
||||||
cat <<- EOF
|
cat <<- EOF
|
||||||
Reduce the filesize of a video file to make it stream well. It also
|
Reduce the filesize of a video file to make it stream well. It also
|
||||||
helps with the file size for placing the file into a backup system.
|
helps with the file size for placing the file into a backup system.
|
||||||
Currently only set up for libopenh264 and mp4 files.
|
Currently only set up for mp4 files.
|
||||||
|
|
||||||
Parameters:
|
Parameters:
|
||||||
-i input : The input file or folder with which to search for video files.
|
-i input : The input file or folder with which to search for video files.
|
||||||
If nothing is provided, current directory (.) is assumed.
|
If nothing is provided, current directory (.) is assumed.
|
||||||
-v bitrate : The video bitrate to convert to, defaults to 2000k.
|
-v bitrate : The video bitrate to convert to, defaults to 2000k.
|
||||||
-a bitrate : The audio bitrate to convert to, defaults to 128k.
|
-a bitrate : The audio bitrate to convert to, defaults to 128k.
|
||||||
|
-c vcodec : The video codec you'd like to use, such as libopenh264.
|
||||||
-r : Recurse the entire directory structure, compressing all video files.
|
-r : Recurse the entire directory structure, compressing all video files.
|
||||||
-f : Force recompressing any files by deleting it if it already exists.
|
-f : Force recompressing any files by deleting it if it already exists.
|
||||||
|
-m : Measure the time it takes to compress each video and do the loop.
|
||||||
|
-V : Add verbosity, such as printing all the variable values.
|
||||||
|
-x : Set the shell's x flag to display every action which is taken.
|
||||||
-h : Display this help messaging.
|
-h : Display this help messaging.
|
||||||
EOF
|
EOF
|
||||||
exit $1
|
exit $1
|
||||||
}
|
}
|
||||||
|
|
||||||
## Parse Input
|
## Parameters ##
|
||||||
while getopts ":i:v:a:rfh" opt; do
|
|
||||||
|
while getopts ":i:v:a:c:rfmVxh" opt; do
|
||||||
case $opt in
|
case $opt in
|
||||||
i) input="$OPTARG"
|
i) input="$OPTARG"
|
||||||
echo "input='$input'"
|
|
||||||
;;
|
;;
|
||||||
v) video_bitrate="$OPTARG"
|
v) video_bitrate="$OPTARG"
|
||||||
echo "video_bitrate='$video_bitrate'"
|
|
||||||
;;
|
;;
|
||||||
a) audio_bitrate="$OPTARG"
|
a) audio_bitrate="$OPTARG"
|
||||||
echo "audio_bitrate='$audio_bitrate'"
|
|
||||||
;;
|
;;
|
||||||
r) recurse="Y"
|
c) codec="-vcodec $OPTARG"
|
||||||
search_command=find
|
;;
|
||||||
echo "recurse='$recurse', search_command='$search_command'"
|
r) search_command="find"
|
||||||
;;
|
;;
|
||||||
f) force="Y"
|
f) force="Y"
|
||||||
echo "force='$force'"
|
;;
|
||||||
|
m) time_command="time -p"
|
||||||
|
;;
|
||||||
|
V) verbose="Y"
|
||||||
|
;;
|
||||||
|
x) set_x="Y"
|
||||||
;;
|
;;
|
||||||
h) usage 0
|
h) usage 0
|
||||||
;;
|
;;
|
||||||
|
*) echo "ERROR: Option '$OPTARG' not recognized." >&2
|
||||||
|
usage 1
|
||||||
|
;;
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
|
||||||
|
if [[ $set_x == "Y" ]]; then
|
||||||
|
set -x
|
||||||
|
fi
|
||||||
|
|
||||||
if [[ -z "$input" ]]; then
|
if [[ -z "$input" ]]; then
|
||||||
if [[ ! -z "$1" ]]; then
|
echo "WARNING: Program was not passed an input. Using current directory."
|
||||||
echo "WARNING: Program was not passed a file. Using input $1."
|
input="."
|
||||||
input=$1
|
|
||||||
else
|
|
||||||
echo "WARNING: Program was not passed a file. Using current directory."
|
|
||||||
input='.'
|
|
||||||
fi
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ -z $video_bitrate ]]; then
|
if [[ -z $video_bitrate ]]; then
|
||||||
video_bitrate='2000k'
|
video_bitrate="2000k"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ -z $audio_bitrate ]]; then
|
if [[ -z $audio_bitrate ]]; then
|
||||||
audio_bitrate='128k'
|
audio_bitrate="128k"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ -z $recurse ]]; then
|
if [[ -z $codec ]]; then
|
||||||
search_command=ls
|
codec=""
|
||||||
fi
|
fi
|
||||||
|
|
||||||
## Other Variables
|
if [[ -z $search_command ]]; then
|
||||||
filename_flag='compressed.'
|
search_command="ls"
|
||||||
|
fi
|
||||||
|
|
||||||
## Main Loop
|
if [[ -z $time_command ]]; then
|
||||||
$search_command $input | while read file; do
|
time_command=""
|
||||||
|
fi
|
||||||
|
|
||||||
|
## Other Variables ##
|
||||||
|
|
||||||
|
filename_flag='compressed'
|
||||||
|
date_YYYYMMDD="`date "+%Y%m%d"`"
|
||||||
|
|
||||||
|
## Main ##
|
||||||
|
|
||||||
|
if [[ $verbose == "Y" ]]; then
|
||||||
|
cat <<- EOF
|
||||||
|
VERBOSE: Full list of variables.
|
||||||
|
input='$input'
|
||||||
|
video_bitrate='$video_bitrate'
|
||||||
|
audio_bitrate='$audio_bitrate'
|
||||||
|
codec='$codec'
|
||||||
|
search_command='$search_command'
|
||||||
|
force='$force'
|
||||||
|
time_command='$time_command'
|
||||||
|
verbose='$verbose'
|
||||||
|
set_x='$set_x'
|
||||||
|
filename_flag='$filename_flag'
|
||||||
|
date_YYYYMMDD='$date_YYYYMMDD'
|
||||||
|
SECONDS='$SECONDS'
|
||||||
|
EOF
|
||||||
|
fi
|
||||||
|
|
||||||
|
SECONDS=0
|
||||||
|
$search_command $input | sort | while read file; do
|
||||||
echo -e "\n$file"
|
echo -e "\n$file"
|
||||||
|
|
||||||
|
if [[ -n $time_command ]]; then
|
||||||
|
date
|
||||||
|
fi
|
||||||
|
|
||||||
# Exception checks for the existing file.
|
# Exception checks for the existing file.
|
||||||
if [[ $file != *'.mp4' ]]; then
|
if [[ $file != *'.mp4' ]]; then
|
||||||
echo "SKIP: Not an MP4."
|
echo "SKIP: Not an MP4."
|
||||||
@ -93,7 +138,7 @@ $search_command $input | while read file; do
|
|||||||
|
|
||||||
# Build the new filename to signify it is different thn the original.
|
# Build the new filename to signify it is different thn the original.
|
||||||
extension=${file##*.}
|
extension=${file##*.}
|
||||||
newfile=${file//$extension/$filename_flag$extension}
|
newfile=${file//$extension/$filename_flag-$date_YYYYMMDD.$extension}
|
||||||
|
|
||||||
# More exception checks based on the new file.
|
# More exception checks based on the new file.
|
||||||
if [[ -e $newfile ]]; then
|
if [[ -e $newfile ]]; then
|
||||||
@ -108,9 +153,20 @@ $search_command $input | while read file; do
|
|||||||
|
|
||||||
# Convert the file.
|
# Convert the file.
|
||||||
echo "Converting to $newfile."
|
echo "Converting to $newfile."
|
||||||
ffmpeg -nostdin -hide_banner -loglevel quiet \
|
$time_command bash -c "ffmpeg -nostdin -hide_banner -loglevel quiet \
|
||||||
-i $file -b:v $video_bitrate -b:a $audio_bitrate \
|
-i $file -b:v $video_bitrate -b:a $audio_bitrate \
|
||||||
-vcodec libopenh264 -movflags +faststart $newfile
|
$vcodec -movflags +faststart $newfile"
|
||||||
done
|
done
|
||||||
|
|
||||||
|
echo "\nDone!"
|
||||||
|
|
||||||
|
# Display elapsed time
|
||||||
|
if [[ -n $time_command ]]; then
|
||||||
|
typeset -i hours minutes seconds
|
||||||
|
hours=$(( SECONDS / 3600 ))
|
||||||
|
minutes=$(( (SECONDS % 3600) / 60 ))
|
||||||
|
seconds=$(( SECONDS % 60 ))
|
||||||
|
echo "Loop Performance: ${hours}h ${minutes}m ${seconds}s"
|
||||||
|
fi
|
||||||
|
|
||||||
exit 0
|
exit 0
|
||||||
|
@ -164,9 +164,9 @@
|
|||||||
|
|
||||||
ignore_errors: yes
|
ignore_errors: yes
|
||||||
|
|
||||||
- name: Workstation | Account Management | GNOME | Favorites (Linux)
|
- name: Workstation | Account Management | GNOME + Cinnamon | Favorites (Linux)
|
||||||
dconf:
|
dconf:
|
||||||
key: /org/gnome/shell/favorite-apps
|
key: "{{ item }}"
|
||||||
value: "[ 'org.gnome.Terminal.desktop', 'gnome-system-monitor.desktop'
|
value: "[ 'org.gnome.Terminal.desktop', 'gnome-system-monitor.desktop'
|
||||||
, 'org.gnome.Nautilus.desktop'
|
, 'org.gnome.Nautilus.desktop'
|
||||||
, 'io.gitlab.librewolf-community.desktop', '{{ browser }}'
|
, 'io.gitlab.librewolf-community.desktop', '{{ browser }}'
|
||||||
@ -180,6 +180,14 @@
|
|||||||
state: present
|
state: present
|
||||||
become_user: "{{ user }}"
|
become_user: "{{ user }}"
|
||||||
when: ansible_system == "Linux"
|
when: ansible_system == "Linux"
|
||||||
|
loop:
|
||||||
|
- /org/gnome/shell/favorite-apps
|
||||||
|
- /org/cinnamon/favorite-apps
|
||||||
|
# As of 2023-07-01 this only sets the Menu Favorites on Cinnamon, not the
|
||||||
|
# Panel Pins. Cannot find any details online of where the pinned application
|
||||||
|
# data lives. Cloned and searched the linuxmint/cinnamon project too and
|
||||||
|
# couldn't find which function handles it. Leaving the loop for it but it's
|
||||||
|
# not what was hoped for and is sort of a TBD/TODO.
|
||||||
|
|
||||||
- name: Workstation | Account Management | GNOME | Favorites (FreeBSD)
|
- name: Workstation | Account Management | GNOME | Favorites (FreeBSD)
|
||||||
dconf:
|
dconf:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user