Enhancements + Fixes (#41)
* Signal does seem good after all. * Add alias `here` which shows details of everything in the current location. * Move instant messengers to consistently be at the end of the favorites bar. * Change to single quotes so that the pwd is per-call instead of per-source. * Specify the video codec so that the command works on openSUSE. * Refactor so that there is a shared/common fact list. * Add ffmpeg as a package variable. * Reformat long comment. * New file for installing package manager apps for workstations. * Call the workstation package manager tasks. * Change to parenthesis to look better. * Explicitly add a video flag, add recursive searching, fix a bug with -f ignoring input. * Add ability to "force" the compression, deletes old files and regenerates them. Input is now passed with i rather than f for file/folder. f is now used for force. * Fix skipping the file if it's already compressed. Enhance readability of log text.
This commit is contained in:
@ -14,41 +14,52 @@ function usage {
|
||||
cat <<- EOF
|
||||
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.
|
||||
Currently only set up for libopenh264 and mp4 files.
|
||||
|
||||
Parameters:
|
||||
-f 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.
|
||||
-v bitrate : The video bitrate to convert to, defaults to 2000k.
|
||||
-a bitrate : The audio bitrate to convert to, defaults to 128k.
|
||||
-r : Recurse the entire directory structure, compressing all video files.
|
||||
-f : Force recompressing any files by deleting it if it already exists.
|
||||
-h : Display this help messaging.
|
||||
EOF
|
||||
exit $1
|
||||
}
|
||||
|
||||
## Parse Input
|
||||
while getopts ":f:v:a:h" opt; do
|
||||
while getopts ":i:v:a:rfh" opt; do
|
||||
case $opt in
|
||||
f)
|
||||
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'"
|
||||
;;
|
||||
h)
|
||||
usage 0
|
||||
r) recurse="Y"
|
||||
search_command=find
|
||||
echo "recurse='$recurse', search_command='$search_command'"
|
||||
;;
|
||||
f) force="Y"
|
||||
echo "force='$force'"
|
||||
;;
|
||||
h) usage 0
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
if [[ -z $input && ! -z $1 ]]; then
|
||||
echo "WARNING: Program was not passed a file. Using input 1."
|
||||
input=$1
|
||||
else
|
||||
echo "WARNING: Program was not passed a file. Using current directory."
|
||||
input='.'
|
||||
if [[ -z "$input" ]]; then
|
||||
if [[ ! -z "$1" ]]; then
|
||||
echo "WARNING: Program was not passed a file. Using input $1."
|
||||
input=$1
|
||||
else
|
||||
echo "WARNING: Program was not passed a file. Using current directory."
|
||||
input='.'
|
||||
fi
|
||||
fi
|
||||
|
||||
if [[ -z $video_bitrate ]]; then
|
||||
@ -59,14 +70,24 @@ if [[ -z $audio_bitrate ]]; then
|
||||
audio_bitrate='128k'
|
||||
fi
|
||||
|
||||
if [[ -z $recurse ]]; then
|
||||
search_command=ls
|
||||
fi
|
||||
|
||||
## Other Variables
|
||||
filename_flag='compressed.'
|
||||
|
||||
## Main Loop
|
||||
ls $input | while read file; do
|
||||
## Exception Checks
|
||||
if [[ $file != *'.mp4' && $file != *'.mpeg' ]]; then
|
||||
echo "Skipping $file, not an MP4 or MPEG."
|
||||
$search_command $input | while read file; do
|
||||
echo -e "\n$file"
|
||||
|
||||
# Exception checks for the existing file.
|
||||
if [[ $file != *'.mp4' ]]; then
|
||||
echo "SKIP: Not an MP4."
|
||||
continue
|
||||
fi
|
||||
if [[ $file == *"$filename_flag"* ]]; then
|
||||
echo "SKIP: Input is already compressed."
|
||||
continue
|
||||
fi
|
||||
|
||||
@ -74,16 +95,22 @@ ls $input | while read file; do
|
||||
extension=${file##*.}
|
||||
newfile=${file//$extension/$filename_flag$extension}
|
||||
|
||||
if [[ $file == *"$filename_flag"* || -e $newfile ]]; then
|
||||
echo "Skipping $file, already compressed."
|
||||
continue
|
||||
# More exception checks based on the new file.
|
||||
if [[ -e $newfile ]]; then
|
||||
if [[ $force == "Y" ]]; then
|
||||
echo "FORCE: Removing $newfile."
|
||||
rm -vf $newfile
|
||||
else
|
||||
echo "SKIP: Already has a compressed version ($newfile)."
|
||||
continue
|
||||
fi
|
||||
fi
|
||||
|
||||
# Convert the file.
|
||||
echo "Converting $file to $newfile."
|
||||
echo "Converting to $newfile."
|
||||
ffmpeg -nostdin -hide_banner -loglevel quiet \
|
||||
-i $file -b:v $video_bitrate -b:a $audio_bitrate \
|
||||
$newfile
|
||||
-vcodec libopenh264 -movflags +faststart $newfile
|
||||
done
|
||||
|
||||
exit 0
|
||||
|
Reference in New Issue
Block a user