Are there any good tutorials on decoding audio with libavcodec? I've seen
the one about "How to write a video player in less than 1000 lines" but that
uses SDL for audio output, and that's not what I want. I've looked at
apiexample.c from the ffmpeg git sources, and still cannot get this to work.
Here is my code that's supposed to decode the file (right now, I'm trying a
simple .wav file):

void
playsound()
{
    AVPacket packet;
    uint16_t *outbuf = 0;
    uint8_t inbuf[AVCODEC_MAX_AUDIO_FRAME_SIZE +
FF_INPUT_BUFFER_PADDING_SIZE], *inbuf_ptr;
    int lenread, lenwrite, outbuf_size = 4096;

    outbuf = malloc(AVCODEC_MAX_AUDIO_FRAME_SIZE);

    inbuf_ptr = inbuf;
    while (av_read_frame(formatContext, &packet) >= 0)
    {
        memcpy(inbuf_ptr, packet.data, packet.size);

        lenread = avcodec_decode_audio2(codecContext, outbuf, &outbuf_size,
inbuf_ptr, AVCODEC_MAX_AUDIO_FRAME_SIZE);
        fprintf(stderr, "playsound(): bytes read = %d\n", lenread);

        if (lenread <= 0)
        {
            fprintf(stderr, "playsound(): There was an error reading from
audio stream...\n");
        }
        else
        {
            lenwrite = snd_pcm_writei(_soundDevice, outbuf, outbuf_size);
            fprintf(stderr, "playsound(): bytes written = %d\n", lenwrite);
        }
    }
}

Here is the error that I get: *[pcm_s16le @ 0xb7e25648]buffer smaller than
AVCODEC_MAX_AUDIO_FRAME_SIZE.* As you can see, both my input and output
buffer variable are set to this exact size, or greater. Not sure what's
going on.

The code to initialize libavcodec is fine, and correctly detects and opens
the appropriate codec, here is a sample of the output from calling
dump_format():

Input #0, wav, from 'example2.wav':
  Duration: 00:05:16.3, start: 0.000000, bitrate: 1411 kb/s
  Stream #0.0: Audio: pcm_s16le, 44100 Hz, stereo, 1411 kb/s

And just for good measure, here is a pastebin of the entire code file:
http://pastebin.com/f27cc39c2

Any help is greatly appreciated!

Thanks in advance,
mw007
_______________________________________________
libav-user mailing list
libav-user@mplayerhq.hu
https://lists.mplayerhq.hu/mailman/listinfo/libav-user

Reply via email to