Hello everyone,
I am creating a library to put more than one file into one file (some
kind of package file). So, I need to use a custom AVIOContext. I try
the following code to test and the "avformat_open_input" give function
give me an "Invalid data found when processing input" error.

The Code:

#include <stdio.h>
#include <libavcodec/avcodec.h>
#include <libavformat/avformat.h>

int read_packet(void *opaque, uint8_t *buf, int buf_size){
        FILE *the_file = (FILE *) opaque;
        return(fread(buf,1,buf_size,the_file));
}


int64_t seek(void *opaque, int64_t offset, int whence){
        FILE *the_file = (FILE *) opaque;
        return(fseek ( the_file, offset, whence ));
}

int main(){
        AVFormatContext *input;
        AVIOContext * avio_context;
        unsigned char * bio_buffer;
        FILE *the_file;

        the_file=fopen("sound.flac","rb");
        input=avformat_alloc_context();
        bio_buffer=(unsigned char *)av_malloc(4092);
        
avio_context=avio_alloc_context(bio_buffer,4092,0,the_file,&read_packet,NULL,&seek);
        input->pb=avio_context;
        if(!input->pb) {
                return 1;
        }
        int r=avformat_open_input(&input,"stream",NULL,NULL);
        if(r<0){
                char * error;
                error=malloc(64);
                av_strerror(r,error,64);
                printf("Error: %s\n",error);
                free(error);
                return 1;
        }
        avformat_free_context(input);
        av_free(avio_context);
        av_free(bio_buffer);
        fclose(the_file);
}


The "sound.flac" file is a standard flac file. Here is what the
"ffmpeg -i sound.flac" command line give me:

[flac @ 0x1c0a7a0] max_analyze_duration reached
Input #0, flac, from 'sound.flac':
  Duration: 00:00:15.31, bitrate: 342 kb/s
    Stream #0.0: Audio: flac, 44100 Hz, 1 channels, s16
At least one output file must be specified


So, if someone can help me out. I'm a stuck here.

Thanks in advance.

Louis M
_______________________________________________
Libav-user mailing list
[email protected]
http://ffmpeg.org/mailman/listinfo/libav-user

Reply via email to