1

ローカル ビデオ (将来的にはデバイスから) からバッファを取得し、このバッファを 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) ;

ファイルの終わりに到達するまでブロックされません。

何か不足していますか?私はあなたの助けに感謝します。

4

1 に答える 1

0

ほとんどの場合、avformat はストリームのタイプを判別できません。次のようなものを使用する必要があります

avFormatContextPtr->iformat = av_find_input_format("mpegts");
于 2014-07-15T14:12:40.597 に答える