forked from mediamicroservices/mm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmakedvd
executable file
·166 lines (159 loc) · 7.03 KB
/
makedvd
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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
#!/bin/bash
# makedvd
version="1.0"
scriptdir=$(dirname $(which "${0}"))
. "${scriptdir}/mmfunctions" || { echo "Missing '${scriptdir}/mmfunctions'. Exiting." ; exit 1 ;};
dependencies=(ffmpeg ffprobe dvdauthor mkisofs)
_initialize_make
suffix=""
extension="iso"
usage(){
echo
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 " -l (only use the left channel of the first audio track)"
echo " -r (only use the right channel of the first audio track)"
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 " -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
# command-line options to set mediaid and original variables
OPTIND=1
while getopts ":lrv:o:d:e:E:nth" opt ; do
case "${opt}" in
l) audiomap="L";;
r) audiomap="R";;
v) DVDLABELPREFIX="$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}" ;;
t) TCBURN=Y;;
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
# get context about the input
input="${1}"
shift
if [ -z "${outputdir_forced}" ] ; 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
outputdir="${outputdir_forced}"
logdir="${outputdir}/logs"
fi
_find_input "${input}"
mediaid=$(basename "${input}" | cut -d. -f1)
_set_up_output
# get information on the input
get_height "${sourcefile}"
get_width "${sourcefile}"
get_dar "${sourcefile}"
darratio=$(echo "scale=3 ; $dar" | bc)
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
unset audiomapping_ffmpeg
get_videostreamcount "${sourcefile}"
get_audiostreamcount "${sourcefile}"
# encoding options
inputoptions+=" -y"
inputoptions+=(-nostdin)
if [[ "${VIDEOSTREAMCOUNT}" > 0 ]] ; then
get_codectagstring "${sourcefile}"
TIMECODEOVERLAY=""
if [ "${TCBURN}" = "Y" ] ; then
_get_timecode_overlay "${sourcefile}"
fi
if [[ "${codec_tag_string}" == "mjp2" ]] ; then
inputoptions+=(-vcodec libopenjpeg)
fi
middleoptions+=(-r:v ntsc)
middleoptions+=(-c:v mpeg2video)
middleoptions+=(-c:a ac3)
middleoptions+=(-f dvd)
middleoptions+=(-bf 2)
middleoptions+=(-qscale:v 2)
middleoptions+=(-mbd rd)
middleoptions+=(-s 720x480)
middleoptions+=(-pix_fmt yuv420p)
middleoptions+=(-g 18)
middleoptions+=(-b:v $MAXDVDBITRATE)
middleoptions+=(-bt 400k)
middleoptions+=(-top 0)
middleoptions+=(-flags +ildct+ilme)
middleoptions+=(-maxrate $MAXDVDBITRATE)
middleoptions+=(-minrate 0)
middleoptions+=(-bufsize 3600k)
middleoptions+=(-packetsize 2048)
middleoptions+=(-muxrate 10080000)
middleoptions+=(-lmin 1)
middleoptions+=(-lmax 200000)
if [[ "${width}" == 720 && "${height}" == 486 ]] ; then
middleoptions+=(-vf "fieldorder=bff,crop=720:480:0:4,setdar=${aspect}${TIMECODEOVERLAY}" -aspect ${aspect})
elif [[ "${width}" == 720 && "${height}" == 480 ]] ; then
middleoptions+=(-vf "fieldorder=bff,setdar=${aspect}${TIMECODEOVERLAY}" -aspect ${aspect})
elif [[ "${width}" == 720 && "${height}" == 512 ]] ; then
middleoptions+=(-vf "fieldorder=bff,crop=720:480:0:32,setdar=${aspect}${TIMECODEOVERLAY}" -aspect ${aspect})
else
middleoptions+=(-vf "fieldorder=bff,scale=720:480:interl=1,setdar=${aspect}${TIMECODEOVERLAY}" -aspect ${aspect})
fi
fi
if [[ "${AUDIOSTREAMCOUNT}" > 0 ]] ; then
middleoptions+=(-b:a 448000)
middleoptions+=(-ar 48000)
get_audio_index "${sourcefile}"
if [ "${audiomap}" = "L" ] ; then
audiomapping_ffmpeg=(-map_channel 0.${audio_index_1}.0)
elif [ "${audiomap}" = "R" ] ; then
audiomapping_ffmpeg=(-map_channel 0.${audio_index_1}.1)
else
get_audio_mapping "${sourcefile}"
fi
middleoptions+=(${audiomapping_ffmpeg[@]})
fi
_prep_ffmpeg_log
# making the initial mpeg2 for the dvd
if [ "${concatsource}" != "" ] ; then
ffmpeginput="${concatsource}"
else
ffmpeginput="${sourcefile}"
fi
_run_critical ffmpeg ${inputoptions[@]} -i "${ffmpeginput}" ${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
_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}")
_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
_log -e
done