diff --git a/barcodeinterpret b/barcodeinterpret index 88f2053c..ede05354 100755 --- a/barcodeinterpret +++ b/barcodeinterpret @@ -5,12 +5,12 @@ scriptdir=$(dirname "$0") . "$scriptdir/mmfunctions" || { echo "Missing '$scriptdir/mmfunctions'. Exiting." ; exit 1 ;}; cleanup(){ - log -a "Process aborted" + _log -a "Process aborted" exit 1 } trap cleanup SIGHUP SIGINT SIGTERM -log -b +_log -b if test $# != 1 ; then echo "You must supply one argument, a scanned interleaved 2/5 barcode value"; exit @@ -65,4 +65,4 @@ if [[ $(echo "$materialid" | tail -c +9 | head -c 1) == "H" ]] ; then materialid="${materialid}D" fi echo deviceid,$(echo $ids | cut -d ' ' -f 1),materialid,$materialid,som,$(addcolons $(echo $barcode | cut -c 42-49)),duration,$(addcolons $(echo $barcode | cut -c 50-57)) -log -e +_log -e diff --git a/blackatends b/blackatends index 26f60bc4..59e27ad4 100755 --- a/blackatends +++ b/blackatends @@ -6,7 +6,7 @@ scriptdir=$(dirname "$0") version=1.0 cleanup(){ - log -a "Process aborted" + _log -a "Process aborted" exit 1 } @@ -38,9 +38,9 @@ done shift $(( ${OPTIND} - 1 )) while [ "$*" != "" ] ; do - log -b + _log -b [ "$#" != 0 ] && sourcefile="$1" black_at_ends "$sourcefile" - log -e + _log -e shift done diff --git a/checksumpackage b/checksumpackage index b0e4378a..681b538e 100755 --- a/checksumpackage +++ b/checksumpackage @@ -22,7 +22,7 @@ usage(){ check_dependencies "${dependencies[@]}" cleanup(){ - log -a "Process aborted" + _log -a "Process aborted" exit 1 } @@ -33,7 +33,7 @@ CHECKSUMNAME="checksum.md5" DFXMLNAME="dfxml.xml" while [ "${*}" != "" ] ; do - log -b + _log -b if [ -d "${1}" ] ; then PWD=$(pwd) "${scriptdir}/removeDSStore" "$1" @@ -59,6 +59,6 @@ while [ "${*}" != "" ] ; do else report -dt "ERROR: ${0} requires directories as input and $1 is not a directory." fi - log -e + _log -e shift done diff --git a/fix_left2stereo b/fix_left2stereo index 6b29601b..6f325b3f 100755 --- a/fix_left2stereo +++ b/fix_left2stereo @@ -9,7 +9,7 @@ scriptdir=$(dirname "$0") usage(){ echo - echo "$(basename $0) ${version}" + echo "$(basename ${0}) ${version}" echo "This application takes an input video file(s) and produces outputs that are map the left channel of the input to a stereo mix in the output." echo "Dependencies: ${dependencies[@]}" echo "Usage: $(basename $0) file1 [ file2 ...]" @@ -20,7 +20,7 @@ usage(){ check_dependencies "${dependencies[@]}" cleanup(){ - log -a "Process aborted" + _log -a "Process aborted" exit 1 } @@ -28,7 +28,7 @@ cleanup(){ suffix="_left2stereo" trap cleanup SIGHUP SIGINT SIGTERM -log -b +_log -b while [ "$*" != "" ] ; do @@ -52,4 +52,4 @@ while [ "$*" != "" ] ; do fi shift done -log -e +_log -e diff --git a/fix_rewrap b/fix_rewrap index 286b4fab..1b1e2ea3 100755 --- a/fix_rewrap +++ b/fix_rewrap @@ -9,7 +9,7 @@ scriptdir=$(dirname "$0") usage(){ echo - echo "$(basename $0) ${version}" + echo "$(basename ${0}) ${version}" echo "This application takes an input video file(s) and produces outputs through re-multiplexing all tracks of the input into a new container." echo "Dependencies: ${dependencies[@]}" echo "Usage: $(basename $0) file1 [ file2 ...]" @@ -20,7 +20,7 @@ usage(){ check_dependencies "${dependencies[@]}" cleanup(){ - log -a "Process aborted" + _log -a "Process aborted" exit 1 } @@ -28,7 +28,7 @@ cleanup(){ suffix="_rewrap" trap cleanup SIGHUP SIGINT SIGTERM -log -b +_log -b while [ "$*" != "" ] ; do @@ -51,4 +51,4 @@ while [ "$*" != "" ] ; do fi shift done -log -e +_log -e diff --git a/fix_volume b/fix_volume index 25e1e82a..8a0b09e1 100755 --- a/fix_volume +++ b/fix_volume @@ -34,12 +34,12 @@ done shift $(( ${OPTIND} - 1 )) cleanup(){ - log -a "Process aborted" + _log -a "Process aborted" exit 1 } trap cleanup SIGHUP SIGINT SIGTERM -log -b +_log -b while [ "$*" != "" ] ; do input_movie="${1}" @@ -69,4 +69,4 @@ while [ "$*" != "" ] ; do fi shift done -log -e +_log -e diff --git a/ingestfile b/ingestfile index 9bb90f40..50edd18c 100755 --- a/ingestfile +++ b/ingestfile @@ -29,7 +29,7 @@ remove_mediaid_from_queue(){ } cleanup(){ - log -a "Process aborted" + _log -a "Process aborted" remove_mediaid_from_queue [ -d "${OUTDIR_INGESTFILE}/${mediaid}" ] && mv "${OUTDIR_INGESTFILE}/${mediaid}" "${OUTDIR_INGESTFILE}/${mediaid}_aborted_ingest_$(get_iso8601_c)" exit 1 @@ -171,23 +171,20 @@ if [ "${priority}" = "put in queue" ] ; then done fi -log -b +_log -b # set up package directories -mkdir -p "${objectsdir}" +_run_critical mkdir -p "${objectsdir}" logdir="${OUTDIR_INGESTFILE}/${mediaid}/metadata/submissionDocumentation/logs" -mkdir -p "${logdir}" +_run mkdir -p "${logdir}" submissiondocdir="${OUTDIR_INGESTFILE}/${mediaid}/metadata/submissionDocumentation" -mkdir -p "${submissiondocdir}" +_run mkdir -p "${submissiondocdir}" start=$(get_iso8601) # rsync report -dt "STATUS Copying the original file to library storage at ${objectsdir}." -rsync -rt --progress --log-file="${logdir}/rsync_$(get_iso8601_c)_$(basename $0)_${version}.txt" "${input}" "${objectsdir}/" - -rsync_err="${?}" -[ "${rsync_err}" -gt "0" ] && { report -wt "rsync failed with error ${rsync_err}" ; exit 1 ;}; +_run_critical rsync -rt --progress --log-file="${logdir}/rsync_$(get_iso8601_c)_$(basename $0)_${version}.txt" "${input}" "${objectsdir}/" # make copy for broadcast unset makebroadcastopts @@ -243,11 +240,11 @@ if [ "${cleanup}" == "Y" ] ; then report -wt "Cancelling requested deletion of source file, not looking safe." else report -dt "Removing the source file from ${input} as requested." - rm -f "${input}" + _run rm -f "${input}" fi fi # clean up queue [ "${priority}" == "put in queue" ] && remove_mediaid_from_queue -log -e +_log -e diff --git a/makebroadcast b/makebroadcast index 36608f6a..d9e689a5 100755 --- a/makebroadcast +++ b/makebroadcast @@ -1,17 +1,12 @@ #!/bin/bash # makebroadcast -# make broadcast version -# history # v 1.1 change from mov output to mxf output, force all output to hd # v 1.2 revert to mov and ffmbc version="1.2" -unset dependencies -unset audiomapping_ffmbc +scriptdir=$(dirname $(which "$0")) +. "$scriptdir/mmfunctions" || { echo "Missing '$scriptdir/mmfunctions'. Exiting." ; exit 1 ;}; dependencies=(ffmbc ffprobe) -DRYRUN=false - -scriptdir=$(dirname "${0}") -. "${scriptdir}/mmfunctions" || { echo "Missing '${scriptdir}/mmfunctions'. Exiting." ; exit 1 ;}; +_initialize_make usage(){ echo @@ -23,75 +18,64 @@ usage(){ echo " -r (only use the right channel of the first audio track)" echo " -c (run the video through a crop detection filter, then crop the video accordingly during transcoding, slower)" echo " -v (run the video through a volume adjustment filter, then adjust the volume accordingly during transcoding, slower)" + echo " -d directory ( directory to deliver the resulting file to )" + echo " -o directory ( directory to write the resulting file to )" echo " -n (dry-run mode, show the commands that would be run but don't do anything)" - echo " -h display this help" + echo " -e emailaddress ( send an email about the delivery, only valid if -d is used )" + echo " -E emailaddress ( send an email about process outcome )" + echo " -h ( display this help )" echo exit } [ "${#}" = 0 ] && usage -check_dependencies "${dependencies[@]}" -# command line arguments +# command-line options to set mediaid and original variables OPTIND=1 -while getopts ":lrcvhn" opt ; do - case ${opt} in - n) DRYRUN=true;; +while getopts ":lrcvo:d:e:E:nh" opt ; do + case "${opt}" in l) audiomap="L";; r) audiomap="R";; c) cropdetect="Y" ;; v) voladjust="Y" ;; + o) outputdir="$OPTARG" && check_outputdir ;; + d) deliverdir="$OPTARG" && check_deliverdir ;; + e) emailaddress_delivery="$OPTARG" && check_emailaddress "${emailaddress_delivery}" ;; + E) emailaddress_outcome="$OPTARG" && check_emailaddress "${emailaddress_outcome}" ;; + n) DRYRUN=true;; h) usage ;; - *) echo "Invalid option: -${OPTARG}" ; exit 1 ;; - :) echo "Option -${OPTARG} requires an argument" ; exit 1 ;; + *) echo "bad option -$OPTARG" ; usage ;; + :) echo "Option -$OPTARG requires an argument" ; exit 1 ;; esac done shift $(( ${OPTIND} - 1 )) -cleanup(){ - log -a "Process aborted" - exit 1 -} - -trap cleanup SIGHUP SIGINT SIGTERM - while [ "${*}" != "" ] ; do - - # clear local arrays - unset inputoptions - unset ffmbc_opts - filterchain_start="" - + # get context about the input input="$1" - [ -d "${input}" ] && { outputdir="${input}/objects/service" && logdir="${input}/metadata/submissionDocumentation/logs" ;}; - [ -f "${input}" ] && { outputdir=$(dirname "${input}")"/service" && logdir="$(dirname "${input}")/service/logs" ;}; - [ ! "${outputdir}" ] && { outputdir="${input}/objects/service" && logdir="${input}/metadata/submissionDocumentation/logs" ;}; - find_input "${input}" - - get_audio_index "${sourcefile}" - if [ "${audiomap}" = "L" ] ; then - audiomapping_ffmbc=(-map_audio_channel 0:${audio_index_1}:0:0:1:0 -map_audio_channel 0:${audio_index_1}:0:0:1:1) - elif [ "${audiomap}" = "R" ] ; then - audiomapping_ffmbc=(-map_audio_channel 0:${audio_index_1}:1:0:1:0 -map_audio_channel 0:${audio_index_1}:1:0:1:1) + if [ -z "${outputdir}" ] ; then + [ -d "${input}" ] && { outputdir="${input}/objects/service" && logdir="${input}/metadata/submissionDocumentation/logs" ;}; + [ -f "${input}" ] && { outputdir=$(dirname "${input}")"/service" && logdir="$(dirname "${input}")/service/logs" ;}; + [ ! "${outputdir}" ] && { outputdir="${input}/objects/service" && logdir="${input}/metadata/submissionDocumentation/logs" ;}; else - get_audio_mapping "${sourcefile}" + logdir="${outputdir}/logs" fi - ffmbc_opts+=(${audiomapping_ffmbc[@]}) - + _find_input "${input}" mediaid=$(basename "${input}" | cut -d. -f1) - log -b - - servicefile="${outputdir}/${mediaid%.*}.mov" - [ -s "${servicefile}" ] && { report -wt "${servicefile} already exists, skipping transcode" ; [ "${#}" = 1 ] && exit 86 || { shift ; continue ;} ;}; - - report -dt "Starting transcode of $(basename "${sourcefile}") for broadcast compliance." + # set up output + _log -b + output="${outputdir}/${mediaid%.*}.mov" + [ -s "${output}" ] && { report -wt "WARNING ${output} already exists, skipping transcode" ; shift ; continue ;}; + _run mkdir -p "${outputdir}" - # set fixed transcoding options - ffmbc_opts+=(-r ntsc) - ffmbc_opts+=(-tff) - ffmbc_opts+=(-threads 4) + # clear local arrays + unset inputoptions + unset middleoptions + unset audiomapping_ffmbc + filterchain_start="" - # decide on an output codec, aspect ratio, and padding strategy + # get information on the input + get_audio_index "${sourcefile}" get_sar "${sourcefile}" if [ "${cropdetect}" = "Y" ] ; then get_cropdetection "${sourcefile}" @@ -108,56 +92,71 @@ while [ "${*}" != "" ] ; do if [ "${fieldorder}" != "tff" ] ; then filterchain_start+="fieldorder=tff," fi + + if [ "${audiomap}" = "L" ] ; then + audiomapping_ffmbc=(-map_audio_channel 0:${audio_index_1}:0:0:1:0 -map_audio_channel 0:${audio_index_1}:0:0:1:1) + elif [ "${audiomap}" = "R" ] ; then + audiomapping_ffmbc=(-map_audio_channel 0:${audio_index_1}:1:0:1:0 -map_audio_channel 0:${audio_index_1}:1:0:1:1) + else + get_audio_mapping "${sourcefile}" + fi + middleoptions+=(${audiomapping_ffmbc[@]}) + + # set fixed transcoding options + middleoptions+=(-r ntsc) + middleoptions+=(-tff) + middleoptions+=(-threads 4) + + # decide on an output codec, aspect ratio, and padding strategy darratio=$(echo "scale=3 ; ${dar}" | bc) if [ "${darratio}" = "1.777" -a ! "${cropdetect}" = "Y" ] ; then - ffmbc_opts+=(-s 1920x1080) - ffmbc_opts+=(-target xdcamhd422) - ffmbc_opts+=(-vtag xd5b) - ffmbc_opts+=(-aspect 16:9) + middleoptions+=(-s 1920x1080) + middleoptions+=(-target xdcamhd422) + middleoptions+=(-vtag xd5b) + middleoptions+=(-aspect 16:9) elif [ $(echo "scale=3 ; ${darratio} > (16/9)" | bc -l) = 1 ] ; then - ffmbc_opts+=(-vf "${filterchain_start}pad=${width}:${width}*(9/16)*(${sar}):(ow-${width})/2:(oh-${height})/2,scale=1920:1080:interl=1") - ffmbc_opts+=(-target xdcamhd422) - ffmbc_opts+=(-vtag xd5b) - ffmbc_opts+=(-aspect 16:9) + middleoptions+=(-vf "${filterchain_start}pad=${width}:${width}*(9/16)*(${sar}):(ow-${width})/2:(oh-${height})/2,scale=1920:1080:interl=1") + middleoptions+=(-target xdcamhd422) + middleoptions+=(-vtag xd5b) + middleoptions+=(-aspect 16:9) elif [ $(echo "scale=3 ; $darratio > (3/2)" | bc -l) = 1 ] ; then - ffmbc_opts+=(-vf "${filterchain_start}pad=${height}*(16/9)/(${sar}):${height}:(ow-${width})/2:(oh-${height})/2,scale=1920:1080:interl=1") - ffmbc_opts+=(-target xdcamhd422) - ffmbc_opts+=(-vtag xd5b) - ffmbc_opts+=(-aspect 16:9) + middleoptions+=(-vf "${filterchain_start}pad=${height}*(16/9)/(${sar}):${height}:(ow-${width})/2:(oh-${height})/2,scale=1920:1080:interl=1") + middleoptions+=(-target xdcamhd422) + middleoptions+=(-vtag xd5b) + middleoptions+=(-aspect 16:9) elif [ "$width" = "720" -a "$height" = "480" -a $(echo "scale=3 ; $darratio < (3/2)" | bc -l) = 1 -a ! "$cropdetect" = "Y" ] ; then filterchain_start=$(echo "${filterchain_start}" | sed 's/,$//g') - ffmbc_opts+=(-vf ${filterchain_start}) - ffmbc_opts+=(-target imx30) - ffmbc_opts+=(-aspect 4:3) + middleoptions+=(-vf ${filterchain_start}) + middleoptions+=(-target imx30) + middleoptions+=(-aspect 4:3) elif [ "${height}" -eq "486" -a "${width}" -eq "720" ] ; then filterchain_start+="crop=720:480:0:4" filterchain_start=$(echo "$filterchain_start" | sed 's/,$//g') - ffmbc_opts+=(-vf ${filterchain_start}) - ffmbc_opts+=(-target imx30) - ffmbc_opts+=(-aspect 4:3) + middleoptions+=(-vf ${filterchain_start}) + middleoptions+=(-target imx30) + middleoptions+=(-aspect 4:3) elif [ "${height}" -eq "512" -a "${width}" -eq "720" ] ;then filterchain_start+="crop=720:480:0:32" filterchain_start=$(echo "${filterchain_start}" | sed 's/,$//g') - ffmbc_opts+=(-vf ${filterchain_start}) - ffmbc_opts+=(-target imx30) - ffmbc_opts+=(-aspect 4:3) + middleoptions+=(-vf ${filterchain_start}) + middleoptions+=(-target imx30) + middleoptions+=(-aspect 4:3) else - ffmbc_opts+=(-vf "${filterchain_start}pad=${height}*(4/3)/(${sar}):${height}:(ow-${width})/2:(oh-${height})/2,scale=720:480:interl=1") - ffmbc_opts+=(-target imx30) - ffmbc_opts+=(-aspect 4:3) + middleoptions+=(-vf "${filterchain_start}pad=${height}*(4/3)/(${sar}):${height}:(ow-${width})/2:(oh-${height})/2,scale=720:480:interl=1") + middleoptions+=(-target imx30) + middleoptions+=(-aspect 4:3) fi # add audio options - ffmbc_opts+=(-acodec pcm_s24be) - ffmbc_opts+=(-ar 48k) - ffmbc_opts+=(-ac 2) + middleoptions+=(-acodec pcm_s24be) + middleoptions+=(-ar 48k) + middleoptions+=(-ac 2) # set input options for ffmbc inputoptions+=(-y) inputoptions+=(-threads 8) inputoptions+=(-loglevel verbose) - - _run mkdir -p "${outputdir}" + # log ffmbc process if [ "${logdir}" != "" ] ; then _run mkdir -p "${logdir}" @@ -171,26 +170,22 @@ while [ "${*}" != "" ] ; do get_volume_adjustment "${sourcefile}" unset audio_pipe_opts audio_pipe_opts=(-f s24le -ar 48000 -ac 2) - report -dt "ffmpeg -v warning -stats -i \"${input_movie}\" -af volume=${VOLADJ}dB ${audio_pipe_opts[@]} - | ffmbc ${inputoptions[@]} -i ${input_movie} ${audio_pipe_opts[@]} -i pipe:0 -map 0:v -map 1:a ${ffmbc_opts[@]} ${servicefile}" - echo "ffmpeg -v warning -stats -i \"${input_movie}\" -af volume=${VOLADJ}dB ${audio_pipe_opts[@]} - | ffmbc ${inputoptions[@]} -i \"${input_movie}\" ${audio_pipe_opts[@]} -i pipe:0 -map 0:v -map 1:a ${ffmbc_opts[@]} \"${servicefile}\"" >> "${logdir}/${reportfile}" - _run ffmpeg -v warning -stats -i "${input_movie}" -af volume=${VOLADJ}dB ${audio_pipe_opts[@]} - | ffmbc ${inputoptions[@]} -i "${input_movie}" ${audio_pipe_opts[@]} -i pipe:0 -map 0:v -map 1:a ${ffmbc_opts[@]} "${servicefile}" + _run ffmpeg -v warning -stats -i "${input_movie}" -af volume=${VOLADJ}dB ${audio_pipe_opts[@]} - | ffmbc ${inputoptions[@]} -i "${input_movie}" ${audio_pipe_opts[@]} -i pipe:0 -map 0:v -map 1:a ${middleoptions[@]} "${output}" else - echo "ffmbc ${inputoptions[@]} -i \"${sourcefile}\" ${ffmbc_opts[@]} \"${servicefile}\"" >> "${logdir}/${reportfile}" get_codectagstring "${sourcefile}" - echo "codec $codec_tag_string version $ffv1_version" if [ "$codec_tag_string" = "FFV1" -a "$ffv1_version" = "3" ] ; then - echo VERSION 3 if [ "${logdir}" != "" ] ; then _run rm "${logdir}/${reportfile}" fi - _run ffmpeg -report ${inputoptions[@]} -i "${sourcefile}" -vf "fieldorder=tff,pad=720:512:0:24,format=yuv422p,setsar=1/1,setdar=4/3,fps=fps=ntsc" -c:v mpeg2video -intra_vlc 1 -non_linear_quant 1 -qmin 1 -qmax 12 -intra -top 1 -b:v 30M -maxrate:v 30M -minrate:v 30M -bufsize 1001000 -rc_init_occupancy 1001000 -rc_max_vbv_use 1 -rc_min_vbv_use 1 -rc_buf_aggressivity 0.25 -dc 10 -lmin QP2LAMBDA -vbsf imxdump -flags +ildct+ilme+low_delay -ps 1 -tag:v mx3n -c:a pcm_s24be -ar 48k -ac 2 "${servicefile}" + _run ffmpeg -report ${inputoptions[@]} -i "${sourcefile}" -vf "fieldorder=tff,pad=720:512:0:24,format=yuv422p,setsar=1/1,setdar=4/3,fps=fps=ntsc" -c:v mpeg2video -intra_vlc 1 -non_linear_quant 1 -qmin 1 -qmax 12 -intra -top 1 -b:v 30M -maxrate:v 30M -minrate:v 30M -bufsize 1001000 -rc_init_occupancy 1001000 -rc_max_vbv_use 1 -rc_min_vbv_use 1 -rc_buf_aggressivity 0.25 -dc 10 -lmin QP2LAMBDA -vbsf imxdump -flags +ildct+ilme+low_delay -ps 1 -tag:v mx3n -c:a pcm_s24be -ar 48k -ac 2 "${output}" else - echo "ffmbc ${inputoptions[@]} -i \"${sourcefile}\" ${ffmbc_opts[@]} \"${servicefile}\"" >> "${logdir}/${reportfile}" - _run ffmbc ${inputoptions[@]} -i "${sourcefile}" ${ffmbc_opts[@]} "${servicefile}" + _run ffmbc ${inputoptions[@]} -i "${sourcefile}" ${middleoptions[@]} "${output}" fi fi - ffmbc_err="$?" - [ "${ffmbc_err}" -gt "0" ] && { report -wt "ffmbc failed with error ${ffmbc_err}" ; exit 1 ;}; + echo + _summarize_make + _deliver_output + _email_outcome shift + _log -e done -log -e diff --git a/makedvd b/makedvd index 90edead6..28f2c7c5 100755 --- a/makedvd +++ b/makedvd @@ -1,73 +1,84 @@ #!/bin/bash # makedvd -# make dvd version="1.0" -unset dependencies -dependencies=(ffmpeg dvdauthor mkisofs) -DRYRUN=false - -scriptdir=$(dirname "$0") +scriptdir=$(dirname $(which "$0")) . "$scriptdir/mmfunctions" || { echo "Missing '$scriptdir/mmfunctions'. Exiting." ; exit 1 ;}; - -cleanup(){ - log -a "Process aborted" - exit 1 -} - -trap cleanup SIGHUP SIGINT SIGTERM +dependencies=(ffmpeg dvdauthor mkisofs) +_initialize_make usage(){ echo - echo "$(basename $0) ${version}" + echo "$(basename ${0}) ${version}" echo "This application will create a DVD .iso file from a video file or package input with the following options." echo "Dependencies: ${dependencies[@]}" echo "Usage: $(basename $0) [ -v dvd_label_prefix ] fileorpackage1 [ fileorpackage2 ...]" echo " -v dvdlabelprefix (optional)" + echo " -d directory ( directory to deliver the resulting file to )" + echo " -o directory ( directory to write the resulting file to )" echo " -n (dry-run mode, show the commands that would be run but don't do anything)" - echo " -h display this help" + echo " -e emailaddress ( send an email about the delivery, only valid if -d is used )" + echo " -E emailaddress ( send an email about process outcome )" + echo " -h ( display this help )" echo exit } -[ "$#" = 0 ] && usage -check_dependencies "${dependencies[@]}" +[ "${#}" = 0 ] && usage # command-line options to set mediaid and original variables OPTIND=1 -while getopts ":hv:n" opt; do - case "$opt" in +while getopts ":v:o:d:e:E:nh" opt ; do + case "${opt}" in + v) DVDLABELPREFIX="$OPTARG";; + o) outputdir="$OPTARG" && check_outputdir ;; + d) deliverdir="$OPTARG" && check_deliverdir ;; + e) emailaddress_delivery="$OPTARG" && check_emailaddress "${emailaddress_delivery}" ;; + E) emailaddress_outcome="$OPTARG" && check_emailaddress "${emailaddress_outcome}" ;; n) DRYRUN=true;; h) usage ;; - v) DVDLABELPREFIX="$OPTARG";; *) echo "bad option -$OPTARG" ; usage ;; :) echo "Option -$OPTARG requires an argument" ; exit 1 ;; esac done shift $(( ${OPTIND} - 1 )) -while [ "$*" != "" ] ; do +while [ "${*}" != "" ] ; do + # get context about the input input="$1" - [ -d "$input" ] && { outputdir="$input/objects/access/dvd" && logdir="$input/metadata/submissionDocumentation/logs" ;}; - [ -f "$input" ] && { outputdir=$(dirname "$input")"/access/dvd" && logdir="$(dirname "$input")/access/logs" ;}; - [ ! "$outputdir" ] && { outputdir="$input/objects/access/dvd" && logdir="$input/metadata/submissionDocumentation/logs" ;}; - find_input "$input" - - mediaid=$(basename "$input" | cut -d. -f1) + if [ -z "${outputdir}" ] ; then + [ -d "${input}" ] && { outputdir="${input}/objects/access/dvd" && logdir="${input}/metadata/submissionDocumentation/logs" ;}; + [ -f "${input}" ] && { outputdir=$(dirname "${input}")"/access/dvd" && logdir="$(dirname "${input}")/access/logs" ;}; + [ ! "${outputdir}" ] && { outputdir="${input}/objects/access/dvd" && logdir="${input}/metadata/submissionDocumentation/logs" ;}; + else + logdir="${outputdir}/logs" + fi + _find_input "${input}" + mediaid=$(basename "${input}" | cut -d. -f1) - log -b + # set up output + _log -b + output="${outputdir}/${mediaid%.*}.iso" + [ -s "${output}" ] && { report -wt "WARNING ${output} already exists, skipping transcode" ; shift ; continue ;}; + _run mkdir -p "${outputdir}" - isooutput="$outputdir/${mediaid%.*}.iso" - [ -s "$isooutput" ] && { report -wt "WARNING $isooutput already exists, skipping transcode" ; [ "$#" = 1 ] && exit 86 || { shift ; continue ;} ;}; - _run mkdir -p "$outputdir" - get_height "$sourcefile" - get_width "$sourcefile" - get_dar "$sourcefile" + # get information on the input + get_height "${sourcefile}" + get_width "${sourcefile}" + get_dar "${sourcefile}" darratio=$(echo "scale=3 ; $dar" | bc) - [ $(echo "scale=5 ; $darratio > 1.5" | bc -l) = 1 ] && { aspect="16/9" ; dvdaspect="16:9" ;}; - [ $(echo "scale=5 ; $darratio > 1.5" | bc -l) = 1 ] || { aspect="4/3" ; dvdaspect="4:3" ;}; - + if [ $(echo "scale=5 ; $darratio > 1.5" | bc -l) = 1 ] ;then + aspect="16/9" + dvdaspect="16:9" + else + aspect="4/3" + dvdaspect="4:3" + fi get_maxdvdbitrate "$sourcefile" + + # clear local arrays unset inputoptions unset middleoptions + + # encoding options middleoptions+=(-r:v ntsc) middleoptions+=(-c:v mpeg2video) middleoptions+=(-c:a ac3) @@ -88,47 +99,32 @@ while [ "$*" != "" ] ; do middleoptions+=(-lmax 200000) middleoptions+=(-b:a 448000) middleoptions+=(-ar 48000) - if [ "$height" -eq "486" -a "$width" -eq "720" ] ; then - middleoptions+=(-vf "fieldorder=bff,crop=720:480:0:4,setdar=${aspect}" -aspect $aspect) - elif [ "$height" -eq "480" -a "$width" -eq "720" ] ; then - middleoptions+=(-vf "fieldorder=bff,setdar=${aspect}" -aspect $aspect) - elif [ "$height" -eq "512" -a "$width" -eq "720" ] ; then - middleoptions+=(-vf "fieldorder=bff,crop=720:480:0:32,setdar=${aspect}" -aspect $aspect) + if [[ "${height}" == 486 && "${width}" == 720 ]] ; then + middleoptions+=(-vf "fieldorder=bff,crop=720:480:0:4,setdar=${aspect}" -aspect ${aspect}) + elif [[ "{$height}" == 480 && "${width}" == 720 ]] ; then + middleoptions+=(-vf "fieldorder=bff,setdar=${aspect}" -aspect ${aspect}) + elif [[ "${height}" == 512 && "${width}" == 720 ]] ; then + middleoptions+=(-vf "fieldorder=bff,crop=720:480:0:32,setdar=${aspect}" -aspect ${aspect}) else - middleoptions+=(-vf "fieldorder=bff,scale=720:480:interl=1,setdar=${aspect}" -aspect $aspect) + middleoptions+=(-vf "fieldorder=bff,scale=720:480:interl=1,setdar=${aspect}" -aspect ${aspect}) fi inputoptions+=" -y" - if [ "$logdir" != "" ] ; then - _run mkdir -p "$logdir" - export FFREPORT="file=${logdir}/%p_%t_$(basename $0)_${version}.txt" - inputoptions+=(-v warning -stats) - fi - report -dt "Working on $(basename $isooutput) DVD image." + _prep_ffmpeg_log + # making the initial mpeg2 for the dvd _run ffmpeg ${inputoptions[@]} -i "${sourcefile}" ${middleoptions[@]} "${outputdir}/${mediaid%.*}.mpeg" + # Making DVD VIDEO_TS folder, chapters every 5 minutes, dvdauthor will ignore chapter markers greater than duration export VIDEO_FORMAT=NTSC - # chapters every 5 minutes, dvdauthor will ignore chapter markers greater than duration - report -dt "Making DVD VIDEO_TS folder." - _run dvdauthor --title -v "ntsc+${dvdaspect}" -a ac3+en -c 0,5:00,10:00,15:00,20:00,25:00,30:00,35:00,40:00,45:00,50:00,55:00,1:00:00,1:05:00,1:10:00,1:15:00,1:20:00,1:25:00,1:30:00,1:35:00,1:40:00,1:45:00,1:50:00,1:55:00,2:00:00,2:05:00,2:10:00,2:15:00,2:20:00,2:25:00,2:30:00,2:35:00,2:40:00,2:45:00,2:50:00,2:55:00,3:00:00,3:05:00,3:10:00,3:15:00,3:20:00,3:25:00,3:30:00,3:35:00,3:40:00,3:45:00,3:50:00,3:55:00 -f "$outputdir/${mediaid%.*}.mpeg" -o "$outputdir/${mediaid%.*}/" 2> "${logdir}/dvdauthor_$(get_iso8601_c)_$(basename $0)_${version}.txt" - dvdauthor_err="$?" - if [ "$dvdauthor_err" -gt "0" ] ; then - report -wt "ERROR dvdauthor reported error code $dvdauthor_err. Please review $outputdir/${mediaid%.*}/" - exit "$dvdauthor_err" - else - _run rm "$outputdir/${mediaid%.*}.mpeg" - fi - _run dvdauthor -T -o "$outputdir/${mediaid%.*}/" + _run_critical dvdauthor --title -v "ntsc+${dvdaspect}" -a ac3+en -c 0,5:00,10:00,15:00,20:00,25:00,30:00,35:00,40:00,45:00,50:00,55:00,1:00:00,1:05:00,1:10:00,1:15:00,1:20:00,1:25:00,1:30:00,1:35:00,1:40:00,1:45:00,1:50:00,1:55:00,2:00:00,2:05:00,2:10:00,2:15:00,2:20:00,2:25:00,2:30:00,2:35:00,2:40:00,2:45:00,2:50:00,2:55:00,3:00:00,3:05:00,3:10:00,3:15:00,3:20:00,3:25:00,3:30:00,3:35:00,3:40:00,3:45:00,3:50:00,3:55:00 -f "${outputdir}/${mediaid%.*}.mpeg" -o "${outputdir}/${mediaid%.*}/" 2> "${logdir}/dvdauthor_$(get_iso8601_c)_$(basename $0)_${version}.txt" + _run rm "${outputdir}/${mediaid%.*}.mpeg" + _run_critical dvdauthor -T -o "${outputdir}/${mediaid%.*}/" + # Making DVD image file. volname=$(echo "${DVDLABELPREFIX}${mediaid}") - report -dt "Making DVD image file." - _run mkisofs -f -dvd-video -udf -V "${volname:0:32}" -v -v -o "$isooutput" "$outputdir/${mediaid%.*}" 2> "${logdir}/mkisofs_$(get_iso8601_c)_$(basename $0)_${version}.txt" - mkisofs_err="$?" - if [ "$mkisofs_err" -gt "0" ] ; then - report -wt "ERROR mkisofs reported error code $mkisofs_err. Please review $isooutput." - exit "$mkisofs_err" - else - _run rm -r "$outputdir/${mediaid%.*}/" - fi - report -dt "$(basename "${isooutput}") is done." - log -e + _run_critical mkisofs -f -dvd-video -udf -V "${volname:0:32}" -v -v -o "${output}" "${outputdir}/${mediaid%.*}" 2> "${logdir}/mkisofs_$(get_iso8601_c)_$(basename $0)_${version}.txt" + _run rm -r "${outputdir}/${mediaid%.*}/" + echo + _summarize_make + _deliver_output + _email_outcome shift + _log -e done - diff --git a/makeframes b/makeframes index 04f23a17..70c4ed24 100755 --- a/makeframes +++ b/makeframes @@ -1,18 +1,17 @@ #!/bin/bash # makeframes - version="1.0" -unset dependencies +scriptdir=$(dirname $(which "$0")) +. "$scriptdir/mmfunctions" || { echo "Missing '$scriptdir/mmfunctions'. Exiting." ; exit 1 ;}; dependencies=(ffmpeg) -deliverdir="" -DRYRUN=false +_initialize_make -scriptdir=$(dirname "$0") -. "$scriptdir/mmfunctions" || { echo "Missing '$scriptdir/mmfunctions'. Exiting." ; exit 1 ;}; +# local variables +IMAGECOUNT=10 usage(){ echo - echo "$(basename $0) ${version}" + echo "$(basename ${0}) ${version}" echo "This application will create a series of still images from a video file or package input with the following options." echo "Dependencies: ${dependencies[@]}" echo "Usage: $(basename $0) [ -d /path/to/deliver/to/ ] fileorpackage1 [ fileorpackage2 ...]" @@ -22,29 +21,18 @@ usage(){ echo exit } -[ "$#" = 0 ] && usage -check_dependencies "${dependencies[@]}" - -# local variables -IMAGECOUNT=10 - -cleanup(){ - log -a "Process aborted" - exit 1 -} -trap cleanup SIGHUP SIGINT SIGTERM +[ "${#}" = 0 ] && usage # command-line options to set mediaid and original variables OPTIND=1 -while getopts ":hd:n" opt; do - case "$opt" in +while getopts ":d:e:E:nh" opt ; do + case "${opt}" in + d) deliverdir="$OPTARG" && check_deliverdir ;; + e) emailaddress_delivery="$OPTARG" && check_emailaddress "${emailaddress_delivery}" ;; + E) emailaddress_outcome="$OPTARG" && check_emailaddress "${emailaddress_outcome}" ;; n) DRYRUN=true;; - h) usage;; - d) - deliverdir="$OPTARG" - [ ! -d "$deliverdir" ] && report -wt "The delivery directory, ${deliverdir}, does not exist. Can not deliver the output of $(basename "$0")." - ;; - *) echo "Invalid option: -$OPTARG" ; exit 1 ;; + h) usage ;; + *) echo "bad option -$OPTARG" ; usage ;; :) echo "Option -$OPTARG requires an argument" ; exit 1 ;; esac done @@ -55,19 +43,20 @@ while [ "$*" != "" ] ; do [ -d "$input" ] && { outputdir="$input/objects/access/images" && logdir="$input/metadata/submissionDocumentation/logs" ;}; [ -f "$input" ] && { outputdir=$(dirname "$input")"/access/images" && logdir="$(dirname "$input")/access/logs" ;}; [ ! "$outputdir" ] && { outputdir="$input/objects/access/images" && logdir="$input/metadata/submissionDocumentation/logs" ;}; - find_input "$input" + _find_input "$input" mediaid=$(basename "$1" | cut -d. -f1) - log -b - [ -s "$outputdir" ] && { report -wt "WARNING $outputdir already exists, skipping transcode" ; [ "$#" = 1 ] && exit 86 || { shift ; continue ;} ;}; - BASE=$(basename "$sourcefile") - DURATION=$(ffprobe 2>/dev/null $sourcefile -show_format | grep duration | cut -d= -f2) - _run mkdir -p "$outputdir" + _log -b + DURATION=$(ffprobe 2>/dev/null $sourcefile -show_format | grep duration | cut -d= -f2) + _run_critical mkdir -p "$outputdir" for (( IMAGENUMBER=1; IMAGENUMBER<=$IMAGECOUNT; IMAGENUMBER++)) ; do START=$(echo "( $DURATION / ( $IMAGECOUNT + 1 )) * $IMAGENUMBER" | bc) - report -d "Making frame $IMAGENUMBER of $IMAGECOUNT $outputdir/${BASE%.*}_${IMAGENUMBER}.tiff" - _run ffmpeg -y -v warning -ss "$START" -i $sourcefile -vf yadif,thumbnail=100 -frames:v 1 "$outputdir/${mediaid}_${IMAGENUMBER}.tiff" + output="$outputdir/${mediaid}_${IMAGENUMBER}.tiff" + report -d "Making frame $IMAGENUMBER of $IMAGECOUNT - $output" + [ -s "${output}" ] && { report -wt "WARNING ${output} already exists, skipping transcode" ; shift ; continue ;}; + _prep_ffmpeg_log + _run ffmpeg -y -v warning -ss "$START" -i $sourcefile -vf yadif,thumbnail=100 -frames:v 1 "$output" done echo if [ -d "${deliverdir}" ] ; then @@ -75,7 +64,6 @@ while [ "$*" != "" ] ; do _run mkdir -p "${deliverdir}/${mediaid}_images/" _run cp -av "${outputdir}/" "${deliverdir}/${mediaid}_images/" fi - log -e shift + _log -e done -log -e diff --git a/makelossless b/makelossless index ec1cd3e9..c2b2ded2 100755 --- a/makelossless +++ b/makelossless @@ -1,21 +1,14 @@ #!/bin/bash -unset dependencies +# makelossless +version="1.0" +scriptdir=$(dirname $(which "$0")) +. "$scriptdir/mmfunctions" || { echo "Missing '$scriptdir/mmfunctions'. Exiting." ; exit 1 ;}; dependencies=(ffmpeg muxmovie mediainfo) -DRYRUN=false - -scriptdir=$(dirname "${0}") -. "${scriptdir}/mmfunctions" || { echo "Missing '${scriptdir}/mmfunctions'. Exiting." ; exit 1 ;}; - -cleanup(){ - log -a "Process aborted" - exit 1 -} - -trap cleanup SIGHUP SIGINT SIGTERM +_initialize_make usage(){ echo - echo "$(basename $0) ${version}" + echo "$(basename ${0}) ${version}" echo "This application will create lossless ffv1 files from a video file or package input with the following options." echo "Dependencies: ${dependencies[@]}" echo "Usage: $(basename $0) fileorpackage1 [ fileorpackage2 ...]" @@ -24,13 +17,12 @@ usage(){ echo exit } -[ "$#" = 0 ] && usage -check_dependencies "${dependencies[@]}" +[ "${#}" = 0 ] && usage # command-line options to set mediaid and original variables OPTIND=1 -while getopts ":hn" opt; do - case "$opt" in +while getopts ":nh" opt ; do + case "${opt}" in n) DRYRUN=true;; h) usage ;; *) echo "bad option -$OPTARG" ; usage ;; @@ -40,93 +32,68 @@ done shift $(( ${OPTIND} - 1 )) while [ "${*}" != "" ] ; do - file="${1}" - outputdir="" - - [ "${#}" != 0 ] && input="${1}" + # get context about the input + input="$1" [ -d "${input}" ] && { logdir="${input}/metadata/submissionDocumentation/logs" && trimmingsdir="${input}/objects/trimmed_materials" ;}; [ -f "${input}" ] && { logdir="$(dirname "${input}")/lossless/logs" && trimmingsdir="$(dirname "${input}")/lossless/trimmed_materials" ;}; [ ! "${logdir}" ] && logdir="${input}/metadata/submissionDocumentation/logs" + [ ! "${trimmingsdir}" ] && trimmingsdir="${input}/lossless/trimmed_materials" - find "${input}" -type f \( -name "*.mov" -o -name "*.avi" -o -name "*.mxf" \) -print0 | while read -d $'\0' file ; do - sourcefile="${file}" + find "${input}" -type f \( -name "*.mov" -o -name "*.avi" -o -name "*.mxf" \) -print0 | while read -d $'\0' sourcefile ; do outputdir=$(dirname "${sourcefile}") sourcefilename=$(basename "${sourcefile}") - log -b + _log -b get_codectagstring "${sourcefile}" get_fieldorder "${sourcefile}" get_pix_fmt "${sourcefile}" + _run mkdir -p "${outputdir}" "${logdir}" if [ "${codec_tag_string}" == "2vuy" -o "${codec_tag_string}" == "v210" ] ; then - report -dt "${sourcefilename} is ${codec_tag_string}, starting encode" - _run mkdir -p "${outputdir}" "${logdir}" "${trimmingsdir}" - export FFREPORT="file=${logdir}/%p_%t_makelossless.log" - _run ffmpeg -nostdin -v warning -stats -vsync 0 -i "${sourcefile}" -map 0:v -map 0:a -c:v ffv1 -level 3 -vf setfield=bff -g 1 -c:a copy "${outputdir}/${sourcefilename%.*}_ffv1.mov" -f framemd5 -an "${logdir}/${sourcefilename%.*}.framemd5" - ffmpeg_ffv1_err="${?}" - [ "${ffmpeg_ffv1_err}" -gt 0 ] && { report -wt "ffmpeg ended with error with ${sourcefile}" ; shift ; continue ;}; + suffix="_ffv1" + report -dt "${sourcefilename} is ${codec_tag_string} at ${fieldorder}, starting encode" + _run mkdir -p "${trimmingsdir}" + export FFREPORT="file=${logdir}/%p_%t_makelossless${suffix}.log" + _run_critical ffmpeg -nostdin -v warning -stats -vsync 0 -i "${sourcefile}" -map 0:v -map 0:a -c:v ffv1 -level 3 -vf setfield=bff -g 1 -c:a copy "${outputdir}/${sourcefilename%.*}${suffix}.mov" -f framemd5 -an "${logdir}/${sourcefilename%.*}.framemd5" if [ "${codec_tag_string}" == "2vuy" ] ; then - _run ffmpeg -nostdin -v warning -stats -i "${outputdir}/${sourcefilename%.*}_ffv1.mov" -f framemd5 -pix_fmt uyvy422 -an "${logdir}/${sourcefilename%.*}_ffv1.framemd5" + _run_critical ffmpeg -nostdin -v warning -stats -i "${outputdir}/${sourcefilename%.*}${suffix}.mov" -f framemd5 -pix_fmt uyvy422 -an "${logdir}/${sourcefilename%.*}${suffix}.framemd5" else - _run ffmpeg -nostdin -v warning -stats -i "${outputdir}/${sourcefilename%.*}_ffv1.mov" -f framemd5 -an "${logdir}/${sourcefilename%.*}_ffv1.framemd5" + _run_critical ffmpeg -nostdin -v warning -stats -i "${outputdir}/${sourcefilename%.*}${suffix}.mov" -f framemd5 -an "${logdir}/${sourcefilename%.*}${suffix}.framemd5" fi - ffmpeg_md5_err="${?}" - [ "${ffmpeg_md5_err}" -gt 0 ] && { report -wt "ffmpeg md5 ended with error with ${sourcefile}" ; shift ; continue ;}; defaults write com.pair.3am.QTCoffee BugMe NO - _run muxmovie "${sourcefile}" -track "Timecode Track" -track "Closed Caption Track" -self-contained -o "${trimmingsdir}/${sourcefilename%.*}_tc_c608.mov" - muxmovie_err="${?}" - [ "${muxmovie_err}" -gt 0 ] && { report -wt "muxmovie ended with error with ${sourcefile}" ; exit 1 ;}; - if [ $(md5 -q "${logdir}/${sourcefilename%.*}.framemd5") = $(md5 -q "${logdir}/${sourcefilename%.*}_ffv1.framemd5") ] ; then + _run_critical muxmovie "${sourcefile}" -track "Timecode Track" -track "Closed Caption Track" -self-contained -o "${trimmingsdir}/${sourcefilename%.*}_tc_c608.mov" + if [ $(md5 -q "${logdir}/${sourcefilename%.*}.framemd5") = $(md5 -q "${logdir}/${sourcefilename%.*}${suffix}.framemd5") ] ; then report -dt "Everything looks safe. Going to delete the original." - _run mediainfo -f --language=raw --output=XML "${sourcefile}" > "${logdir}/${sourcefilename%.*}_mediainfo.xml" - _run rm -f -v "${sourcefile}" + _run_critical mediainfo -f --language=raw --output=XML "${sourcefile}" > "${logdir}/${sourcefilename%.*}_mediainfo.xml" + _run_critical rm -f -v "${sourcefile}" else report -wt "Not looking safe. Going to keep the original." fi elif [ "${codec_tag_string}" == "FFV1" -a "${fieldorder}" == "progressive" ] ; then + suffix="_bfffix" + report -dt "${sourcefilename} is ${codec_tag_string} at ${fieldorder}, starting encode" + export FFREPORT="file=${logdir}/%p_%t_makelossless${suffix}.log" + _run_critical ffmpeg -nostdin -v warning -stats -vsync 0 -i "${sourcefile}" -map 0:v -map 0:a -c:v ffv1 -level 3 -vf setfield=bff -g 1 -c:a copy "${outputdir}/${sourcefilename%.*}${suffix}.mov" if [ "${pixfmt}" == "yuv422p" ] ; then - report -dt "${sourcefilename} is yuv422p ffv1 progressive, starting encode" - _run mkdir -p "${outputdir}" "${logdir}" - export FFREPORT="file=${logdir}/%p_%t_makelossless_bfffix.log" - _run ffmpeg -nostdin -v warning -stats -vsync 0 -i "${sourcefile}" -map 0:v -map 0:a -c:v ffv1 -level 3 -vf setfield=bff -g 1 -c:a copy "${outputdir}/${sourcefilename%.*}_bfffix.mov" - ffmpeg_ffv1_err="${?}" - [ "${ffmpeg_ffv1_err}" -gt 0 ] && { report -wt "ffmpeg ended with error with ${sourcefile}" ; shift ; continue ;}; - _run ffmpeg -nostdin -v warning -stats -i "${outputdir}/${sourcefilename%.*}_bfffix.mov" -f framemd5 -pix_fmt uyvy422 -an "${logdir}/${sourcefilename%.*}_bfffix.framemd5" - ffmpeg_md5_err="${?}" - [ "${ffmpeg_md5_err}" -gt 0 ] && { report -wt "ffmpeg md5 ended with error with ${sourcefile}" ; shift ; continue ;}; - if [ $(md5 -q "${logdir}/${sourcefilename%.*}.framemd5") = $(md5 -q "${logdir}/${sourcefilename%.*}_bfffix.framemd5") ] ; then - report -dt "Everything looks safe. Going to delete the original." - _run mediainfo -f --language=raw --output=XML "${sourcefile}" > "${logdir}/${sourcefilename%.*}_bfffix_mediainfo.xml" - _run mv -f -v "${outputdir}/${sourcefilename%.*}_bfffix.mov" "${sourcefile}" - else - report -wt "Not looking safe. Going to keep the original." - fi - elif [ "${pixfmt}" == "yuv422p10le" ] ; then - report -dt "${sourcefilename} is yuv422p10le ffv1 progressive, starting encode" - _run mkdir -p "${outputdir}" "${logdir}" - export FFREPORT="file=${logdir}/%p_%t_makelossless_bfffix.log" - _run ffmpeg -nostdin -v warning -stats -vsync 0 -i "${sourcefile}" -map 0:v -map 0:a -c:v ffv1 -level 3 -vf setfield=bff -g 1 -c:a copy "${outputdir}/${sourcefilename%.*}_bfffix.mov" - ffmpeg_ffv1_err="${?}" - [ "${ffmpeg_ffv1_err}" -gt 0 ] && { report -wt "ffmpeg ended with error with ${sourcefile}" ; shift ; continue ;}; - _run ffmpeg -nostdin -v warning -stats -i "${outputdir}/${sourcefilename%.*}_bfffix.mov" -f framemd5 -an "${logdir}/${sourcefilename%.*}_bfffix.framemd5" - ffmpeg_md5_err="${?}" - [ "${ffmpeg_md5_err}" -gt 0 ] && { report -wt "ffmpeg md5 ended with error with ${sourcefile}" ; shift ; continue ;}; - if [ $(md5 -q "${logdir}/${sourcefilename%.*}.framemd5") = $(md5 -q "${logdir}/${sourcefilename%.*}_bfffix.framemd5") ] ; then - report -dt "Everything looks safe. Going to delete the original." - _run mediainfo -f --language=raw --output=XML "$sourcefile" > "${logdir}/${sourcefilename%.*}_bfffix_mediainfo.xml" - _run mv -f -v "${outputdir}/${sourcefilename%.*}_bfffix.mov" "${sourcefile}" - else - report -wt "Not looking safe. Going to keep the original." - fi + _run_critical ffmpeg -nostdin -v warning -stats -i "${outputdir}/${sourcefilename%.*}${suffix}.mov" -f framemd5 -pix_fmt uyvy422 -an "${logdir}/${sourcefilename%.*}${suffix}.framemd5" + elif [ "${pixfmt}" == "yuv422p10le" ] ; then + _run_critical ffmpeg -nostdin -v warning -stats -i "${outputdir}/${sourcefilename%.*}${suffix}.mov" -f framemd5 -an "${logdir}/${sourcefilename%.*}${suffix}.framemd5" else report -wt "uh oh unsupported" fi + if [ $(md5 -q "${logdir}/${sourcefilename%.*}.framemd5") = $(md5 -q "${logdir}/${sourcefilename%.*}${suffix}.framemd5") ] ; then + report -dt "Everything looks safe. Going to delete the original." + _run_critical mediainfo -f --language=raw --output=XML "$sourcefile" > "${logdir}/${sourcefilename%.*}${suffix}_mediainfo.xml" + _run_critical mv -f -v "${outputdir}/${sourcefilename%.*}${suffix}.mov" "${sourcefile}" + else + report -wt "Not looking safe. Going to keep the original." + fi else - report -wt "${sourcefilename} is not 2vuy or v210 or progress ffv1, quitting" + report -wt "${sourcefilename} is not 2vuy or v210 or progressive ffv1, skipping" continue fi report -dt done with "${sourcefile}" done shift + _log -e done -log -e diff --git a/makemetadata b/makemetadata index bc07d0bb..a647d7e8 100755 --- a/makemetadata +++ b/makemetadata @@ -1,42 +1,37 @@ #!/bin/bash # make metadata version="0.2" -DRYRUN=false - scriptdir=$(dirname $(which "$0")) . "$scriptdir/mmfunctions" || { echo "Missing '$scriptdir/mmfunctions'. Exiting." ; exit 1 ;}; - -cleanup(){ - log -a "Process aborted" - exit 1 -} - -trap cleanup SIGHUP SIGINT SIGTERM +dependencies=(ffprobe mediainfo exiftool) +_initialize_make usage(){ echo - echo "$(basename $0) ${version}" + echo "$(basename ${0}) ${version}" echo "This script may be run interactively by running it with no arguments or may be used with the following options." echo "Usage: $(basename $0) [ -m mediaid ]" echo " -n (dry-run mode, show the commands that would be run but don't do anything)" echo " -m mediaid" exit } +[ "${#}" = 0 ] && usage # command-line options to set mediaid and original variables OPTIND=1 -while getopts ":hm:n" opt; do - case "$opt" in +while getopts ":e:E:nh" opt ; do + case "${opt}" in + e) emailaddress_delivery="$OPTARG" && check_emailaddress "${emailaddress_delivery}" ;; + E) emailaddress_outcome="$OPTARG" && check_emailaddress "${emailaddress_outcome}" ;; n) DRYRUN=true;; h) usage ;; - m) mediaid="$OPTARG" ;; - \?) echo "Invalid option: -$OPTARG" ; exit 1 ;; + *) echo "bad option -$OPTARG" ; usage ;; :) echo "Option -$OPTARG requires an argument" ; exit 1 ;; esac done shift $(( ${OPTIND} - 1 )) -log -b +_log -b outputdir="./metadata/submissionDocumentation/fileMeta" _run mkdir -p "$outputdir" @@ -53,7 +48,6 @@ while [ "$*" != "" ] ; do servicebasename=$(basename "$service_file") fi - echo "STATUS Making metadata reports for ${mediaid}." while read file ; do filenameroot=$(basename "$file") parentdir=$(dirname "$file") @@ -70,6 +64,5 @@ while [ "$*" != "" ] ; do cd "$pwd" _run rm -r -f "$FILELIST" shift - + _log -e done -log -e diff --git a/makepodcast b/makepodcast index cb507aa5..2348c674 100755 --- a/makepodcast +++ b/makepodcast @@ -1,66 +1,68 @@ #!/bin/bash -# makepodcast -# makes a file appropriate for podcasting +# makepodcast, makes a file appropriate for podcasting version="1.0" -unset dependencies -dependencies=(ffmpeg) -deliverdir="" -DRYRUN=false - -scriptdir=$(dirname "$0") +scriptdir=$(dirname $(which "$0")) . "$scriptdir/mmfunctions" || { echo "Missing '$scriptdir/mmfunctions'. Exiting." ; exit 1 ;}; +dependencies=(ffmpeg) +_initialize_make usage(){ echo - echo "$(basename $0) ${version}" + echo "$(basename ${0}) ${version}" echo "This application will create a QuickTime file suitable for podcasting from a video file or package input with the following options." echo "Dependencies: ${dependencies[@]}" echo "Usage: $(basename $0) [ -d /path/to/deliver/to/ ] fileorpackage1 [ fileorpackage2 ...]" echo " -d directory ( directory to deliver the resulting file to )" + echo " -o directory ( directory to write the resulting file to )" echo " -n (dry-run mode, show the commands that would be run but don't do anything)" + echo " -e emailaddress ( send an email about the delivery, only valid if -d is used )" + echo " -E emailaddress ( send an email about process outcome )" echo " -h ( display this help )" echo exit } -[ "$#" = 0 ] && usage -check_dependencies "${dependencies[@]}" - -cleanup(){ - log -a "Process aborted" - exit 1 -} - -trap cleanup SIGHUP SIGINT SIGTERM +[ "${#}" = 0 ] && usage # command-line options to set mediaid and original variables OPTIND=1 -while getopts ":hd:n" opt; do - case "$opt" in +while getopts ":o:d:e:E:nh" opt ; do + case "${opt}" in + o) outputdir="$OPTARG" && check_outputdir ;; + d) deliverdir="$OPTARG" && check_deliverdir ;; + e) emailaddress_delivery="$OPTARG" && check_emailaddress "${emailaddress_delivery}" ;; + E) emailaddress_outcome="$OPTARG" && check_emailaddress "${emailaddress_outcome}" ;; n) DRYRUN=true;; h) usage ;; - d) - deliverdir="$OPTARG" - [ ! -d "$deliverdir" ] && report -wt "The delivery directory, ${deliverdir}, does not exist. Can not deliver the output of $(basename "$0")." - ;; *) echo "bad option -$OPTARG" ; usage ;; :) echo "Option -$OPTARG requires an argument" ; exit 1 ;; esac done shift $(( ${OPTIND} - 1 )) -while [ "$*" != "" ] ; do +while [ "${*}" != "" ] ; do + # get context about the input input="$1" - [ -d "$input" ] && { outputdir="$input/objects/access/podcast" && logdir="$input/metadata/submissionDocumentation/logs" ;}; - [ -f "$input" ] && { outputdir=$(dirname "$input")"/access/podcast" && logdir="$(dirname "$input")/access/logs" ;}; - [ ! "$outputdir" ] && { outputdir="$input/objects/access/podcast" && logdir="$input/metadata/submissionDocumentation/logs" ;}; - find_input "$input" - mediaid=$(basename "$input" | cut -d. -f1) - log -b - podcastoutput="$outputdir/${mediaid%.*}_podcast.mov" - [ -s "${podcastoutput}" ] && { report -wt "WARNING ${podcastoutput} already exists, skipping transcode" ; [ "$#" = 1 ] && exit 86 || { shift ; continue ;} ;}; + if [ -z "${outputdir}" ] ; then + [ -d "${input}" ] && { outputdir="$input/objects/access/podcast" && logdir="${input}/metadata/submissionDocumentation/logs" ;}; + [ -f "${input}" ] && { outputdir=$(dirname "${input}")"/access/podcast" && logdir="$(dirname "${input}")/access/logs" ;}; + [ ! "${outputdir}" ] && { outputdir="${input}/objects/access/podcast" && logdir="${input}/metadata/submissionDocumentation/logs" ;}; + else + logdir="${outputdir}/logs" + fi + _find_input "${input}" + mediaid=$(basename "${input}" | cut -d. -f1) + + # set up output + _log -b + output="${outputdir}/${mediaid%.*}_podcast.mov" + [ -s "${output}" ] && { report -wt "WARNING ${output} already exists, skipping transcode" ; shift ; continue ;}; _run mkdir -p "${outputdir}" + + # clear local arrays unset inputoptions unset middleoptions + + # encoding options middleoptions+=(-movflags faststart) middleoptions+=(-pix_fmt yuv420p) middleoptions+=(-c:v libx264) @@ -71,22 +73,16 @@ while [ "$*" != "" ] ; do middleoptions+=(-vf "yadif,scale=640:trunc(ow/dar/2)*2:interl=1") middleoptions+=(-c:a libfaac) middleoptions+=(-b:a 96k) - + get_audio_mapping "${sourcefile}" middleoptions+=(${audiomapping_ffmpeg[@]}) - - if [ "${logdir}" != "" ] ; then - _run mkdir -p "${logdir}" - export FFREPORT="file=${logdir}/%p_%t_$(basename $0)_${version}.txt" - inputoptions+=(-v warning -stats) - fi - report -dt "Running: ffmpeg ${inputoptions[@]} -i \"${sourcefile}\" ${middleoptions[@]} \"${podcastoutput}\"" - _run ffmpeg ${inputoptions[@]} -i "${sourcefile}" ${middleoptions[@]} "${podcastoutput}" + + _prep_ffmpeg_log + _run ffmpeg ${inputoptions[@]} -i "${sourcefile}" ${middleoptions[@]} "${output}" echo - if [ -d "${deliverdir}" ] ;then - report -dt "Delivering output" - _run cp -av "${podcastoutput}" "${deliverdir}/" - fi - log -e + _summarize_make + _deliver_output + _email_outcome shift + _log -e done diff --git a/makeprores b/makeprores index 9fe3b71a..25897755 100755 --- a/makeprores +++ b/makeprores @@ -1,96 +1,82 @@ #!/bin/bash -# makeprores -# makes a file appropriate for keeping editors happy +# makeprores, makes a file appropriate for keeping editors happy version="1.0" -unset dependencies +scriptdir=$(dirname $(which "$0")) +. "$scriptdir/mmfunctions" || { echo "Missing '$scriptdir/mmfunctions'. Exiting." ; exit 1 ;}; dependencies=(ffmpeg) -outputdir="$HOME/Desktop/$(basename $0)" # default output directory, override with -o -DRYRUN=false +_initialize_make -scriptdir=$(dirname "$0") -. "$scriptdir/mmfunctions" || { echo "Missing '$scriptdir/mmfunctions'. Exiting." ; exit 1 ;}; +outputdir="$HOME/Desktop/$(basename $0)" # default output directory, override with -o usage(){ echo - echo "$(basename $0) ${version}" + echo "$(basename ${0}) ${version}" echo "This application will create a prores/quicktime file (suitable for editing) from a video file or package input with the following options. By default the output will be written to ${outputdir}. You can override this with the -o option." echo "Dependencies: ${dependencies[@]}" echo "Usage: $(basename $0) [ -o /directory/to/write/to/ ] fileorpackage1 [ fileorpackage2 ...]" - echo " -n (dry-run mode, show the commands that would be run but don't do anything)" + echo " -d directory ( directory to deliver the resulting file to )" echo " -o directory ( directory to write the resulting file to )" + echo " -n (dry-run mode, show the commands that would be run but don't do anything)" + echo " -e emailaddress ( send an email about the delivery, only valid if -d is used )" + echo " -E emailaddress ( send an email about process outcome )" echo " -h ( display this help )" echo exit } -[ "$#" = 0 ] && usage -check_dependencies "${dependencies[@]}" - -cleanup(){ - log -a "Process aborted" - exit 1 -} - -trap cleanup SIGHUP SIGINT SIGTERM +[ "${#}" = 0 ] && usage +# command-line options to set mediaid and original variables OPTIND=1 -while getopts ":ho:n" opt; do - case "$opt" in +while getopts ":o:d:e:E:nh" opt ; do + case "${opt}" in + o) outputdir="$OPTARG" && check_outputdir ;; + d) deliverdir="$OPTARG" && check_deliverdir ;; + e) emailaddress_delivery="$OPTARG" && check_emailaddress "${emailaddress_delivery}" ;; + E) emailaddress_outcome="$OPTARG" && check_emailaddress "${emailaddress_outcome}" ;; n) DRYRUN=true;; h) usage ;; - o) - outputdir="$OPTARG" - if [ ! -d "$outputdir" ] ; then - report -wt "The output directory option, $outputdir, does not refer to an actual directory. Quitting." - exit 1 - fi - ;; *) echo "bad option -$OPTARG" ; usage ;; :) echo "Option -$OPTARG requires an argument" ; exit 1 ;; esac done shift $(( ${OPTIND} - 1 )) -while [ "$*" != "" ] ; do +while [ "${*}" != "" ] ; do + # get context about the input input="$1" if [ -z "${outputdir}" ] ; then - [ -d "$input" ] && { outputdir="$input/objects/access/prores" && logdir="$input/metadata/submissionDocumentation/logs" ;}; - [ -f "$input" ] && { outputdir=$(dirname "$input")"/access/prores" && logdir="$(dirname "$input")/access/logs" ;}; - [ ! "$outputdir" ] && { outputdir="$input/objects/access/prores" && logdir="$input/metadata/submissionDocumentation/logs" ;}; + [ -d "${input}" ] && { outputdir="${input}/objects/access/prores" && logdir="${input}/metadata/submissionDocumentation/logs" ;}; + [ -f "${input}" ] && { outputdir=$(dirname "${input}")"/access/prores" && logdir="$(dirname "${input}")/access/logs" ;}; + [ ! "${outputdir}" ] && { outputdir="${input}/objects/access/prores" && logdir="${input}/metadata/submissionDocumentation/logs" ;}; else - logdir="$outputdir/logs" + logdir="${outputdir}/logs" fi - - find_input "$input" - - mediaid=$(basename "$1" | cut -d. -f1) + _find_input "${input}" + mediaid=$(basename "${input}" | cut -d. -f1) - log -b - - outputfile="${outputdir}/${mediaid%.*}_prores.mov" - [ -s "${outputfile}" ] && { report -wt "WARNING ${outputfile} already exists, skipping transcode" ; [ "$#" = 1 ] && exit 86 || { shift ; continue ;} ;}; + # set up output + _log -b + output="${outputdir}/${mediaid%.*}_prores.mov" + [ -s "${output}" ] && { report -wt "WARNING ${output} already exists, skipping transcode" ; shift ; continue ;}; _run mkdir -p "${outputdir}" - get_height "${sourcefile}" - get_width "${sourcefile}" + # clear local arrays unset inputoptions - inputoptions+=(-vsync 0) unset middleoptions + + # encoding options + inputoptions+=(-vsync 0) middleoptions+=(-map 0:v) middleoptions+=(-map 0:a) middleoptions+=(-c:v prores) middleoptions+=(-c:a pcm_s16le) - if [ "${logdir}" != "" ] ; then - _run mkdir -p "${logdir}" - export FFREPORT="file=${logdir}/%p_%t_$(basename $0)_${version}.txt" - inputoptions+=(-v warning -stats) - fi - report -dt "Working on $(basename ${outputfile})." - report -dt "Running: ffmpeg ${inputoptions[@]} -i \"${sourcefile}\" ${middleoptions[@]} \"${outputfile}\"" - _run ffmpeg ${inputoptions[@]} -i "${sourcefile}" ${middleoptions[@]} "${outputfile}" + _prep_ffmpeg_log + _run ffmpeg ${inputoptions[@]} -i "${sourcefile}" ${middleoptions[@]} "${output}" echo - report -dt "$(basename "${outputfile}") is done." + _summarize_make + _deliver_output + _email_outcome shift - log -e + _log -e done - diff --git a/makeyoutube b/makeyoutube index 4f172383..a77597bb 100755 --- a/makeyoutube +++ b/makeyoutube @@ -1,76 +1,73 @@ #!/bin/bash -# makeyoutube -# makes a file appropriate for uploading to youtube +# makeyoutube, makes a file appropriate for uploading to youtube version="1.0" -unset dependencies -dependencies=(ffmpeg) -deliverdir="" -DRYRUN=false -emailaddress="" - -scriptdir=$(dirname "$0") +scriptdir=$(dirname $(which "$0")) . "$scriptdir/mmfunctions" || { echo "Missing '$scriptdir/mmfunctions'. Exiting." ; exit 1 ;}; +dependencies=(ffmpeg) +_initialize_make usage(){ echo - echo "$(basename $0) ${version}" + echo "$(basename ${0}) ${version}" echo "This application will create a high quality h264 file (suitable for uploading to YouTube) from a video file or package input with the following options." echo "Dependencies: ${dependencies[@]}" echo "Usage: $(basename $0) [ -d /path/to/deliver/to/ ] fileorpackage1 [ fileorpackage2 ...]" echo " -d directory ( directory to deliver the resulting file to )" + echo " -o directory ( directory to write the resulting file to )" echo " -n (dry-run mode, show the commands that would be run but don't do anything)" echo " -e emailaddress ( send an email about the delivery, only valid if -d is used )" + echo " -E emailaddress ( send an email about process outcome )" echo " -h ( display this help )" echo exit } -[ "$#" = 0 ] && usage -check_dependencies "${dependencies[@]}" - -cleanup(){ - log -a "Process aborted" - exit 1 -} - -trap cleanup SIGHUP SIGINT SIGTERM +[ "${#}" = 0 ] && usage # command-line options to set mediaid and original variables OPTIND=1 -while getopts ":hd:e:n" opt; do - case "$opt" in +while getopts ":o:d:e:E:nh" opt ; do + case "${opt}" in + o) outputdir="$OPTARG" && check_outputdir ;; + d) deliverdir="$OPTARG" && check_deliverdir ;; + e) emailaddress_delivery="$OPTARG" && check_emailaddress "${emailaddress_delivery}" ;; + E) emailaddress_outcome="$OPTARG" && check_emailaddress "${emailaddress_outcome}" ;; n) DRYRUN=true;; h) usage ;; - d) - deliverdir="$OPTARG" - [ ! -d "$deliverdir" ] && report -wt "The delivery directory, ${deliverdir}, does not exist. Can not deliver the output of $(basename "$0")." - ;; - e) emailaddress="$OPTARG" ;; *) echo "bad option -$OPTARG" ; usage ;; :) echo "Option -$OPTARG requires an argument" ; exit 1 ;; esac done shift $(( ${OPTIND} - 1 )) -while [ "$*" != "" ] ; do +while [ "${*}" != "" ] ; do + # get context about the input input="$1" - [ -d "$input" ] && { outputdir="$input/objects/access/youtube_up" && logdir="$input/metadata/submissionDocumentation/logs" ;}; - [ -f "$input" ] && { outputdir=$(dirname "$input")"/access/youtube_up" && logdir="$(dirname "$input")/access/logs" ;}; - [ ! "$outputdir" ] && { outputdir="$input/objects/access/youtube_up" && logdir="$input/metadata/submissionDocumentation/logs" ;}; - find_input "$input" - - mediaid=$(basename "$1" | cut -d. -f1) - - log -b + if [ -z "${outputdir}" ] ; then + [ -d "${input}" ] && { outputdir="${input}/objects/access/youtube_up" && logdir="${input}/metadata/submissionDocumentation/logs" ;}; + [ -f "${input}" ] && { outputdir=$(dirname "${input}")"/access/youtube_up" && logdir="$(dirname "${input}")/access/logs" ;}; + [ ! "${outputdir}" ] && { outputdir="${input}/objects/access/youtube_up" && logdir="${input}/metadata/submissionDocumentation/logs" ;}; + else + logdir="${outputdir}/logs" + fi + _find_input "${input}" + mediaid=$(basename "${input}" | cut -d. -f1) - youtubeoutput="${outputdir}/${mediaid%.*}.mp4" - [ -s "${youtubeoutput}" ] && { report -wt "WARNING ${youtubeoutput} already exists, skipping transcode" ; [ "$#" = 1 ] && exit 86 || { shift ; continue ;} ;}; + # set up output + _log -b + output="${outputdir}/${mediaid%.*}.mp4" + [ -s "${output}" ] && { report -wt "WARNING ${output} already exists, skipping transcode" ; shift ; continue ;}; _run mkdir -p "${outputdir}" + + # get information on the input get_height "${sourcefile}" get_width "${sourcefile}" + # clear local arrays unset inputoptions - inputoptions+=(-vsync 0) unset middleoptions + + # encoding options + inputoptions+=(-vsync 0) middleoptions+=(-movflags faststart) middleoptions+=(-pix_fmt yuv420p) middleoptions+=(-c:v libx264) @@ -86,28 +83,16 @@ while [ "$*" != "" ] ; do middleoptions+=(-ac 2) middleoptions+=(-b:a 128k) middleoptions+=(-f mp4) - + get_audio_mapping "${sourcefile}" middleoptions+=(${audiomapping_ffmpeg[@]}) - if [ "${logdir}" != "" ] ; then - _run mkdir -p "${logdir}" - export FFREPORT="file=${logdir}/%p_%t_$(basename $0)_${version}.txt" - inputoptions+=(-v warning -stats) - fi - report -dt "Working on $(basename "${youtubeoutput}") for youtube upload." - report -dt "Running: ffmpeg ${inputoptions[@]} -i \"${sourcefile}\" ${middleoptions[@]} \"${youtubeoutput}\"" - ffmpeg ${inputoptions[@]} -i "${sourcefile}" ${middleoptions[@]} "${youtubeoutput}" + _prep_ffmpeg_log + _run_critical ffmpeg ${inputoptions[@]} -i "${sourcefile}" ${middleoptions[@]} "${output}" echo - report -dt "$(basename "${youtubeoutput}") is done." - if [ -d "${deliverdir}" ] ; then - report -dt "Delivering output" - cp -av "${youtubeoutput}" "${deliverdir}/" - cp_exit="$?" - if [[ "${emailaddress}" == "Y" ]] ; then - echo -e "Subject: $(basename ${youtubeoutput}) delivered\nBody A file has been delivered to ${deliverdir}.\n\n Filename: ${youtubeoutput}\nProcess: $(basename $0)\nMediaID: ${mediaid}\nSourcefile: ${sourcefile}\nDecoding_options: ${inputoptions[@]}\nEncoding_options: ${middleoptions[@]}\nOperator ${op}.\n\nEnjoy!" | sendmail "${emailaddress}" - fi - fi + _summarize_make + _deliver_output + _email_outcome shift - log -e + _log -e done diff --git a/mmfunctions b/mmfunctions index 783a7108..5a7ebdbf 100755 --- a/mmfunctions +++ b/mmfunctions @@ -19,7 +19,7 @@ get_iso8601_c(){ date +%Y%m%d-%I%M%S } -log(){ +_log(){ mmlogname="mm.log" mmlogdir="${CUSTOM_LOG_DIR:-/tmp}" mmlogfile="${mmlogdir}/${mmlogname}" @@ -68,14 +68,26 @@ report(){ shift $(( ${OPTIND} - 1 )) message="$1" echo $echoopt "${color}${startmessage[@]}${message}${NC}" - [ "$log" = "Y" ] && log -w "$message" + [ "$log" = "Y" ] && _log -w "$message" } -function _run(){ +_run(){ + run_err="" + report -sdt "Running: $*" if [[ ! $DRYRUN == true ]] ; then - "$@" - else - report -sdt "Running: $*" + "$@" + fi + run_err="$?" + if [[ "${run_err}" != 0 ]] ; then + report -wts "Error: Running: \"$*\" gave an Error Code - $run_err" + fi +} + +_run_critical(){ + _run "${@}" + if [[ "${run_err}" != 0 ]] ; then + report -wts "The process ran into a critical error and can not proceed." + exit 1 fi } @@ -158,6 +170,82 @@ check_dependencies(){ fi } +_initialize_make(){ + check_dependencies "${dependencies[@]}" + unset dependencies + unset audiomapping_ffmbc + deliverdir="" + DRYRUN=false + emailaddress="" + cleanup(){ + _log -a "Process aborted" + echo + report -wts "THE PROCESS WAS ABORTED" + exit 1 + } + trap cleanup SIGHUP SIGINT SIGTERM +} + +check_deliverdir(){ + if [ ! -d "$deliverdir" ] ; then + report -wt "The delivery directory, ${deliverdir}, does not exist. Can not deliver the output of $(basename "$0")." + fi +} + +check_outputdir(){ + if [ ! -d "$outputdir" ] ; then + report -wt "The output directory, ${outputdir}, does not exist. Can not write the output of $(basename "$0")." + fi +} + +check_emailaddress(){ + emailregex="^[a-z0-9!#\$%&'*+/=?^_\`{|}~-]+(\.[a-z0-9!#$%&'*+/=?^_\`{|}~-]+)*@([a-z0-9]([a-z0-9-]*[a-z0-9])?\.)+[a-z0-9]([a-z0-9-]*[a-z0-9])?\$" + if [[ ! "$1" =~ "$emailregex" ]] ; then + report -wt "$1 is not a valid email address." + fi +} + +email_delivery(){ + if [[ "${emailaddress}" == "Y" ]] ; then + echo -e "Subject: $(basename ${youtubeoutput}) delivered + A file has been delivered to ${deliverdir}. + + Filename: ${youtubeoutput} + Process: $(basename $0) + MediaID: ${mediaid} + Sourcefile: ${sourcefile} + Decoding_options: ${inputoptions[@]} + Encoding_options: ${middleoptions[@]} + Operator ${op}. + + Enjoy!" | sendmail "${emailaddress}" + fi +} + +_email_outcome(){ + if [[ "${emailaddress}" == "Y" ]] ; then + echo -e "Subject: $(basename ${youtubeoutput}) processed + Delivery directory: ${deliverdir}. + Filename: ${youtubeoutput} + Process: $(basename $0) + MediaID: ${mediaid} + Sourcefile: ${sourcefile} + Decoding_options: ${inputoptions[@]} + Encoding_options: ${middleoptions[@]} + Operator ${op}. + + Enjoy!" | sendmail "${emailaddress}" + fi +} + +_deliver_output(){ + if [[ "${deliverdir}" ]] ; then + report -dt "Delivering ${output} to ${deliverdir}" + _run cp -av "${output}" "${deliverdir}/" + email_delivery + fi +} + ask(){ # This function requires 3 arguments # 1) A prompt @@ -214,7 +302,7 @@ make_mezz_for_xdcam(){ popd } -find_input (){ +_find_input (){ sourcefile="" [ -d "$1" ] && [ -d "$1/objects/service" ] && sourcefile=$(find "$1/objects/service" -maxdepth 1 -mindepth 1 -type f \( -name "*.mov" -o -name "*.mxf" -o -name "*.mp4" -o -name "*.dv" \) ! -name ".*") [ -f "$1" ] && sourcefile="$1" @@ -367,3 +455,17 @@ free_space(){ exit 1 fi } + +_summarize_make(){ + report -dt "$(basename "${output}") is done." +} + +_prep_ffmpeg_log(){ + if [ "${logdir}" != "" ] ; then + _run mkdir -p "${logdir}" + export FFREPORT="file=${logdir}/%p_%t_$(basename "$0")_${version}.txt" + inputoptions+=(-v warning -stats) + else + export FFREPORT="" + fi +} diff --git a/paperingest b/paperingest index 4ab0a375..cc101801 100755 --- a/paperingest +++ b/paperingest @@ -5,12 +5,12 @@ scriptdir=$(dirname "$0") . "$scriptdir/mmfunctions" || { echo "Missing '$scriptdir/mmfunctions'. Exiting." ; exit 1 ;}; cleanup(){ - log -a "Process aborted" + _log -a "Process aborted" exit 1 } trap cleanup SIGHUP SIGINT SIGTERM -log -b +_log -b ask_operator @@ -56,4 +56,4 @@ echo "command: ${command}" >> "$submissionMetadataDir/operation_process.txt" echo done scanning "$mediaid" -log -e +_log -e diff --git a/quickcompare b/quickcompare index 06f121fd..03f375e5 100755 --- a/quickcompare +++ b/quickcompare @@ -6,16 +6,16 @@ scriptdir=$(dirname "$0") . "$scriptdir/mmfunctions" || { echo "Missing '$scriptdir/mmfunctions'. Exiting." ; exit 1 ;}; cleanup(){ - log -a "Process aborted" + _log -a "Process aborted" exit 1 } trap cleanup SIGHUP SIGINT SIGTERM -log -b +_log -b [ ! "$#" = "2" ] && { echo Use two possibly similar files are arguments. ; exit 1 ;}; #[ ! $(du "$1" | cut -f1) = $(du "$2" | cut -f1) ] && echo The files are different sizes [ ! $(head -c "$checksize" "$1" | md5) = $(head -c "$checksize" "$2" | md5) ] && echo The first "$checksize" bytes have different md5s. [ ! $(tail -c "$checksize" "$1" | md5) = $(tail -c "$checksize" "$2" | md5) ] && echo The last "$checksize" bytes have different md5s. -log -e +_log -e diff --git a/removeDSStore b/removeDSStore index f4a931dd..5251829f 100755 --- a/removeDSStore +++ b/removeDSStore @@ -5,12 +5,12 @@ scriptdir=$(dirname "$0") . "$scriptdir/mmfunctions" || { echo "Missing '$scriptdir/mmfunctions'. Exiting." ; exit 1 ;}; cleanup(){ - log -a "Process aborted" + _log -a "Process aborted" exit 1 } trap cleanup SIGHUP SIGINT SIGTERM -log -b +_log -b while [ "$*" != "" ] ; do target=$1 @@ -19,4 +19,4 @@ while [ "$*" != "" ] ; do fi shift done -log -e +_log -e diff --git a/uploadomneon b/uploadomneon index 5ed76b40..c16115c3 100755 --- a/uploadomneon +++ b/uploadomneon @@ -10,7 +10,7 @@ scriptdir=$(dirname "$0") usage(){ echo - echo "$(basename $0) ${version}" + echo "$(basename ${0}) ${version}" echo "This application will upload file(s) to a server via rsync in sequential order. Options are specified via 'mmconfig'." echo echo "Settings:" @@ -25,12 +25,12 @@ usage(){ [ "$#" = 0 ] && usage cleanup(){ - log -a "Process aborted" + _log -a "Process aborted" exit 1 } trap cleanup SIGHUP SIGINT SIGTERM -log -b +_log -b # command-line options to set mediaid and original variables OPTIND=1 @@ -54,7 +54,7 @@ sourcefile="$1" removetmp="n" filename=$(basename "$sourcefile") -log -b +_log -b status=$(ftp -a "$OMNEONIP" <