You are not logged in.

#1 2008-11-09 17:13:57

voteforpedro36
Member
Registered: 2008-08-06
Posts: 99

Merge 2 mp3s into one file?

Googling comes up with a lot of stuff, but I see nothing Linux specific, so I'm gonna ask here:

I have 2 songs, and they're both mp3s. I want them to be combined into one mp3, so that there is absolutely NO silence in between the two parts. Hopefully there is an automated way to do this, but I can do it manually over some time if I need to. If my question isn't clear, sorry, tell me and I'll try to explain better.

Thanks in advance.

Offline

#2 2008-11-09 17:16:40

ise
Developer
From: Karlsruhe / Germany
Registered: 2005-10-06
Posts: 404
Website

Re: Merge 2 mp3s into one file?

You can do it with mp3wrap (http://mp3wrap.sourceforge.net or in AUR: http://aur.archlinux.org/packages.php?ID=14603). It's a small but very good program.

Daniel

Offline

#3 2008-11-09 17:16:55

Echo
Member
From: Ohio, United States
Registered: 2006-05-16
Posts: 239

Re: Merge 2 mp3s into one file?

Perhaps "cat" command can do it. A quick google search looked like it was so. I've use cat to join video files before if memory serves.

Offline

#4 2008-11-09 17:27:01

skottish
Forum Fellow
From: Here
Registered: 2006-06-16
Posts: 7,942

Re: Merge 2 mp3s into one file?

Echo wrote:

Perhaps "cat" command can do it. A quick google search looked like it was so. I've use cat to join video files before if memory serves.

cat does work with simple mpeg files. Although sometimes it can be weird about timestamps. I think that mp3 are fine though:

cat first.mp3 second.mp3 last.mp3 > new.mp3

Offline

#5 2008-11-09 20:51:50

voteforpedro36
Member
Registered: 2008-08-06
Posts: 99

Re: Merge 2 mp3s into one file?

Okay, cat seems to work, and i have mp3wrap installed too. The songs have a little skip in them, but that's not cat's fault, and I can live with it. Now here's my problem, and I am not savvy enough to figure it out. I now have a good number of songs in two different parts in one folder. I would love a script to be able to fix this, without me having to type cat a thousand times. The songs have a number at the beginning, then the name, and then the second part has "REQUESTED ...", then .mp3. I would guess there is a way to automate this cat'ing process instead of me having to do it hand by hand, judging by this. I hate to ask people to do it for me, but how could I do this?

Offline

#6 2008-11-09 20:59:58

skymt
Member
Registered: 2006-11-27
Posts: 443

Re: Merge 2 mp3s into one file?

If you'll give a couple example filenames (anonymize them if you want, just leave the relevant indicators where they are), I (or someone else who gets to it first) can whip up a shell loop to do it.

Offline

#7 2008-11-09 21:09:03

voteforpedro36
Member
Registered: 2008-08-06
Posts: 99

Re: Merge 2 mp3s into one file?

Alright

0212_Metallica - Hero of the Day.mp3
0213_Metallica - Hero of the Day - -Requested-.mp3

are a couple.

And if it's not too much, rm'ing the ones that I've cat'ed (which I could do if it was just the Requested part, but getting the one right before that I wouldn't know how to do) out of this folder would be cool too.

Thanks a lot.

Offline

#8 2008-11-09 21:17:00

skymt
Member
Registered: 2006-11-27
Posts: 443

Re: Merge 2 mp3s into one file?

mkdir requested merged
mv *-Requested-.mp3 requested
for file in *.mp3 ; do
    cat "$file" "requested/${file%.mp3} - -Requested-.mp3" > "merged/$file"
done
rm -r *.mp3 requested

That should work. The result will end up in the "merged" directory. Careful about the rm at the end, you probably want to make sure the merged files are all okay before you delete the originals.

Last edited by skymt (2008-11-09 21:17:34)

Offline

#9 2008-11-09 21:22:46

voteforpedro36
Member
Registered: 2008-08-06
Posts: 99

Re: Merge 2 mp3s into one file?

Question before I try: If there are songs in this folder that aren't split into two parts, it won't touch them will it? (well, the last command will, but other than that?)

EDIT: Nevermind, I took the ones without a requested to a different folder. Now it is close to working, but it returns:
cat: requested/0066_Led Zeppelin - Immigrant Song - -Requested-.mp3: No such file or directory
This makes since, as 0066 is the original, but 0067 is the one it should be looking for. It needs to add one to that number, then it would work.

Last edited by voteforpedro36 (2008-11-09 21:28:19)

Offline

#10 2008-11-09 21:28:05

skymt
Member
Registered: 2006-11-27
Posts: 443

Re: Merge 2 mp3s into one file?

voteforpedro36 wrote:

Question before I try: If there are songs in this folder that aren't split into two parts, it won't touch them will it? (well, the last command will, but other than that?)

It would. Here's a version that wouldn't.

mkdir first second merged
for file in *-Requested-.mp3 ; do
    mv "$file" second
    mv "${file%-Requested-.mp3}" first
done
# Check here to make sure the correct files are in the correct directories
for file in first/*.mp3 ; do
    cat "$file" "second/${file%.mp3} - -Requested-.mp3" > "merged/$file"
done
rm -r first second

Offline

#11 2008-11-09 21:29:45

voteforpedro36
Member
Registered: 2008-08-06
Posts: 99

Re: Merge 2 mp3s into one file?

^^ See edit.

Offline

#12 2008-11-09 21:55:05

skymt
Member
Registered: 2006-11-27
Posts: 443

Re: Merge 2 mp3s into one file?

Oh right, sorry. My eyes skipped over the number difference.

mkdir first second merged
for file in *-Requested-.mp3 ; do
    mv "$file" second
    mv "${file%-Requested-.mp3}" first
done
# Check here to make sure the correct files are in the correct directories
for first in first/*.mp3 ; do
    firstnum=${first%%_*}
    firstnum=${firstnum#*/}
    secondnum=$(( 10#$firstnum + 1 ))
    secondnum=$(printf "%04i" $secondnum)
    second=second/$secondnum_*
    cat "$first" "$second" > "merged/$first"
done
rm -r first second

I really hope that works. Shell arithmetic is fun. roll

Offline

#13 2008-11-09 22:16:31

voteforpedro36
Member
Registered: 2008-08-06
Posts: 99

Re: Merge 2 mp3s into one file?

Lol I see. Now here's a problem. Nothing gets moved to 'first'. I have to change

for file in *-Requested-.mp3 ; do
    mv "$file" second
    mv "${file%-Requested-.mp3}" first
done

the first *-Requested-.mp3 to *-Requested*.mp3 (not all of them end with that), and more things get moved to second, and less errors. If I try to change the second -Requested- in that code to -Requested* again, it throws more 'no such directory' at me, and still nothing in 'first'. If I understand correctly, what that second mv does is take $file, which has *Requested*.mp3 at the end, and take everything after Requested off, and move those files to 'first'. But it forgets about the *.mp3, and the numbers, as it tells me:

mv: cannot stat `0218_Guns N\' Roses - Civil War - ': No such file or directory

I'm guessing it wants to move it to first. What it needs to move, though, is a file called 0217_Guns N\' Roses - Civil War.mp3. Sorry if none of this made sense. It's getting close though, thanks a lot.

Last edited by voteforpedro36 (2008-11-09 22:17:52)

Offline

#14 2008-11-09 22:26:50

skymt
Member
Registered: 2006-11-27
Posts: 443

Re: Merge 2 mp3s into one file?

Ouch. Looks like the names are less consistent than I knew. Is everything in the right folder now?

Offline

#15 2008-11-09 23:06:01

voteforpedro36
Member
Registered: 2008-08-06
Posts: 99

Re: Merge 2 mp3s into one file?

Okay done. The ones with -Requested* are in second, the ones without it but that need to be cat'ed are in first. I couldn't fix the problemso I just moved them manually to first.

EDIT: Tried running the second half:

bash: merged/first/0189_The Who - Baba O'Riley.mp3: No such file or directory

On and on. I know there is no such file or directory, I'm trying to make it wink

Last edited by voteforpedro36 (2008-11-09 23:09:23)

Offline

#16 2008-11-09 23:25:54

skymt
Member
Registered: 2006-11-27
Posts: 443

Re: Merge 2 mp3s into one file?

The script really depends on being run from the right directory. Are you running it from the top directory, that is, the one containing first, second, and merged?

Offline

#17 2008-11-09 23:30:56

voteforpedro36
Member
Registered: 2008-08-06
Posts: 99

Re: Merge 2 mp3s into one file?

skymt wrote:

The script really depends on being run from the right directory. Are you running it from the top directory, that is, the one containing first, second, and merged?

Yes, just

for first in first/*.mp3 ; do
    firstnum=${first%%_*}
    firstnum=${firstnum#*/}
    secondnum=$(( 10#$firstnum + 1 ))
    secondnum=$(printf "%04i" $secondnum)
    second=second/$secondnum_*
    cat "$first" "$second" > "merged/$first"
done

though, as I would suppose I have done the first part already.

Last edited by voteforpedro36 (2008-11-09 23:32:20)

Offline

#18 2008-11-10 12:20:38

skymt
Member
Registered: 2006-11-27
Posts: 443

Re: Merge 2 mp3s into one file?

for first in first/*.mp3 ; do
    firstnum=${first%%_*}
    firstnum=${firstnum#*/}
    secondnum=$(( 10#$firstnum + 1 ))
    secondnum=$(printf "%04i" $secondnum)
    second=second/$secondnum_*
    cat "$first" "$second" > "merged/${first#*/}"
done

hmm That should work. Sorry for the delay, I was AFK due to sleep.

Offline

#19 2008-11-10 21:26:51

voteforpedro36
Member
Registered: 2008-08-06
Posts: 99

Re: Merge 2 mp3s into one file?

cat: second/*: No such file or directory

This results in the first file just being moved to the merged folder. I have a feeling it's getting really close though, thanks a ton.

Offline

Board footer

Powered by FluxBB