forked from mediamicroservices/mm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
makeflv
executable file
·121 lines (111 loc) · 4.6 KB
/
makeflv
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
#!/bin/bash
# makeflv, makes a crappy flash file
VERSION="1.0"
SCRIPTDIR=$(dirname $(which "${0}"))
. "${SCRIPTDIR}/mmfunctions" || { echo "Missing '${SCRIPTDIR}/mmfunctions'. Exiting." ; exit 1 ;};
DEPENDENCIES=(ffmpeg)
_initialize_make
SUFFIX=""
EXTENSION="flv"
RELATIVEPATH="access/flv"
OUTPUTDIR="${HOME}/Desktop/$(basename ${0})" # default output directory, override with -o
_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 " -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 ":o:d:e:E:nh" OPT ; do
case "${OPT}" in
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" ; _writeerrorlog "makeflv" "The option selected required an argument and none was provided. The script had to exit." ; 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/logs" ;};
[ -f "${INPUT}" ] && { OUTPUTDIR=$(dirname "${INPUT}")"/${RELATIVEPATH}" && LOGDIR="$(dirname "${INPUT}")/${RELATIVEPATH}/logs" ;};
[ ! "${OUTPUTDIR}" ] && { OUTPUTDIR="${INPUT}/objects/${RELATIVEPATH}" && LOGDIR="${INPUT}/metadata/logs" ;};
else
OUTPUTDIR="${OUTPUTDIR_FORCED}"
LOGDIR="${OUTPUTDIR}/logs"
fi
_unset_variables
_find_input "${INPUT}"
MEDIAID=$(basename "${INPUT}" | cut -d. -f1)
_set_up_output
# 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+=(-map 0:v)
MIDDLEOPTIONS+=(-c:v libx264)
MIDDLEOPTIONS+=(-pix_fmt yuv420p)
MIDDLEOPTIONS+=(-b:v 4500k)
MIDDLEOPTIONS+=(-s 480x360)
_add_video_filter "setdar=4/3"
_add_video_filter "setsar=1/1"
fi
if [[ "${AUDIOSTREAMCOUNT}" > 0 ]] ; then
_get_audio_index "${SOURCEFILE}"
_get_audio_mapping "${SOURCEFILE}"
MIDDLEOPTIONS+=(-map 0:a)
MIDDLEOPTIONS+=(-sample_fmt s16p)
MIDDLEOPTIONS+=(-ar 44100)
MIDDLEOPTIONS+=(-b:a 320k)
MIDDLEOPTIONS+=(-ac 2)
fi
# set in and out times if used
INGESTLOG="${LOGDIR}/capture.log"
if [[ -f "${INGESTLOG}" && "${ISOBJECT}" = "Y" ]] ; then
INTIME=$(_readingestlog "intime")
OUTTIME=$(_readingestlog "outtime")
if [[ "${INTIME}" ]] ; then
_report -dt "ATTENTION: Transcoding will use intime (${INTIME}) during transcoding."
INPUTOPTIONS+=(-seek_timestamp 1)
MIDDLEOPTIONS+=(-ss "${INTIME}")
fi
if [[ "${OUTTIME}" ]] ; then
_report -dt "ATTENTION: Transcoding will use outtime (${OUTTIME}) during transcoding."
MIDDLEOPTIONS+=(-to "${OUTTIME}")
fi
fi
_prep_ffmpeg_log
if [ "${CONCATSOURCE}" != "" ] ; then
FFMPEGINPUT="${CONCATSOURCE}"
fi
_filter_to_middle_option
_run_critical ffmpeg "${INPUTOPTIONS[@]}" "${FFMPEGINPUT[@]}" "${MIDDLEOPTIONS[@]}" "${OUTPUT}"
echo
_summarize_make
_deliver_output
_log -e
done