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;
}
将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;
}
相关文章推荐
- Android ListView 去除边缘阴影、选中色、拖动背景色等
- 简单的单例实现
- 黑马程序员_C语言基本概念
- git 分支管理策略 与 物理实现 --author by阮一峰 & 小鱼
- 黑马程序员_C语言概述
- Linux基础学习(意义、文件系统)
- ecshop的小总结
- 都市感衣橱 权利套装单品举荐女程序猿你值得拥有
- ajax打开一个新页面
- 【黑马程序员】C语言学习笔记之结构体(十二)
- 常用代码片段集锦
- 低内存处理
- QT OSG 浏览器插件 ,将OSG嵌入到IE中
- 3. web前端开发分享-css,js提高篇
- 单播,广播域多播区别及IP范围
- SAS硬盘和SATA硬盘的区别
- J2EE Java黑客大曝光:开发安全的Java应用程序
- 战网登录器:完美解决炉石美台国服三合一
- HTTP 错误 500.19 - Internal Server Error 错误解决方法 集锦iis7(在window7下)
- SQL存储过程-新增和修改,参数Xml数据类型