-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy pathmakedvd
executable file
·119 lines (104 loc) · 4.71 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
#!/bin/bash
# makedvd
# make dvd
version="1.0"
scriptdir=`dirname "$0"`
. "$scriptdir/mmfunctions" || { echo "Missing '$scriptdir/mmfunctions'. Exiting." ; exit 1 ;};
cleanup(){
log -a "Process aborted"
exit 1
}
trap cleanup SIGHUP SIGINT SIGTERM
usage(){
echo
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 ] [ -f sourcefile ] [ -v dvd_label_prefix ]"
echo " -m mediaid"
echo " -f sourcefile"
echo " -v dvdlabelprefix"
echo " -h display this help"
echo
exit
}
# command-line options to set mediaid and original variables
OPTIND=1
while getopts ":hm:f:v:" opt; do
case "$opt" in
h) usage ;;
m) mediaid="$OPTARG";;
f) input="$OPTARG" ; once="y" ;;
v) DVDLABELPREFIX="$OPTARG";;
*) echo "bad option -$OPTARG" ; usage ;;
:) echo "Option -$OPTARG requires an argument" ; exit 1 ;;
esac
done
shift $(( ${OPTIND} - 1 ))
check_dependencies ffmpeg dvdauthor mkisofs
[ "$#" = 0 -a ! "$input" ] && { ask_input ; once="y" ;};
while [ "$*" != "" -o "$once" = "y" ] ; do
once="n"
[ "$#" != 0 ] && 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"
filename=`basename "$sourcefile"`
mediaid=`basename "$input" | cut -d. -f1`
log -b
isooutput="$outputdir/${mediaid%.*}.iso"
[ -s "$isooutput" ] && { report -wt "WARNING $isooutput already exists, skipping transcode" ; exit 1 ;};
mkdir -p "$outputdir"
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" ;};
get_maxdvdbitrate "$sourcefile"
middleoptions="-r:v ntsc -c:v mpeg2video -c:a ac3 -f dvd -s 720x480 -pix_fmt yuv420p -g 18 -b:v $MAXDVDBITRATE -maxrate 9000k -minrate 0 -bufsize 1835008 -packetsize 2048 -muxrate 10080000 -b:a 448000 -ar 48000 "
if [ "$height" -eq "486" -a "$width" -eq "720" ] ; then
middleoptions+=" -vf \"crop=720:480:0:4,setdar=${aspect}\" -aspect $aspect "
elif [ "$height" -eq "480" -a "$width" -eq "720" ] ; then
middleoptions+=" -vf \"setdar=${aspect}\" -aspect $aspect "
elif [ "$height" -eq "512" -a "$width" -eq "720" ] ; then
middleoptions+=" -vf \"crop=720:480:0:32,setdar=${aspect}\" -aspect $aspect "
else
middleoptions+=" -vf \"scale=720:480:interl=1,setdar=${aspect}\" -aspect $aspect "
fi
inputoptions+=" -y"
if [ "$logdir" != "" ] ; then
mkdir -p "$logdir"
export FFREPORT="file=${logdir}/%p_%t_$(basename $0)_${version}.txt"
inputoptions+=" -report"
fi
report -dt "Transcoding to DVD compliant mpeg2."
dvdffmpegcommand="ffmpeg $inputoptions -i \"$sourcefile\" $middleoptions \"$outputdir/${mediaid%.*}.mpeg\""
report -dt "Running: $dvdffmpegcommand"
eval "$dvdffmpegcommand"
export VIDEO_FORMAT=NTSC
# chapters every 5 minutes, dvdauthor will ignore chapter markers greater than duration
report -dt "Making DVD VIDEO_TS folder."
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
rm "$outputdir/${mediaid%.*}.mpeg"
fi
dvdauthor -T -o "$outputdir/${mediaid%.*}/"
volname=`echo "${DVDLABELPREFIX}${mediaid}"`
report -dt "Making DVD image file."
mkisofs -f -dvd-video -udf -V "${volname:0:32}" -v -v -o "$outputdir/${mediaid%.*}.iso" "$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 $outputdir/${mediaid%.*}.iso."
exit "$mkisofs_err"
else
rm -r "$outputdir/${mediaid%.*}/"
fi
report -dt "STATUS ${mediaid%.*}.iso is generated."
shift
done
log -e