Added --safe as a flag

This commit is contained in:
Nathaniel Landau
2015-03-31 08:28:10 -04:00
parent e3afe47568
commit 2334c41ecc

View File

@@ -6,9 +6,6 @@
version="1.0.0" # Sets version variable for this script version="1.0.0" # Sets version variable for this script
# #
scriptTemplateVersion="1.1.1" # Version of scriptTemplate.sh that this script is based on scriptTemplateVersion="1.1.1" # Version of scriptTemplate.sh that this script is based on
# v.1.1.0 - Added 'debug' option
# v.1.1.1 - Moved all shared variables to Utils
# - Added $PASS variable when -p is passed
# #
# #
# HISTORY: # HISTORY:
@@ -53,6 +50,7 @@ verbose=0
force=0 force=0
strict=0 strict=0
debug=0 debug=0
safeRun=0
downsize720=0 downsize720=0
deleteOriginal=0 deleteOriginal=0
@@ -92,7 +90,7 @@ dependencies=(ffmpeg gifsicle jq)
videoTypes=(mp4 mov avi mkv wmv flv ogg m4p m4v 3gp divx h264) videoTypes=(mp4 mov avi mkv wmv flv ogg m4p m4v 3gp divx h264)
function checkDependencies() { function checkDependencies() {
for i in ${dependencies[@]}; do for i in "${dependencies[@]}"; do
if type_not_exists "${i}"; then if type_not_exists "${i}"; then
die "Can not proceed without '${i}'. Please install it before rerunning this script." die "Can not proceed without '${i}'. Please install it before rerunning this script."
fi fi
@@ -188,6 +186,7 @@ convert() {
verbose "audioBitRate="${audioBitRate}"" verbose "audioBitRate="${audioBitRate}""
# SET OUTPUT FORMAT # SET OUTPUT FORMAT
# Default to 'mp4' for everything. # Default to 'mp4' for everything.
# TODO - think through additional defaults # TODO - think through additional defaults
@@ -353,12 +352,18 @@ convert() {
# CONVERT THE FILE # CONVERT THE FILE
# ################################ # ################################
info "ffmpeg -i ""${f}"" "${videoCommand}" "${audioCommand}" ""${output}"""
ffmpeg -i "${f}" ${videoResize} ${videoCommand} ${audioCommand} "${output}"
# delete original if requested # Respect --safe flag.
if [[ "${deleteOriginal}" = "1" ]]; then if [[ "${safeRun}" == "1" ]]; then
rm -f "${f}" && verbose "Deleting "${f}"" notice "ffmpeg -i "${f}" ${videoResize} ${videoCommand} ${audioCommand} "${output}""
else
verbose "ffmpeg -i "${f}" ${videoResize} ${videoCommand} ${audioCommand} "${output}""
ffmpeg -i "${f}" ${videoResize} ${videoCommand} ${audioCommand} "${output}"
# delete original if requested
if [[ "${deleteOriginal}" = "1" ]]; then
rm -f "${f}" && verbose "Deleting "${f}""
fi
fi fi
# Unset variables # Unset variables
@@ -396,7 +401,7 @@ convert
# Print usage # Print usage
usage() { usage() {
echo -n "${scriptName} [OPTION]... [ARGUMENT]... echo -n "${scriptName} ${version} [OPTION]... [ARGUMENT]...
This is my master FFMPEG media conversion script. It will convert audio and video 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 into many different formats. I wrote it to eliminate the need to remember archaic
@@ -412,6 +417,8 @@ General Options:
-l, --log Print log to file -l, --log Print log to file
-q, --quiet Quiet (no output) -q, --quiet Quiet (no output)
-v, --verbose Output more information. (Items echoed to 'verbose') -v, --verbose Output more information. (Items echoed to 'verbose')
--safe Runs the script without actually invoking FFMPEG. Will simply print
the FFMPEG commands to the terminal
--version Output version information and exit --version Output version information and exit
File Options: File Options:
@@ -471,7 +478,7 @@ unset options
# Print help if no arguments were passed. # Print help if no arguments were passed.
# Uncomment to force arguments when invoking the script # Uncomment to force arguments when invoking the script
# [[ $# -eq 0 ]] && set -- "--help" [[ $# -eq 0 ]] && set -- "--help"
# Read the options and set stuff # Read the options and set stuff
while [[ $1 = -?* ]]; do while [[ $1 = -?* ]]; do
@@ -479,6 +486,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 ;;
--safe) safeRun=1 ;;
--size) shift; videoSize=$1 ;; --size) shift; videoSize=$1 ;;
--height) shift; height=$1 ;; --height) shift; height=$1 ;;
--width) shift; width=$1 ;; --width) shift; width=$1 ;;