I have an ogg audio file and some information which is saved as sequence of bytes. I need to pack this audio and information in a single container such as RIFF开发者_开发百科 or something else. I'm searching solutions which can be written under .NET.
Ogg is a container format. What you perhaps will want is either use some Ogg format tools to attach your data directly to existing file, or re-stream the data into different container format where you have tools to attach your data to.
The formats might be WAV/RIFF, Matroska, MP4. It also perhaps depends what is exactly this additional data, more like a thumbnail, or additional stream (user comments with timestamps etc).
A popular framework for such manipulation in .NET is DirectShow.NET library, but as you clarify your need, you might end up using a different tool.
See also a neighboring thread with a code snippet: Ogg to Riff/Wave encoding with acm
How to move Ogg file to Wav file with Ogg Vorbis data in C#
static void OggToWavWithOgg()
{
string fileName = @"e:\Down\fortuna.ogg";
using (DsReader dr = new DsReader(fileName))
{
if (dr.HasAudio)
{
short oggFormatTag = 26479;
IntPtr format = dr.ReadFormat();
WaveFormat waveFormat = AudioCompressionManager.GetWaveFormat(format);
IntPtr formatOgg = AudioCompressionManager.GetCompatibleFormat(format, oggFormatTag);
using (WaveWriter ww = new WaveWriter(File.Create(fileName + ".wav"),
AudioCompressionManager.FormatBytes(formatOgg)))
{
AudioCompressionManager.Convert(dr, ww, true);
}
}
}
}
精彩评论