-
Notifications
You must be signed in to change notification settings - Fork 1
/
mp3merge
executable file
·58 lines (46 loc) · 1.4 KB
/
mp3merge
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
## Merge multiple MP3 files into one MP3
if ! test $# -ne 0
then
echo "usage: $0 merged.mp3 file1.mp3 file2.mp3 ..."
exit 1
fi
# Tested with files produced by ripit. Install lame first for
# mp3 support, then ripit will read and encode the tracks from
# the CD. Take caution that the names used by ripit will have
# correct alphabetical name sorting.
# ripit -o `pwd` && eject
# update id3 tags with
# id3v2
#Environment and temp files
set -o errexit
tmp_mp1=$(mktemp).mp3
tmp_mp2=$(mktemp).mp3
trap '
rm -f $tmp_mp1
rm -f $tmp_mp2
set +o xtrace
set +o errexit
' EXIT
set -o xtrace
final_mp3=$1
shift 1
# merge all mp3 files to tmp_mp1
mpgtx -j -o $tmp_mp1 "$@"
# merge alternatives
#
# mp3merge Messes up the ic3 tags, result file is slightly larger
#mp3merge out.mp3 "$@"
#
# find Handles large number of files but the result file is slightly larger
#find mp3directory -name "*.mp3" -print0|xargs -0 cat >> merged.mp3
## Corrects the headler length so many players show correct scrolling
ffmpeg -i $tmp_mp1 -acodec copy $tmp_mp2
rm $tmp_mp1
## Recalc the variable bit rate
# -allways required to avoid an error exit value (non variable bit rate mp3)
vbrfix -allways -ri1 -ri2 -lameinfo $tmp_mp2 $tmp_mp1
# if the mp3 is non-variable bit rate a destination file is not written
test -f $tmp_mp1 && mv $tmp_mp1 $tmp_mp2
#tmp_mp2 is the latest file in both cases
mv $tmp_mp2 "$final_mp3"
echo Finished : $final_mp3