FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/fftools/cmdutils.c
Date: 2022-12-09 07:38:14
Exec Total Coverage
Lines: 357 483 73.9%
Functions: 30 37 81.1%
Branches: 248 407 60.9%

Line Branch Exec Source
1 /*
2 * Various utilities for command line tools
3 * Copyright (c) 2000-2003 Fabrice Bellard
4 *
5 * This file is part of FFmpeg.
6 *
7 * FFmpeg is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * FFmpeg is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with FFmpeg; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
22 #include <string.h>
23 #include <stdint.h>
24 #include <stdlib.h>
25 #include <errno.h>
26 #include <math.h>
27
28 /* Include only the enabled headers since some compilers (namely, Sun
29 Studio) will not omit unused inline functions and create undefined
30 references to libraries that are not being built. */
31
32 #include "config.h"
33 #include "compat/va_copy.h"
34 #include "libavformat/avformat.h"
35 #include "libswscale/swscale.h"
36 #include "libswscale/version.h"
37 #include "libswresample/swresample.h"
38 #include "libavutil/avassert.h"
39 #include "libavutil/avstring.h"
40 #include "libavutil/channel_layout.h"
41 #include "libavutil/display.h"
42 #include "libavutil/getenv_utf8.h"
43 #include "libavutil/mathematics.h"
44 #include "libavutil/imgutils.h"
45 #include "libavutil/libm.h"
46 #include "libavutil/parseutils.h"
47 #include "libavutil/eval.h"
48 #include "libavutil/dict.h"
49 #include "libavutil/opt.h"
50 #include "cmdutils.h"
51 #include "fopen_utf8.h"
52 #include "opt_common.h"
53 #ifdef _WIN32
54 #include <windows.h>
55 #include "compat/w32dlfcn.h"
56 #endif
57
58 AVDictionary *sws_dict;
59 AVDictionary *swr_opts;
60 AVDictionary *format_opts, *codec_opts;
61
62 int hide_banner = 0;
63
64 13038 void uninit_opts(void)
65 {
66 13038 av_dict_free(&swr_opts);
67 13038 av_dict_free(&sws_dict);
68 13038 av_dict_free(&format_opts);
69 13038 av_dict_free(&codec_opts);
70 13038 }
71
72 void log_callback_help(void *ptr, int level, const char *fmt, va_list vl)
73 {
74 vfprintf(stdout, fmt, vl);
75 }
76
77 6582 void init_dynload(void)
78 {
79 #if HAVE_SETDLLDIRECTORY && defined(_WIN32)
80 /* Calling SetDllDirectory with the empty string (but not NULL) removes the
81 * current working directory from the DLL search path as a security pre-caution. */
82 SetDllDirectory("");
83 #endif
84 6582 }
85
86 static void (*program_exit)(int ret);
87
88 6582 void register_exit(void (*cb)(int ret))
89 {
90 6582 program_exit = cb;
91 6582 }
92
93 void report_and_exit(int ret)
94 {
95 av_log(NULL, AV_LOG_FATAL, "%s\n", av_err2str(ret));
96 exit_program(AVUNERROR(ret));
97 }
98
99 6457 void exit_program(int ret)
100 {
101
1/2
✓ Branch 0 taken 6457 times.
✗ Branch 1 not taken.
6457 if (program_exit)
102 6457 program_exit(ret);
103
104 6457 exit(ret);
105 }
106
107 30186 double parse_number_or_die(const char *context, const char *numstr, int type,
108 double min, double max)
109 {
110 char *tail;
111 const char *error;
112 30186 double d = av_strtod(numstr, &tail);
113
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 30186 times.
30186 if (*tail)
114 error = "Expected number for %s but found: %s\n";
115
2/4
✓ Branch 0 taken 30186 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 30186 times.
30186 else if (d < min || d > max)
116 error = "The value for %s was %s which is not within %f - %f\n";
117
3/4
✓ Branch 0 taken 29905 times.
✓ Branch 1 taken 281 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 29905 times.
30186 else if (type == OPT_INT64 && (int64_t)d != d)
118 error = "Expected int64 for %s but found %s\n";
119
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 30186 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
30186 else if (type == OPT_INT && (int)d != d)
120 error = "Expected int for %s but found %s\n";
121 else
122 30186 return d;
123 av_log(NULL, AV_LOG_FATAL, error, context, numstr, min, max);
124 exit_program(1);
125 return 0;
126 }
127
128 201 int64_t parse_time_or_die(const char *context, const char *timestr,
129 int is_duration)
130 {
131 int64_t us;
132
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 201 times.
201 if (av_parse_time(&us, timestr, is_duration) < 0) {
133 av_log(NULL, AV_LOG_FATAL, "Invalid %s specification for %s: %s\n",
134 is_duration ? "duration" : "date", context, timestr);
135 exit_program(1);
136 }
137 201 return us;
138 }
139
140 void show_help_options(const OptionDef *options, const char *msg, int req_flags,
141 int rej_flags, int alt_flags)
142 {
143 const OptionDef *po;
144 int first;
145
146 first = 1;
147 for (po = options; po->name; po++) {
148 char buf[128];
149
150 if (((po->flags & req_flags) != req_flags) ||
151 (alt_flags && !(po->flags & alt_flags)) ||
152 (po->flags & rej_flags))
153 continue;
154
155 if (first) {
156 printf("%s\n", msg);
157 first = 0;
158 }
159 av_strlcpy(buf, po->name, sizeof(buf));
160 if (po->argname) {
161 av_strlcat(buf, " ", sizeof(buf));
162 av_strlcat(buf, po->argname, sizeof(buf));
163 }
164 printf("-%-17s %s\n", buf, po->help);
165 }
166 printf("\n");
167 }
168
169 void show_help_children(const AVClass *class, int flags)
170 {
171 void *iter = NULL;
172 const AVClass *child;
173 if (class->option) {
174 av_opt_show2(&class, NULL, flags, 0);
175 printf("\n");
176 }
177
178 while (child = av_opt_child_class_iterate(class, &iter))
179 show_help_children(child, flags);
180 }
181
182 984596 static const OptionDef *find_option(const OptionDef *po, const char *name)
183 {
184
2/2
✓ Branch 0 taken 137931209 times.
✓ Branch 1 taken 561769 times.
138492978 while (po->name) {
185 const char *end;
186
6/6
✓ Branch 1 taken 996550 times.
✓ Branch 2 taken 136934659 times.
✓ Branch 3 taken 617915 times.
✓ Branch 4 taken 378635 times.
✓ Branch 5 taken 573723 times.
✓ Branch 6 taken 44192 times.
137931209 if (av_strstart(name, po->name, &end) && (!*end || *end == ':'))
187 break;
188 137508382 po++;
189 }
190 984596 return po;
191 }
192
193 /* _WIN32 means using the windows libc - cygwin doesn't define that
194 * by default. HAVE_COMMANDLINETOARGVW is true on cygwin, while
195 * it doesn't provide the actual command line via GetCommandLineW(). */
196 #if HAVE_COMMANDLINETOARGVW && defined(_WIN32)
197 #include <shellapi.h>
198 /* Will be leaked on exit */
199 static char** win32_argv_utf8 = NULL;
200 static int win32_argc = 0;
201
202 /**
203 * Prepare command line arguments for executable.
204 * For Windows - perform wide-char to UTF-8 conversion.
205 * Input arguments should be main() function arguments.
206 * @param argc_ptr Arguments number (including executable)
207 * @param argv_ptr Arguments list.
208 */
209 static void prepare_app_arguments(int *argc_ptr, char ***argv_ptr)
210 {
211 char *argstr_flat;
212 wchar_t **argv_w;
213 int i, buffsize = 0, offset = 0;
214
215 if (win32_argv_utf8) {
216 *argc_ptr = win32_argc;
217 *argv_ptr = win32_argv_utf8;
218 return;
219 }
220
221 win32_argc = 0;
222 argv_w = CommandLineToArgvW(GetCommandLineW(), &win32_argc);
223 if (win32_argc <= 0 || !argv_w)
224 return;
225
226 /* determine the UTF-8 buffer size (including NULL-termination symbols) */
227 for (i = 0; i < win32_argc; i++)
228 buffsize += WideCharToMultiByte(CP_UTF8, 0, argv_w[i], -1,
229 NULL, 0, NULL, NULL);
230
231 win32_argv_utf8 = av_mallocz(sizeof(char *) * (win32_argc + 1) + buffsize);
232 argstr_flat = (char *)win32_argv_utf8 + sizeof(char *) * (win32_argc + 1);
233 if (!win32_argv_utf8) {
234 LocalFree(argv_w);
235 return;
236 }
237
238 for (i = 0; i < win32_argc; i++) {
239 win32_argv_utf8[i] = &argstr_flat[offset];
240 offset += WideCharToMultiByte(CP_UTF8, 0, argv_w[i], -1,
241 &argstr_flat[offset],
242 buffsize - offset, NULL, NULL);
243 }
244 win32_argv_utf8[i] = NULL;
245 LocalFree(argv_w);
246
247 *argc_ptr = win32_argc;
248 *argv_ptr = win32_argv_utf8;
249 }
250 #else
251 6582 static inline void prepare_app_arguments(int *argc_ptr, char ***argv_ptr)
252 {
253 /* nothing to do */
254 6582 }
255 #endif /* HAVE_COMMANDLINETOARGVW */
256
257 77268 static int write_option(void *optctx, const OptionDef *po, const char *opt,
258 const char *arg)
259 {
260 /* new-style options contain an offset into optctx, old-style address of
261 * a global var*/
262 154536 void *dst = po->flags & (OPT_OFFSET | OPT_SPEC) ?
263
2/2
✓ Branch 0 taken 38052 times.
✓ Branch 1 taken 39216 times.
77268 (uint8_t *)optctx + po->u.off : po->u.dst_ptr;
264 int *dstcount;
265
266
2/2
✓ Branch 0 taken 26251 times.
✓ Branch 1 taken 51017 times.
77268 if (po->flags & OPT_SPEC) {
267 26251 SpecifierOpt **so = dst;
268 26251 char *p = strchr(opt, ':');
269 char *str;
270
271 26251 dstcount = (int *)(so + 1);
272 26251 *so = grow_array(*so, sizeof(**so), dstcount, *dstcount + 1);
273
2/2
✓ Branch 0 taken 13955 times.
✓ Branch 1 taken 12296 times.
26251 str = av_strdup(p ? p + 1 : "");
274
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 26251 times.
26251 if (!str)
275 return AVERROR(ENOMEM);
276 26251 (*so)[*dstcount - 1].specifier = str;
277 26251 dst = &(*so)[*dstcount - 1].u;
278 }
279
280
2/2
✓ Branch 0 taken 30779 times.
✓ Branch 1 taken 46489 times.
77268 if (po->flags & OPT_STRING) {
281 char *str;
282 30779 str = av_strdup(arg);
283 30779 av_freep(dst);
284
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 30779 times.
30779 if (!str)
285 return AVERROR(ENOMEM);
286 30779 *(char **)dst = str;
287
4/4
✓ Branch 0 taken 21377 times.
✓ Branch 1 taken 25112 times.
✓ Branch 2 taken 136 times.
✓ Branch 3 taken 21241 times.
46489 } else if (po->flags & OPT_BOOL || po->flags & OPT_INT) {
288 25248 *(int *)dst = parse_number_or_die(opt, arg, OPT_INT64, INT_MIN, INT_MAX);
289
2/2
✓ Branch 0 taken 4657 times.
✓ Branch 1 taken 16584 times.
21241 } else if (po->flags & OPT_INT64) {
290 4657 *(int64_t *)dst = parse_number_or_die(opt, arg, OPT_INT64, INT64_MIN, INT64_MAX);
291
2/2
✓ Branch 0 taken 199 times.
✓ Branch 1 taken 16385 times.
16584 } else if (po->flags & OPT_TIME) {
292 199 *(int64_t *)dst = parse_time_or_die(opt, arg, 1);
293
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 16383 times.
16385 } else if (po->flags & OPT_FLOAT) {
294 2 *(float *)dst = parse_number_or_die(opt, arg, OPT_FLOAT, -INFINITY, INFINITY);
295
2/2
✓ Branch 0 taken 279 times.
✓ Branch 1 taken 16104 times.
16383 } else if (po->flags & OPT_DOUBLE) {
296 279 *(double *)dst = parse_number_or_die(opt, arg, OPT_DOUBLE, -INFINITY, INFINITY);
297
1/2
✓ Branch 0 taken 16104 times.
✗ Branch 1 not taken.
16104 } else if (po->u.func_arg) {
298 16104 int ret = po->u.func_arg(optctx, opt, arg);
299
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 16104 times.
16104 if (ret < 0) {
300 av_log(NULL, AV_LOG_ERROR,
301 "Failed to set value '%s' for option '%s': %s\n",
302 arg, opt, av_err2str(ret));
303 return ret;
304 }
305 }
306
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 77267 times.
77268 if (po->flags & OPT_EXIT)
307 1 exit_program(0);
308
309 77267 return 0;
310 }
311
312 8603 int parse_option(void *optctx, const char *opt, const char *arg,
313 const OptionDef *options)
314 {
315 static const OptionDef opt_avoptions = {
316 .name = "AVOption passthrough",
317 .flags = HAS_ARG,
318 .u.func_arg = opt_default,
319 };
320
321 const OptionDef *po;
322 int ret;
323
324 8603 po = find_option(options, opt);
325
5/6
✓ Branch 0 taken 7 times.
✓ Branch 1 taken 8596 times.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 6 times.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
8603 if (!po->name && opt[0] == 'n' && opt[1] == 'o') {
326 /* handle 'no' bool option */
327 1 po = find_option(options, opt + 2);
328
2/4
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 if ((po->name && (po->flags & OPT_BOOL)))
329 1 arg = "0";
330
2/2
✓ Branch 0 taken 120 times.
✓ Branch 1 taken 8482 times.
8602 } else if (po->flags & OPT_BOOL)
331 120 arg = "1";
332
333
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 8597 times.
8603 if (!po->name)
334 6 po = &opt_avoptions;
335
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8603 times.
8603 if (!po->name) {
336 av_log(NULL, AV_LOG_ERROR, "Unrecognized option '%s'\n", opt);
337 return AVERROR(EINVAL);
338 }
339
3/4
✓ Branch 0 taken 8389 times.
✓ Branch 1 taken 214 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 8389 times.
8603 if (po->flags & HAS_ARG && !arg) {
340 av_log(NULL, AV_LOG_ERROR, "Missing argument for option '%s'\n", opt);
341 return AVERROR(EINVAL);
342 }
343
344 8603 ret = write_option(optctx, po, opt, arg);
345
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8603 times.
8603 if (ret < 0)
346 return ret;
347
348 8603 return !!(po->flags & HAS_ARG);
349 }
350
351 125 void parse_options(void *optctx, int argc, char **argv, const OptionDef *options,
352 void (*parse_arg_function)(void *, const char*))
353 {
354 const char *opt;
355 125 int optindex, handleoptions = 1, ret;
356
357 /* perform system-dependent conversions for arguments list */
358 125 prepare_app_arguments(&argc, &argv);
359
360 /* parse options */
361 125 optindex = 1;
362
2/2
✓ Branch 0 taken 572 times.
✓ Branch 1 taken 125 times.
697 while (optindex < argc) {
363 572 opt = argv[optindex++];
364
365
4/6
✓ Branch 0 taken 572 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 457 times.
✓ Branch 3 taken 115 times.
✓ Branch 4 taken 457 times.
✗ Branch 5 not taken.
572 if (handleoptions && opt[0] == '-' && opt[1] != '\0') {
366
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 457 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
457 if (opt[1] == '-' && opt[2] == '\0') {
367 handleoptions = 0;
368 continue;
369 }
370 457 opt++;
371
372
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 457 times.
457 if ((ret = parse_option(optctx, opt, argv[optindex], options)) < 0)
373 exit_program(1);
374 457 optindex += ret;
375 } else {
376
1/2
✓ Branch 0 taken 115 times.
✗ Branch 1 not taken.
115 if (parse_arg_function)
377 115 parse_arg_function(optctx, opt);
378 }
379 }
380 125 }
381
382 19403 int parse_optgroup(void *optctx, OptionGroup *g)
383 {
384 int i, ret;
385
386 19403 av_log(NULL, AV_LOG_DEBUG, "Parsing a group of options: %s %s.\n",
387 19403 g->group_def->name, g->arg);
388
389
2/2
✓ Branch 0 taken 68665 times.
✓ Branch 1 taken 19402 times.
88067 for (i = 0; i < g->nb_opts; i++) {
390 68665 Option *o = &g->opts[i];
391
392
2/2
✓ Branch 0 taken 38432 times.
✓ Branch 1 taken 30233 times.
68665 if (g->group_def->flags &&
393
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 38432 times.
38432 !(g->group_def->flags & o->opt->flags)) {
394 av_log(NULL, AV_LOG_ERROR, "Option %s (%s) cannot be applied to "
395 "%s %s -- you are trying to apply an input option to an "
396 "output file or vice versa. Move this option before the "
397 "file it belongs to.\n", o->key, o->opt->help,
398 g->group_def->name, g->arg);
399 return AVERROR(EINVAL);
400 }
401
402 68665 av_log(NULL, AV_LOG_DEBUG, "Applying option %s (%s) with argument %s.\n",
403 68665 o->key, o->opt->help, o->val);
404
405 68665 ret = write_option(optctx, o->opt, o->key, o->val);
406
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 68664 times.
68664 if (ret < 0)
407 return ret;
408 }
409
410 19402 av_log(NULL, AV_LOG_DEBUG, "Successfully parsed a group of options.\n");
411
412 19402 return 0;
413 }
414
415 32910 int locate_option(int argc, char **argv, const OptionDef *options,
416 const char *optname)
417 {
418 const OptionDef *po;
419 int i;
420
421
2/2
✓ Branch 0 taken 745070 times.
✓ Branch 1 taken 32895 times.
777965 for (i = 1; i < argc; i++) {
422 745070 const char *cur_opt = argv[i];
423
424
2/2
✓ Branch 0 taken 20538 times.
✓ Branch 1 taken 724532 times.
745070 if (*cur_opt++ != '-')
425 20538 continue;
426
427 724532 po = find_option(options, cur_opt);
428
5/6
✓ Branch 0 taken 475567 times.
✓ Branch 1 taken 248965 times.
✓ Branch 2 taken 96640 times.
✓ Branch 3 taken 378927 times.
✓ Branch 4 taken 96640 times.
✗ Branch 5 not taken.
724532 if (!po->name && cur_opt[0] == 'n' && cur_opt[1] == 'o')
429 96640 po = find_option(options, cur_opt + 2);
430
431
3/4
✓ Branch 0 taken 378967 times.
✓ Branch 1 taken 345565 times.
✓ Branch 2 taken 378967 times.
✗ Branch 3 not taken.
724532 if ((!po->name && !strcmp(cur_opt, optname)) ||
432
4/4
✓ Branch 0 taken 345565 times.
✓ Branch 1 taken 378967 times.
✓ Branch 2 taken 15 times.
✓ Branch 3 taken 345550 times.
724532 (po->name && !strcmp(optname, po->name)))
433 15 return i;
434
435
4/4
✓ Branch 0 taken 345550 times.
✓ Branch 1 taken 378967 times.
✓ Branch 2 taken 219520 times.
✓ Branch 3 taken 126030 times.
724517 if (!po->name || po->flags & HAS_ARG)
436 598487 i++;
437 }
438 32895 return 0;
439 }
440
441 static void dump_argument(FILE *report_file, const char *a)
442 {
443 const unsigned char *p;
444
445 for (p = a; *p; p++)
446 if (!((*p >= '+' && *p <= ':') || (*p >= '@' && *p <= 'Z') ||
447 *p == '_' || (*p >= 'a' && *p <= 'z')))
448 break;
449 if (!*p) {
450 fputs(a, report_file);
451 return;
452 }
453 fputc('"', report_file);
454 for (p = a; *p; p++) {
455 if (*p == '\\' || *p == '"' || *p == '$' || *p == '`')
456 fprintf(report_file, "\\%c", *p);
457 else if (*p < ' ' || *p > '~')
458 fprintf(report_file, "\\x%02x", *p);
459 else
460 fputc(*p, report_file);
461 }
462 fputc('"', report_file);
463 }
464
465 6582 static void check_options(const OptionDef *po)
466 {
467
2/2
✓ Branch 0 taken 1196463 times.
✓ Branch 1 taken 6582 times.
1203045 while (po->name) {
468
2/2
✓ Branch 0 taken 193710 times.
✓ Branch 1 taken 1002753 times.
1196463 if (po->flags & OPT_PERFILE)
469
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 193710 times.
193710 av_assert0(po->flags & (OPT_INPUT | OPT_OUTPUT));
470 1196463 po++;
471 }
472 6582 }
473
474 6582 void parse_loglevel(int argc, char **argv, const OptionDef *options)
475 {
476 6582 int idx = locate_option(argc, argv, options, "loglevel");
477 char *env;
478
479 6582 check_options(options);
480
481
1/2
✓ Branch 0 taken 6582 times.
✗ Branch 1 not taken.
6582 if (!idx)
482 6582 idx = locate_option(argc, argv, options, "v");
483
3/4
✓ Branch 0 taken 15 times.
✓ Branch 1 taken 6567 times.
✓ Branch 2 taken 15 times.
✗ Branch 3 not taken.
6582 if (idx && argv[idx + 1])
484 15 opt_loglevel(NULL, "loglevel", argv[idx + 1]);
485 6582 idx = locate_option(argc, argv, options, "report");
486 6582 env = getenv_utf8("FFREPORT");
487
2/4
✓ Branch 0 taken 6582 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 6582 times.
6582 if (env || idx) {
488 FILE *report_file = NULL;
489 init_report(env, &report_file);
490 if (report_file) {
491 int i;
492 fprintf(report_file, "Command line:\n");
493 for (i = 0; i < argc; i++) {
494 dump_argument(report_file, argv[i]);
495 fputc(i < argc - 1 ? ' ' : '\n', report_file);
496 }
497 fflush(report_file);
498 }
499 }
500 6582 freeenv_utf8(env);
501 6582 idx = locate_option(argc, argv, options, "hide_banner");
502
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6582 times.
6582 if (idx)
503 hide_banner = 1;
504 6582 }
505
506 234089 static const AVOption *opt_find(void *obj, const char *name, const char *unit,
507 int opt_flags, int search_flags)
508 {
509 234089 const AVOption *o = av_opt_find(obj, name, unit, opt_flags, search_flags);
510
4/4
✓ Branch 0 taken 66917 times.
✓ Branch 1 taken 167172 times.
✓ Branch 2 taken 2 times.
✓ Branch 3 taken 66915 times.
234089 if(o && !o->flags)
511 2 return NULL;
512 234087 return o;
513 }
514
515 #define FLAGS (o->type == AV_OPT_TYPE_FLAGS && (arg[0]=='-' || arg[0]=='+')) ? AV_DICT_APPEND : 0
516 86161 int opt_default(void *optctx, const char *opt, const char *arg)
517 {
518 const AVOption *o;
519 86161 int consumed = 0;
520 char opt_stripped[128];
521 const char *p;
522 86161 const AVClass *cc = avcodec_get_class(), *fc = avformat_get_class();
523 #if CONFIG_SWSCALE
524 86161 const AVClass *sc = sws_get_class();
525 #endif
526 #if CONFIG_SWRESAMPLE
527 86161 const AVClass *swr_class = swr_get_class();
528 #endif
529
530
2/4
✓ Branch 0 taken 86161 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 86161 times.
86161 if (!strcmp(opt, "debug") || !strcmp(opt, "fdebug"))
531 av_log_set_level(AV_LOG_DEBUG);
532
533
2/2
✓ Branch 0 taken 86153 times.
✓ Branch 1 taken 8 times.
86161 if (!(p = strchr(opt, ':')))
534 86153 p = opt + strlen(opt);
535 86161 av_strlcpy(opt_stripped, opt, FFMIN(sizeof(opt_stripped), p - opt + 1));
536
537
2/2
✓ Branch 1 taken 42366 times.
✓ Branch 2 taken 43795 times.
86161 if ((o = opt_find(&cc, opt_stripped, NULL, 0,
538 42366 AV_OPT_SEARCH_CHILDREN | AV_OPT_SEARCH_FAKE_OBJ)) ||
539
8/8
✓ Branch 0 taken 42363 times.
✓ Branch 1 taken 3 times.
✓ Branch 2 taken 42351 times.
✓ Branch 3 taken 12 times.
✓ Branch 4 taken 11569 times.
✓ Branch 5 taken 30782 times.
✓ Branch 6 taken 1 times.
✓ Branch 7 taken 11583 times.
53950 ((opt[0] == 'v' || opt[0] == 'a' || opt[0] == 's') &&
540 11584 (o = opt_find(&cc, opt + 1, NULL, 0, AV_OPT_SEARCH_FAKE_OBJ)))) {
541
5/6
✓ Branch 0 taken 17788 times.
✓ Branch 1 taken 26008 times.
✓ Branch 2 taken 17788 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 11500 times.
✓ Branch 5 taken 6288 times.
43796 av_dict_set(&codec_opts, opt, arg, FLAGS);
542 43796 consumed = 1;
543 }
544
2/2
✓ Branch 1 taken 11574 times.
✓ Branch 2 taken 74587 times.
86161 if ((o = opt_find(&fc, opt, NULL, 0,
545 AV_OPT_SEARCH_CHILDREN | AV_OPT_SEARCH_FAKE_OBJ))) {
546
5/6
✓ Branch 0 taken 11368 times.
✓ Branch 1 taken 206 times.
✓ Branch 2 taken 11368 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 11355 times.
✓ Branch 5 taken 13 times.
11574 av_dict_set(&format_opts, opt, arg, FLAGS);
547
2/2
✓ Branch 0 taken 73 times.
✓ Branch 1 taken 11501 times.
11574 if (consumed)
548 73 av_log(NULL, AV_LOG_VERBOSE, "Routing option %s to both codec and muxer layer\n", opt);
549 11574 consumed = 1;
550 }
551 #if CONFIG_SWSCALE
552
4/4
✓ Branch 0 taken 30864 times.
✓ Branch 1 taken 55297 times.
✓ Branch 3 taken 11545 times.
✓ Branch 4 taken 19319 times.
86161 if (!consumed && (o = opt_find(&sc, opt, NULL, 0,
553 AV_OPT_SEARCH_CHILDREN | AV_OPT_SEARCH_FAKE_OBJ))) {
554
2/4
✓ Branch 0 taken 11545 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 11545 times.
✗ Branch 3 not taken.
11545 if (!strcmp(opt, "srcw") || !strcmp(opt, "srch") ||
555
2/4
✓ Branch 0 taken 11545 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 11545 times.
✗ Branch 3 not taken.
11545 !strcmp(opt, "dstw") || !strcmp(opt, "dsth") ||
556
2/4
✓ Branch 0 taken 11545 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 11545 times.
11545 !strcmp(opt, "src_format") || !strcmp(opt, "dst_format")) {
557 av_log(NULL, AV_LOG_ERROR, "Directly using swscale dimensions/format options is not supported, please use the -s or -pix_fmt options\n");
558 return AVERROR(EINVAL);
559 }
560
4/6
✓ Branch 0 taken 11545 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 11545 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 11360 times.
✓ Branch 5 taken 185 times.
11545 av_dict_set(&sws_dict, opt, arg, FLAGS);
561
562 11545 consumed = 1;
563 }
564 #else
565 if (!consumed && !strcmp(opt, "sws_flags")) {
566 av_log(NULL, AV_LOG_WARNING, "Ignoring %s %s, due to disabled swscale\n", opt, arg);
567 consumed = 1;
568 }
569 #endif
570 #if CONFIG_SWRESAMPLE
571
3/4
✓ Branch 0 taken 19319 times.
✓ Branch 1 taken 66842 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 19319 times.
86161 if (!consumed && (o=opt_find(&swr_class, opt, NULL, 0,
572 AV_OPT_SEARCH_CHILDREN | AV_OPT_SEARCH_FAKE_OBJ))) {
573 av_dict_set(&swr_opts, opt, arg, FLAGS);
574 consumed = 1;
575 }
576 #endif
577
578
2/2
✓ Branch 0 taken 66842 times.
✓ Branch 1 taken 19319 times.
86161 if (consumed)
579 66842 return 0;
580 19319 return AVERROR_OPTION_NOT_FOUND;
581 }
582
583 /*
584 * Check whether given option is a group separator.
585 *
586 * @return index of the group definition that matched or -1 if none
587 */
588 141990 static int match_group_separator(const OptionGroupDef *groups, int nb_groups,
589 const char *opt)
590 {
591 int i;
592
593
2/2
✓ Branch 0 taken 283980 times.
✓ Branch 1 taken 135501 times.
419481 for (i = 0; i < nb_groups; i++) {
594 283980 const OptionGroupDef *p = &groups[i];
595
4/4
✓ Branch 0 taken 141990 times.
✓ Branch 1 taken 141990 times.
✓ Branch 2 taken 6489 times.
✓ Branch 3 taken 135501 times.
283980 if (p->sep && !strcmp(p->sep, opt))
596 6489 return i;
597 }
598
599 135501 return -1;
600 }
601
602 /*
603 * Finish parsing an option group.
604 *
605 * @param group_idx which group definition should this group belong to
606 * @param arg argument of the group delimiting option
607 */
608 12946 static void finish_group(OptionParseContext *octx, int group_idx,
609 const char *arg)
610 {
611 12946 OptionGroupList *l = &octx->groups[group_idx];
612 OptionGroup *g;
613
614 12946 GROW_ARRAY(l->groups, l->nb_groups);
615 12946 g = &l->groups[l->nb_groups - 1];
616
617 12946 *g = octx->cur_group;
618 12946 g->arg = arg;
619 12946 g->group_def = l->group_def;
620 12946 g->sws_dict = sws_dict;
621 12946 g->swr_opts = swr_opts;
622 12946 g->codec_opts = codec_opts;
623 12946 g->format_opts = format_opts;
624
625 12946 codec_opts = NULL;
626 12946 format_opts = NULL;
627 12946 sws_dict = NULL;
628 12946 swr_opts = NULL;
629
630 12946 memset(&octx->cur_group, 0, sizeof(octx->cur_group));
631 12946 }
632
633 /*
634 * Add an option instance to currently parsed group.
635 */
636 68665 static void add_opt(OptionParseContext *octx, const OptionDef *opt,
637 const char *key, const char *val)
638 {
639 68665 int global = !(opt->flags & (OPT_PERFILE | OPT_SPEC | OPT_OFFSET));
640
2/2
✓ Branch 0 taken 30233 times.
✓ Branch 1 taken 38432 times.
68665 OptionGroup *g = global ? &octx->global_opts : &octx->cur_group;
641
642 68665 GROW_ARRAY(g->opts, g->nb_opts);
643 68665 g->opts[g->nb_opts - 1].opt = opt;
644 68665 g->opts[g->nb_opts - 1].key = key;
645 68665 g->opts[g->nb_opts - 1].val = val;
646 68665 }
647
648 6457 static void init_parse_context(OptionParseContext *octx,
649 const OptionGroupDef *groups, int nb_groups)
650 {
651 static const OptionGroupDef global_group = { "global" };
652 int i;
653
654 6457 memset(octx, 0, sizeof(*octx));
655
656 6457 octx->nb_groups = nb_groups;
657 6457 octx->groups = av_calloc(octx->nb_groups, sizeof(*octx->groups));
658
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6457 times.
6457 if (!octx->groups)
659 report_and_exit(AVERROR(ENOMEM));
660
661
2/2
✓ Branch 0 taken 12914 times.
✓ Branch 1 taken 6457 times.
19371 for (i = 0; i < octx->nb_groups; i++)
662 12914 octx->groups[i].group_def = &groups[i];
663
664 6457 octx->global_opts.group_def = &global_group;
665 6457 octx->global_opts.arg = "";
666 6457 }
667
668 6456 void uninit_parse_context(OptionParseContext *octx)
669 {
670 int i, j;
671
672
2/2
✓ Branch 0 taken 12912 times.
✓ Branch 1 taken 6456 times.
19368 for (i = 0; i < octx->nb_groups; i++) {
673 12912 OptionGroupList *l = &octx->groups[i];
674
675
2/2
✓ Branch 0 taken 12946 times.
✓ Branch 1 taken 12912 times.
25858 for (j = 0; j < l->nb_groups; j++) {
676 12946 av_freep(&l->groups[j].opts);
677 12946 av_dict_free(&l->groups[j].codec_opts);
678 12946 av_dict_free(&l->groups[j].format_opts);
679
680 12946 av_dict_free(&l->groups[j].sws_dict);
681 12946 av_dict_free(&l->groups[j].swr_opts);
682 }
683 12912 av_freep(&l->groups);
684 }
685 6456 av_freep(&octx->groups);
686
687 6456 av_freep(&octx->cur_group.opts);
688 6456 av_freep(&octx->global_opts.opts);
689
690 6456 uninit_opts();
691 6456 }
692
693 6457 int split_commandline(OptionParseContext *octx, int argc, char *argv[],
694 const OptionDef *options,
695 const OptionGroupDef *groups, int nb_groups)
696 {
697 6457 int optindex = 1;
698 6457 int dashdash = -2;
699
700 /* perform system-dependent conversions for arguments list */
701 6457 prepare_app_arguments(&argc, &argv);
702
703 6457 init_parse_context(octx, groups, nb_groups);
704 6457 av_log(NULL, AV_LOG_DEBUG, "Splitting the commandline.\n");
705
706
2/2
✓ Branch 0 taken 148447 times.
✓ Branch 1 taken 6457 times.
154904 while (optindex < argc) {
707 148447 const char *opt = argv[optindex++], *arg;
708 const OptionDef *po;
709 int ret;
710
711 148447 av_log(NULL, AV_LOG_DEBUG, "Reading option '%s' ...", opt);
712
713
3/6
✓ Branch 0 taken 144454 times.
✓ Branch 1 taken 3993 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 144454 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
148447 if (opt[0] == '-' && opt[1] == '-' && !opt[2]) {
714 dashdash = optindex;
715 continue;
716 }
717 /* unnamed group separators, e.g. output filename */
718
5/6
✓ Branch 0 taken 144454 times.
✓ Branch 1 taken 3993 times.
✓ Branch 2 taken 141990 times.
✓ Branch 3 taken 2464 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 141990 times.
148447 if (opt[0] != '-' || !opt[1] || dashdash+1 == optindex) {
719 6457 finish_group(octx, 0, opt);
720 6457 av_log(NULL, AV_LOG_DEBUG, " matched as %s.\n", groups[0].name);
721 6457 continue;
722 }
723 141990 opt++;
724
725 #define GET_ARG(arg) \
726 do { \
727 arg = argv[optindex++]; \
728 if (!arg) { \
729 av_log(NULL, AV_LOG_ERROR, "Missing argument for option '%s'.\n", opt);\
730 return AVERROR(EINVAL); \
731 } \
732 } while (0)
733
734 /* named group separators, e.g. -i */
735
2/2
✓ Branch 1 taken 6489 times.
✓ Branch 2 taken 135501 times.
141990 if ((ret = match_group_separator(groups, nb_groups, opt)) >= 0) {
736
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6489 times.
6489 GET_ARG(arg);
737 6489 finish_group(octx, ret, arg);
738 6489 av_log(NULL, AV_LOG_DEBUG, " matched as %s with argument '%s'.\n",
739 6489 groups[ret].name, arg);
740 6489 continue;
741 }
742
743 /* normal options */
744 135501 po = find_option(options, opt);
745
2/2
✓ Branch 0 taken 49346 times.
✓ Branch 1 taken 86155 times.
135501 if (po->name) {
746
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 49345 times.
49346 if (po->flags & OPT_EXIT) {
747 /* optional argument, e.g. -h */
748 1 arg = argv[optindex++];
749
2/2
✓ Branch 0 taken 43673 times.
✓ Branch 1 taken 5672 times.
49345 } else if (po->flags & HAS_ARG) {
750
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 43673 times.
43673 GET_ARG(arg);
751 } else {
752 5672 arg = "1";
753 }
754
755 49346 add_opt(octx, po, opt, arg);
756 49346 av_log(NULL, AV_LOG_DEBUG, " matched as option '%s' (%s) with "
757 49346 "argument '%s'.\n", po->name, po->help, arg);
758 49346 continue;
759 }
760
761 /* AVOptions */
762
1/2
✓ Branch 0 taken 86155 times.
✗ Branch 1 not taken.
86155 if (argv[optindex]) {
763 86155 ret = opt_default(NULL, opt, argv[optindex]);
764
2/2
✓ Branch 0 taken 66836 times.
✓ Branch 1 taken 19319 times.
86155 if (ret >= 0) {
765 66836 av_log(NULL, AV_LOG_DEBUG, " matched as AVOption '%s' with "
766 66836 "argument '%s'.\n", opt, argv[optindex]);
767 66836 optindex++;
768 66836 continue;
769
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 19319 times.
19319 } else if (ret != AVERROR_OPTION_NOT_FOUND) {
770 av_log(NULL, AV_LOG_ERROR, "Error parsing option '%s' "
771 "with argument '%s'.\n", opt, argv[optindex]);
772 return ret;
773 }
774 }
775
776 /* boolean -nofoo options */
777
3/6
✓ Branch 0 taken 19319 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 19319 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 19319 times.
✗ Branch 5 not taken.
38638 if (opt[0] == 'n' && opt[1] == 'o' &&
778 19319 (po = find_option(options, opt + 2)) &&
779
2/4
✓ Branch 0 taken 19319 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 19319 times.
✗ Branch 3 not taken.
19319 po->name && po->flags & OPT_BOOL) {
780 19319 add_opt(octx, po, opt, "0");
781 19319 av_log(NULL, AV_LOG_DEBUG, " matched as option '%s' (%s) with "
782 19319 "argument 0.\n", po->name, po->help);
783 19319 continue;
784 }
785
786 av_log(NULL, AV_LOG_ERROR, "Unrecognized option '%s'.\n", opt);
787 return AVERROR_OPTION_NOT_FOUND;
788 }
789
790
3/6
✓ Branch 0 taken 6457 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6457 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 6457 times.
6457 if (octx->cur_group.nb_opts || codec_opts || format_opts)
791 av_log(NULL, AV_LOG_WARNING, "Trailing option(s) found in the "
792 "command: may be ignored.\n");
793
794 6457 av_log(NULL, AV_LOG_DEBUG, "Finished splitting the commandline.\n");
795
796 6457 return 0;
797 }
798
799 71 void print_error(const char *filename, int err)
800 {
801 71 av_log(NULL, AV_LOG_ERROR, "%s: %s\n", filename, av_err2str(err));
802 71 }
803
804 int read_yesno(void)
805 {
806 int c = getchar();
807 int yesno = (av_toupper(c) == 'Y');
808
809 while (c != '\n' && c != EOF)
810 c = getchar();
811
812 return yesno;
813 }
814
815 FILE *get_preset_file(char *filename, size_t filename_size,
816 const char *preset_name, int is_path,
817 const char *codec_name)
818 {
819 FILE *f = NULL;
820 int i;
821 #if HAVE_GETMODULEHANDLE && defined(_WIN32)
822 char *datadir = NULL;
823 #endif
824 char *env_home = getenv_utf8("HOME");
825 char *env_ffmpeg_datadir = getenv_utf8("FFMPEG_DATADIR");
826 const char *base[3] = { env_ffmpeg_datadir,
827 env_home, /* index=1(HOME) is special: search in a .ffmpeg subfolder */
828 FFMPEG_DATADIR, };
829
830 if (is_path) {
831 av_strlcpy(filename, preset_name, filename_size);
832 f = fopen_utf8(filename, "r");
833 } else {
834 #if HAVE_GETMODULEHANDLE && defined(_WIN32)
835 wchar_t *datadir_w = get_module_filename(NULL);
836 base[2] = NULL;
837
838 if (wchartoutf8(datadir_w, &datadir))
839 datadir = NULL;
840 av_free(datadir_w);
841
842 if (datadir)
843 {
844 char *ls;
845 for (ls = datadir; *ls; ls++)
846 if (*ls == '\\') *ls = '/';
847
848 if (ls = strrchr(datadir, '/'))
849 {
850 ptrdiff_t datadir_len = ls - datadir;
851 size_t desired_size = datadir_len + strlen("/ffpresets") + 1;
852 char *new_datadir = av_realloc_array(
853 datadir, desired_size, sizeof *datadir);
854 if (new_datadir) {
855 datadir = new_datadir;
856 datadir[datadir_len] = 0;
857 strncat(datadir, "/ffpresets", desired_size - 1 - datadir_len);
858 base[2] = datadir;
859 }
860 }
861 }
862 #endif
863 for (i = 0; i < 3 && !f; i++) {
864 if (!base[i])
865 continue;
866 snprintf(filename, filename_size, "%s%s/%s.ffpreset", base[i],
867 i != 1 ? "" : "/.ffmpeg", preset_name);
868 f = fopen_utf8(filename, "r");
869 if (!f && codec_name) {
870 snprintf(filename, filename_size,
871 "%s%s/%s-%s.ffpreset",
872 base[i], i != 1 ? "" : "/.ffmpeg", codec_name,
873 preset_name);
874 f = fopen_utf8(filename, "r");
875 }
876 }
877 }
878
879 #if HAVE_GETMODULEHANDLE && defined(_WIN32)
880 av_free(datadir);
881 #endif
882 freeenv_utf8(env_ffmpeg_datadir);
883 freeenv_utf8(env_home);
884 return f;
885 }
886
887 27614 int check_stream_specifier(AVFormatContext *s, AVStream *st, const char *spec)
888 {
889 27614 int ret = avformat_match_stream_specifier(s, st, spec);
890
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 27614 times.
27614 if (ret < 0)
891 av_log(s, AV_LOG_ERROR, "Invalid stream specifier: %s.\n", spec);
892 27614 return ret;
893 }
894
895 20850 AVDictionary *filter_codec_opts(AVDictionary *opts, enum AVCodecID codec_id,
896 AVFormatContext *s, AVStream *st, const AVCodec *codec)
897 {
898 20850 AVDictionary *ret = NULL;
899 20850 const AVDictionaryEntry *t = NULL;
900 41700 int flags = s->oformat ? AV_OPT_FLAG_ENCODING_PARAM
901
2/2
✓ Branch 0 taken 6702 times.
✓ Branch 1 taken 14148 times.
20850 : AV_OPT_FLAG_DECODING_PARAM;
902 20850 char prefix = 0;
903 20850 const AVClass *cc = avcodec_get_class();
904
905
2/2
✓ Branch 0 taken 7558 times.
✓ Branch 1 taken 13292 times.
20850 if (!codec)
906 7558 codec = s->oformat ? avcodec_find_encoder(codec_id)
907
2/2
✓ Branch 0 taken 483 times.
✓ Branch 1 taken 7075 times.
7558 : avcodec_find_decoder(codec_id);
908
909
4/4
✓ Branch 0 taken 15916 times.
✓ Branch 1 taken 4574 times.
✓ Branch 2 taken 220 times.
✓ Branch 3 taken 140 times.
20850 switch (st->codecpar->codec_type) {
910 15916 case AVMEDIA_TYPE_VIDEO:
911 15916 prefix = 'v';
912 15916 flags |= AV_OPT_FLAG_VIDEO_PARAM;
913 15916 break;
914 4574 case AVMEDIA_TYPE_AUDIO:
915 4574 prefix = 'a';
916 4574 flags |= AV_OPT_FLAG_AUDIO_PARAM;
917 4574 break;
918 220 case AVMEDIA_TYPE_SUBTITLE:
919 220 prefix = 's';
920 220 flags |= AV_OPT_FLAG_SUBTITLE_PARAM;
921 220 break;
922 }
923
924
2/2
✓ Branch 1 taken 60353 times.
✓ Branch 2 taken 20850 times.
81203 while (t = av_dict_iterate(opts, t)) {
925 const AVClass *priv_class;
926 60353 char *p = strchr(t->key, ':');
927
928 /* check stream specification in opt name */
929
2/2
✓ Branch 0 taken 251 times.
✓ Branch 1 taken 60102 times.
60353 if (p)
930
2/3
✓ Branch 1 taken 202 times.
✓ Branch 2 taken 49 times.
✗ Branch 3 not taken.
251 switch (check_stream_specifier(s, st, p + 1)) {
931 202 case 1: *p = 0; break;
932 49 case 0: continue;
933 default: exit_program(1);
934 }
935
936
4/4
✓ Branch 1 taken 2206 times.
✓ Branch 2 taken 58098 times.
✓ Branch 3 taken 1911 times.
✓ Branch 4 taken 295 times.
60304 if (av_opt_find(&cc, t->key, NULL, flags, AV_OPT_SEARCH_FAKE_OBJ) ||
937 1911 !codec ||
938
4/4
✓ Branch 0 taken 696 times.
✓ Branch 1 taken 1215 times.
✓ Branch 2 taken 309 times.
✓ Branch 3 taken 387 times.
2607 ((priv_class = codec->priv_class) &&
939 696 av_opt_find(&priv_class, t->key, NULL, flags,
940 AV_OPT_SEARCH_FAKE_OBJ)))
941 58702 av_dict_set(&ret, t->key, t->value, 0);
942
4/4
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 1600 times.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 1 times.
1604 else if (t->key[0] == prefix &&
943 2 av_opt_find(&cc, t->key + 1, NULL, flags,
944 AV_OPT_SEARCH_FAKE_OBJ))
945 1 av_dict_set(&ret, t->key + 1, t->value, 0);
946
947
2/2
✓ Branch 0 taken 202 times.
✓ Branch 1 taken 60102 times.
60304 if (p)
948 202 *p = ':';
949 }
950 20850 return ret;
951 }
952
953 6612 AVDictionary **setup_find_stream_info_opts(AVFormatContext *s,
954 AVDictionary *codec_opts)
955 {
956 int i;
957 AVDictionary **opts;
958
959
2/2
✓ Branch 0 taken 80 times.
✓ Branch 1 taken 6532 times.
6612 if (!s->nb_streams)
960 80 return NULL;
961 6532 opts = av_calloc(s->nb_streams, sizeof(*opts));
962
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6532 times.
6532 if (!opts)
963 report_and_exit(AVERROR(ENOMEM));
964
2/2
✓ Branch 0 taken 7015 times.
✓ Branch 1 taken 6532 times.
13547 for (i = 0; i < s->nb_streams; i++)
965 7015 opts[i] = filter_codec_opts(codec_opts, s->streams[i]->codecpar->codec_id,
966 7015 s, s->streams[i], NULL);
967 6532 return opts;
968 }
969
970 120330 void *grow_array(void *array, int elem_size, int *size, int new_size)
971 {
972
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 120330 times.
120330 if (new_size >= INT_MAX / elem_size) {
973 av_log(NULL, AV_LOG_ERROR, "Array too big.\n");
974 exit_program(1);
975 }
976
1/2
✓ Branch 0 taken 120330 times.
✗ Branch 1 not taken.
120330 if (*size < new_size) {
977 120330 uint8_t *tmp = av_realloc_array(array, new_size, elem_size);
978
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 120330 times.
120330 if (!tmp)
979 report_and_exit(AVERROR(ENOMEM));
980 120330 memset(tmp + *size*elem_size, 0, (new_size-*size) * elem_size);
981 120330 *size = new_size;
982 120330 return tmp;
983 }
984 return array;
985 }
986
987 39020 void *allocate_array_elem(void *ptr, size_t elem_size, int *nb_elems)
988 {
989 void *new_elem;
990
991
2/4
✓ Branch 1 taken 39020 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 39020 times.
78040 if (!(new_elem = av_mallocz(elem_size)) ||
992 39020 av_dynarray_add_nofree(ptr, nb_elems, new_elem) < 0)
993 report_and_exit(AVERROR(ENOMEM));
994 39020 return new_elem;
995 }
996
997 5013 double get_rotation(int32_t *displaymatrix)
998 {
999 5013 double theta = 0;
1000
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 5012 times.
5013 if (displaymatrix)
1001 1 theta = -round(av_display_rotation_get((int32_t*) displaymatrix));
1002
1003 5013 theta -= 360*floor(theta/360 + 0.9/360);
1004
1005
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 5013 times.
5013 if (fabs(theta - 90*round(theta/90)) > 2)
1006 av_log(NULL, AV_LOG_WARNING, "Odd rotation angle.\n"
1007 "If you want to help, upload a sample "
1008 "of this file to https://streams.videolan.org/upload/ "
1009 "and contact the ffmpeg-devel mailing list. (ffmpeg-devel@ffmpeg.org)");
1010
1011 5013 return theta;
1012 }
1013