MP3

From Audacity Wiki
Revision as of 07:12, 20 March 2017 by PeterSampson (Talk | contribs)

Jump to: navigation, search
Gale 08Jan 16: ToDo Check over Talk:MP3 in case anything useful is still there which should be here or somewhere else.
Gale 07May14: I updated this page for current Audacity, though some of what I updated is duplicative of the Manual and could be trimmed. I think we need an MP3 page because of the importance of the format, even if we lose most of the Lame Installation content. I think some of the "troubleshooting content" on that page e.g. the list of valid sample rate/ bit rate combinations is ideal material for this page. MP3 encoding and decoding is such a complex matter that I doubt you could ever fit everything into the Manual.
  • Gale 17Jun14: As per my comment above I reverted your deletion of Lame Installation and set a P2 to incorporate useful material from there to this page (or possibly elsewhere). Lame Installation is also linked to quite a lot so when it is finally deleted, it needs a redirect. I suggest it redirects here because if it goes to the Manual that may not address the question the link was addressing.
    • Peter 07Jan17: I transferred the LAME "Legal Issues" to this page. It's looking likely that after 2.1.3 is released I will deprecate the Lame Installation page, but leave it as s stub page with redirects.
    • Peter 07Jan17: I also transferred the Troubleshooting section - do some (all?) of these belong better in Manual>FAQ ?
MP3  is a size-compressed, lossy audio format. This means that it uses less disk space to store audio than uncompressed formats like WAV, but loses some of the original sound quality in doing so. To reduce the quality loss, the audio removed is mainly outside the adult range of hearing, and the artefacts  it introduces are chosen so they are largely masked by louder or more prominent sounds. The actual quality achieved depends on the bit rate you encode at, higher bit rates giving better quality but resulting in larger files.
Other compressed lossy formats exist that work in a broadly similar way, such as MP2 and the more modern and arguably superior OGG and M4A formats.
 
Related article(s):


Contents

MP3 support in Audacity using the LAME MP3 encoder

Audacity can both import audio in MP3 format, and export to MP3 format. Audacity can use the LAME  MP3 encoding library in order to export MP3s, but we do not distribute LAME because of patent restrictions. Instead, you need to download LAME separately.

Warning icon

Legal Issues

While the LAME source code is free, the encoding technology that ready-compiled LAME binaries use is patented. The patents are held by Fraunhofer and administered by Thomson. Patenting raises a theoretical possibility that in some countries a user might need to pay a licence fee to legally encode MP3s. This might vary according to the purpose of the encoding and whether the software being used is licensed.

There is no definitive list of countries where the patents unambiguously hold sway. However they are generally assumed to be enforceable in USA, Canada, the EEC and Japan. This means that in these countries (in theory), software that encodes MP3s must be licensed by the patent holders, and that anyone encoding MP3s with unlicensed encoders may also be infringing patents.

The best advice that can be given is that the user makes their own decision, based on their conscience, the country they are in, and taking into account the following:

  • The patent holders have tended to enforce licence fees against commercial rather than free MP3 encoders
  • Thomson themselves have said that no license is needed by individuals creating music libraries of MP3 files for personal use (interpretations vary whether that sanctions using unlicensed encoders, free or otherwise)
  • Existing MP3 patents will expire worldwide between 2010 and 2012 (but not until 2017 in the USA)
  • The possibility remains at least in the USA that patents could be extended.

Downloading and Installing LAME

Instructions for downloading and installing LAME are in the FAQ section in the Audacity Manual.

Settings

See the Setup section in MP3 Export Options in the Audacity Manual.

Add information about what the bit rate actually means in practice and what the other settings do. Explain stereo MP3 does not tend to use 2x as much space as mono, unlike wav and other uncompressed formats.
  • Peter 08Jan17:Done with a link to the relevant Manual page (to avoid duplication of documentation).

ID3 Tags

MP3 files contain "metadata" at the start of the file as ID3 tags . These tags typically contain information such as Track Title, Artist Name, Year and Genre. Some of this information may be visible in the playing window of software and hardware players. The tags can be edited with Audacity's tag editor.

By default, the Metadata Editor will always appear at export time. Enter any metadata you require in the editor, then click OK (not "Save"). The Export window lets you choose the file name, path and any custom encoding settings (by clicking the Options button).

