简体   繁体   English

c ++音频转换(mp3 - > ogg)问题

[英]c++ audio conversion ( mp3 -> ogg ) question

I was wondering if anyone knew how to convert an mp3 audio file to an ogg audio file. 我想知道是否有人知道如何将mp3音频文件转换为ogg音频文件。 I know there are programs you can buy online, but I would rather just have my own little app that allowed me to convert as many files I wanted. 我知道你可以在线购买程序,但我宁愿拥有自己的小应用程序,它允许我转换我想要的多个文件。

It's realtive simple. 这很简单。 I wouldn't use the Windows Media Format SDK. 我不会使用Windows Media Format SDK。 Simply because of the fact that it's overkill for the job. 仅仅是因为这对工作来说太过分了。

You need a MP3 decoder and a OGG encoder and a little bit of glue code around that (opening files, setting up the codecs, piping raw audio data around ect.) 你需要一个MP3解码器和一个OGG编码器以及一些胶水代码(打开文件,设置编解码器,管道原始音频数据等)。

For the MP3 decoder I suggest that you take a look at the liblame library or use this decoding lib http://www.codeproject.com/KB/audio-video/madlldlib.aspx as a starting point. 对于MP3解码器,我建议您查看liblame库或使用此解码库http://www.codeproject.com/KB/audio-video/madlldlib.aspx作为起点。

For OGG there aren't many choices. 对于OGG来说,选择并不多。 You need libogg and libvorbis. 你需要libogg和libvorbis。 Easy as that. 很简单。 The example codes that come with the libs show you how to do the encoding. libs附带的示例代码向您展示了如何进行编码。

Good luck. 祝好运。

It's a bad idea. 这是个坏主意。 To quote from the Vorbis FAQ 引用Vorbis常见问题解答

You can convert any audio format to Ogg Vorbis. 您可以将任何音频格式转换为Ogg Vorbis。 However, converting from one lossy format, like MP3, to another lossy format, like Vorbis, is generally a bad idea. 然而,从一种有损格式(如MP3)转换为另一种有损格式(如Vorbis)通常是一个坏主意。 Both MP3 and Vorbis encoders achieve high compression ratios by throwing away parts of the audio waveform that you probably won't hear. MP3和Vorbis编码器都可以通过丢弃您可能听不到的部分音频波形来实现高压缩比。 However, the MP3 and Vorbis codecs are very different, so they each will throw away different parts of the audio, although there certainly is some overlap. 然而,MP3和Vorbis编解码器是非常不同的,因此它们每个都会丢弃音频的不同部分,尽管肯定存在一些重叠。 Converting a MP3 to Vorbis involves decoding the MP3 file back to an uncompressed format, like WAV, and recompressing it using the Ogg Vorbis encoder. 将MP3转换为Vorbis涉及将MP3文件解码为未压缩格式(如WAV),并使用Ogg Vorbis编码器对其进行重新压缩。 The decoded MP3 will be missing the parts of the original audio that the MP3 encoder chose to discard. 解码的MP3将丢失MP3编码器选择丢弃的原始音频部分。 The Ogg Vorbis encoder will then discard other audio components when it compresses the data. 然后,Ogg Vorbis编码器在压缩数据时将丢弃其他音频组件。 At best, the result will be an Ogg file that sounds the same as your original MP3, but it is most likely that the resulting file will sound worse than your original MP3. 充其量,结果将是一个听起来与原始MP3相同的Ogg文件,但最终文件听起来可能比原始MP3更糟糕。 In no case will you get a file that sounds better than the original MP3. 在任何情况下,您都不会得到比原始MP3更好的文件。

Since many music players can play both MP3 and Ogg files, there is no reason that you should have to switch all of your files to one format or the other. 由于许多音乐播放器可以同时播放MP3和Ogg文件,因此您没有必要将所有文件切换为一种格式或另一种格式。 If you like Ogg Vorbis, then we would encourage you to use it when you encode from original, lossless audio sources (like CDs). 如果您喜欢Ogg Vorbis,那么当您使用原始的无损音频源(如CD)进行编码时,我们建议您使用它。 When encoding from originals, you will find that you can make Ogg files that are smaller or of better quality (or both) than your MP3s. 从原件进行编码时,您会发现可以制作比MP3更小或质量更好(或两者兼有)的Ogg文件。

(If you must absolutely must convert from MP3 to Ogg, there are several conversion scripts available on Freshmeat .) (如果必须绝对必须从MP3转换为Ogg, Freshmeat上有几个转换脚本。)

http://www.vorbis.com/faq/#transcode http://www.vorbis.com/faq/#transcode

And, for the sake of accuracy, from the same FAQ: 并且,为了准确起见,来自同一个FAQ:

