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

Michael Niedermayer michaelni at gmx.at
Thu May 2 23:52:22 CEST 2013


On Wed, May 01, 2013 at 07:41:20PM +0100, Hafedh Haouala wrote:
> 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.

did you try reading the same filw withg unmodified ffmpeg ?
does that read less ?

[...]
-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

The worst form of inequality is to try to make unequal things equal.
-- Aristotle
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: Digital signature
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20130502/4f6771d9/attachment.asc>


More information about the ffmpeg-devel mailing list