您的位置:首页 > 其它

ffmpeg 中avio_alloc_context的使用

2014-03-17 09:36 597 查看
关键点1

将avio_alloc_context产生的AVIOContext设置到AVFormatContext的pb变量。

实例代码

#define BUF_SIZE (1*1024*1024)

uint8_t *pAvioBuf = (uint8_t*)av_mallocz(sizeof(uint8_t)*BUF_SIZE);

AVIOContext *avioCtx = avio_alloc_context(pAvioBuf, BUF_SIZE, 0, NULL, read_packet, NULL, seek_packet);

g_pFmtCtx = avformat_alloc_context();

g_pFmtCtx->pb = avioCtx;

关键点2

关于read_packet,seek_packet函数怎么写。

参考file.c

static int file_read(URLContext *h, unsigned char *buf, int size)

{

FileContext *c = h->priv_data;

int r;

size = FFMIN(size, c->blocksize);

r = read(c->fd, buf, size);

return (-1 == r)?AVERROR(errno):r;

}

static int64_t file_seek(URLContext *h, int64_t pos, int whence)

{

FileContext *c = h->priv_data;

int64_t ret;

if (whence == AVSEEK_SIZE) {

struct stat st;

ret = fstat(c->fd, &st);

return ret < 0 ? AVERROR(errno) : (S_ISFIFO(st.st_mode) ? 0 : st.st_size);

}

ret = lseek(c->fd, pos, whence);

return ret < 0 ? AVERROR(errno) : ret;

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: