[libav-api] How to play/decode audio file with libav
manuel.spam at nurfuerspam.de
Mon Jun 27 12:12:48 CEST 2011
Ronald S. Bultje <rsbultje <at> gmail.com> writes:
> Yes it can do all of that. Start looking at ffplay.c it is way more
> complex than what you need, but will serve as an example.
> libavcodec/api-example.c is a simple decoding example, and the packet
> reading can be got from ffplay.c.
Had a look at those.
Maybe decoding from a file is easy.
I would start with "av_register_all();". Then I have to open the file with
avformat_open_input. av_find_stream_info should allow me to find out what kinds
of streams are in that file. I would just loop over them to find the first audio
stream. Next step would be avcodec_find_decoder, then avcodec_open. Stuff about
actually decoding the input file still has to be discovered...
What I can't find out is how to read my custom stream.
What I have is a C++ class. I create a instance of this and pass the URL to the
constructor. The class then offers a "read" function, which returns a memory
buffer to what already has been received and a byte count so I know how many
bytes are in that buffer. The buffer has to be emptied completely, so I hope
ffmpeg provides buffers with an matching size... At end of playback the class
function "close" has to be called.
First problem is, that I need a way to forward the class pointer of my c++ class
down to whatever function libavcodec uses to read the stream, so I can avoid
And the biggest problem: I have no idea how I can connect my custom stream
handling to libavcodec... "Seek", of course, doesn't work for a stream. So what
I need is some kind of "open()", "read()" and "close()".
More information about the libav-api