2013-05-01 96 views
1

我试图实施的ffmpeg,将检索本地视频(从设备在未来)的缓冲区的自定义读取功能,然后deocde该缓冲区等。FFMPEG自定义读取功能读取所有的数据

所以,这是我读功能

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

至于的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; 
     }; 
}; 

,为我执行:

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 
    {...} 

然而,一旦avformat_open_input()被调用时,读取功能IORead被调用,并不断读取文件clip.ts直到它到达其最终才把它退出,并没有数据到达解码过程解码(因为所有的它被消耗)

我不知道是什么特别,该代码

AVFormatContext *avFormatContextPtr = NULL; 
int err = avformat_open_input(&avFormatContextPtr, "/sdcard/clip.ts", NULL, NULL) ; 

没有阻止,直到该文件的末尾达到的问题。

我错过了什么吗? 我感谢您的帮助。

回答

0

很可能,avformat无法确定您的流的类型。你应该使用类似于

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