avcodec/libx264: use a function to parse x264opts

This is needed for the following patch.

Signed-off-by: James Almer <jamrial@gmail.com>
This commit is contained in:
James Almer 2020-07-10 17:10:33 -03:00
parent 3a37aa597f
commit d1bd079d11

View File

@ -519,19 +519,25 @@ static av_cold int X264_close(AVCodecContext *avctx)
return 0; return 0;
} }
#define OPT_STR(opt, param) \ static int parse_opts(AVCodecContext *avctx, const char *opt, const char *param)
do { \ {
int ret; \ X264Context *x4 = avctx->priv_data;
if ((ret = x264_param_parse(&x4->params, opt, param)) < 0) { \ int ret;
if(ret == X264_PARAM_BAD_NAME) \
av_log(avctx, AV_LOG_ERROR, \ if ((ret = x264_param_parse(&x4->params, opt, param)) < 0) {
"bad option '%s': '%s'\n", opt, param); \ if (ret == X264_PARAM_BAD_NAME) {
else \ av_log(avctx, AV_LOG_ERROR,
av_log(avctx, AV_LOG_ERROR, \ "bad option '%s': '%s'\n", opt, param);
"bad value for '%s': '%s'\n", opt, param); \ ret = AVERROR(EINVAL);
return -1; \ } else {
} \ av_log(avctx, AV_LOG_ERROR,
} while (0) "bad value for '%s': '%s'\n", opt, param);
ret = AVERROR(EINVAL);
}
}
return ret;
}
static int convert_pix_fmt(enum AVPixelFormat pix_fmt) static int convert_pix_fmt(enum AVPixelFormat pix_fmt)
{ {
@ -581,6 +587,7 @@ static av_cold int X264_init(AVCodecContext *avctx)
X264Context *x4 = avctx->priv_data; X264Context *x4 = avctx->priv_data;
AVCPBProperties *cpb_props; AVCPBProperties *cpb_props;
int sw,sh; int sw,sh;
int ret;
if (avctx->global_quality > 0) if (avctx->global_quality > 0)
av_log(avctx, AV_LOG_WARNING, "-qscale is ignored, -crf is recommended.\n"); av_log(avctx, AV_LOG_WARNING, "-qscale is ignored, -crf is recommended.\n");
@ -890,9 +897,14 @@ FF_ENABLE_DEPRECATION_WARNINGS
while(p){ while(p){
char param[4096]={0}, val[4096]={0}; char param[4096]={0}, val[4096]={0};
if(sscanf(p, "%4095[^:=]=%4095[^:]", param, val) == 1){ if(sscanf(p, "%4095[^:=]=%4095[^:]", param, val) == 1){
OPT_STR(param, "1"); ret = parse_opts(avctx, param, "1");
}else if (ret < 0)
OPT_STR(param, val); return ret;
} else {
ret = parse_opts(avctx, param, val);
if (ret < 0)
return ret;
}
p= strchr(p, ':'); p= strchr(p, ':');
p+=!!p; p+=!!p;
} }