mirror of
https://github.com/natelandau/shell-scripting-templates.git
synced 2025-11-10 14:13:45 -05:00
Updated help documentation and uncommented some code
This commit is contained in:
106
bin/convertMedia
106
bin/convertMedia
@@ -10,24 +10,10 @@ scriptTemplateVersion="1.1.1" # Version of scriptTemplate.sh that this script is
|
|||||||
# v.1.1.1 - Moved all shared variables to Utils
|
# v.1.1.1 - Moved all shared variables to Utils
|
||||||
# - Added $PASS variable when -p is passed
|
# - Added $PASS variable when -p is passed
|
||||||
#
|
#
|
||||||
# A Bash script boilerplate. Allows for common functions, logging, tmp
|
|
||||||
# file creation, CL option passing, and more.
|
|
||||||
#
|
|
||||||
# For logging levels use the following functions:
|
|
||||||
# - header: Prints a script header
|
|
||||||
# - input: Ask for user input
|
|
||||||
# - success: Print script success
|
|
||||||
# - info: Print information to the user
|
|
||||||
# - notice: Notify the user of something
|
|
||||||
# - warning: Warn the user of something
|
|
||||||
# - error: Print a non-fatal error
|
|
||||||
# - die: A fatal error. Will exit the script
|
|
||||||
# - debug: Debug information
|
|
||||||
# - verbose: Debug info only printed when 'verbose' flag is set to 'true'.
|
|
||||||
#
|
#
|
||||||
# HISTORY:
|
# HISTORY:
|
||||||
#
|
#
|
||||||
# * DATE - v1.0.0 - First Creation
|
# * 2015-03-31 - v1.0.0 - First Creation
|
||||||
#
|
#
|
||||||
# ##################################################
|
# ##################################################
|
||||||
|
|
||||||
@@ -188,7 +174,6 @@ convert() {
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
# Confirm variables in verbose mode
|
# Confirm variables in verbose mode
|
||||||
verbose "_"
|
|
||||||
verbose "file="$f""
|
verbose "file="$f""
|
||||||
verbose "videoCodec="$videoCodec""
|
verbose "videoCodec="$videoCodec""
|
||||||
verbose "videoCodecLong="$videoCodecLong""
|
verbose "videoCodecLong="$videoCodecLong""
|
||||||
@@ -201,20 +186,21 @@ convert() {
|
|||||||
verbose "audioCodecLong="$audioCodecLong""
|
verbose "audioCodecLong="$audioCodecLong""
|
||||||
verbose "audioSampleRate="${audioSampleRate}""
|
verbose "audioSampleRate="${audioSampleRate}""
|
||||||
verbose "audioBitRate="${audioBitRate}""
|
verbose "audioBitRate="${audioBitRate}""
|
||||||
#pauseScript
|
|
||||||
|
|
||||||
# SET OUTPUT FORMAT
|
|
||||||
# Default to 'mkv' for everything except for 'mkv' files.
|
# SET OUTPUT FORMAT
|
||||||
|
# Default to 'mp4' for everything.
|
||||||
|
# TODO - think through additional defaults
|
||||||
##########################################################
|
##########################################################
|
||||||
case "${format}" in
|
case "${format}" in
|
||||||
'Matroska / WebM') outputFormat='mp4' ;;
|
'Matroska / WebM') outputFormat='mp4' ;;
|
||||||
*) outputFormat='mkv' ;;
|
*) outputFormat='mp4' ;;
|
||||||
esac
|
esac
|
||||||
# Override with CLI
|
# Override with CLI
|
||||||
if [[ -n "$userOutput" ]]; then
|
if [[ -n "$userOutput" ]]; then
|
||||||
outputFormat="$userOutput"
|
outputFormat="${userOutput}"
|
||||||
fi
|
fi
|
||||||
verbose "outputFormat=$outputFormat"
|
verbose "outputFormat=${outputFormat}"
|
||||||
|
|
||||||
# Set output filename
|
# Set output filename
|
||||||
output="$(basename "${f%.*}").$outputFormat"
|
output="$(basename "${f%.*}").$outputFormat"
|
||||||
@@ -273,6 +259,7 @@ convert() {
|
|||||||
if [[ "${videoPreset}" == "1080p" ]]; then
|
if [[ "${videoPreset}" == "1080p" ]]; then
|
||||||
videoSize="hd720"
|
videoSize="hd720"
|
||||||
else
|
else
|
||||||
|
breakLoop
|
||||||
continue
|
continue
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
@@ -296,23 +283,23 @@ convert() {
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
# Confirm if user wants to upscale their video
|
# Confirm if user wants to upscale their video
|
||||||
# if [[ "${videoSize}" == "hd1080" || "${videoSize}" == "1080" ]]; then
|
if [[ "${videoSize}" == "hd1080" || "${videoSize}" == "1080" ]]; then
|
||||||
# userWidth="1920"
|
userWidth="1920"
|
||||||
# userHeight="1080"
|
userHeight="1080"
|
||||||
# elif [[ "${videoSize}" == "hd720" ]] || [[ "${videoSize}" == "720" ]]; then
|
elif [[ "${videoSize}" == "hd720" ]] || [[ "${videoSize}" == "720" ]]; then
|
||||||
# userWidth="1280"
|
userWidth="1280"
|
||||||
# userHeight="720"
|
userHeight="720"
|
||||||
# else
|
else
|
||||||
# userWidth=$(echo ${videoSize} | cut -f1 -dx)
|
userWidth=$(echo ${videoSize} | cut -f1 -dx)
|
||||||
# userHeight=$(echo ${videoSize} | cut -f2 -dx)
|
userHeight=$(echo ${videoSize} | cut -f2 -dx)
|
||||||
# if [ "${userWidth}" -gt "${videoWidth}" ] || [ "${userHeight}" -gt "${videoHeight}" ]; then
|
if [ "${userWidth}" -gt "${videoWidth}" ] || [ "${userHeight}" -gt "${videoHeight}" ]; then
|
||||||
# seek_confirmation "Upscale "${f}" to "${videoSize}"? It is already "${videoWidth}"x"${videoHeight}"."
|
seek_confirmation "Upscale "${f}" to "${videoSize}"? It is already "${videoWidth}"x"${videoHeight}"."
|
||||||
# if is_not_confirmed; then
|
if is_not_confirmed; then
|
||||||
# breakLoop
|
breakLoop
|
||||||
# continue
|
continue
|
||||||
# fi
|
fi
|
||||||
# fi
|
fi
|
||||||
# fi
|
fi
|
||||||
|
|
||||||
# Finally, set the resize variable
|
# Finally, set the resize variable
|
||||||
videoResize="-vf scale=${videoSize}"
|
videoResize="-vf scale=${videoSize}"
|
||||||
@@ -358,6 +345,7 @@ convert() {
|
|||||||
output="$(basename "${f%.*}").new."${outputFormat}""
|
output="$(basename "${f%.*}").new."${outputFormat}""
|
||||||
else
|
else
|
||||||
notice "Skipping...."
|
notice "Skipping...."
|
||||||
|
breakLoop
|
||||||
continue
|
continue
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
@@ -408,17 +396,40 @@ convert
|
|||||||
|
|
||||||
# Print usage
|
# Print usage
|
||||||
usage() {
|
usage() {
|
||||||
echo -n "${scriptName} [OPTION]... [FILE]...
|
echo -n "${scriptName} [OPTION]... [ARGUMENT]...
|
||||||
|
|
||||||
This is my script template.
|
This is my master FFMPEG media conversion script. It will convert audio and video
|
||||||
|
into many different formats. I wrote it to eliminate the need to remember archaic
|
||||||
|
FFMPEG commands.
|
||||||
|
|
||||||
Options:
|
Default behavior is to parse through directories of files and take actions on multiple
|
||||||
-q, --quiet Quiet (no output)
|
files at a time. You can easily specify a specific file to act on if needed.
|
||||||
-l, --log Print log to file
|
|
||||||
-v, --verbose Output more information. (Items echoed to 'verbose')
|
General Options:
|
||||||
-d, --debug Runs script in BASH debug mode (set -x)
|
|
||||||
-h, --help Display this help and exit
|
-h, --help Display this help and exit
|
||||||
|
-d, --debug Runs script in BASH debug mode ('set -x')
|
||||||
|
--force Skip all user interaction. Implied 'Yes' to all actions.
|
||||||
|
-l, --log Print log to file
|
||||||
|
-q, --quiet Quiet (no output)
|
||||||
|
-v, --verbose Output more information. (Items echoed to 'verbose')
|
||||||
--version Output version information and exit
|
--version Output version information and exit
|
||||||
|
|
||||||
|
File Options:
|
||||||
|
-f, --file Specify a specific file to take actions on.
|
||||||
|
-i, --input Specify the specific media type to search for and take action
|
||||||
|
on. ('mov', 'mp4', 'mp3')
|
||||||
|
-o, --output Specify the output format for the file(s) to be converted to.
|
||||||
|
('mkv', 'mp4', 'm4a')
|
||||||
|
--delete Delete the original file after conversion.
|
||||||
|
|
||||||
|
Video Specific Options:
|
||||||
|
--size Set the size of the target file. Can be one of 'hd1080', 'hd720',
|
||||||
|
or 'HeightxWidth' (ie. 1920x1080)
|
||||||
|
--height Set a height in pixels to scale the target file.
|
||||||
|
--width Set a width in pixels to scale the target file.
|
||||||
|
--downsize720 Searches for 1080p videos and downsizes them to 720p. No need
|
||||||
|
for other scaling options.
|
||||||
|
|
||||||
"
|
"
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -468,7 +479,7 @@ while [[ $1 = -?* ]]; do
|
|||||||
-f|--file) shift; userFile=$1 ;;
|
-f|--file) shift; userFile=$1 ;;
|
||||||
-i|--input) shift; MEDIATYPE=$1 ;;
|
-i|--input) shift; MEDIATYPE=$1 ;;
|
||||||
-o|--output) shift; userOutput=$1 ;;
|
-o|--output) shift; userOutput=$1 ;;
|
||||||
-s|--size) shift; videoSize=$1 ;;
|
--size) shift; videoSize=$1 ;;
|
||||||
--height) shift; height=$1 ;;
|
--height) shift; height=$1 ;;
|
||||||
--width) shift; width=$1 ;;
|
--width) shift; width=$1 ;;
|
||||||
--downsize720) downsize720=1 ;;
|
--downsize720) downsize720=1 ;;
|
||||||
@@ -477,6 +488,7 @@ while [[ $1 = -?* ]]; do
|
|||||||
|
|
||||||
|
|
||||||
-h|--help) usage >&2; safeExit ;;
|
-h|--help) usage >&2; safeExit ;;
|
||||||
|
--force) force=1 ;;
|
||||||
--version) echo "$(basename $0) $version"; safeExit ;;
|
--version) echo "$(basename $0) $version"; safeExit ;;
|
||||||
-v|--verbose) verbose=1 ;;
|
-v|--verbose) verbose=1 ;;
|
||||||
-l|--log) printLog=1 ;;
|
-l|--log) printLog=1 ;;
|
||||||
|
|||||||
Reference in New Issue
Block a user