To prevent Metadata Editor appearing at export time, click Edit > Preferences, then the Import / Export tab, and in the "When exporting tracks..." section, uncheck "Show Metadata Editor prior to export step". The tags can still be viewed or edited at any time prior to export at File > Edit Metadata..., and the tags in the editor at export time will still be exported.

When using Export Multiple, Metadata Editor pops up as many times as there are files to export. This gives flexibility to adjust the tags separately for tracks which form compilations with different artists or genres. If all the tracks to be exported have common information except for Track Title and Track Number, you may prefer to set Preferences as above so that Metadata Editor does not appear prior to export. Then make any necessary edits to the common tags at File > Edit Metadata... prior to export, and the multiple export will proceed silently with the Track Title and Track Number tags added automatically. The Track Title tag will be the same as the file name chosen in the label or track name, and the Track Number tag will be generated according to the order of the labels or tracks.

Each time an MP3 is imported in to a project window, the tags for that file replace the previous content of the Metadata Editor, so if the last imported MP3 has no tags, Metadata Editor will then have no content. If you want to export tags that a previously imported MP3 had, open File > Edit Metadata... to change the tags before export. Alternatively you could use File > Open... to import each MP3 into separate project windows which would preserve the tags for each file.

ID3v2.3 tags are exported. Note that some players don't yet fully support these tags, and so may not see all the tags. To prevent any tags being exported, uncheck "Show Metadata Editor..." in Preferences, open the Editor and delete any text showing in the "Tag Value" fields. Note that when using Export Multiple, the automatically generated Track Title and Track Number tags will still be produced, unless you show Metadata Editor at export and empty all the fields.

ID3v1 is only supported if you use Audacity's command-line encoder and add the --id3v1-only option. ID3v1 should only be needed for very old software or hardware players.

Limitations

In addition to the degrading of sound quality, MP3 files also have a short silence at the beginning. This is not a bug in Audacity or in Lame but is a limitation of the MP3 format. If this is an important issue (for example when making audio loops) you will need to use a format that does not have this limitation, such as WAV, Flac or Ogg.

Re-encoding to MP3

Every time you export from Audacity as an MP3 (or other lossy audio format), this encoding necessarily degrades some of the original quality of the audio. If you import an MP3 into Audacity, edit it then export it as an MP3, you are thus losing quality twice - once in the original MP3 encoding of the imported audio, then again when you export it from Audacity as MP3. Therefore when you are exporting as MP3, work with the highest quality copy of the audio that you can - preferably a copy in a lossless format such as WAV, AIFF or FLAC. You can always obtain a lossless copy of an audio CD by extracting its audio to a WAV or AIFF file. Never extract the audio from a CD to MP3 if you want to export it from Audacity as an MP3.

If you can't avoid importing an MP3 into Audacity and then re-encoding to MP3, don't believe what you sometimes hear that using the same or higher bit rate as the original file will prevent quality loss. This is incorrect. All you can say is that the higher the bit rate you re-encode to, the less will be the quality loss that results.

MP3 files of the same bit rate, sample rate, number of channels and stereo encoding mode can be typically be split, joined or volume-adjusted non-destructively with the below tools without the need for lossy re-encoding.

  • mp3wrap - Cross-Platform command-line only tool for joining MP3 files.

For more advanced edits such as effects, the audio needs to be decompressed in an editor like Audacity, so you must then accept any perceptible quality loss from re-encoding the MP3.

Troubleshooting MP3 export problems

Peter07Jan17: Do some (all?) of these belong better in Manual>FAQ ?

Crash or excessive processing time on export

If Audacity crashes or hangs when exporting MP3s, or the export takes a long time to process, the usual reason is that your chosen Project Rate (the sample rate bottom left of the Audacity screen) is very different from the sample rate of the audio track on the screen (as shown in Hz on the Track Control Panel above the mute/solo buttons). As a result, resampling has to be done while exporting, which can create problems on long tracks. Try resampling the track to your chosen Project Rate before exporting as MP3. To do this, select all the track by clicking in the Track Control Panel, then Tracks > Mix and Render. If there is any silence added to the end of the track as a result of the resampling, you can select and delete it. Now when you export the MP3, the process should go smoothly and quickly. If it doesn't, there could be a number of reasons, e.g. if you have a virus scanner set to scan all created files, this will slow the process of writing the exported file considerably. The higher the bit rate you export at, the larger the file will be, so giving a greater time penalty if you enable virus scanning.

