Skip to main content

Notice

Please note that most of the software linked on this forum is likely to be safe to use. If you are unsure, feel free to ask in the relevant topics, or send a private message to an administrator or moderator. To help curb the problems of false positives, or in the event that you do find actual malware, you can contribute through the article linked here.
Topic: Multiple .wav files into one .mp3 file with one lame command (Read 215 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

Multiple .wav files into one .mp3 file with one lame command

Fifteen years ago I used a brand new Ubuntu computer with cdparanoa and lame to encode my hundreds of classical CDs to mp3 files, and I've been happily listening to them ever since. Whenever I learn how to do something from the command line it is my custom to write up the process and save it in a text file because I know that when I need to do it again years later I won't remember. Well, now I've bought some new CDs to expand my collection, but after scouring my computer for the instructions I can't find them. Sigh.

Not a big deal, I can remember parts of it. Previously I used cdparanoia to create .wav files and then lame with VBR to encode them. I popped a new CD into the drive and, amazingly, there were nine tracks on it already as .wav files. The first three were tracks for a concerto, so I dragged them to a blank folder and renameed them as 1.wav, 2.wav and3.wav, changed the command line to the folder, and typed 'lame -V 0 1.wav 2.wav 3.wav concerto.mp3.' This errored out as '3.wav is unneeded argument.' So after several more tries I discovered that lame was ignoring anything but the first .wav file. 'OK,' I thought, 'maybe I need commas between the file names.' That didn't work, nor did + or a couple other characters. So then I tried just 'lame -V 0 1.wav 1.mp3' and it worked like a champ. I played the mp3 file and it sounded great.

Now, I know how to use mp3wrap, so I could use lame to create three mp3 files and then wrap them. But mp3wrap has its annoyances, so I'd rather have lame encode and wrap the wav files all at once. I've searched all over the net for examples of how to do this with lame, but not a word, and every code example I've found just uses one .wav file.

Can this be done?

Re: Multiple .wav files into one .mp3 file with one lame command

Reply #1
IDK about lame specifically, but

* Hopefully you want to keep your lossless files?

Then you can try to use CUETools via Mono, and store as single flac + cuesheet - or as WavPack with embedded cuesheet, for that matter.
I don't think Whipper has single flac + cuesheet. (It uses cdparanoia internally.)


* Is there any particular reason to use .mp3?
Asking because you can get cuesheet + single mp3 working - but also if you have a player that supports MP4 or Matroska, you can get it all converted with chapters. Just like embedded cue sheets, you will have one file but which in the player appears like several tracks.

Now for this:

I popped a new CD into the drive and, amazingly, there were nine tracks on it already as .wav files.
CD-audio does not have wav files - indeed it does not have files! Assuming that this was not a data CD, I can only make a hunch that your software presents it as if it were .wav files, because that is what it will get for you if you try to copy out.
High Voltage socket-nose-avatar

Re: Multiple .wav files into one .mp3 file with one lame command

Reply #2
Use the --nogap option:
Code: [Select]
lame -V0 --nogap 1.wav 2.wav 3.wav

If you're combining all wave files to a single mp3, this might be the easiest way.
Code: [Select]
sox 1.wav 2.wav 3.wav output.wav 
lame -V0 output.wav


Alternatively, if your files are in numerical order, you can use wildcards instead of specifying each input file separately:

To convert all wav files to separate mp3 files:
Code: [Select]
lame -V0 --nogap *.wav

To convert all wav files to one mp3 file:
Code: [Select]
sox *.wav output.wav; lame -V0 output.wav

Re: Multiple .wav files into one .mp3 file with one lame command

Reply #3
CD-audio does not have wav files - indeed it does not have files! Assuming that this was not a data CD, I can only make a hunch that your software presents it as if it were .wav files, because that is what it will get for you if you try to copy out.

That's kind of weird. I stuck the CD into a player connect to my laptop that has Ubuntu on it, and in the GUI file manager I clicked on the device which opened a window which said it was displaying the contents of 'cdda://sr0/, and it lists the files as Track 1.wav through Track 9.wave.  Using the file manager I dragged the first three .wav files to an empty folder on my hard drive, where I used lame to encode one of them to an .mp3. It worked great. I can double-click on the .mp3 file on my hard drive or on the .wav file as displayed in the file manager window for cdda://sr0/, and they both play the same. The file manager says Trac 1.wav on the CD and Track 1.wav on the hard drive are both 83.4MB. It did take the file manager about a minute and a half to 'copy' Track 1.wav from the CD to the hard drive, but that may be just because the optical drive is slow compared to the hard drive (which is SSD).

Assuming you're right, I'm curious how that Track 1.wav file got on my hard drive. Did something convert it? And from what? And if it's not really a .wav file on the CD, why did the file manager display it as that? And if I want to point lame directly to the CD, how do I tell it which 'track' to use as the source file?

Regarding cue files and flac, and lossy vs lossless, I just don't care. I can install players that can work from a cue file, and I tried it once, and I hated it. I have all my mp3 files in a single folder and I play them with quodlibet one after the other. When quodlibet gets to the end it stops until I start it over from the beginning. I like every bit of music that I have, and it's just background as I write, read a book, cook dinner, or whatever. I don't think about the music. I never suddenly think 'hey, now I want to hear <name of composer>' so I have to go search for the right track. I just let them play one after the other. If I want the music to stop for bedtime or to watch a movie, I hit the stop button. Cue sheets are pointless for my needs.

Regarding lossless vs. lossy, when I encode with lame I use -V 0, which is nearly lossless, yet the file sizes are a fraction of wav or even flac files. My current ~1400 mp3 files are only about 30GB and I can't hear the difference between playing the original wav file or the mp3 file. If I can't hear the difference, what's the point?

Finally, regarding sox, I tried to install it to take it for a spin, but apparently it's Windows only. At least, it's not in the repositories for Linux. But if there's another way to combine the wav files and then encode the resulting file with one lame command, that might be useful. Right now I am doing the opposite - using lame to create one mp3 file for each wav file, and then using mp3wrap to combine the several mp3 files into one, then deleting the individual mp3 files. I do this, for example, when a symphony has a separate wav file for each of its several movements. It works OK, even adding a few seconds of silence between each mp3 file, but it annoyingly nukes all of the tags from the original files and replaces them with advertising for mp3wrap, so then I have to open a tag editor and replace all the original tags.


Re: Multiple .wav files into one .mp3 file with one lame command

Reply #5
Regarding Replica9000's comment:

To convert all wav files to separate mp3 files:
Code: [Select]
lame -V0 --nogap *.wav

I just tried this, because it might solve my problem completely. I used three tracks named 1.wav, 2.wav and 3.wav for a Holmboe symphony. However, it failed:

lame -V0 *.wav Holmboe.mp3
lame: excess arg 3.wav

I took out the 'nogap' because I do want a few seconds of silence between the movements, but when the above failed I added it back, and then the error was 'lame: excess arg 2.wav.'

The man page for lame doesn't say anything about gaps between tracks. And I suspect that the error messages occurred because lame thought that 1.wav was the source and 2.wav was the output, hence 3.wav was an excess argument. But when I added 'nogap' back in the command and got that 2.wav was an excess argument, I totally don't understand.

Re: Multiple .wav files into one .mp3 file with one lame command

Reply #6
sox is definitely available.  I tested those commands on Debian before posting. 

Well, duh! Of course I couldn't install it - it was already installed! Apologies for my moment of stupidity.

And then I tried it, and it worked! Playing the three wav files individually totaled 22:16 and playing the resulting mp3 file came to the same length. I haven't played the mp3 all the way through to see if there are a few seconds break between the movements, but it looks like I have the solution.

Re: Multiple .wav files into one .mp3 file with one lame command

Reply #7
Well, duh! Of course I couldn't install it - it was already installed! Apologies for my moment of stupidity.

And then I tried it, and it worked! Playing the three wav files individually totaled 22:16 and playing the resulting mp3 file came to the same length. I haven't played the mp3 all the way through to see if there are a few seconds break between the movements, but it looks like I have the solution.

You can also use sox to generate silence.  For example, to generate 2 seconds of silence:
Code: [Select]
sox -n -r 44100 -c 2 silence.wav trim 0.0 2.0

You could then use sox to combine the wave files with the silence in between:
Code: [Select]
sox 1.wav silence.wav 2.wav silence.wav 3.wav output.wav


Re: Multiple .wav files into one .mp3 file with one lame command

Reply #8
You can also use sox to generate silence.  For example, to generate 2 seconds of silence:
Code: [Select]
sox -n -r 44100 -c 2 silence.wav trim 0.0 2.0
You could then use sox to combine the wave files with the silence in between:
Code: [Select]
sox 1.wav silence.wav 2.wav silence.wav 3.wav output.wav

That worked great. If you go to a symphony performance when the orchestra gets to the end of a movement the conductor stands with arms held up so the audience knows not to start clapping, counts a few seconds, then starts the next movement. I am sitting in front of my speakers and I want that same experience. I used your code to create a three second silence, which I named just s.wav to minimize typing commands, and it is the perfect solution.

I read through the sox man page (great job on the man page), and was planning on trying the pad option, but I like your method better. It's easier to see what I'm doing.

 
SimplePortal 1.0.0 RC1 © 2008-2021