Ogg Ogg is the name of Xiph.org's container format for audio, video, and metadata. Ogg Ogg是Xiph.org的音频,视频和元数据容器格式的名称。

Vorbis Vorbis is the name of a specific audio compression scheme that's designed to be contained in Ogg. Vorbis Vorbis是特定音频压缩方案的名称,旨在包含在Ogg中。 Note that other formats are capable of being embedded in Ogg such as FLAC and Speex. 请注意,其他格式可以嵌入到Ogg中,例如FLAC和Speex。

I imagine it's theoretically possible to embed MP3 in Ogg, though I'm not sure why anyone would want to. 我想在理论上可以在Ogg中嵌入MP3,虽然我不确定为什么有人想要。 FLAC is a lossless audio codec. FLAC是一种无损音频编解码器。 Speex is a very lossy audio codec optimised for encoding speech. Speex是一种非常有损的音频编解码器,针对语音编码进行了优化。 Vorbis is a general-use lossy audio codec. Vorbis是一种通用的有损音频编解码器。 "Ogg audio" is, therefore, a bit of a misnomer. 因此,“Ogg音频”有点用词不当。 Ogg Vorbis is the proper term for what I imagine you mean. Ogg Vorbis是我想象中的合适术语。

All that said, if you still want to convert from MP3 to Ogg Vorbis, you could (a) try the Freshmeat link above, (b) look at the other answers, or (c) look at FFmpeg. 所有这一切,如果您仍然希望从MP3转换为Ogg Vorbis,您可以(a)尝试上面的Freshmeat链接,(b)查看其他答案,或(c)查看FFmpeg。 FFmpeg is a general-purpose library for converting lots of video and audio codecs and formats. FFmpeg是一个通用库,用于转换大量视频和音频编解码器和格式。 It can do a lot of clever stuff. 它可以做很多聪明的事情。 I have heard that its default Vorbis encoder is poor quality, but it can be configured to use libvorbis instead of its inbuilt Vorbis encoder. 我听说它的默认Vorbis编码器质量很差,但它可以配置为使用libvorbis而不是内置的Vorbis编码器。 (That last sentence may be out of date now. I don't know.) (最后一句话现在可能已经过时了。我不知道。)

Note that FFmpeg will be using LAME and libvorbis, just as you already are. 请注意,FFmpeg将使用LAME和libvorbis,就像您现在一样。 It won't do anything new for you that way. 它不会对你做任何新的事情。 It just gives you the option to do all sorts of other conversions too. 它只是让您可以选择进行各种其他转换。

You will need to decode mp3 then encode into ogg. 你需要解码mp3然后编码成ogg。

One possibility is to use liblame for mp3 decoding and libogg/libvorbis for encoding into ogg. 一种可能性是使用liblame进行mp3解码,使用libogg / libvorbis进行编码进入ogg。 Or just use the command line versions of those. 或者只使用那些命令行版本。

But I wouldn't say converting from one lossy format to another is a great idea. 但我不会说从一种有损格式转换到另一种格式是一个好主意。

Foobar2000 ( http://www.foobar2000.org/ ) is free and makes it quite easy to convert between file formats. Foobar2000( http://www.foobar2000.org/ )是免费的,可以很容易地在文件格式之间进行转换。 It would take only a few clicks to convert from MP3 to OGG. 只需几次点击即可将MP3转换为OGG。

Keep in mind that moving from a lossy format to a lossy format will reduce the quality of the audio more than moving from a lossless format (FLAC, CD Audio, Apple Lossless Codec) to a lossy format (MP3, OGG, M4A). 请记住,从有损格式转换为有损格式会降低音频质量,而不是从无损格式(FLAC,CD音频,Apple无损编解码器)转换为有损格式(MP3,OGG,M4A)。 If you have access to the lossless source audio use that to convert it instead. 如果您可以访问无损源音频,请使用它来转换它。

You can certainly do this in C++ with the Windows Media Format SDK . 您当然可以使用Windows Media Format SDK在C ++中执行此操作。

I have only used WMFSDK9 myself. 我自己只使用过WMFSDK9。 It contains a sample called UncompAVIToWMV, which may get you started. 它包含一个名为UncompAVIToWMV的示例,可以帮助您入门。 From the Readme: 从自述文件:

It shows how to merge samples for audio and video streams from several AVI files and either merge these into similar streams or create a new stream based on the source stream profile. 它显示了如何合并来自多个AVI文件的音频和视频流的样本,并将它们合并到类似的流中,或者根据源流配置文件创建新的流。 It also shows how to create an arbitrary stream, do multipass encoding and add SMPTE time codes. 它还显示了如何创建任意流,执行多通道编码和添加SMPTE时间代码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM