Better debug logging

This commit is contained in:
Nathaniel Landau
2015-04-06 22:33:01 -04:00
parent b56a329c61
commit 282670d774

View File

@@ -131,7 +131,8 @@ function outputDir() {
die "Can't run without a place to save the files."
fi
fi
outputDir="${saveDir%/}/" # remove trailing slash if included. Add back to ensure it's always there.
# remove trailing slash if included. Add back to ensure it's always there.
outputDir="${saveDir%/}/" && verbose "outputDir=${saveDir%/}/"
fi
}
@@ -160,8 +161,7 @@ function doConvert() {
verbose "outputFormat=${outputFormat}"
# Set output filename
output="$(basename "${f%.*}").$outputFormat"
verbose "output="${output}""
output="$(basename "${f%.*}").$outputFormat" && verbose "output="${output}""
# Don't convert to self if no other options set
if [[ -z $height && -z $width && -z $videoSize && $downsize720 == "0" && "$outputFormat" == "$extension" ]]; then
@@ -171,21 +171,17 @@ function doConvert() {
# Add users output save directory if used
if [[ -n "${outputDir}" ]]; then
output="${outputDir}${output}"
output="${outputDir}${output}" && verbose "output=${outputDir}${output}"
fi
# Confirm we're not overwriting an existing file
if [[ "${safeRun}" -ne "1" ]]; then
if [ -e "${output}" ]; then
# Rename and move the existing file
oldFile=""$(basename "${output%.*}").old."${outputFormat}"""
mv "${output}" "${oldFile}"
# rename the new file to '.new'
output="$(basename "${f%.*}").new."${outputFormat}""
output="$(basename "${f%.*}").new."${outputFormat}"" && verbose "Adding '.new' to the new file name"
if [[ -n "${outputDir}" ]]; then
output="${outputDir}${output}"
output="${outputDir}${output}" && verbose "output=${outputDir}${output}"
fi
notice "Renamed existing file to '.old'"
fi
fi
@@ -194,6 +190,7 @@ function doConvert() {
# Use XLD for audio file conversion if available
if [[ "$XLD" == "1" ]]; then
verbose "Running XLD commands for audio. No FFMPEG"
# Respect --safe flag.
if [[ "${safeRun}" == "1" ]]; then
notice "xld -o "${output}" ${audioConvertCommand} "${f}""
@@ -231,6 +228,8 @@ convertVideo() {
# JSON METADATA FOR EACH ASSET
######################################################################
verbose "Reading JSON and writing to TMP"
# Output a JSON file for each video asset being parsed.
ffprobe -v quiet -print_format json -show_format -show_streams "${f}" >> "${informationFile}"
@@ -272,17 +271,6 @@ convertVideo() {
safeExit
fi
# Is input video a known preset size?
if [[ "$videoWidth" == "1920" && "$videoHeight" == "1080" ]] || [[ "$videoWidth" == "1920" && "$videoHeight" == "816" ]]; then
videoPreset="1080p"
fi
if [[ "$videoWidth" == "1280" && "$videoHeight" == "720" ]] || [[ "$videoWidth" == "1280" && "$videoHeight" == "544" ]]; then
videoPreset="720p"
fi
if [[ "$videoWidth" == "720" && "$videoHeight" == "576" ]]; then
videoPreset="DVPAL"
fi
# SET OUTPUT FORMAT
# Default to 'mp4' for everything.
# TODO - think through additional defaults
@@ -302,16 +290,16 @@ convertVideo() {
# Pick the best aac audio encoder
if $(ffmpeg -version | grep enable-libfdk-aac >/dev/null); then
aacEncoder='libfdk_aac'
aacEncoder="libfdk_aac" && verbose "aac encoder set to libfdk_aac"
else
aacencoder='libfaac'
aacencoder="libfaac" && verbose "aac encoder set to libfaac"
fi
supportedAudioCodecs=(aac ac3 eac3)
if [[ "${supportedAudioCodecs[*]}" =~ "${audioCodec}" ]]; then
videoAudioCommand="-c:a copy"
videoAudioCommand="-c:a copy" && verbose "videoAudioCommand set to -c:a copy"
else
videoAudioCommand="-c:a "${aacEncoder}" -b:a 160k"
videoAudioCommand="-c:a ${aacEncoder} -b:a 160k" && verbose "videoAudioCommand set to -c:a ${aacEncoder} -b:a 160k"
fi
# SET VIDEO INFORMATION
@@ -319,6 +307,17 @@ convertVideo() {
# Set resizing options
################################################################
# Is input video a known preset size?
if [[ "$videoWidth" == "1920" && "$videoHeight" == "1080" ]] || [[ "$videoWidth" == "1920" && "$videoHeight" == "816" ]]; then
videoPreset="1080p" && verbose "Input video has preset: 1080p"
fi
if [[ "$videoWidth" == "1280" && "$videoHeight" == "720" ]] || [[ "$videoWidth" == "1280" && "$videoHeight" == "544" ]]; then
videoPreset="720p" && verbose "Input video has preset: 720p"
fi
if [[ "$videoWidth" == "720" && "$videoHeight" == "576" ]]; then
videoPreset="DVPAL" && verbose "Input video has preset: DVPAL"
fi
# Enable resizing of videos
# #############################
@@ -329,7 +328,7 @@ convertVideo() {
# if user sets both a height and width, run that as a videoSize variable
if [[ -n "${width}" ]] && [[ -n "${height}" ]]; then
videoSize="${width}x${height}"
videoSize="${width}x${height}" && verbose "videoSize=${width}x${height}"
unset width
unset height
fi
@@ -338,8 +337,9 @@ convertVideo() {
# Commonly used function to downsize 1080p to 720p
if [[ "${downsize720}" == "1" ]]; then
if [[ "${videoPreset}" == "1080p" ]]; then
videoSize="hd720"
videoSize="hd720" && verbose "videoSize=hd720"
else
warning "Skipping ${f}. It's not 1080p"
breakLoop
continue
fi
@@ -384,7 +384,7 @@ convertVideo() {
fi
# Finally, set the resize variable
videoResize="-vf scale=${videoSize}"
videoResize="-vf scale=${videoSize}" && verbose "videoResize='-vf scale=${videoSize}'"
fi
# Scaling variables
@@ -397,7 +397,7 @@ convertVideo() {
continue
fi
fi
videoResize="-vf scale=-1:${height}"
videoResize="-vf scale=-1:${height}" && verbose "videoResize='-vf scale=-1:${height}'"
fi
if is_not_empty "$width"; then
if [ "${width}" -gt "${videoWidth}" ]; then
@@ -407,16 +407,16 @@ convertVideo() {
continue
fi
fi
videoResize="-vf scale=${width}:-1"
videoResize="-vf scale=${width}:-1" && verbose "videoResize='-vf scale=${width}:-1'"
fi
# Copy h264 when possible
# Save precious time by not re-encoding files that are already H264.
# ###########################
if [[ "${videoCodec}" == "h264" ]] && [[ -z "${videoResize}" ]]; then
videoCommand="-c:v copy"
videoCommand="-c:v copy" && verbose "videoCommand='-c:v copy'"
else
videoCommand="-c:v libx264 -crf 18 -preset slow"
videoCommand="-c:v libx264 -crf 18 -preset slow" && verbose "videoCommand'-c:v libx264 -crf 18 -preset slow'"
fi
# Do the conversion
@@ -456,6 +456,7 @@ convertMusic() {
# JSON METADATA FOR EACH ASSET
######################################################################
verbose "Reading audio data and writing JSON to tmp"
# Output a JSON file for each video asset being parsed.
ffprobe -v quiet -print_format json -show_format -show_streams "${f}" >> "${informationFile}"