This way it can be applied to cmdutils too -- e.g. showing the banner and printing startup messages.
Unified · Split
| @@ -4019,6 +4019,7 @@ int main(int argc, char **argv) · 4018 unmodified lines | ||
| 4019 | 4019 | reset_options(&o); |
| 4020 | 4020 | |
| 4021 | 4021 | av_log_set_flags(AV_LOG_SKIP_REPEATED); |
| 4022 | + parse_loglevel(argc, argv, options); | |
| 4022 | 4023 | |
| 4023 | 4024 | avcodec_register_all(); |
| 4024 | 4025 | #if CONFIG_AVDEVICE |
| @@ -3050,6 +3050,7 @@ int main(int argc, char **argv) · 3049 unmodified lines | ||
| 3050 | 3050 | int flags; |
| 3051 | 3051 | |
| 3052 | 3052 | av_log_set_flags(AV_LOG_SKIP_REPEATED); |
| 3053 | + parse_loglevel(argc, argv, options); | |
| 3053 | 3054 | |
| 3054 | 3055 | /* register all codecs, demux and protocols */ |
| 3055 | 3056 | avcodec_register_all(); |
| @@ -399,6 +399,7 @@ int main(int argc, char **argv) · 398 unmodified lines | ||
| 399 | 399 | { |
| 400 | 400 | int ret; |
| 401 | 401 | |
| 402 | + parse_loglevel(argc, argv, options); | |
| 402 | 403 | av_register_all(); |
| 403 | 404 | init_opts(); |
| 404 | 405 | #if CONFIG_AVDEVICE |
| @@ -4668,6 +4668,7 @@ int main(int argc, char **argv) · 4667 unmodified lines | ||
| 4668 | 4668 | { |
| 4669 | 4669 | struct sigaction sigact; |
| 4670 | 4670 | |
| 4671 | + parse_loglevel(argc, argv, options); | |
| 4671 | 4672 | av_register_all(); |
| 4672 | 4673 | |
| 4673 | 4674 | show_banner(); |
| @@ -304,6 +304,41 @@ void parse_options(void *optctx, int argc, char **argv, const OptionDef *options · 303 unmodified lines | ||
| 304 | 304 | } |
| 305 | 305 | } |
| 306 | 306 | |
| 307 | +/* | |
| 308 | + * Return index of option opt in argv or 0 if not found. | |
| 309 | + */ | |
| 310 | +static int locate_option(int argc, char **argv, const OptionDef *options, const char *optname) | |
| 311 | +{ | |
| 312 | + const OptionDef *po; | |
| 313 | + int i; | |
| 314 | + | |
| 315 | + for (i = 1; i < argc; i++) { | |
| 316 | + const char *cur_opt = argv[i]; | |
| 317 | + | |
| 318 | + if (*cur_opt++ != '-') | |
| 319 | + continue; | |
| 320 | + | |
| 321 | + po = find_option(options, cur_opt); | |
| 322 | + if (!po->name && cur_opt[0] == 'n' && cur_opt[1] == 'o') | |
| 323 | + po = find_option(options, cur_opt + 2); | |
| 324 | + | |
| 325 | + if ((!po->name && !strcmp(cur_opt, optname)) || | |
| 326 | + (po->name && !strcmp(optname, po->name))) | |
| 327 | + return i; | |
| 328 | + | |
| 329 | + if (!po || po->flags & HAS_ARG) | |
| 330 | + i++; | |
| 331 | + } | |
| 332 | + return 0; | |
| 333 | +} | |
| 334 | + | |
| 335 | +void parse_loglevel(int argc, char **argv, const OptionDef *options) | |
| 336 | +{ | |
| 337 | + int idx = locate_option(argc, argv, options, "loglevel"); | |
| 338 | + if (idx && argv[idx + 1]) | |
| 339 | + opt_loglevel("loglevel", argv[idx + 1]); | |
| 340 | +} | |
| 341 | + | |
| 307 | 342 | #define FLAGS (o->type == FF_OPT_TYPE_FLAGS) ? AV_DICT_APPEND : 0 |
| 308 | 343 | int opt_default(const char *opt, const char *arg) |
| 309 | 344 | { |
| @@ -174,6 +174,11 @@ void parse_options(void *optctx, int argc, char **argv, const OptionDef *options · 173 unmodified lines | ||
| 174 | 174 | */ |
| 175 | 175 | int parse_option(void *optctx, const char *opt, const char *arg, const OptionDef *options); |
| 176 | 176 | |
| 177 | +/** | |
| 178 | + * Find the '-loglevel' option in the commandline args and apply it. | |
| 179 | + */ | |
| 180 | +void parse_loglevel(int argc, char **argv, const OptionDef *options); | |
| 181 | + | |
| 177 | 182 | /** |
| 178 | 183 | * Check if the given stream matches a stream specifier. |
| 179 | 184 | * |
| @@ -4357,6 +4357,7 @@ int main(int argc, char **argv) · 4356 unmodified lines | ||
| 4357 | 4357 | int64_t ti; |
| 4358 | 4358 | |
| 4359 | 4359 | av_log_set_flags(AV_LOG_SKIP_REPEATED); |
| 4360 | + parse_loglevel(argc, argv, options); | |
| 4360 | 4361 | |
| 4361 | 4362 | avcodec_register_all(); |
| 4362 | 4363 | #if CONFIG_AVDEVICE |