[FFmpeg-devel] problem with wma files

cab www.bigcab
Sun Aug 19 21:41:36 CEST 2007


Hi

I've got some problems with libavcodec and a wma file

here's my source code

#include <stdio.h>
#include <string.h>
#include <math.h>
#include <ao/ao.h>
#include <stdlib.h>
#include <ffmpeg/avcodec.h>
#include <ffmpeg/avformat.h>
#define BUFFER_SIZE 4096
void audio_decode_example(const char *filename)
{
	ao_initialize();
	int ao_id=ao_default_driver_id();
	ao_sample_format format;
	format.bits=16;
	format.rate=44100;
	format.byte_format = AO_FMT_LITTLE;
	format.channels = 2;
	ao_device*ao_dev=ao_open_live(ao_id,&format,NULL);
	AVInputFormat*av_format=av_find_input_format(filename);
    AVCodec *codec;
    AVCodecContext *c= NULL;
    int out_size, size, len;
    FILE *f, *outfile;
    short *outbuf;
    uint8_t inbuf[BUFFER_SIZE + FF_INPUT_BUFFER_PADDING_SIZE],
*inbuf_ptr;
	
    memset(inbuf + BUFFER_SIZE, 0, FF_INPUT_BUFFER_PADDING_SIZE);
	
    codec=avcodec_find_decoder_by_name("wmav2");
    if (!codec) {
        fprintf(stderr, "codec not found\n");
        exit(1);
    }
	
    c= avcodec_alloc_context();
	printf("ok\n");
	if (avcodec_open(c,codec) < 0) {
        fprintf(stderr, "could not open codec\n");
        exit(1);
    }
    outbuf = malloc(AVCODEC_MAX_AUDIO_FRAME_SIZE);
    f = fopen(filename, "r+");
    if (!f) {
        fprintf(stderr, "could not open %s\n", filename);
        exit(1);
    }
    

    inbuf_ptr = inbuf;
    for(;;) {
        size = fread(inbuf, 1, BUFFER_SIZE, f);
        if (size == 0)
            break;

        inbuf_ptr = inbuf;
        while (size > 0) {
            len = avcodec_decode_audio(c, (short *)outbuf, &out_size,
                                       inbuf_ptr, size);
            if (len < 0) {
                fprintf(stderr, "Error while decoding\n");
                exit(1);
            }
            if (out_size > 0) {
                ao_play(ao_dev,(char*)outbuf,out_size);
            }
            size -= len;
            inbuf_ptr += len;
        }
    }

    fclose(outfile);
    fclose(f);
    free(outbuf);
	ao_close(ao_dev);
	ao_shutdown();

    avcodec_close(c);
    av_free(c);
}

int main()
{
	avcodec_init();
	avcodec_register_all();
	audio_decode_example("kelly.wma");
	return 0;
}



and the result is :
 
error code 8 : floating point exception




Thanks for your help



Cab





More information about the ffmpeg-devel mailing list