FFmpeg中的AVDictionary是一个结构体,简单的key/value存储,经常使用AVDictionary设置或读取内部参数,声明如下,具体实现在libavutil模块中的dict.c/h,提供此结构体是为了与libav兼容,但它实现效率低下,在FFmpeg 4.1.3版本中已弃用(deprecated),推荐使用libavutil模块中的tree.c/h来替代,但是在一些代码中或API中还是会使用到AVDictionary,包括FFmpeg中的examples,因此这里整理介绍下AVDictionary用法。

typedef struct AVDictionaryEntry {char *key;char *value;
} AVDictionaryEntry;struct AVDictionary {int count;AVDictionaryEntry *elems;
};

1. 一个空字典:AVDictionary* dict = nullptr;

2. 由指定的key获取一个字典条目(dictionary entry):av_dict_get

3. 获取字典条目数:av_dict_count

4. 设置一个字典条目,value为const char*:av_dict_set

5. 设置一个字典条目,value为int:av_dict_set_init,此函数内部会将int转为char*,然后再调用av_dict_set

6. 解析key/value对列表,并将解析的条目添加到字典中:av_dict_parse_string

7. 将条目从一个字典拷贝到另一个字典:av_dict_copy

8. 释放为AVDictonary结构分配的内存以及所有的key/value:av_dict_free

9. 以字符串形式获取一个字典条目:av_dict_get_string

10. av_dict_*中有些接口的最后一个参数为int flags,此参数可接受的有效值为在dict.h文件中定义的宏:

(1). AV_DICT_MATCH_CASE:设置字典中检索的key区分大小写,默认不区分大小写

(2). AV_DICT_IGNORE_SUFFIX:忽略字典中指定条目key的后缀

(3). AV_DICT_DONT_STRDUP_KEY:若key已分配,则不进行复制

(4). AV_DICT_DONT_STRDUP_VAL:若value已分配,则不进行复制

(5). AV_DICT_DONT_OVERWRITE:若指定key在字典中已存在,则不进行覆盖

(6). AV_DICT_APPEND:若指定key在字典中已存在,则value直接拼接到已存在value值的后面

(7). AV_DICT_MULTIKE:允许在字典中存储多个相同的key

FFmpeg中有些API都是通过AVDictionary来设置/读取内部参数的,如avformat_open_input,可设置video size、input format等,其使用可参见https://blog.csdn.net/fengbingchun/article/details/93975844

libavformat模块的options_table.h文件中列出了AVFormatContext支持的options选项;libavcodec模块的options_table.h文件中列出了AVCodecContext支持的options选项。

注:有时设置的参数会无效

测试代码如下(test_ffmpeg_libavutil.cpp):

#include "funset.hpp"
#include <string.h>
#include <iostream>
#include <string>
#include <memory>
#include <vector>#ifdef __cplusplus
extern "C" {
#endif#include <libavutil/dict.h>
#include <libavformat/avformat.h>
#include <libavdevice/avdevice.h>#ifdef __cplusplus
}
#endifint test_ffmpeg_libavutil_avdictionary()
{
{AVFormatContext* format_ctx = avformat_alloc_context();const char* url = "rtsp://184.72.239.149/vod/mp4://BigBuckBunny_175k.mov";int ret = -1;AVDictionary* dict = nullptr;av_dict_set(&dict, "max_delay", "100", 0);ret = avformat_open_input(&format_ctx, url, nullptr, &dict);if (ret != 0) {fprintf(stderr, "fail to open url: %s, return value: %d\n", url, ret);return -1;}fprintf(stdout, "dictionary count: %d\n", av_dict_count(format_ctx->metadata));AVDictionaryEntry* entry = nullptr;while ((entry = av_dict_get(format_ctx->metadata, "", entry, AV_DICT_IGNORE_SUFFIX))) {fprintf(stdout, "key: %s, value: %s\n", entry->key, entry->value);}avformat_free_context(format_ctx);av_dict_free(&dict);
}{ // reference: https://ffmpeg.org/doxygen/4.1/group__lavu__dict.htmlAVDictionary* d = nullptr; // "create" an empty dictionaryAVDictionaryEntry* t = nullptr;av_dict_set(&d, "foo", "bar", 0); // add an entrychar* k = av_strdup("key"); // if your strings are already allocated, you can avoid copying them like thischar* v = av_strdup("value");av_dict_set(&d, k, v, AV_DICT_DONT_STRDUP_KEY | AV_DICT_DONT_STRDUP_VAL);fprintf(stdout, "dictionary count: %d\n", av_dict_count(d));while (t = av_dict_get(d, "", t, AV_DICT_IGNORE_SUFFIX)) {fprintf(stdout, "key: %s, value: %s\n", t->key, t->value); // iterate over all entries in d}av_dict_free(&d);
}{avdevice_register_all();AVDictionary* options = nullptr;
#ifdef _MSC_VERconst char* input_format_name = "vfwcap";const char* url = "";
#elseconst char* input_format_name = "video4linux2";const char* url = "/dev/video0";av_dict_set(&options, "video_size", "640x480", 0);av_dict_set(&options, "input_format", "mjpeg", 0);
#endifAVInputFormat* input_fmt = av_find_input_format(input_format_name);AVFormatContext* format_ctx = avformat_alloc_context();int ret = avformat_open_input(&format_ctx, url, input_fmt, &options);if (ret != 0) {fprintf(stderr, "fail to open url: %s, return value: %d\n", url, ret);return -1;}fprintf(stdout, "dictionary count: %d\n", av_dict_count(format_ctx->metadata));AVDictionaryEntry* entry = nullptr;while ((entry = av_dict_get(format_ctx->metadata, "", entry, AV_DICT_IGNORE_SUFFIX))) {fprintf(stdout, "key: %s, value: %s\n", entry->key, entry->value);}av_dict_free(&options);avformat_close_input(&format_ctx);
}return 0;
}

