如何利用 AVDictionary 配置参数
来源:互联网 发布:淘宝风衣长款外套 编辑:程序博客网 时间:2024/04/27 23:05
本文是我的 FFMPEG Tips 系列的第五篇文章,准备介绍下 ffmpeg 提供的一个非常好用的健值对工具:AVDictionary,特别是对于没有 map 容器的 c 代码,可以充分利用它来配置和定义播放器的参数,ffmpeg 本身也有很多 API 通过它来传递参数。
1. AVDictionary 的用法简介
AVDictionary 所在的头文件在 libavutil/dict.h,其定义如下:
struct AVDictionary { int count; AVDictionaryEntry *elems; };
其中,AVDictionaryEntry 的定义如下:
typedef struct AVDictionaryEntry { char *key; char *value; } AVDictionaryEntry;
下面就用示例的方式简单介绍下用法
(1)创建一个字典
AVDictionary *d = NULL;
(2) 销毁一个字典
av_dict_free(&d);
(3)添加一对 key-value
av_dict_set(&d, "name", "jhuster", 0);av_dict_set_int(&d, "age", "29", 0);
(4) 获取 key 的值
AVDictionaryEntry *t = NULL;t = av_dict_get(d, "name", NULL, AV_DICT_IGNORE_SUFFIX);av_log(NULL, AV_LOG_DEBUG, "name: %s", t->value);t = av_dict_get(d, "age", NULL, AV_DICT_IGNORE_SUFFIX);av_log(NULL, AV_LOG_DEBUG, "age: %d", (int) (*t->value));
(5) 遍历字典
AVDictionaryEntry *t = NULL;while ((t = av_dict_get(d, "", t, AV_DICT_IGNORE_SUFFIX))) { av_log(NULL, AV_LOG_DEBUG, "%s: %s", t->key, t->value);}
2. ffmpeg 参数的传递
ffmpeg 中很多 API 都是靠 AVDictionary 来传递参数的,比如常用的:
int avformat_open_input(AVFormatContext **ps, const char *url, AVInputFormat *fmt, AVDictionary **options);
最后一个参数就是 AVDictionary,我们可以在打开码流前指定各种参数,比如:探测时间、超时时间、最大延时、支持的协议的白名单等等,例如:
AVDictionary *options = NULL;av_dict_set(&options, “probesize”, “4096", 0);av_dict_set(&options, “max_delay”, “5000000”, 0);AVFormatContext *ic = avformat_alloc_context();if (avformat_open_input(&ic, url, NULL, &options) < 0) { LOGE("could not open source %s", url); return -1;}
那么,我们怎么知道 ffmpeg 的这个 API 支持哪些可配置的参数呢 ?
我们可以查看 ffmpeg 源码,比如 avformat_open_input 是结构体 AVFormatContext 提供的 API,在 libavformat/options_table.h 中定义了 AVFormatContext 所有支持的 options 选项,如下所示:
https://www.ffmpeg.org/doxygen/trunk/libavformat_2options__table_8h-source.html
同理,AVCodec 相关 API 支持的 options 选项则可以在 libavcodec/options_table.h 文件中找到,如下所示:
https://www.ffmpeg.org/doxygen/3.1/libavcodec_2options__table_8h_source.html
3. 小结
当然,我们也可以仿照 ffmpeg,给自己的核心结构体对象定义这样的 options 选项,这篇文章就不展开详述了。
- 如何利用 AVDictionary 配置参数
- 如何利用AVDictionary配置参数
- FFMPEG 如何利用 AVDictionary 配置参数
- 利用environment文件配置heat模板参数
- 如何利用eclipse传递args[]参数
- lxc如何修改配置参数
- ffmpeg数据结构之AVDictionary
- 如何利用mysql里的show global status和show variables来优化mysql的配置参数
- 教你如何利用分布式的思想处理集群的参数配置信息——spring的configurer妙用
- 如何利用Win2000 Server配置路由(图)
- ffmpeg metadata及AVDictionary分析
- 核心网络设备配置及参数如何备份
- 高手教大家如何配置JVM参数
- 如何在代码里配置-D 参数?
- 如何配置JVM的GC参数
- redis之如何配置jedisPool参数
- 高手教大家如何配置jvm参数
- redis之如何配置jedisPool参数
- using和typedef区别
- easyUI中的combobox联动
- 天瑞地安电子锁APP应用 为安全家居保驾护航
- Hibernate (一)概述
- 475. Heaters
- 如何利用 AVDictionary 配置参数
- hdu ACM steps 1.2.7 hdu 2629
- jQuery Mobile插件
- ubuntu中安装chkconfig
- 《程序员的自我修养》--静态链接
- python学习笔记-基于flask的web服务提供
- 如何把本地时间转换成UTC(通用时间)
- EditText单行显示
- py模块下载总结