AVDictionary结构体相关源码介绍

本文介绍了FFmpeg中的AVDictionary结构体及相关的函数使用方法,包括创建、读取和释放AVDictionary的具体步骤。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

本文对AVDictionary结构体部分相关函数代码进行了介绍

[cpp]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. 本文研究分析AVDictionary相关代码  
  2.   
  3.  struct AVDictionary {  
  4.      int count;  
  5.      AVDictionaryEntry *elems;  
  6.  };  
  7.   
  8. typedef struct AVDictionaryEntry {  
  9.     char *key;  
  10.     char *value;  
  11. } AVDictionaryEntry;  
  12. /* 
  13.  *这就是一个键值对或者叫键值对数组。为了create一个AVDictionary, 
  14.  *用到了av_dict_set()函数,将一个空指针传入该函数,这个空指针为 
  15.  *空的AVDictionary。生成AVDictionary后,可以通过av_dict_get()函 
  16.  *来找回一个数组或者递归所有数组,最后用av_dict_free()来释放。 
  17.  */  
  18.     AVDictionary *d = NULL;           // "create" an empty dictionary  
  19.     AVDictionaryEntry *t = NULL;  
  20.     av_dict_set(&d, "foo""bar", 0); // add an entry  
  21.     char *k = av_strdup("key");       // if your strings are already allocated,  
  22.     char *v = av_strdup("value");     // you can avoid copying them like this  
  23.     av_dict_set(&d, k, v, AV_DICT_DONT_STRDUP_KEY | AV_DICT_DONT_STRDUP_VAL);  
  24.     while (t = av_dict_get(d, "", t, AV_DICT_IGNORE_SUFFIX)) {  
  25.         <....>                             // iterate over all entries in d  
  26.     }  
  27.     av_dict_free(&d);  
  28.       
  29.     /* 
  30.      *介绍主要函数 
  31.      */  
  32.     /* 
  33.      *这个函数是把给定的key/value放入*pm中,如果数组已存在则覆盖 
  34.      *Note:增加一个新的数组到dictionary中会使之前由av_dict_get()返回的数组失效 
  35.      *  pm   指向一个dictionary的指针的指针。如果*pm是空,那么一个dictionary结构将 
  36.      *       由函数分配并放入*pm 
  37.      *  key  数组中的key值要加入*pm,由av_strduped设置一个值或者根据一个flag增加 
  38.      *  value 数组中的value值要加入*pm,由av_strduped设置一个值或者根据一个flag增加 
  39.      * 
  40.      *  函数成功执行返回0,否则返回<0 
  41.     */  
  42.          int av_dict_set    (   AVDictionary **     pm,  
  43.             const char *    key,  
  44.             const char *    value,  
  45.             int     flags )       
  46.         
  47.      /* 
  48.       *通过匹配的key值得到一个dictionary entry,返回的entry key或value值不能被修改 
  49.       *为递归所有dictionary entry,可以set the matching key to null,并且set the  
  50.       *AV_DICT_IGNORE_SUFFIX flag 
  51.       *   prev  Set to the previous matching element to find the next.If set to null 
  52.       *         the first matching element is returned 
  53.       *   key   matching key 
  54.       *   flags a collection of AV_DICT_ *flags,控制着如何检索数组 
  55.       * 
  56.       * 执行结果是:found entry or NULL in case no matching entry was found in the dictionary 
  57.      */  
  58.           AVDictionaryEntry* av_dict_get    (   const AVDictionary *    m,  
  59.                      const char *   key,  
  60.                      const AVDictionaryEntry *  prev,  
  61.                      int    flags )         
  62.         
  63.      /* 
  64.       *对av_dict_set的一个包装处理,将其参数value转换成一个string类型并存储下来 
  65.       */   
  66.          int av_dict_set_int    (   AVDictionary **     pm,  
  67.                     const char *    key,  
  68.                     int64_t     value,  
  69.                     int     flags )   
[cpp]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. <pre name="code" class="cpp">/* 
  2.       *拷贝entries从一个AVDictionary到另一个AVDictionary 
  3.       *   dst   指向一个AVDictionary结构体 
  4.       *   src   指向原AVDictionary结构体 
  5.       *   flag  在set dst中的entries时用到 
  6.       *   成功返回0,失败返回负。 
  7.       */   
  8.       int av_dict_copy  (   AVDictionary **     dst,  
  9.                const AVDictionary *     src,  
  10.                int  flags )  
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值