Automate open/export

I am using Audacity 2.0.4 on Windows 7. I have over a thousand mp3 files that I need to be able to stream down to my new iPhone app. I found that 95% of these files will not stream successfully, though they play just fine in browsers and on the desktop. I found through lots of experimentation that if I simply open any of the “bad” files in Audacity, then export and overwrite (without changing anything), it fixes the file, and I get successful streaming after that. The fix is great, but it’s not really a solution because I shudder at the fact of manually opening 1,300 mp3 files in audacity, then saving.

Is there any way to automate this? I don’t think audacity has a cmd-line option or a batch-process option. Is there?

If not, any easy way to automate this? Any other non-Audacity ideas that would be quick and somewhat automated? I’m a programmer so I can write scripts, programs, whatever I need to. Thanks.

That is obsolete now: Audacity ® | Downloads .

So what is the difference? 128 kbps? CBR? 44100 Hz sample rate? Images or lyrics in the files? Something weird in the header?

If you found the reason you could use SoX at the command-line to make the change. If it wasn’t a bit rate or sample rate problem you could possibly use a direct MP3 editor like mp3DirectCut in batch mode. Using a direct MP3 editor would avoid the quality loss of re-encoding the files.

If you are forced to re-encode the files, you can use Chains in Audacity. This will be slower than SoX because Audacity must first decode each file to PCM then draw the waveform.

Also you may find that Chains chokes on doing 1000 files at once especially if the file names are long. I think it is because a character limit in the file name box is exceeded.

Chains are rather neglected, so patches are welcome to improve it. Please see Submitting Patches.


Gale

Gale,

Thank you for your detailed reply. I installed the latest version of Audacity (2.0.6). I tried what you suggested using Chains but it didn’t do anything. And after running files through it:

1- The files were not fixed, same problem as before.
2- The Last Modified Date of the files remained unchanged.

When I manually opened these files in Audacity, did nothing, just exported back to mp3…fixed every time! This Chains approach looks awesome if I can use it correctly. Here is exactly what I did:

1- Opened Audacity
2- Click File → Apply Chain
3- Chose the default/only option (MP3 Conversion) – Note: What this does seems like it’s what I need but I have no idea if I should use something else.
4- Click “Apply to Files” button
5- Selected some files and clicked the Open button
6- The files seemed to quickly open, flash, and close. That looks promising.

But the files weren’t fixed and the datestamps weren’t changed.

Gale: What type of Chain commands should I use so that it simply does a new export of the file and saves over the original? Why does the Export command not do the same thing as manually opening and exporting an mp3?

The first thing to do is to find out why some of the files don’t work. If we know what we are trying to fix I expect there will be an easy solution. So, as Gale asked, what is the difference between the ones that work and the ones that don’t?

Here is the mp3 after running it through foobar2000 (this didn’t fix anything):
http://www.zerogravpro.com/temp/foobar2000.mp3

And here is the same mp3 after regenerating it in Audacity (this DID fix it):
http://www.zerogravpro.com/temp/audacity.mp3

I don’t know mp3 file structures well enough, or even the tools used, to be able to answer the question. But here’s a “bad” file, and a good file that streams down and plays correctly in an iphone app. You’ll notice that even the “bad” file plays fine in a browser, and you can download it and play it locally with no problems. There has to be something in the bad file that chokes the streaming.

The “good” file is “CBR” (constant bit rate) and the bad file is “VBR” (variable bit rate).

To check if this is the defining issue, try exporting from Audacity as VBR and you should find that the resulting file does not stream down to my new iPhone app.
By default Audacity uses 128 kbps CBR. To change that to VBR, go through the normal exporting procedure, then when in the export dialog screen, click on the “Options” button and select VBR. Then complete the Export and test the exported file.

See Audacity Manual. There is no ability to overwrite the original. The changed files are in a “cleaned” folder in the same folder the files came from.

The ExportMP3 command in the Chain uses the same export parameters as standard MP3 export, so you need to set those parameters first in the MP3 Export Options before running the Chain.

Gale

Steve: I exported to VBR format and it still worked fine. So I’m thinking the difference is unrelated to VBR vs CBR.

Gale: I missed the fact that there was a “cleaned” folder created and the files get put in there. Thanks for the tip.

All: This Chain approach seemed to work for some files, but not others. In fact, the files it didn’t fix couldn’t even be fixed by what I thought was my bulletproof fallback: manually export the file in Audacity. Here’s an example of a file that seems unfixable for iphone streaming:

