Can I see a simple example of ogg audio decoding - c++

I want to write my own icecast2 client because I can't seem to find one that will work with what I need. But, I am so overwhelmed by everything that entails. I'm familiar with networking, and I know a thing or too about audio as well. But, I've never written or used a decoder. I see a lot of things on xiph.org that could be useful if I could just see the basics.
Could someone post an answer that contains a few frames of ogg with an example of how to convert that raw ogg into audio (does it ultimately turn into wav to play?)

Related

Partial decoding h264 stream

I'm trying to get information about frames in h264 bitstream. Especially motion vectors of macroblocks. I think, I have to use ffmpeg code for it, but it's really huge and hard to understand.
So, can someone give me some tips or exapmles of partial decoding from raw data of single frame from h264 stream?
Thank you.
Unfortunately, to get that level of information from the bitstream you have to decode every macroblock, there's no quick option, like there would be for getting information from the slice header.
One option is to use the h.264 reference software and turn on the verbose debug output and/or add your own printf's where needed, but this is also a large code base to navigate:
http://iphome.hhi.de/suehring/tml/
(You can also use ffmpeg and add output where needed too as you said, but it would take some understanding of that code base too)
There are graphical tools for analyzing video bitstreams which will show you this type of information on a per-macroblock basis, many are expensive, but sometimes there are free trial versions available.

video/audio encoding/decoding/playback

I've always wanted to try and make a media player but I don't understand how. I found FFmpeg and GStreamer but I seem to be favoring FFmpeg despite its worse documentation even though I haven't written anything at all. That being said, I feel I would understand how things worked more if I knew what they were doing. I have no idea how video/audio streams work and the several media types so that doesn't help. At the end of the day, I'm just 'emulating' some of the code samples.
Where do I start to learn how to encode/decode/playback video/audio streams without having to read hundreds of pages of several 'standards'. Perhaps to a certain extent also be enough knowledge to playback media without relying on another API. Googling 'basic video audio decoding encoding' doesn't seem to help. :(
This seem to be a black art that nobody is out to tell anyone about.
The first part is extracting streams from the container. From there, you need to decode the streams into media. I recommend finding a small Theora video and seeing how the pieces relate there.
you want that we write one answer and you read that and be master in multimedia domain..!!!!
Anyway that can not be by one answer.
First of all understand this terminolgy by googling
1> container -- muxer/demuxer
2> codec --coder/decoder
If you like ffmpeg then go with its basic video plater application. iT is well documented at here http://dranger.com/ffmpeg/ it will shows the method of demuxing container and decoding any elementry stream with ffmpeg api. more about this at http://ffmpeg.org/ffplay.html
i like gstreamer more then ffmpeg. it has well documentation. it will be good choise if you start with gstreamer

How to extract audio from a video with ffmpeg in C++?

I'm using FFmpeg to extract informations about a video file.
But i want to extract the audio channels to read it with FMOD.
How can I do that ? Is it simple ?
Do you know a good tutorial about FFmpeg in C++ ?
Thanks
For tutorials on FFMPEG, have a look at this question: FFmpeg API books, tutorial, etc. The tutorials are in C, but so is FFMPEG. They're a bit out of date and won't compile with the most recent FFMPEG, but the required changes aren't that great. I've started updating them on my github.
Work your way through the tutorials (it will take around a week at a slow pace) and you'll enough to know where to grab the audio from. If you just want the stream, you can probably just dump the audio packets to a file. If you want to transcode the audio, then it will require more effort.
Since the ffmpeg source is open, feel free to look around yourself. The main file to look at is ffmpeg.c. It's big, so you're better off getting your hands dirty with the tutorial first.

c++ audio conversion ( mp3 -> ogg ) question