执行结果如下:

GitHub:https://github.com//fengbingchun/OpenCV_Test

FFmpeg中AVDictionary介绍相关推荐

  1. ffmpeg中的时间 DTS、PTS、AV_TIME_BASE、AV_TIME_BASE_Q 介绍

    ffmpeg中的时间 DTS.PTS.AV_TIME_BASE.AV_TIME_BASE_Q等介绍  原文:http://www.cnblogs.com/yinxiangpei/articles/38 ...

  2. 关于FFMPEG中的filter滤镜的简单介绍

    滤镜的作用主要是对原始的音视频数据进行处理以实现各种各样的效果.比如叠加水印,翻转缩放视频等. 下图表示的正常转码流程,滤镜在解码和编码中间,虚线表示可有可无. 使用命令查看ffmpeg支持的滤镜 f ...

  3. 理解ffmpeg中的pts,dts,time_base

    首先介绍下概念: PTS:Presentation Time Stamp.PTS主要用于度量解码后的视频帧什么时候被显示出来 DTS:Decode Time Stamp.DTS主要是标识读入内存中的b ...

  4. 英特尔QSV技术在FFmpeg中的实现与使用

    本文来自英特尔资深软件工程师张华在LiveVideoStackCon 2018讲师热身分享,并由LiveVideoStack整理而成.在分享中张华介绍了英特尔GPU硬件架构,并详细解析了英特尔QSV技 ...

  5. ffmpeg 分辨率 压缩_用GPU加速FFmpeg中的超分辨率功能

    1. 简要回顾 首先简单复述一下FFmpeg中对深度学习的支持情况,如上图所示,FFmpeg在libavfilter中支持基于深度学习的filter,目前已经支持sr, derain和dnn_proc ...

  6. 英特尔 QSV 在 FFMPEG 中的使用(Linux)

    Intel Media SDK 现在 Intel 不再发布单独的 Intel Media SDK, 这个组件在 Linux 平台下集成在 Intel Media Server Studio 中,后文简 ...

  7. ffmpeg中av_read_frame 超时设置

    https://trac.ffmpeg.org/ ffmpeg wiki ffmpeg中avformat_open_input超时设置 这里有日志可以参考:日志 y也可以参考: https://blo ...

  8. ffmpeg中字典类型的描述

    原创:https://blog.csdn.net/ice_ly000/article/details/90599713?spm=1001.2014.3001.5501 ffmpeg中字典类型的描述: ...

  9. ffmpeg源码简析(十二)FFMPEG中的主要结构体总结

    FFMPEG中结构体很多.最关键的结构体可以分成以下几类: a) 解协议(http,rtsp,rtmp,mms) AVIOContext,URLProtocol,URLContext主要存储视音频使用 ...

最新文章

  1. 用Python分析《红楼梦》:见证了贾府的兴衰,你是否还能“笑道”世事无常
  2. 【Data Algorithms CHP07】数组生成组合排列
  3. 加密日记 android,深挖Android加密到崩溃
  4. ivy java_使用Ivy管理项目中的依赖
  5. qt 中转化图片格式与大小的方法
  6. mysql004操作表.增删改
  7. echarts中triggeron与trigger不能同时出现吗_好物|痛风、血糖高、虚不受补能吃它吗?你想知道的阿胶十问十答一锅出!...
  8. oracle crc32函数,CSS_ORACLE中实现CRC32的计算函数,SOLARIS平台,声明:这是我07年的一个偶然 - phpStudy...
  9. 基于shiro+jwt的真正rest url权限管理,前后端分离
  10. php 复选框 未选,php – 在表单发布时如何获取复选框元素中未选中复选框的值?...
  11. 物联网核心安全系列——物联网安全需求
  12. 矩阵、优化理论常用记号
  13. c++ list遍历_List集合就这么简单「源码剖析」
  14. 制作.rpgsave存档修改器
  15. 面试时要怎么做自我介绍呢?
  16. springcloud之服务发现笔记
  17. 民航产业发展趋势及对策建议(2021-10-21)
  18. 地下城与勇士正在自动连接频道服务器,DNF爆满频道服务器连接失败解决方法分享...
  19. linux的ping命令含义,Linux ping命令详解
  20. 国内外研究现状和发展趋势

热门文章

  1. QT:qt安装缺少GUI Application 选项
  2. CV算法复现(分类算法4/6):GoogLeNet(2014年 谷歌)
  3. 三维点云语义分割总览
  4. 基于CUDA实现立方体贴图 (Cubemaps) 转换为全景图 (Equirectangular Panorama)
  5. 在Ubuntu 14.04 64bit上安装字体管理器font-manager
  6. 在Uubuntu 14.04 64bit上搭建NumPy函数库环境
  7. vim学习笔记(四)
  8. C++ 通过模版工厂实现 简单反射机制
  9. C++的STL栈实现队列
  10. linux系统调用 ftruncate设置文件大小