Searching Google on how to join/merge many mp3 files, it suggests that I should just cat them together.
That might "work", but clearly it is not the correct way to do it, as each header and set of IDv3 tags will also be concatenated.
Does a Linux program exist that can be scripted to join/merge many mp3?
Can mplayer/mencoder/ffmpeg do it?
10 Answers
This will concatenate two mp3 files, and the resulting metadata will be that of the first file:
ffmpeg -i "concat:file1.mp3|file2.mp3" -acodec copy output.mp3This is because, for ffmpeg, the whole "concat:" part is a single "input file", and its metadata will be of the first concatenated file. If you want to use metadata from the second file instead, you have to add it as a dummy input file and map its metadata to that of the output:
ffmpeg -i "concat:file1.mp3|file2.mp3" -i file2.mp3 -acodec copy test.mp3 -map_metadata 0:1If you want to construct your metadata from the two metadatas, you'll have to do it by hand. You can dump a file's metadata with
ffmpeg -i file1.mp3 -f ffmetadata file1.metadataAfter dumping both metadatas and constructing new metadata, you can add it to the output file with -metadata, and you can disable metadata copying by setting a -map_metadata mapping from a negative input file number. This sets a name value and no other metadata:
ffmpeg -i "concat:file1.mp3|file2.mp3" -acodec copy -metadata "title=Some Song" test.mp3 -map_metadata 0:-1 13 This will concatenate a folder full of MP3 into a single MP3 file:
1) Save a list of the MP3 files to concatenate, e.g.,
$ cat mylist.txt
file '/tmp/01.mp3'
file '/tmp/02.mp3'
file '/tmp/03.mp3'
file '/tmp/04.mp3'
file '/tmp/05.mp3'
file '/tmp/06.mp3'
file '/tmp/07.mp3'2) Run the following command (-safe 0 is not required if mylist.txt uses relative paths instead):
$ ffmpeg -f concat -safe 0 -i mylist.txt -c copy output.mp3 3 Mp3Wrap - Command-line utility that wraps multiple MP3 files into a single, playable MP3, without losing filenames or ID3 information, and without reencoding. Also supports archiving non-audio data such as playlists, info files, and cover images inside the MP3. These files can be unpacked later (using mp3splt, e.g.); ordinary MP3 decoders can play the entire audio stream as one long track.
3zsh:
audio-join() ffmpeg -i "concat:${(j:|:)@[2,-1]}" -acodec copy $1
audio-join output.mp3 *.mp3 3 Based on Miles Wolbe's answer, here is a one-liner that worked for me:
ls *.mp3 | \ sed -e "s/\(.*\)/file '\1'/" | \ ffmpeg -protocol_whitelist 'file,pipe' -f concat -i - -c copy output.mp3 1 One liner based on Miles Wolbe's answer to join all .mp3 sorted by name in current directory:
ffmpeg \
-f concat \
-safe 0 \
-i <(find "$(pwd)" -iname '*.mp3' -printf "file '%p'\n" | sort) \
-c copy \
merged.mp3The find command finds any *.mp3 and prints it with file prepended to the path. $(pwd) makes find print the absolute path. Piping to sort sorts the files by name. <() is process substitution which allows output of find to appear as contents of a file.
If you want to concat all mp3 files of the current directory:
function join_by { local IFS="$1"; shift; echo "$*"; }
files=(*.mp3)
ffmpeg -i "concat:`join_by "|" $files`" -acodec copy output.mp3 If you need scripting, you're probably better off using the ffmpeg solution. However, if you ever just need an application to do stuff like that, you could try out Audacity. It's open source and cross platform. I haven't used it to join mp3s, but I've used it to crop sections out of an mp3 and fade them out at the end. I'm be willing to bet you can join mp3s and cross-fade them into each other with it as well.
1couple windows scripts I created to do this (using ffmpeg)
direnhanced.bat
@echo off
setlocal enabledelayedexpansion
for /f "tokens=*" %%f in ('dir /b *.mp3') do ( echo file '%%f' )
endlocalmergemp3s.bat
call direnhanced.bat > fileList.txt
set /p FILENAME=Output file name then hit ENTER to continue...
ffmpeg -f concat -safe 0 -i fileList.txt -c copy "%FILENAME%.mp3" To create a list of your MP3 files in a format that meets the requirement, such as:
file '01.mp3'
file '02.mp3'
file '03.mp3'You can do so from the windows command prompt: (Given the current directory is in the mp3 files folder)
c:>(for %i in (*.mp3) do @echo file '%i') > mylist.txt