-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathextract-audio
More file actions
executable file
·44 lines (39 loc) · 896 Bytes
/
extract-audio
File metadata and controls
executable file
·44 lines (39 loc) · 896 Bytes
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
#!/bin/bash
ECHO="echo"
FIND="find"
REV="rev"
CUT="cut"
CAT="cat"
FFMPEG="ffmpeg"
EXEC="exec"
PATTERN=$1
UNIQUE="${RANDOM}_`date +%s`"
ERR=/tmp/err_${UNIQUE}
OUT=/tmp/out_${UNIQUE}
IFS=$(${ECHO} -en "\n\b") # Set the field separator newline
if [[ $# == 0 ]]; then
${ECHO} "Usage:"
${ECHO} "-------------"
${ECHO} "extractAudio <source file name pattern>"
${ECHO} ""
exit
fi
${ECHO}
for f in `${FIND} -iname $PATTERN`
do
target="`${ECHO} ${f}|${REV}|${CUT} -d"." -f2-|${REV}`.mp3"
${ECHO}
${ECHO} " ### Extracting audio..."
${ECHO} " from \"${f}\""
${ECHO} " to \"${target}\""
${FFMPEG} -i "$f" -acodec libmp3lame -ac 2 -ab 320k -vn -y $target 2>${ERR} >${OUT}
if [[ ! $? -eq 0 ]]; then
${ECHO}
${ECHO} "Error Occurred"
${ECHO} "====================="
${CAT} ${OUT}
${CAT} ${ERR}
fi
done
rm $ERR
rm $OUT