1

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 appreciate your help.

1 Answer 1

0

Most likely, avformat cannot determine the type of your stream. You should use something like

avFormatContextPtr->iformat = av_find_input_format("mpegts");

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.