[FFmpeg-devel] FFMPEG Custom Read function reads all the data

Hafedh Haouala haouala-hafedh at live.fr
Wed May 1 20:41:20 CEST 2013


Hi,
I'm trying to implement a custom read function for ffmpeg that will retrieve a buffer from local video ( from device in the future) and then deocde this buffer, etc..

So, here's my read function 

    int IORead(void *opaque, uint8_t *buf, int buf_size)
    {
    FileReader* datrec = (FileReader*)opaque;
    int ret = datrec->Read(buf, buf_size);
    return ret;
    }

As for the FileReader :

     class FileReader { 
     protected:
      int fd;
     public:
      FileReader(const char *filename){ //, int buf_size){
          fd = open(filename, O_RDONLY);
          };

     ~FileReader() {
           close(fd);
         };

     int Read(uint8_t *buf, int buf_size){
       int len = read(fd, buf, buf_size);
       return len;
          };
     };

and for the my execution :

    FileReader *receiver = new FileReader("/sdcard/clip.ts");

    AVFormatContext *avFormatContextPtr = NULL;
    this->iobuffer = (unsigned char*) av_malloc(4096 + FF_INPUT_BUFFER_PADDING_SIZE);
    avFormatContextPtr = avformat_alloc_context();
    avFormatContextPtr->pb = avio_alloc_context(this->iobuffer, 4096, 0, receiver, IORead, NULL, NULL);
    avFormatContextPtr->pb->seekable    = 0;

    int err = avformat_open_input(&avFormatContextPtr, "", NULL, NULL) ;
    if( err != 0)
     {...}
    // Decoding process
      {...}

However, once the `avformat_open_input()` is called, the read function `IORead` is called and keeps reading the file `clip.ts` until it reaches its end and only then it exit and the decoding process is reached with no data to decode ( as all of it was consumed)

I don't know what is the problem especially that this code 
     AVFormatContext *avFormatContextPtr = NULL;
     int err = avformat_open_input(&avFormatContextPtr, "/sdcard/clip.ts", NULL, NULL) ;
isn't blocking untill the end of the file is reached. 

Am I missing something ?
I really appreciate your help.
 		 	   		  


More information about the ffmpeg-devel mailing list