I was wondering if anyone knew how to convert an mp3 audio file to an ogg audio file. 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. 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.)
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.
For OGG there aren't many choices. You need libogg and libvorbis. Easy as that. The example codes that come with the libs show you how to do the encoding.
Good luck.
It's a bad idea. To quote from the Vorbis FAQ
You can convert any audio format to
Ogg Vorbis. However, converting from
one lossy format, like MP3, to another
lossy format, like Vorbis, is
generally a bad idea. Both MP3 and
Vorbis encoders achieve high
compression ratios by throwing away
parts of the audio waveform that you
probably won't hear. 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. 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. The
decoded MP3 will be missing the parts
of the original audio that the MP3
encoder chose to discard. The Ogg
Vorbis encoder will then discard other
audio components when it compresses
the data. 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. In
no case will you get a file that
sounds better than the original 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.
If you like Ogg Vorbis, then we would
encourage you to use it when you
encode from original, lossless audio
sources (like CDs). 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.
(If you must absolutely must convert
from MP3 to Ogg, there are several
conversion scripts available on
Freshmeat.)
http://www.vorbis.com/faq/#transcode
And, for the sake of accuracy, from the same FAQ:
Ogg Ogg is the name of Xiph.org's
container format for audio, video, and
metadata.
Vorbis Vorbis is the name of
a specific audio compression scheme
that's designed to be contained in
Ogg. Note that other formats are
capable of being embedded in Ogg such
as FLAC and Speex.
I imagine it's theoretically possible to embed MP3 in Ogg, though I'm not sure why anyone would want to. FLAC is a lossless audio codec. Speex is a very lossy audio codec optimised for encoding speech. Vorbis is a general-use lossy audio codec. "Ogg audio" is, therefore, a bit of a misnomer. Ogg Vorbis is the proper term for what I imagine you mean.
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. FFmpeg is a general-purpose library for converting lots of video and audio codecs and formats. 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. (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. It won't do anything new for you that way. It just gives you the option to do all sorts of other conversions too.
Foobar2000 (http://www.foobar2000.org/) is free and makes it quite easy to convert between file formats. It would take only a few clicks to convert from MP3 to 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). If you have access to the lossless source audio use that to convert it instead.
You will need to decode mp3 then encode into ogg.
One possibility is to use liblame for mp3 decoding and libogg/libvorbis for encoding into 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.
You can certainly do this in C++ with the Windows Media Format SDK.
I have only used WMFSDK9 myself. It contains a sample called UncompAVIToWMV, which may get you started. 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.
It also shows how to create an
arbitrary stream, do multipass
encoding and add SMPTE time codes.

Extracting raw audio/waveform from an MP3

This question has been in my mind for a few years and I never actually found the answer for this.
What I would like to do is extract the actual waveform/PCM of an MP3 file, so that I can play it using the soundcard (of course).
Ideally I would be experimenting some DSP effects.
My first step was to look into LAME, but I didn't find anything relevant about MP3 decoding in a program or stuff like that.
So I'm asking where I could find something like this.
What language should I use? I was thinking C, but maybe there are programming languages out there that would do the job more efficiently.
Thanks!
Guillaume.
The question boils down to: what are you trying to accomplish?
From the description of your question of decoding an MP3 and playing it on the sound card makes it sounds as if you are trying to make a media player.
However, if your intent is to play around with DSP effects, then it sounds like the question is more about processing the sound rather than decoding MP3s. if that's the case, probably looking into writing plug-ins for existing media players (such as Windows Media Player and Winamp) would be easiest path to what you're trying to accomplish.
Frankly, learning to write your own decoder from scratch is not just a programming problem but a mathematical one, so using existing libraries are the way to go. Talking to the operating system or libraries like DirectSound to output audio seems like unnecessary work if anything. I feel that working on plug-ins for existing players would be the way to go, unless your goal is to make your own media player.
If what you really want to accomplish is playing with audio data, then probably decoding an MP3 to uncompressed PCM using any MP3 decoder, then manipulating it in the language of your choice would accomplish your goal of dealing with effects with sound.
The language choice is going to depend on whether you are going to interact directly with MP3 decoding libraries, or whether you can just use raw audio input, which would allow you to use pretty much any language of your choice.
There was a similar question a while back, Getting started with programmatic audio, where I posted an answer on some basic ways to manipulate audio, such as amplification, changing playback speed, and doing some work with FFT.
libmpg123 should do the trick.
I have been using the Windows Media SDK, not for this purpose, but I am pretty sure there are hooks let that let you intercept the audio stream, or convert MP4 to uncompressed WAV. I used C++.
Lots:
http://www.mp3-tech.org/programmer/decoding.html
Pick your poison...
Also, LAME does decode MP3s (check out --decode option), so you might find something interesting in that source.
-Adam
It really depends what platform you are programming on and what you want to do with the code. If you are on Windows you should look at the windows media format sdk or DirectShow. They should both have the ability to decode mp3 files into the raw waveform. On the Mac, I would expect Quicktime to have this same ability. Others have already suggested source for Linux/open source code.
I would recommend looking at Cubase and Wavelab as both will convert MP3 to WAV etc and allow you to play around with the waveform