本文是我的 FFMPEG Tips 系列的第五篇文章,准备介绍下 ffmpeg 提供的一个非常好用的健值对工具:AVDictionary,特别是对于没有 map 容器的 c 代码,可以充分利用它来配置和定义播放器的参数,ffmpeg 本身也有很多 API 通过它来传递参数。

1.  AVDictionary 的用法简介

AVDictionary 所在的头文件在 libavutil/dict.h,其定义如下:

  1. struct AVDictionary {
  2. int count;
  3. AVDictionaryEntry *elems;
  4. };

其中,AVDictionaryEntry 的定义如下:

  1. typedef struct AVDictionaryEntry {
  2. char *key;
  3. char *value;
  4. } AVDictionaryEntry;

下面就用示例的方式简单介绍下用法

(1)创建一个字典

  1. AVDictionary *d = NULL;

(2) 销毁一个字典

  1. av_dict_free(&d);

(3)添加一对 key-value

  1. av_dict_set(&d, "name", "jhuster", 0);
  2. av_dict_set_int(&d, "age", "29", 0);

(4) 获取 key 的值

  1. AVDictionaryEntry *t = NULL;
  2. t = av_dict_get(d, "name", NULL, AV_DICT_IGNORE_SUFFIX);
  3. av_log(NULL, AV_LOG_DEBUG, "name: %s", t->value);
  4. t = av_dict_get(d, "age", NULL, AV_DICT_IGNORE_SUFFIX);
  5. av_log(NULL, AV_LOG_DEBUG, "age: %d", (int) (*t->value));

(5) 遍历字典

  1. AVDictionaryEntry *t = NULL;
  2. while ((t = av_dict_get(d, "", t, AV_DICT_IGNORE_SUFFIX))) {
  3. av_log(NULL, AV_LOG_DEBUG, "%s: %s", t->key, t->value);
  4. }

2.  ffmpeg 参数的传递

ffmpeg 中很多 API 都是靠 AVDictionary 来传递参数的,比如常用的:

  1. int avformat_open_input(AVFormatContext **ps, const char *url, AVInputFormat *fmt, AVDictionary **options);

最后一个参数就是 AVDictionary,我们可以在打开码流前指定各种参数,比如:探测时间、超时时间、最大延时、支持的协议的白名单等等,例如:

  1. AVDictionary *options = NULL;
  2. av_dict_set(&options, “probesize”, “4096", 0);
  3. av_dict_set(&options, “max_delay”, “5000000”, 0);
  4. AVFormatContext *ic = avformat_alloc_context();
  5. if (avformat_open_input(&ic, url, NULL, &options) < 0) {
  6. LOGE("could not open source %s", url);
  7. return -1;
  8. }

那么,我们怎么知道 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 选项,这篇文章就不展开详述了。

http://blog.csdn.net/encoder1234/article/details/54582676

如何利用 AVDictionary 配置参数(转)的更多相关文章

  1. struts2 笔记01 登录、常用配置参数、Action访问Servlet API 和设置Action中对象的值、命名空间和乱码处理、Action中包含多个方法如何调用

    Struts2登录 1. 需要注意:Struts2需要运行在JRE1.5及以上版本 2. 在web.xml配置文件中,配置StrutsPrepareAndExecuteFilter或FilterDis ...

  2. reids配置参数详解

    转自:http://www.jb51.net/article/60627.htm reids配置参数详解 #daemonize no  默认情况下, redis 不是在后台运行的,如果需要在后台运行, ...

  3. Redis配置参数详解

    Redis配置参数详解 /********************************* GENERAL *********************************/ // 是否作为守护进 ...

  4. Spark配置参数详解

    以下是整理的Spark中的一些配置参数,官方文档请参考Spark Configuration. Spark提供三个位置用来配置系统: Spark属性:控制大部分的应用程序参数,可以用SparkConf ...

  5. 2、haproxy配置参数详解

    代理相关配置参数 内容参考自马哥教育 HAProxy官方文档 https://cbonte.github.io/haproxy-dconv/2.0/configuration.html URI Syn ...

  6. 笔记01 登录、常用配置参数、Action访问Servlet API 和设置Action中对象的值、命名空间和乱码处理、Action中包含多个方法如何调用

    Struts2登录 1. 需要注意:Struts2需要运行在JRE1.5及以上版本 2. 在web.xml配置文件中,配置StrutsPrepareAndExecuteFilter或FilterDis ...

  7. redis.windows.conf各项配置参数介绍 (九)

    # 默认情况下,redis不是在后台模式运行的,如果需要在后台进程运行,把该项的值更改为yes,默认为no daemonize:是否以后台daemon方式运行 # 如redis服务以后台进程运行的时候 ...

  8. 29个酷炫的Firefox配置参数

    你可能安装了许多的firefox插件以增加浏览器的功能,但是如果你想更好地使用firefox,学习如何配置about:config参数是很有必要的. about:config配置页包含了所有的fire ...

  9. IDEA02 利用Maven创建Web项目、为Web应用添加Spring框架支持、bean的创建于获取、利用注解配置Bean、自动装配Bean、MVC配置

    1 环境版本说明 Jdk : 1.8 Maven : 3.5 IDEA : 专业版 2017.2 2 环境准备 2.1 Maven安装及其配置 2.2 Tomcat安装及其配置 3 详细步骤 3.1 ...

随机推荐

  1. SNMP Introduction

    Basic command of SNMP: GET: The GET operation is a request sent by the manager to the managed device ...

  2. PHP中使用OpenSSL下openssl_verify验证签名案例

    使用OpenSSL那么需要先了解一下http://www.cnblogs.com/wt645631686/p/8390936.html <?php //demo $json = '{" ...

  3. 【转载】linux fork死循环炸弹及其预防

    转自linux fork死循环炸弹及其预防 在Linux系统下执行这段代码 :(){ :|:& }:: 就会引起死机,一旦执行起来后,唯一的方法就是重启系统.实际上这段代码是一段无限递归代码, ...

  4. POJ 2240 Arbitrage(判正环)

    http://poj.org/problem?id=2240 题意:货币兑换,判断最否是否能获利. 思路:又是货币兑换题,Belloman-ford和floyd算法都可以的. #include< ...

  5. shell 字符串加入变量

    your_name='runoob' str="Hello, I know you are \"$your_name\"! \n" echo $str

  6. javascript debugger

    打开调试工具,刷新,可以看到脚本被暂停 <!DOCTYPE html> <html> <head> <meta charset="utf-8&quo ...

  7. DB.使用Oracle时的遇到的问题

    1.(20190225)ojdbc14.jar 来自“E:\ZC_DB\_Connector\Oracle\10g\Oracle Database 10g Release 2 (10.2.0.4) J ...

  8. [原][osgearth]osgearth本地(离线)数据源处理小结

    参考:http://docs.osgearth.org/en/latest/data.html Processing Local Source Data If you have geospatial ...

  9. [Err] 1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'number primary key,

    如题,mysql建表语句报错 分析:就是一个语法错误,具体问题具体分析 本例中,直接赋值过来的 sql建表语句,直接粘贴到mysql数据库运行,报错! 经查询,mysql中 number类型的定义有如 ...

  10. RHEL7.X 安装 11.2.0.4 RAC 问题

    随着Linux 7 版本的普及,但Oracle数据库主流版本仍是11gR2,11.2.0.4 是生产安装首选.由于11.2.0.4对Linux 7 的支持不很完美,在Linux 7 上安装会遇到几处问 ...