-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathextractaudio.sh
57 lines (54 loc) · 1.66 KB
/
extractaudio.sh
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
#!/bin/bash
if [ "$1" == "" ] ; then
echo
echo "extractaudio 1.0/5.3.2011 by Oliver Prygotzki"
echo "https://github.com/NoNoNo/shellscripts-extractaudio"
echo
echo "Extracts the audio track of a video file without transcoding:"
echo "MP3 or M4A from container formats like MOV/AVI/FLV/M4V/MP4,"
echo "with autodetection. Syntax: extractaudio INPUT.ext"
echo "The audio track is saved as INPUT.ext.mp3 or INPUT.ext.m4a"
echo
exit
fi
AUDIOCODEC=$(ffmpeg -i "$1" 2>&1 | grep Stream | grep Audio)
echo "${AUDIOCODEC}" | grep mp3 &> /dev/null
if [ "$?" -eq "0" ]; then
nice ffmpeg -loglevel 0 -i "$1" -vn -acodec copy "$1".mp3
if [ "$?" -eq "0" ]; then
STATUSTEXT="Saved as $1.mp3"
else
STATUSTEXT="FFmpeg quit unsuccessfully!"
fi
else
echo "${AUDIOCODEC}" | grep aac &> /dev/null
if [ "$?" -eq "0" ]; then
which MP4Box > /dev/null
if [ "$?" -ne "0" ]; then
echo "MP4Box is missing for processing AAC/M4A, or it is not in PATH!"
echo "Please download here: http://www.tkn.tu-berlin.de/research/evalvid/"
exit
fi
nice ffmpeg -loglevel 0 -i "$1" -vn -acodec copy "$1".temp.aac
if [ "$?" -eq "0" ]; then
nice MP4Box -add "$1".temp.aac "$1".m4a
rm "$1".temp.aac
STATUSTEXT="Saved as $1.m4a"
else
STATUSTEXT="FFmpeg quit unsuccessfully!"
fi
else
echo "${AUDIOCODEC}" | grep Audio &> /dev/null
if [ "$?" -eq "0" ]; then
STATUSTEXT="This script can only extract MP3 and AAC audio tracks!"
else
AUDIOCODEC="- Did not find audio track! -"
STATUSTEXT=""
fi
fi
fi
echo
echo "The video contains this audio track:"
echo "${AUDIOCODEC}"
echo "${STATUSTEXT}"
echo