ffmpeg 中avio_alloc_context的使用

关键点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;
}




  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值