c++ mp3 library [closed]

2020-08-22 06:51发布

问题:

I am exhausted searching for a c++ mp3 decoding library, preferably free (like lgpl) and cross-platform or for windows and mac. Can anyone suggest such library and post some tutorial for using it? ffmpeg and sdl (sdl_sound, sdl_mixer) aren't compiling. I am unable to get mpg123 working - is it for linux world only or what? Is there some tutorial on using mpg123 on windows? mpg123 is unable to find some symbols that is I am not putting some dll's at right path - but which?

Overall, I want be able to read and write all major audio file formats on windows and mac - starting with windows.

回答1:

There are a couple of options:

  • GStreamer:

GStreamer is a cross-platform library for constructing graphs of media-handling components. The applications it supports range from simple Ogg/Vorbis playback, audio/video streaming to complex audio (mixing) and video (non-linear editing) processing.

This page has some very interesting info on GStreamer and the MP3 format, it's a must-read if you decide to go with GStreamer:

The MP3 audio format is a pain. It is patent-encumbered, making it hard for Linux distributors to package (or Linux users to use) legally in various parts of the world. It doesn't even sound all that good, compared to some of the alternatives. Yet MP3 is hard to avoid;

Besides that, Gstreamer ofers a command-line interface through gst-launch which is very useful to test the pipeline you are assembling in your program before you start to write code the actual code:

gst-launch filesrc location=/path/to/audiofile ! decodebin ! oss4sink

And if you need to build GStreamer on Windows, check this tutorial for Visual Studio.

  • PortAudio:

PortAudio is a free, cross-platform, open-source, audio I/O library. It lets you write simple audio programs in 'C' or C++ that will compile and run on many platforms including Windows, Macintosh OS X, and Unix (OSS/ALSA).

The MP3 support comes through libmad. There are tutorials that help building and using the library.



回答2:

Have you looked into LAME? Also, note that the mp3 algorithm is subject to patents, so you need to tread carefully no matter which library you use.



回答3:

I think last time i needed i used libMAD. Worked well but it's a C lib.



回答4:

You could try Helix.

It has an optimized version for embedded platforms and arm architectures.



回答5:

Take a look at bass:

I have worked with it some years ago, it was easy to use, multiplatform, with a good sound quality and the developer was very supportive. It is free for non-commercial use.



回答6:

I guess that the gstreamer is a best choice but you could also use the LibVLC which is a core of vlc player.