forked from mediamicroservices/mm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmakeyoutube
executable file
·148 lines (140 loc) · 5.57 KB
/
makeyoutube
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
#!/bin/bash
# makeyoutube, makes a file appropriate for uploading to youtube
version="1.0"
scriptdir=$(dirname $(which "${0}"))
. "${scriptdir}/mmfunctions" || { echo "Missing '${scriptdir}/mmfunctions'. Exiting." ; exit 1 ;};
dependencies=(ffmpeg ffprobe)
_initialize_make
suffix=""
extension="mp4"
relativepath="access/youtube_up"
unset YOUTUBEUPLOAD
usage(){
echo
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 " -l (only use the left channel of the first audio track)"
echo " -r (only use the right channel of the first audio track)"
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 " -Y ( attempt to use uploadyoutube on the resulting file )"
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:nhY" opt ; do
case "${opt}" in
l) audiomap="L";;
r) audiomap="R";;
v) VOLADJUST="${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;;
Y) YOUTUBEUPLOAD="Y";;
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/${relativepath}" && logdir="${input}/metadata/submissionDocumentation/logs" ;};
[ -f "${input}" ] && { outputdir=$(dirname "${input}")"/${relativepath}" && logdir="$(dirname "${input}")/${relativepath}/logs" ;};
[ ! "${outputdir}" ] && { outputdir="${input}/objects/${relativepath}" && logdir="${input}/metadata/submissionDocumentation/logs" ;};
else
outputdir="${outputdir_forced}"
logdir="${outputdir}/logs"
fi
_find_input "${input}"
mediaid=$(basename "${input}" | cut -d. -f1)
ingestlog="${logdir}/capture.log"
_set_up_output
# get information on the input
get_height "${sourcefile}"
get_width "${sourcefile}"
_get_seconds "${sourcefile}"
# clear local arrays
unset inputoptions
unset middleoptions
unset audiomapping_ffmpeg
# encoding options
get_codectagstring "${sourcefile}"
get_videostreamcount "${sourcefile}"
get_audiostreamcount "${sourcefile}"
inputoptions+=(-vsync 0)
inputoptions+=(-nostdin)
if [[ "${VIDEOSTREAMCOUNT}" > 0 ]] ; then
if [[ "${codec_tag_string}" == "mjp2" ]] ; then
inputoptions+=(-vcodec libopenjpeg)
fi
middleoptions+=(-movflags faststart)
middleoptions+=(-pix_fmt yuv420p)
middleoptions+=(-c:v libx264)
middleoptions+=(-crf 18)
if [ "${seconds%.*}" -gt "7200" ] ; then
middleoptions+=(-maxrate 2190k)
elif [ "${seconds%.*}" -gt "3600" ] ; then
middleoptions+=(-maxrate 4380k)
else
middleoptions+=(-maxrate 8760k)
fi
middleoptions+=(-bufsize 1835k)
if [[ "${width}" == 720 && "${height}" == 486 ]] ; then
middleoptions+=(-vf "crop=720:480:0:4,yadif")
elif [[ "${width}" == 720 && "${height}" == 512 ]] ; then
middleoptions+=(-vf "crop=720:480:0:32,yadif")
else
middleoptions+=(-vf yadif)
fi
fi
if [[ "${AUDIOSTREAMCOUNT}" > 0 ]] ; then
middleoptions+=(-c:a aac -strict -2)
middleoptions+=(-ac 2)
middleoptions+=(-b:a 128k)
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
middleoptions+=(-f mp4)
_prep_ffmpeg_log
_prep_volume_adjustment
if [ "${concatsource}" != "" ] ; then
ffmpeginput="${concatsource}"
else
ffmpeginput="${sourcefile}"
fi
_run_critical ffmpeg ${inputoptions[@]} -i "${ffmpeginput}" ${middleoptions[@]} "${output}"
echo
_summarize_make
_deliver_output "${MAKEYOUTUBE_DELIVERY_EMAIL_TO}"
if [[ "${YOUTUBEUPLOAD}" == "Y" ]] ; then
if [ $(which uploadyoutube) ] ; then
report -dt "Attempting to run uploadyoutube on ${output}"
uploadyoutube "${output}"
echo "$(get_iso8601),${output},attempted upload,$?" >> "$HOME/Desktop/upload.log"
else
report -wt "$(basename "${output}") qualified for uploadyoutube but it is not installed."
fi
fi
_log -e
done