forked from carevealed/cavppers
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmakeprestarget
executable file
·135 lines (127 loc) · 6.1 KB
/
makeprestarget
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
#!/bin/bash
# makeprestarget, makes a file according to the video preservation master specifications listed at http://calpreservation.org/wp-content/uploads/2013/10/CAVPPTargetAudioandVideo-Specs2013_IMLS.pdf as of March 10, 2014
version="1.0"
scriptname=$(basename $(which "$0"))
scriptdir=$(dirname $(which "$0"))
. "$scriptdir/cavpperfunctions" || { echo "Missing '$scriptdir/cavpperfunctions'. Exiting." ; exit 1 ;};
dependencies=(ffmpeg ffprobe)
default_input_framerate=18
extension="_prsv"
_initialize_make
usage(){
echo
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 " -p ( use prores for the output video codec instead of defaults )"
echo " -c ( crop out the center 960x720 of the input video, this is intended to process certain film scans )"
echo " -r framerate ( specify a framerate to interpret to input, used only for dpx and bmp image sequences. If not declared the script will use $default_input_framerate fps as a default )"
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
echo " Examples:"
echo " To read a series of BMP files as 24 frames per second and convert to default settings"
echo " ${scriptname} -r 24 100001.BMP"
echo
echo " To transcode a batch of files to the default settings but use the prores video codec"
echo " ${scriptname} -p firstfile.avi secondfile.mov thirdfile.mkv"
echo
exit
}
[ "${#}" = 0 ] && usage
# command-line options to set mediaid and original variables
OPTIND=1
while getopts ":pcr:o:d:e:E:nh" opt ; do
case "${opt}" in
p) prores="Y" ;;
c) crop="Y" ;;
r) inputframerate="$OPTARG" ;;
o) outputdir_forced="$OPTARG" && _check_outputdir_forced ;;
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 "bad option -$OPTARG" ; usage ;;
:) echo "Option -$OPTARG requires an argument" ; exit 1 ;;
esac
done
shift $(( ${OPTIND} - 1 ))
while [ "${*}" != "" ] ; do
input="$1"
if [[ ! "${outputdir}" ]] ; then
outputdir="$(dirname "$input")/$(basename $0)" # default output directory, override with -o
fi
# get context about the input
if [ -z "${outputdir_forced}" ] ; then
[ -d "${input}" ] && { outputdir="${input}/transcoded" && logdir="${input}/logs" ;};
[ -f "${input}" ] && { outputdir=$(dirname "${input}")"/transcoded" && logdir="$(dirname "${input}")/logs" ;};
[ ! "${outputdir}" ] && { outputdir="${input}/transcoded" && logdir="${input}/logs" ;};
else
outputdir="${outputdir_forced}"
logdir="${outputdir}/logs"
fi
_find_input "${input}"
mediaid=$(basename "${input}" | cut -d. -f1)
# set up output
_log -b
if [[ "${prores}" == "Y" ]] ; then
extension="${extension}_prores"
fi
if [[ "${crop}" == "Y" ]] ; then
croppingprocess="crop=960:720,"
extension="${extension}_cropped"
else
croppingprocess=""
fi
output="${outputdir}/${mediaid%.*}${extension}.mov"
[ -s "${output}" ] && { report -wt "WARNING ${output} already exists, skipping transcode" ; shift ; continue ;};
_run mkdir -p "${outputdir}"
# clear local arrays
unset inputoptions
unset middleoptions
get_videocodecname "${input}"
get_videostreamcount "${input}"
get_audiostreamcount "${input}"
# encoding options
if [[ "${VIDEOCODECNAME}" == "bmp" || "${VIDEOCODECNAME}" == "dpx" ]] ; then
inputoptions+=(-f image2)
if [[ "${inputframerate}" ]] ; then
inputoptions+=(-r:v "${inputframerate}")
else
inputoptions+=(-r:v 18) # otherwise set to a default input frame rate
fi
start_number=$(basename "$sourcefile" | grep -o '[0-9]\{6\}')
inputoptions+=(-start_number "${start_number}")
sourcefile=$(echo "$sourcefile" | sed "s/${start_number}/%06d/")
fi
if [[ "${VIDEOSTREAMCOUNT}" > 0 ]] ; then
middleoptions+=(-map 0:v) # process all video streams of the input
if [[ "${prores}" == "Y" ]] ; then
middleoptions+=(-c:v prores) # force video codec to prores (10 bit 4:2:2)
else
middleoptions+=(-c:v v210) # force video codec to v210 (10 bit 4:2:2 uncompressed)
fi
middleoptions+=(-r:v ntsc) # force NSTC frame rate
middleoptions+=(-vf "${croppingprocess}scale=720:486:interl=1,setdar=4/3") # scale to 720x486 with interlace awareness and set display aspect ratio to 4/3
fi
if [[ "${AUDIOSTREAMCOUNT}" > 0 ]] ; then
middleoptions+=(-map 0:a) # process all audio streams of the input
middleoptions+=(-c:a pcm_s24le) # force audio codec to pcm_s24le (uncompressed signed, 24 bit little endian, audio samples)
middleoptions+=(-ac 2) # force audio to 2 channel configuration
middleoptions+=(-ar 48k) # force audio to 48kHz sampling rate
fi
middleoptions+=(-f mov) # force quicktime format
_prep_ffmpeg_log
_run ffmpeg ${inputoptions[@]} -i "${sourcefile}" ${middleoptions[@]} "${output}"
echo
_summarize_make
_deliver_output
shift
_log -e
done