AVOption用于在FFmpeg中描述结构体中的成员变量。一个AVOption可以包含名称,简短的帮助信息,取值等。

上篇文章中概括了AVClass,AVOption和目标结构体之间的关系。以AVFormatContext为例,可以表示为下图。

上篇文章主要概括了AVClass,AVOption和目标结构体之间的从属关系,但是并没有分析有关AVOption的源代码。本文分析有关AVOption的源代码。

AVOption有关的API

AVOption常用的API可以分成两类:用于设置参数的API和用于读取参数的API。其中最有代表性的用于设置参数的API就是av_opt_set();而最有代表性的用于读取参数的API就是av_opt_get()。除了以上两个函数之外,本文再记录一个在FFmpeg的结构体初始化代码中最常用的用于设置默认值的函数av_opt_set_defaults()


函数调用关系图

av_opt_set()的函数调用关系图如下所示。


av_opt_get()的函数调用关系图如下所示。buf[128]



av_opt_set_defaults()的函数调用关系图如下所示。注:av_opt_set_defaults2是deprecated的api




av_opt_set()

通过AVOption设置参数最常用的函数就是av_opt_set()了。该函数通过字符串的方式(传入的参数是:变量名称的字符串和变量值的字符串)设置一个AVOption的值。此外,还包含了它的一系列“兄弟”函数av_opt_set_XXX(),其中“XXX”代表了int,double这些数据类型。使用这些函数的时候,可以指定int,double这些类型的变量(而不是字符串)作为输入,设定相应的AVOption的值。

  1. /** 
  2.  * @defgroup opt_set_funcs Option setting functions 
  3.  * @{ 
  4.  * Those functions set the field of obj with the given name to value. 
  5.  * 
  6.  * @param[in] obj A struct whose first element is a pointer to an AVClass. 
  7.  * @param[in] name the name of the field to set 
  8.  * @param[in] val The value to set. In case of av_opt_set() if the field is not 
  9.  * of a string type, then the given string is parsed. 
  10.  * SI postfixes and some named scalars are supported. 
  11.  * If the field is of a numeric type, it has to be a numeric or named 
  12.  * scalar. Behavior with more than one scalar and +- infix operators 
  13.  * is undefined. 
  14.  * If the field is of a flags type, it has to be a sequence of numeric 
  15.  * scalars or named flags separated by '+' or '-'. Prefixing a flag 
  16.  * with '+' causes it to be set without affecting the other flags; 
  17.  * similarly, '-' unsets a flag. 
  18.  * @param search_flags flags passed to av_opt_find2. I.e. if AV_OPT_SEARCH_CHILDREN 
  19.  * is passed here, then the option may be set on a child of obj. 
  20.  * 
  21.  * @return 0 if the value has been set, or an AVERROR code in case of 
  22.  * error: 
  23.  * AVERROR_OPTION_NOT_FOUND if no matching option exists 
  24.  * AVERROR(ERANGE) if the value is out of range 
  25.  * AVERROR(EINVAL) if the value is not valid 
  26.  */  
  27. int av_opt_set         (void *obj, const char *name, const char *val, int search_flags);  
  28. int av_opt_set_int     (void *obj, const char *name, int64_t     val, int search_flags);  
  29. int av_opt_set_double  (void *obj, const char *name, double      val, int search_flags);  
  30. int av_opt_set_q       (void *obj, const char *name, AVRational  val, int search_flags);  
  31. int av_opt_set_bin     (void *obj, const char *name, const uint8_t *val, int size, int search_flags);  
  32. int av_opt_set_image_size(void *obj, const char *name, int w, int h, int search_flags);  
  33. int av_opt_set_pixel_fmt (void *obj, const char *name, enum AVPixelFormat fmt, int search_flags);  
  34. int av_opt_set_sample_fmt(void *obj, const char *name, enum AVSampleFormat fmt, int search_flags);  
  35. int av_opt_set_video_rate(void *obj, const char *name, AVRational val, int search_flags);  
  36. int av_opt_set_channel_layout(void *obj, const char *name, int64_t ch_layout, int search_flags);  

相关文章:

  • 2021-06-15
  • 2021-10-29
  • 2022-12-23
  • 2021-10-16
  • 2021-10-15
  • 2021-06-16
  • 2021-12-15
  • 2022-12-23
猜你喜欢
  • 2021-09-17
  • 2022-01-22
  • 2022-12-23
  • 2021-07-15
  • 2021-09-29
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案