forked from mediamicroservices/mm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
makemp3
executable file
·93 lines (81 loc) · 3.03 KB
/
makemp3
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
#!/bin/bash
# makemp3
version="1.0"
unset dependencies
dependencies=(ffmpeg normalize)
suffix=""
extension="mp3"
relativepath="access/mp3"
scriptdir=$(dirname "${0}")
. "${scriptdir}/mmfunctions" || { echo "Missing '${scriptdir}/mmfunctions'. Exiting." ; exit 1 ;};
usage(){
echo
echo "$(basename "${0}") ${version}"
echo "This application will create an mp3 file 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 " -o directory ( directory to write the resulting file to )"
echo " -h ( display this help )"
echo
exit
}
[ "${#}" = 0 ] && usage
check_dependencies "${dependencies[@]}"
cleanup(){
_log -a "Process aborted"
exit 1
}
trap cleanup SIGHUP SIGINT SIGTERM
OPTIND=1
while getopts ":ho:" opt; do
case "${opt}" in
h) usage ;;
o) outputdir="${OPTARG}"
if [ ! -d "${outputdir}" ] ; then
report -wt "The output directory option, ${outputdir}, does not refer to an actual directory. Quitting."
exit 1
fi
;;
*) echo "bad option -${OPTARG}" ; usage ;;
:) echo "Option -${OPTARG} requires an argument" ; exit 1 ;;
esac
done
shift $(( ${OPTIND} - 1 ))
while [ "${*}" != "" ] ; do
input="${1}"
if [ -z "${outputdir}" ] ; 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
logdir="${outputdir}/logs"
fi
_find_input "${input}"
filename=$(basename "${sourcefile}")
mediaid=$(basename "${input}" | cut -d. -f1)
_log -b
_set_up_output
unset inputoptions
unset middleoptions
inputoptions+=(-nostdin)
middleoptions+=(-map 0:a:0)
middleoptions+=(-ac 2)
middleoptions+=(-r:a 44100)
middleoptions+=(-sample_fmt s16p)
get_audio_mapping "${sourcefile}"
middleoptions+=(${audiomapping_ffmpeg[@]})
if [ "${logdir}" != "" ] ; then
mkdir -p "${logdir}"
export FFREPORT="file=${logdir}/%p_%t_$(basename "${0}")_${version}.txt"
inputoptions+=(-v warning -stats)
fi
report -dt "Working on $(basename "${output}")."
report -dt "Running: ffmpeg ${inputoptions[@]} -i \"${sourcefile}\" ${middleoptions[@]} \"${output}\""
ffmpeg ${inputoptions[@]} -i "${sourcefile}" ${middleoptions[@]} "${output}"
report -dt "Adjusting highest audio peak to full scale..."
normalize --peak -v "${output}"
echo
report -dt "$(basename ${output}) is done."
shift
_log -e
done