http://www.zerogravpro.com/temp/unfixable.mp3 (works fine in browser or desktop)

Can anyone see anything in the file that might cause a problem with streaming?

The two features which seem to be in both “bad” files are 22050 Hz sample rate and duplicated information at the end for the name of the encoder.

Have you tried exporting the unfixable one at 44100 Hz? To do that, change the project rate bottom left.


Gale

Gale, I just tried that. Sounded promising, but it didn’t work. Here is the new file at 44100 Hz:
http://www.zerogravpro.com/temp/unfixable2.mp3

And for reference/baseline purposes, here’s one of my original mp3s that I didn’t have to touch with Audacity, yet it worked fine from the beginning. And it’s 22050 Hz:
http://www.zerogravpro.com/temp/good_22050.mp3

Yes that’s what it means, but at least we have eliminated that possibility.

What we have so far:

Bad files:

foobar2000.mp3

File size                                : 20.3 KiB
Duration                                 : 6s 870ms
Format                                   : MPEG Audio
Format version                           : Version 2
Format profile                           : Layer 3
Bit rate mode                            : Variable
Channel(s)                               : 1 channel
Sampling rate                            : 22.05 KHz
Compression mode                         : Lossy
Stream size                              : 19.9 KiB (98%)

unfixable.mp3

File size                                : 29.4 KiB
Duration                                 : 1s 854ms
Format                                   : MPEG Audio
Format version                           : Version 2
Format profile                           : Layer 3
Duration                                 : 1s 854ms
Bit rate mode                            : Constant
Bit rate                                 : 128 Kbps
Channel(s)                               : 1 channel
Sampling rate                            : 22.05 KHz
Compression mode                         : Lossy
Stream size                              : 29.0 KiB (99%)
Writing library                          : LAME3.99r
Encoding settings                        : -m m -V 4 -q 3 -lowpass 11 -b 128

unfixable2.mp3

File size                                : 20.4 KiB
Duration                                 : 1s 828ms
Format                                   : MPEG Audio
Format version                           : Version 1
Format profile                           : Layer 3
Duration                                 : 1s 828ms
Bit rate mode                            : Variable
Bit rate                                 : 89.6 Kbps
Minimum bit rate                         : 32.0 Kbps
Channel(s)                               : 1 channel
Sampling rate                            : 44.1 KHz
Compression mode                         : Lossy
Stream size                              : 20.0 KiB (98%)
Writing library                          : LAME3.99r
Encoding settings                        : -m m -V 4 -q 0 -lowpass 17.5 --vbr-new -b 32

Good files

audacity.mp3

File size                                : 40.6 KiB
Duration                                 : 5s 172ms
Format                                   : MPEG Audio
Format version                           : Version 2
Format profile                           : Layer 3
Duration                                 : 6s 948ms
Bit rate mode                            : Constant
Bit rate                                 : 128 Kbps
Channel(s)                               : 1 channel
Sampling rate                            : 22.05 KHz
Compression mode                         : Lossy
Stream size                              : 108 KiB (100%)
Writing library                          : LAME3.99r
Encoding settings                        : -m m -V 4 -q 3 -lowpass 11 -b 128

good_22050.mp3

File size                                : 40.6 KiB
Duration                                 : 5s 172ms
Format                                   : MPEG Audio
Format version                           : Version 2
Format profile                           : Layer 3
Duration                                 : 5s 172ms
Bit rate mode                            : Variable
Bit rate                                 : 63.9 Kbps
Minimum bit rate                         : 8 000 bps
Channel(s)                               : 1 channel
Sampling rate                            : 22.05 KHz
Compression mode                         : Lossy
Stream size                              : 40.4 KiB (99%)
Writing library                          : LAME3.99r
Encoding settings                        : -m m -V 4 -q 0 -lowpass 11 --vbr-new -b 8

The only pattern that I can see is “File Size”. The “bad” ones are all under 40 kiB and the “good” ones are all over 40 kiB.

Steve: I think you cracked the code. I took the “unfixable” file and made it bigger by doubling the track in audacity. Now it streams perfectly in iphone. It never crossed my mind that iphone demands mp3 files of a certain size before streaming will work. At least that’s how it appears.

Any idea how to (in some automated way) make mp3 files larger without adding junk? Anyway, that is a much smaller problem. Thanks so much for your analysis and help with this.

Encode them at a higher bit rate, or just convert them to WAV format. Do WAV files work?
Here is your “unfixable” file decoded to WAV format: