-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
movie2audio
executable file
·59 lines (48 loc) · 985 Bytes
/
movie2audio
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
#!/bin/sh
##
## Convert video file to audio file by FFmpeg
## Copyright (c) 2013 SATOH Fumiyasu @ OSS Technology Corp., Japan
##
## License: DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE Version 2
##
set -u
perr() {
echo "$0: ERROR: $1" 1>&2
}
pdie() {
perr "$1"
exit "${2-1}"
}
ffprobe="ffprobe"
ffmpeg="ffmpeg"
video_fname="$1"; shift
if [ ! -f "$video_fname" ]; then
pdie "No such file: $video_fname"
fi
if [ ! -r "$video_fname" ]; then
pdie "Permission denied to read: $video_fname"
fi
audio_codec=`
"$ffprobe" \
-loglevel warning \
-i "$video_fname" \
-show_streams \
-select_streams a:0 \
|sed -n 's/^codec_name=//p' \
;
`
if [ -z "$audio_codec" ]; then
pdie "Cannot detect audio codec from video file: $video_fname"
fi
audio_fname="${video_fname%.*}.$audio_codec"
if [ x"$video_fname" = x"$audio_fname" ]; then
exit 0
fi
"$ffmpeg" \
-loglevel warning \
-i "$video_fname" \
-y \
-codec:a:0 copy \
"$audio_fname" \
;
exit $?