AVOption是FFmpeg的选项设置工具。AVOption的核心概念就是“根据字符串操作结构体的属性值”。与AVOption最相关的选项设置函数就是av_opt_set()了。
int av_opt_set (void *obj, const char *name, const char *val, int search_flags);
int av_opt_set_int (void *obj, const char *name, int64_t val, int search_flags);
int av_opt_set_double (void *obj, const char *name, double val, int search_flags);
int av_opt_set_q (void *obj, const char *name, AVRational val, int search_flags);
int av_opt_set_bin (void *obj, const char *name, const uint8_t *val, int size, int search_flags);
int av_opt_set_image_size(void *obj, const char *name, int w, int h, int search_flags);
int av_opt_set_pixel_fmt (void *obj, const char *name, enum AVPixelFormat fmt, int search_flags);
int av_opt_set_sample_fmt(void *obj, const char *name, enum AVSampleFormat fmt, int search_flags);
int av_opt_set_video_rate(void *obj, const char *name, AVRational val, int search_flags);
int av_opt_set_channel_layout(void *obj, const char *name, int64_t ch_layout, int search_flags);
参数1:obj是一个结构体,第一个元素是指向AVClass结构体的指针
参数2:要设置参数的字段名
参数3:设置的值
参数4:子结构体的标志(可忽略)
两种方式作用相同
#if TEST_OPT
av_opt_set(pCodecCtx,"b","400000",0); //bitrate
//Another method
//av_opt_set_int(pCodecCtx,"b",400000,0); //bitrate
av_opt_set(pCodecCtx,"time_base","1/25",0); //time_base
av_opt_set(pCodecCtx,"bf","5",0); //max b frame
av_opt_set(pCodecCtx,"g","25",0); //gop
av_opt_set(pCodecCtx,"qmin","10",0); //qmin/qmax
av_opt_set(pCodecCtx,"qmax","51",0);
#else
pCodecCtx->time_base.num = 1;
pCodecCtx->time_base.den = 25;
pCodecCtx->max_b_frames=5;
pCodecCtx->bit_rate = 400000;
pCodecCtx->gop_size=25;
pCodecCtx->qmin = 10;
pCodecCtx->qmax = 51;
#endif