-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmp3ify
More file actions
executable file
·69 lines (59 loc) · 1.57 KB
/
Copy pathmp3ify
File metadata and controls
executable file
·69 lines (59 loc) · 1.57 KB
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
#!/usr/bin/env sh
set -o errexit
log() {
if [ "${MP3IFY_LOG}" == "true" ]; then
echo $1 1>&2
fi
if [ "${MP3IFY_LOG_FD1}" == "true" ]; then
echo $1 1>&2 >> /proc/1/fd/1
fi
}
USAGE="Usage: `basename $0` input output"
if [ $# -ne 2 ]; then
echo $USAGE >&2
exit 1
fi
I=$1
O=$2
[ ! -e "${I}" ] && \
echo "Input file ${I} does not exist" >&2 && \
exit 1
stream0=$(ffprobe -select_streams 0 -show_streams "${I}" 2>/dev/null)
codec_type=$(echo "${stream0}" | grep "^codec_type=" | cut -d = -f 2)
if [ "${codec_type}" != "audio" ]; then
echo "Expected stream 0 to be audio, but is ${codec_type}" >&2
exit 1
fi
codec_name=$(echo "${stream0}" | grep "^codec_name=" | cut -d = -f 2)
sample_fmt=$(echo "${stream0}" | grep "^sample_fmt=" | cut -d = -f 2)
sample_rate=$(echo "${stream0}" | grep "^sample_rate=" | cut -d = -f 2)
case "${codec_name}" in
mp3)
log "mp3ify: mp3 -> mp3"
ffmpeg \
-i "${I}" \
-map 0:a \
-c:a copy \
-map_metadata -1 \
-flush_packets 1 \
-f mp3 \
"${O}"
;;
flac|alac|aac)
log "mp3ify: ${codec_name} -> mp3"
ffmpeg \
-i "${I}" \
-af aresample=resampler=soxr:precision=28 \
-codec:a libmp3lame \
-q:a 0 \
-frame_duration 10 \
-map_metadata -1 \
-flush_packets 1 \
-f mp3 \
"${O}"
;;
*)
log "mp3ify: File ${I} has an unsupported codec ${codec_name}"
exit 1
;;
esac