Exported MP3 invalid / will not play

Sometimes the exported MP3 may be invalid and only a few bytes in size; as a result, it will not play and give an error.

The safest solution is to always set your Project Rate to 44100 Hz. Make a rule to check this before you export, because importing a file of some other sample rate may change the Project Rate to that rate.

LAME will automatically downsample from 44 100 Hz to a lower sample rate at 56 kbps or lower, because low bit rates may give poor quality with higher sample rates. If especially desired, any valid sample rate/bit rate combination can be enforced by using the command line exporter in the current version of Audacity (choose "external program" in "Save as type" in the Export File dialog). Or export as WAV from Audacity, then use LAME.exe at the command line to convert to MP3.

HINT: If you want to choose specific sample rate/bit rate combinations, the following shows those permitted in the MP3 specification, and which will properly export from Audacity (with or without resampling):

MPEG-1 layer III sample frequencies (kHz): 32 48 44.1:
bit rates (kbps): 32 40 48 56 64 80 96 112 128 160 192 224 256 320

MPEG-2 layer III sample frequencies (kHz): 16 24 22.05:
bit rates (kbps): 8 16 24 32 40 48 56 64 80 96 112 128 144 160

MPEG-2.5 layer III sample frequencies (kHz): 8 12 11.025:
bit rates (kbps): 8 16 24 32 40 48 56 64 80 96 112 128 144 160

Exported MP3 plays too fast

If the MP3 plays at the wrong speed (usually too fast), then the sample rate you exported it at is unsuitable for your player application. Once again, the safe solution is to always set your Project Rate to 44100 Hz. This was a known problem with Adobe Flash Player until some way into version 9: for the file to play properly, the sample rate had to be 11025 Hz or a multiple thereof, such as 22050 Hz or 44100 Hz. This is fixed in the current Adobe Flash Player.

Exported MP3 has low volume or no sound

If you can see your exported MP3 is playing because the timer on the media player is moving, but it has no sound, make sure the sound device is not muted (in the player or in the system control panel), and make sure the correct playback device is being used (in the player preferences or in the system control panel). If this is not the problem, go back to Audacity and make sure the -....+ gain slider on the Track Control Panel (where the mute/solo buttons are) is set centrally at "Gain: 0 db". If this slider is over to left, it will reduce or kill the volume in the exported MP3.

ID3 Tags

Make sure when you use the "Edit ID3 Tags" dialog that you complete this by pressing OK, not escaping or cancelling it.

Exported MP3 larger than imported one

If you import an MP3 file into Audacity, then after export you find it is much larger than before, this is because the bit rate you exported it at is higher than the bit rate of the original file.

Audacity defaults to 128 kbps bit rate then remembers the last used bit rate if you change it.

If you need the exported MP3 to be the same size as before:

  1. Find out the bit rate of the imported file by opening it in Windows Media Player and clicking File > Properties, or in iTunes, right-click or control-click over the file and click Get Info. You can also use standalone programs like MediaInfo.
  2. Click File > Export, choose "MP3 Files" in the file types list, then click the Options button.

If you export a low bit rate MP3 at the same bit rate as the original you will be degrading its quality much more than if you exported it at a higher bit rate. The penalty of the higher bit rate is that the new file would be larger and that file merge tools might no longer be able to join the new MP3 to others that had the original bit rate. If you export a high bit rate MP3 at the same bit rate you are helping to minimise quality loss (but are not saving anything in file size).

All MP3 exports are lossy

Every MP3 export reduces the quality of the original file because Audacity does not edit the file directly. Instead, Audacity decompresses the MP3 upon import to lossless PCM. This does not undo the audio losses caused by the original MP3 compression, but it enables more complex edits such as equalisation and other signal filtering to be made.

Having been decompressed, the MP3 therefore has to be re-encoded as a new compressed MP3 when exporting. The lower the bit rate exported at, the more quality will be lost with that re-encoding.

If you only want to do simple cut, copy, paste, fade and volume edits to your MP3 files, you can do so without audio losses in other tools that can edit MP3 directly without decompressing and re-encoding. Examples are:

  • mp3wrap - Cross-Platform command-line only tool for joining MP3 files.

MP3 files of the same bit rate, sample rate, number of channels and stereo encoding mode can be typically be joined non-destructively with any of the above tools without the need for lossy re-encoding.

Personal tools

Donate securely by PayPal, using your credit card or PayPal account!