2 * Various utilities for command line tools
3 * Copyright (c) 2000-2003 Fabrice Bellard
5 * This file is part of FFmpeg.
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.
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.
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
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. */
33 #include "compat/va_copy.h"
34 #include "libavformat/avformat.h"
35 #include "libswscale/swscale.h"
36 #include "libswresample/swresample.h"
37 #include "libavutil/avassert.h"
38 #include "libavutil/avstring.h"
39 #include "libavutil/bprint.h"
40 #include "libavutil/display.h"
41 #include "libavutil/getenv_utf8.h"
42 #include "libavutil/libm.h"
43 #include "libavutil/mem.h"
44 #include "libavutil/parseutils.h"
45 #include "libavutil/eval.h"
46 #include "libavutil/dict.h"
47 #include "libavutil/opt.h"
49 #include "fopen_utf8.h"
50 #include "opt_common.h"
53 #include "compat/w32dlfcn.h"
56 AVDictionary
*sws_dict
;
57 AVDictionary
*swr_opts
;
58 AVDictionary
*format_opts
, *codec_opts
;
62 void uninit_opts(void)
64 av_dict_free(&swr_opts
);
65 av_dict_free(&sws_dict
);
66 av_dict_free(&format_opts
);
67 av_dict_free(&codec_opts
);
70 void log_callback_help(void *ptr
, int level
, const char *fmt
, va_list vl
)
72 vfprintf(stdout
, fmt
, vl
);
75 void init_dynload(void)
77 #if HAVE_SETDLLDIRECTORY && defined(_WIN32)
78 /* Calling SetDllDirectory with the empty string (but not NULL) removes the
79 * current working directory from the DLL search path as a security pre-caution. */
84 int parse_number(const char *context
, const char *numstr
, enum OptionType type
,
85 double min
, double max
, double *dst
)
89 double d
= av_strtod(numstr
, &tail
);
91 error
= "Expected number for %s but found: %s\n";
92 else if (d
< min
|| d
> max
)
93 error
= "The value for %s was %s which is not within %f - %f\n";
94 else if (type
== OPT_TYPE_INT64
&& (int64_t)d
!= d
)
95 error
= "Expected int64 for %s but found %s\n";
96 else if (type
== OPT_TYPE_INT
&& (int)d
!= d
)
97 error
= "Expected int for %s but found %s\n";
103 av_log(NULL
, AV_LOG_FATAL
, error
, context
, numstr
, min
, max
);
104 return AVERROR(EINVAL
);
107 void show_help_options(const OptionDef
*options
, const char *msg
, int req_flags
,
114 for (po
= options
; po
->name
; po
++) {
117 if (((po
->flags
& req_flags
) != req_flags
) ||
118 (po
->flags
& rej_flags
))
125 av_strlcpy(buf
, po
->name
, sizeof(buf
));
127 if (po
->flags
& OPT_FLAG_PERSTREAM
)
128 av_strlcat(buf
, "[:<stream_spec>]", sizeof(buf
));
129 else if (po
->flags
& OPT_FLAG_SPEC
)
130 av_strlcat(buf
, "[:<spec>]", sizeof(buf
));
133 av_strlcatf(buf
, sizeof(buf
), " <%s>", po
->argname
);
135 printf("-%-17s %s\n", buf
, po
->help
);
140 void show_help_children(const AVClass
*class, int flags
)
143 const AVClass
*child
;
145 av_opt_show2(&class, NULL
, flags
, 0);
149 while (child
= av_opt_child_class_iterate(class, &iter
))
150 show_help_children(child
, flags
);
153 static const OptionDef
*find_option(const OptionDef
*po
, const char *name
)
160 if (av_strstart(name
, po
->name
, &end
) && (!*end
|| *end
== ':'))
167 /* _WIN32 means using the windows libc - cygwin doesn't define that
168 * by default. HAVE_COMMANDLINETOARGVW is true on cygwin, while
169 * it doesn't provide the actual command line via GetCommandLineW(). */
170 #if HAVE_COMMANDLINETOARGVW && defined(_WIN32)
171 #include <shellapi.h>
172 /* Will be leaked on exit */
173 static char** win32_argv_utf8
= NULL
;
174 static int win32_argc
= 0;
177 * Prepare command line arguments for executable.
178 * For Windows - perform wide-char to UTF-8 conversion.
179 * Input arguments should be main() function arguments.
180 * @param argc_ptr Arguments number (including executable)
181 * @param argv_ptr Arguments list.
183 static void prepare_app_arguments(int *argc_ptr
, char ***argv_ptr
)
187 int i
, buffsize
= 0, offset
= 0;
189 if (win32_argv_utf8
) {
190 *argc_ptr
= win32_argc
;
191 *argv_ptr
= win32_argv_utf8
;
196 argv_w
= CommandLineToArgvW(GetCommandLineW(), &win32_argc
);
197 if (win32_argc
<= 0 || !argv_w
)
200 /* determine the UTF-8 buffer size (including NULL-termination symbols) */
201 for (i
= 0; i
< win32_argc
; i
++)
202 buffsize
+= WideCharToMultiByte(CP_UTF8
, 0, argv_w
[i
], -1,
203 NULL
, 0, NULL
, NULL
);
205 win32_argv_utf8
= av_mallocz(sizeof(char *) * (win32_argc
+ 1) + buffsize
);
206 argstr_flat
= (char *)win32_argv_utf8
+ sizeof(char *) * (win32_argc
+ 1);
207 if (!win32_argv_utf8
) {
212 for (i
= 0; i
< win32_argc
; i
++) {
213 win32_argv_utf8
[i
] = &argstr_flat
[offset
];
214 offset
+= WideCharToMultiByte(CP_UTF8
, 0, argv_w
[i
], -1,
215 &argstr_flat
[offset
],
216 buffsize
- offset
, NULL
, NULL
);
218 win32_argv_utf8
[i
] = NULL
;
221 *argc_ptr
= win32_argc
;
222 *argv_ptr
= win32_argv_utf8
;
225 static inline void prepare_app_arguments(int *argc_ptr
, char ***argv_ptr
)
229 #endif /* HAVE_COMMANDLINETOARGVW */
231 static int opt_has_arg(const OptionDef
*o
)
233 if (o
->type
== OPT_TYPE_BOOL
)
235 if (o
->type
== OPT_TYPE_FUNC
)
236 return !!(o
->flags
& OPT_FUNC_ARG
);
240 static int write_option(void *optctx
, const OptionDef
*po
, const char *opt
,
241 const char *arg
, const OptionDef
*defs
)
243 /* new-style options contain an offset into optctx, old-style address of
245 void *dst
= po
->flags
& OPT_FLAG_OFFSET
?
246 (uint8_t *)optctx
+ po
->u
.off
: po
->u
.dst_ptr
;
247 char *arg_allocated
= NULL
;
249 enum OptionType so_type
= po
->type
;
251 SpecifierOptList
*sol
= NULL
;
258 if (!opt_has_arg(po
)) {
259 av_log(NULL
, AV_LOG_FATAL
,
260 "Requested to load an argument from file for an option '%s'"
261 " which does not take an argument\n",
263 return AVERROR(EINVAL
);
266 arg_allocated
= read_file_to_string(arg
);
267 if (!arg_allocated
) {
268 av_log(NULL
, AV_LOG_FATAL
,
269 "Error reading the value for option '%s' from file: %s\n",
271 return AVERROR(EINVAL
);
277 if (po
->flags
& OPT_FLAG_SPEC
) {
278 char *p
= strchr(opt
, ':');
282 ret
= GROW_ARRAY(sol
->opt
, sol
->nb_opt
);
286 str
= av_strdup(p
? p
+ 1 : "");
288 ret
= AVERROR(ENOMEM
);
291 sol
->opt
[sol
->nb_opt
- 1].specifier
= str
;
293 if (po
->flags
& OPT_FLAG_PERSTREAM
) {
294 ret
= stream_specifier_parse(&sol
->opt
[sol
->nb_opt
- 1].stream_spec
,
300 dst
= &sol
->opt
[sol
->nb_opt
- 1].u
;
303 if (po
->type
== OPT_TYPE_STRING
) {
307 arg_allocated
= NULL
;
309 str
= av_strdup(arg
);
313 ret
= AVERROR(ENOMEM
);
318 } else if (po
->type
== OPT_TYPE_BOOL
|| po
->type
== OPT_TYPE_INT
) {
319 ret
= parse_number(opt
, arg
, OPT_TYPE_INT64
, INT_MIN
, INT_MAX
, &num
);
324 so_type
= OPT_TYPE_INT
;
325 } else if (po
->type
== OPT_TYPE_INT64
) {
326 ret
= parse_number(opt
, arg
, OPT_TYPE_INT64
, INT64_MIN
, (double)INT64_MAX
, &num
);
330 *(int64_t *)dst
= num
;
331 } else if (po
->type
== OPT_TYPE_TIME
) {
332 ret
= av_parse_time(dst
, arg
, 1);
334 av_log(NULL
, AV_LOG_ERROR
, "Invalid duration for option %s: %s\n",
338 so_type
= OPT_TYPE_INT64
;
339 } else if (po
->type
== OPT_TYPE_FLOAT
) {
340 ret
= parse_number(opt
, arg
, OPT_TYPE_FLOAT
, -INFINITY
, INFINITY
, &num
);
345 } else if (po
->type
== OPT_TYPE_DOUBLE
) {
346 ret
= parse_number(opt
, arg
, OPT_TYPE_DOUBLE
, -INFINITY
, INFINITY
, &num
);
350 *(double *)dst
= num
;
352 av_assert0(po
->type
== OPT_TYPE_FUNC
&& po
->u
.func_arg
);
354 ret
= po
->u
.func_arg(optctx
, opt
, arg
);
356 if ((strcmp(opt
, "init_hw_device") != 0) || (strcmp(arg
, "list") != 0)) {
357 av_log(NULL
, AV_LOG_ERROR
,
358 "Failed to set value '%s' for option '%s': %s\n",
359 arg
, opt
, av_err2str(ret
));
364 if (po
->flags
& OPT_EXIT
) {
371 sol
->opt_canon
= (po
->flags
& OPT_HAS_CANON
) ?
372 find_option(defs
, po
->u1
.name_canon
) : po
;
376 av_freep(&arg_allocated
);
380 int parse_option(void *optctx
, const char *opt
, const char *arg
,
381 const OptionDef
*options
)
383 static const OptionDef opt_avoptions
= {
384 .name
= "AVOption passthrough",
385 .type
= OPT_TYPE_FUNC
,
386 .flags
= OPT_FUNC_ARG
,
387 .u
.func_arg
= opt_default
,
393 po
= find_option(options
, opt
);
394 if (!po
->name
&& opt
[0] == 'n' && opt
[1] == 'o') {
395 /* handle 'no' bool option */
396 po
= find_option(options
, opt
+ 2);
397 if ((po
->name
&& po
->type
== OPT_TYPE_BOOL
))
399 } else if (po
->type
== OPT_TYPE_BOOL
)
405 av_log(NULL
, AV_LOG_ERROR
, "Unrecognized option '%s'\n", opt
);
406 return AVERROR(EINVAL
);
408 if (opt_has_arg(po
) && !arg
) {
409 av_log(NULL
, AV_LOG_ERROR
, "Missing argument for option '%s'\n", opt
);
410 return AVERROR(EINVAL
);
413 ret
= write_option(optctx
, po
, opt
, arg
, options
);
417 return opt_has_arg(po
);
420 int parse_options(void *optctx
, int argc
, char **argv
, const OptionDef
*options
,
421 int (*parse_arg_function
)(void *, const char*))
424 int optindex
, handleoptions
= 1, ret
;
426 /* perform system-dependent conversions for arguments list */
427 prepare_app_arguments(&argc
, &argv
);
431 while (optindex
< argc
) {
432 opt
= argv
[optindex
++];
434 if (handleoptions
&& opt
[0] == '-' && opt
[1] != '\0') {
435 if (opt
[1] == '-' && opt
[2] == '\0') {
441 if ((ret
= parse_option(optctx
, opt
, argv
[optindex
], options
)) < 0)
445 if (parse_arg_function
) {
446 ret
= parse_arg_function(optctx
, opt
);
456 int parse_optgroup(void *optctx
, OptionGroup
*g
, const OptionDef
*defs
)
460 av_log(NULL
, AV_LOG_DEBUG
, "Parsing a group of options: %s %s.\n",
461 g
->group_def
->name
, g
->arg
);
463 for (i
= 0; i
< g
->nb_opts
; i
++) {
464 Option
*o
= &g
->opts
[i
];
466 if (g
->group_def
->flags
&&
467 !(g
->group_def
->flags
& o
->opt
->flags
)) {
468 av_log(NULL
, AV_LOG_ERROR
, "Option %s (%s) cannot be applied to "
469 "%s %s -- you are trying to apply an input option to an "
470 "output file or vice versa. Move this option before the "
471 "file it belongs to.\n", o
->key
, o
->opt
->help
,
472 g
->group_def
->name
, g
->arg
);
473 return AVERROR(EINVAL
);
476 av_log(NULL
, AV_LOG_DEBUG
, "Applying option %s (%s) with argument %s.\n",
477 o
->key
, o
->opt
->help
, o
->val
);
479 ret
= write_option(optctx
, o
->opt
, o
->key
, o
->val
, defs
);
484 av_log(NULL
, AV_LOG_DEBUG
, "Successfully parsed a group of options.\n");
489 int locate_option(int argc
, char **argv
, const OptionDef
*options
,
495 for (i
= 1; i
< argc
; i
++) {
496 const char *cur_opt
= argv
[i
];
498 if (!(cur_opt
[0] == '-' && cur_opt
[1]))
502 po
= find_option(options
, cur_opt
);
503 if (!po
->name
&& cur_opt
[0] == 'n' && cur_opt
[1] == 'o')
504 po
= find_option(options
, cur_opt
+ 2);
506 if ((!po
->name
&& !strcmp(cur_opt
, optname
)) ||
507 (po
->name
&& !strcmp(optname
, po
->name
)))
510 if (!po
->name
|| opt_has_arg(po
))
516 static void dump_argument(FILE *report_file
, const char *a
)
518 const unsigned char *p
;
521 if (!((*p
>= '+' && *p
<= ':') || (*p
>= '@' && *p
<= 'Z') ||
522 *p
== '_' || (*p
>= 'a' && *p
<= 'z')))
525 fputs(a
, report_file
);
528 fputc('"', report_file
);
529 for (p
= a
; *p
; p
++) {
530 if (*p
== '\\' || *p
== '"' || *p
== '$' || *p
== '`')
531 fprintf(report_file
, "\\%c", *p
);
532 else if (*p
< ' ' || *p
> '~')
533 fprintf(report_file
, "\\x%02x", *p
);
535 fputc(*p
, report_file
);
537 fputc('"', report_file
);
540 static void check_options(const OptionDef
*po
)
543 if (po
->flags
& OPT_PERFILE
)
544 av_assert0(po
->flags
& (OPT_INPUT
| OPT_OUTPUT
| OPT_DECODER
));
546 if (po
->type
== OPT_TYPE_FUNC
)
547 av_assert0(!(po
->flags
& (OPT_FLAG_OFFSET
| OPT_FLAG_SPEC
)));
549 // OPT_FUNC_ARG can only be ser for OPT_TYPE_FUNC
550 av_assert0((po
->type
== OPT_TYPE_FUNC
) || !(po
->flags
& OPT_FUNC_ARG
));
556 void parse_loglevel(int argc
, char **argv
, const OptionDef
*options
)
561 check_options(options
);
563 idx
= locate_option(argc
, argv
, options
, "loglevel");
565 idx
= locate_option(argc
, argv
, options
, "v");
566 if (idx
&& argv
[idx
+ 1])
567 opt_loglevel(NULL
, "loglevel", argv
[idx
+ 1]);
568 idx
= locate_option(argc
, argv
, options
, "report");
569 env
= getenv_utf8("FFREPORT");
571 FILE *report_file
= NULL
;
572 init_report(env
, &report_file
);
575 fprintf(report_file
, "Command line:\n");
576 for (i
= 0; i
< argc
; i
++) {
577 dump_argument(report_file
, argv
[i
]);
578 fputc(i
< argc
- 1 ? ' ' : '\n', report_file
);
584 idx
= locate_option(argc
, argv
, options
, "hide_banner");
589 static const AVOption
*opt_find(void *obj
, const char *name
, const char *unit
,
590 int opt_flags
, int search_flags
)
592 const AVOption
*o
= av_opt_find(obj
, name
, unit
, opt_flags
, search_flags
);
598 #define FLAGS ((o->type == AV_OPT_TYPE_FLAGS && (arg[0]=='-' || arg[0]=='+')) ? AV_DICT_APPEND : 0)
599 int opt_default(void *optctx
, const char *opt
, const char *arg
)
603 char opt_stripped
[128];
605 const AVClass
*cc
= avcodec_get_class(), *fc
= avformat_get_class();
607 const AVClass
*sc
= sws_get_class();
609 #if CONFIG_SWRESAMPLE
610 const AVClass
*swr_class
= swr_get_class();
613 if (!strcmp(opt
, "debug") || !strcmp(opt
, "fdebug"))
614 av_log_set_level(AV_LOG_DEBUG
);
616 if (!(p
= strchr(opt
, ':')))
617 p
= opt
+ strlen(opt
);
618 av_strlcpy(opt_stripped
, opt
, FFMIN(sizeof(opt_stripped
), p
- opt
+ 1));
620 if ((o
= opt_find(&cc
, opt_stripped
, NULL
, 0,
621 AV_OPT_SEARCH_CHILDREN
| AV_OPT_SEARCH_FAKE_OBJ
)) ||
622 ((opt
[0] == 'v' || opt
[0] == 'a' || opt
[0] == 's') &&
623 (o
= opt_find(&cc
, opt
+ 1, NULL
, 0, AV_OPT_SEARCH_FAKE_OBJ
)))) {
624 av_dict_set(&codec_opts
, opt
, arg
, FLAGS
);
627 if ((o
= opt_find(&fc
, opt
, NULL
, 0,
628 AV_OPT_SEARCH_CHILDREN
| AV_OPT_SEARCH_FAKE_OBJ
))) {
629 av_dict_set(&format_opts
, opt
, arg
, FLAGS
);
631 av_log(NULL
, AV_LOG_VERBOSE
, "Routing option %s to both codec and muxer layer\n", opt
);
635 if (!consumed
&& (o
= opt_find(&sc
, opt
, NULL
, 0,
636 AV_OPT_SEARCH_CHILDREN
| AV_OPT_SEARCH_FAKE_OBJ
))) {
637 if (!strcmp(opt
, "srcw") || !strcmp(opt
, "srch") ||
638 !strcmp(opt
, "dstw") || !strcmp(opt
, "dsth") ||
639 !strcmp(opt
, "src_format") || !strcmp(opt
, "dst_format")) {
640 av_log(NULL
, AV_LOG_ERROR
, "Directly using swscale dimensions/format options is not supported, please use the -s or -pix_fmt options\n");
641 return AVERROR(EINVAL
);
643 av_dict_set(&sws_dict
, opt
, arg
, FLAGS
);
648 if (!consumed
&& !strcmp(opt
, "sws_flags")) {
649 av_log(NULL
, AV_LOG_WARNING
, "Ignoring %s %s, due to disabled swscale\n", opt
, arg
);
653 #if CONFIG_SWRESAMPLE
654 if (!consumed
&& (o
=opt_find(&swr_class
, opt
, NULL
, 0,
655 AV_OPT_SEARCH_CHILDREN
| AV_OPT_SEARCH_FAKE_OBJ
))) {
656 av_dict_set(&swr_opts
, opt
, arg
, FLAGS
);
663 return AVERROR_OPTION_NOT_FOUND
;
667 * Check whether given option is a group separator.
669 * @return index of the group definition that matched or -1 if none
671 static int match_group_separator(const OptionGroupDef
*groups
, int nb_groups
,
676 for (i
= 0; i
< nb_groups
; i
++) {
677 const OptionGroupDef
*p
= &groups
[i
];
678 if (p
->sep
&& !strcmp(p
->sep
, opt
))
686 * Finish parsing an option group.
688 * @param group_idx which group definition should this group belong to
689 * @param arg argument of the group delimiting option
691 static int finish_group(OptionParseContext
*octx
, int group_idx
,
694 OptionGroupList
*l
= &octx
->groups
[group_idx
];
698 ret
= GROW_ARRAY(l
->groups
, l
->nb_groups
);
702 g
= &l
->groups
[l
->nb_groups
- 1];
704 *g
= octx
->cur_group
;
706 g
->group_def
= l
->group_def
;
707 g
->sws_dict
= sws_dict
;
708 g
->swr_opts
= swr_opts
;
709 g
->codec_opts
= codec_opts
;
710 g
->format_opts
= format_opts
;
717 memset(&octx
->cur_group
, 0, sizeof(octx
->cur_group
));
723 * Add an option instance to currently parsed group.
725 static int add_opt(OptionParseContext
*octx
, const OptionDef
*opt
,
726 const char *key
, const char *val
)
728 int global
= !(opt
->flags
& OPT_PERFILE
);
729 OptionGroup
*g
= global
? &octx
->global_opts
: &octx
->cur_group
;
732 ret
= GROW_ARRAY(g
->opts
, g
->nb_opts
);
736 g
->opts
[g
->nb_opts
- 1].opt
= opt
;
737 g
->opts
[g
->nb_opts
- 1].key
= key
;
738 g
->opts
[g
->nb_opts
- 1].val
= val
;
743 static int init_parse_context(OptionParseContext
*octx
,
744 const OptionGroupDef
*groups
, int nb_groups
)
746 static const OptionGroupDef global_group
= { "global" };
749 memset(octx
, 0, sizeof(*octx
));
751 octx
->groups
= av_calloc(nb_groups
, sizeof(*octx
->groups
));
753 return AVERROR(ENOMEM
);
754 octx
->nb_groups
= nb_groups
;
756 for (i
= 0; i
< octx
->nb_groups
; i
++)
757 octx
->groups
[i
].group_def
= &groups
[i
];
759 octx
->global_opts
.group_def
= &global_group
;
760 octx
->global_opts
.arg
= "";
765 void uninit_parse_context(OptionParseContext
*octx
)
769 for (i
= 0; i
< octx
->nb_groups
; i
++) {
770 OptionGroupList
*l
= &octx
->groups
[i
];
772 for (j
= 0; j
< l
->nb_groups
; j
++) {
773 av_freep(&l
->groups
[j
].opts
);
774 av_dict_free(&l
->groups
[j
].codec_opts
);
775 av_dict_free(&l
->groups
[j
].format_opts
);
777 av_dict_free(&l
->groups
[j
].sws_dict
);
778 av_dict_free(&l
->groups
[j
].swr_opts
);
780 av_freep(&l
->groups
);
782 av_freep(&octx
->groups
);
784 av_freep(&octx
->cur_group
.opts
);
785 av_freep(&octx
->global_opts
.opts
);
790 int split_commandline(OptionParseContext
*octx
, int argc
, char *argv
[],
791 const OptionDef
*options
,
792 const OptionGroupDef
*groups
, int nb_groups
)
798 /* perform system-dependent conversions for arguments list */
799 prepare_app_arguments(&argc
, &argv
);
801 ret
= init_parse_context(octx
, groups
, nb_groups
);
805 av_log(NULL
, AV_LOG_DEBUG
, "Splitting the commandline.\n");
807 while (optindex
< argc
) {
808 const char *opt
= argv
[optindex
++], *arg
;
812 av_log(NULL
, AV_LOG_DEBUG
, "Reading option '%s' ...", opt
);
814 if (opt
[0] == '-' && opt
[1] == '-' && !opt
[2]) {
818 /* unnamed group separators, e.g. output filename */
819 if (opt
[0] != '-' || !opt
[1] || dashdash
+1 == optindex
) {
820 ret
= finish_group(octx
, 0, opt
);
824 av_log(NULL
, AV_LOG_DEBUG
, " matched as %s.\n", groups
[0].name
);
829 #define GET_ARG(arg) \
831 arg = argv[optindex++]; \
833 av_log(NULL, AV_LOG_ERROR, "Missing argument for option '%s'.\n", opt);\
834 return AVERROR(EINVAL); \
838 /* named group separators, e.g. -i */
839 group_idx
= match_group_separator(groups
, nb_groups
, opt
);
840 if (group_idx
>= 0) {
842 ret
= finish_group(octx
, group_idx
, arg
);
846 av_log(NULL
, AV_LOG_DEBUG
, " matched as %s with argument '%s'.\n",
847 groups
[group_idx
].name
, arg
);
852 po
= find_option(options
, opt
);
854 if (po
->flags
& OPT_EXIT
) {
855 /* optional argument, e.g. -h */
856 arg
= argv
[optindex
++];
857 } else if (opt_has_arg(po
)) {
863 ret
= add_opt(octx
, po
, opt
, arg
);
867 av_log(NULL
, AV_LOG_DEBUG
, " matched as option '%s' (%s) with "
868 "argument '%s'.\n", po
->name
, po
->help
, arg
);
873 if (argv
[optindex
]) {
874 ret
= opt_default(NULL
, opt
, argv
[optindex
]);
876 av_log(NULL
, AV_LOG_DEBUG
, " matched as AVOption '%s' with "
877 "argument '%s'.\n", opt
, argv
[optindex
]);
880 } else if (ret
!= AVERROR_OPTION_NOT_FOUND
) {
881 av_log(NULL
, AV_LOG_ERROR
, "Error parsing option '%s' "
882 "with argument '%s'.\n", opt
, argv
[optindex
]);
887 /* boolean -nofoo options */
888 if (opt
[0] == 'n' && opt
[1] == 'o' &&
889 (po
= find_option(options
, opt
+ 2)) &&
890 po
->name
&& po
->type
== OPT_TYPE_BOOL
) {
891 ret
= add_opt(octx
, po
, opt
, "0");
895 av_log(NULL
, AV_LOG_DEBUG
, " matched as option '%s' (%s) with "
896 "argument 0.\n", po
->name
, po
->help
);
900 av_log(NULL
, AV_LOG_ERROR
, "Unrecognized option '%s'.\n", opt
);
901 return AVERROR_OPTION_NOT_FOUND
;
904 if (octx
->cur_group
.nb_opts
|| codec_opts
|| format_opts
)
905 av_log(NULL
, AV_LOG_WARNING
, "Trailing option(s) found in the "
906 "command: may be ignored.\n");
908 av_log(NULL
, AV_LOG_DEBUG
, "Finished splitting the commandline.\n");
916 int yesno
= (av_toupper(c
) == 'Y');
918 while (c
!= '\n' && c
!= EOF
)
924 FILE *get_preset_file(char *filename
, size_t filename_size
,
925 const char *preset_name
, int is_path
,
926 const char *codec_name
)
930 #if HAVE_GETMODULEHANDLE && defined(_WIN32)
931 char *datadir
= NULL
;
933 char *env_home
= getenv_utf8("HOME");
934 char *env_ffmpeg_datadir
= getenv_utf8("FFMPEG_DATADIR");
935 const char *base
[3] = { env_ffmpeg_datadir
,
936 env_home
, /* index=1(HOME) is special: search in a .ffmpeg subfolder */
940 av_strlcpy(filename
, preset_name
, filename_size
);
941 f
= fopen_utf8(filename
, "r");
943 #if HAVE_GETMODULEHANDLE && defined(_WIN32)
944 wchar_t *datadir_w
= get_module_filename(NULL
);
947 if (wchartoutf8(datadir_w
, &datadir
))
954 for (ls
= datadir
; *ls
; ls
++)
955 if (*ls
== '\\') *ls
= '/';
957 if (ls
= strrchr(datadir
, '/'))
959 ptrdiff_t datadir_len
= ls
- datadir
;
960 size_t desired_size
= datadir_len
+ strlen("/ffpresets") + 1;
961 char *new_datadir
= av_realloc_array(
962 datadir
, desired_size
, sizeof *datadir
);
964 datadir
= new_datadir
;
965 datadir
[datadir_len
] = 0;
966 strncat(datadir
, "/ffpresets", desired_size
- 1 - datadir_len
);
972 for (i
= 0; i
< 3 && !f
; i
++) {
975 snprintf(filename
, filename_size
, "%s%s/%s.ffpreset", base
[i
],
976 i
!= 1 ? "" : "/.ffmpeg", preset_name
);
977 f
= fopen_utf8(filename
, "r");
978 if (!f
&& codec_name
) {
979 snprintf(filename
, filename_size
,
980 "%s%s/%s-%s.ffpreset",
981 base
[i
], i
!= 1 ? "" : "/.ffmpeg", codec_name
,
983 f
= fopen_utf8(filename
, "r");
988 #if HAVE_GETMODULEHANDLE && defined(_WIN32)
991 freeenv_utf8(env_ffmpeg_datadir
);
992 freeenv_utf8(env_home
);
996 int cmdutils_isalnum(char c
)
998 return (c
>= '0' && c
<= '9') ||
999 (c
>= 'A' && c
<= 'Z') ||
1000 (c
>= 'a' && c
<= 'z');
1003 void stream_specifier_uninit(StreamSpecifier
*ss
)
1005 av_freep(&ss
->meta_key
);
1006 av_freep(&ss
->meta_val
);
1007 av_freep(&ss
->remainder
);
1009 memset(ss
, 0, sizeof(*ss
));
1012 int stream_specifier_parse(StreamSpecifier
*ss
, const char *spec
,
1013 int allow_remainder
, void *logctx
)
1018 memset(ss
, 0, sizeof(*ss
));
1021 ss
->media_type
= AVMEDIA_TYPE_UNKNOWN
;
1022 ss
->stream_list
= STREAM_LIST_ALL
;
1024 av_log(logctx
, AV_LOG_TRACE
, "Parsing stream specifier: %s\n", spec
);
1027 if (*spec
<= '9' && *spec
>= '0') { /* opt:index */
1028 ss
->idx
= strtol(spec
, &endptr
, 0);
1030 av_assert0(endptr
> spec
);
1033 av_log(logctx
, AV_LOG_TRACE
,
1034 "Parsed index: %d; remainder: %s\n", ss
->idx
, spec
);
1036 // this terminates the specifier
1038 } else if ((*spec
== 'v' || *spec
== 'a' || *spec
== 's' ||
1039 *spec
== 'd' || *spec
== 't' || *spec
== 'V') &&
1040 !cmdutils_isalnum(*(spec
+ 1))) { /* opt:[vasdtV] */
1041 if (ss
->media_type
!= AVMEDIA_TYPE_UNKNOWN
) {
1042 av_log(logctx
, AV_LOG_ERROR
, "Stream type specified multiple times\n");
1043 ret
= AVERROR(EINVAL
);
1048 case 'v': ss
->media_type
= AVMEDIA_TYPE_VIDEO
; break;
1049 case 'a': ss
->media_type
= AVMEDIA_TYPE_AUDIO
; break;
1050 case 's': ss
->media_type
= AVMEDIA_TYPE_SUBTITLE
; break;
1051 case 'd': ss
->media_type
= AVMEDIA_TYPE_DATA
; break;
1052 case 't': ss
->media_type
= AVMEDIA_TYPE_ATTACHMENT
; break;
1053 case 'V': ss
->media_type
= AVMEDIA_TYPE_VIDEO
;
1054 ss
->no_apic
= 1; break;
1055 default: av_assert0(0);
1058 av_log(logctx
, AV_LOG_TRACE
, "Parsed media type: %s; remainder: %s\n",
1059 av_get_media_type_string(ss
->media_type
), spec
);
1060 } else if (*spec
== 'g' && *(spec
+ 1) == ':') {
1061 if (ss
->stream_list
!= STREAM_LIST_ALL
)
1062 goto multiple_stream_lists
;
1065 if (*spec
== '#' || (*spec
== 'i' && *(spec
+ 1) == ':')) {
1066 ss
->stream_list
= STREAM_LIST_GROUP_ID
;
1068 spec
+= 1 + (*spec
== 'i');
1070 ss
->stream_list
= STREAM_LIST_GROUP_IDX
;
1072 ss
->list_id
= strtol(spec
, &endptr
, 0);
1073 if (spec
== endptr
) {
1074 av_log(logctx
, AV_LOG_ERROR
, "Expected stream group idx/ID, got: %s\n", spec
);
1075 ret
= AVERROR(EINVAL
);
1080 av_log(logctx
, AV_LOG_TRACE
, "Parsed stream group %s: %"PRId64
"; remainder: %s\n",
1081 ss
->stream_list
== STREAM_LIST_GROUP_ID
? "ID" : "index", ss
->list_id
, spec
);
1082 } else if (*spec
== 'p' && *(spec
+ 1) == ':') {
1083 if (ss
->stream_list
!= STREAM_LIST_ALL
)
1084 goto multiple_stream_lists
;
1086 ss
->stream_list
= STREAM_LIST_PROGRAM
;
1089 ss
->list_id
= strtol(spec
, &endptr
, 0);
1090 if (spec
== endptr
) {
1091 av_log(logctx
, AV_LOG_ERROR
, "Expected program ID, got: %s\n", spec
);
1092 ret
= AVERROR(EINVAL
);
1097 av_log(logctx
, AV_LOG_TRACE
,
1098 "Parsed program ID: %"PRId64
"; remainder: %s\n", ss
->list_id
, spec
);
1099 } else if (!strncmp(spec
, "disp:", 5)) {
1100 const AVClass
*st_class
= av_stream_get_class();
1101 const AVOption
*o
= av_opt_find(&st_class
, "disposition", NULL
, 0, AV_OPT_SEARCH_FAKE_OBJ
);
1107 if (ss
->disposition
) {
1108 av_log(logctx
, AV_LOG_ERROR
, "Multiple disposition specifiers\n");
1109 ret
= AVERROR(EINVAL
);
1115 for (len
= 0; cmdutils_isalnum(spec
[len
]) ||
1116 spec
[len
] == '_' || spec
[len
] == '+'; len
++)
1119 disp
= av_strndup(spec
, len
);
1121 ret
= AVERROR(ENOMEM
);
1125 ret
= av_opt_eval_flags(&st_class
, o
, disp
, &ss
->disposition
);
1128 av_log(logctx
, AV_LOG_ERROR
, "Invalid disposition specifier\n");
1134 av_log(logctx
, AV_LOG_TRACE
,
1135 "Parsed disposition: 0x%x; remainder: %s\n", ss
->disposition
, spec
);
1136 } else if (*spec
== '#' ||
1137 (*spec
== 'i' && *(spec
+ 1) == ':')) {
1138 if (ss
->stream_list
!= STREAM_LIST_ALL
)
1139 goto multiple_stream_lists
;
1141 ss
->stream_list
= STREAM_LIST_STREAM_ID
;
1143 spec
+= 1 + (*spec
== 'i');
1144 ss
->list_id
= strtol(spec
, &endptr
, 0);
1145 if (spec
== endptr
) {
1146 av_log(logctx
, AV_LOG_ERROR
, "Expected stream ID, got: %s\n", spec
);
1147 ret
= AVERROR(EINVAL
);
1152 av_log(logctx
, AV_LOG_TRACE
,
1153 "Parsed stream ID: %"PRId64
"; remainder: %s\n", ss
->list_id
, spec
);
1155 // this terminates the specifier
1157 } else if (*spec
== 'm' && *(spec
+ 1) == ':') {
1158 av_assert0(!ss
->meta_key
&& !ss
->meta_val
);
1161 ss
->meta_key
= av_get_token(&spec
, ":");
1162 if (!ss
->meta_key
) {
1163 ret
= AVERROR(ENOMEM
);
1168 ss
->meta_val
= av_get_token(&spec
, ":");
1169 if (!ss
->meta_val
) {
1170 ret
= AVERROR(ENOMEM
);
1175 av_log(logctx
, AV_LOG_TRACE
,
1176 "Parsed metadata: %s:%s; remainder: %s", ss
->meta_key
,
1177 ss
->meta_val
? ss
->meta_val
: "<any value>", spec
);
1179 // this terminates the specifier
1181 } else if (*spec
== 'u' && (*(spec
+ 1) == '\0' || *(spec
+ 1) == ':')) {
1182 ss
->usable_only
= 1;
1184 av_log(logctx
, AV_LOG_ERROR
, "Parsed 'usable only'\n");
1186 // this terminates the specifier
1196 if (!allow_remainder
) {
1197 av_log(logctx
, AV_LOG_ERROR
,
1198 "Trailing garbage at the end of a stream specifier: %s\n",
1200 ret
= AVERROR(EINVAL
);
1207 ss
->remainder
= av_strdup(spec
);
1208 if (!ss
->remainder
) {
1209 ret
= AVERROR(EINVAL
);
1216 multiple_stream_lists
:
1217 av_log(logctx
, AV_LOG_ERROR
,
1218 "Cannot combine multiple program/group designators in a "
1219 "single stream specifier");
1220 ret
= AVERROR(EINVAL
);
1223 stream_specifier_uninit(ss
);
1227 unsigned stream_specifier_match(const StreamSpecifier
*ss
,
1228 const AVFormatContext
*s
, const AVStream
*st
,
1231 const AVStreamGroup
*g
= NULL
;
1232 const AVProgram
*p
= NULL
;
1233 int start_stream
= 0, nb_streams
;
1236 switch (ss
->stream_list
) {
1237 case STREAM_LIST_STREAM_ID
:
1238 // <n-th> stream with given ID makes no sense and should be impossible to request
1239 av_assert0(ss
->idx
< 0);
1240 // return early if we know for sure the stream does not match
1241 if (st
->id
!= ss
->list_id
)
1243 start_stream
= st
->index
;
1244 nb_streams
= st
->index
+ 1;
1246 case STREAM_LIST_ALL
:
1247 start_stream
= ss
->idx
>= 0 ? 0 : st
->index
;
1248 nb_streams
= st
->index
+ 1;
1250 case STREAM_LIST_PROGRAM
:
1251 for (unsigned i
= 0; i
< s
->nb_programs
; i
++) {
1252 if (s
->programs
[i
]->id
== ss
->list_id
) {
1258 av_log(logctx
, AV_LOG_WARNING
, "No program with ID %"PRId64
" exists,"
1259 " stream specifier can never match\n", ss
->list_id
);
1262 nb_streams
= p
->nb_stream_indexes
;
1264 case STREAM_LIST_GROUP_ID
:
1265 for (unsigned i
= 0; i
< s
->nb_stream_groups
; i
++) {
1266 if (ss
->list_id
== s
->stream_groups
[i
]->id
) {
1267 g
= s
->stream_groups
[i
];
1272 case STREAM_LIST_GROUP_IDX
:
1273 if (ss
->stream_list
== STREAM_LIST_GROUP_IDX
&&
1274 ss
->list_id
>= 0 && ss
->list_id
< s
->nb_stream_groups
)
1275 g
= s
->stream_groups
[ss
->list_id
];
1278 av_log(logctx
, AV_LOG_WARNING
, "No stream group with group %s %"
1279 PRId64
" exists, stream specifier can never match\n",
1280 ss
->stream_list
== STREAM_LIST_GROUP_ID
? "ID" : "index",
1284 nb_streams
= g
->nb_streams
;
1286 default: av_assert0(0);
1289 for (int i
= start_stream
; i
< nb_streams
; i
++) {
1290 const AVStream
*candidate
= s
->streams
[g
? g
->streams
[i
]->index
:
1291 p
? p
->stream_index
[i
] : i
];
1293 if (ss
->media_type
!= AVMEDIA_TYPE_UNKNOWN
&&
1294 (ss
->media_type
!= candidate
->codecpar
->codec_type
||
1295 (ss
->no_apic
&& (candidate
->disposition
& AV_DISPOSITION_ATTACHED_PIC
))))
1299 const AVDictionaryEntry
*tag
= av_dict_get(candidate
->metadata
,
1300 ss
->meta_key
, NULL
, 0);
1304 if (ss
->meta_val
&& strcmp(tag
->value
, ss
->meta_val
))
1308 if (ss
->usable_only
) {
1309 const AVCodecParameters
*par
= candidate
->codecpar
;
1311 switch (par
->codec_type
) {
1312 case AVMEDIA_TYPE_AUDIO
:
1313 if (!par
->sample_rate
|| !par
->ch_layout
.nb_channels
||
1314 par
->format
== AV_SAMPLE_FMT_NONE
)
1317 case AVMEDIA_TYPE_VIDEO
:
1318 if (!par
->width
|| !par
->height
|| par
->format
== AV_PIX_FMT_NONE
)
1321 case AVMEDIA_TYPE_UNKNOWN
:
1326 if (ss
->disposition
&&
1327 (candidate
->disposition
& ss
->disposition
) != ss
->disposition
)
1330 if (st
== candidate
)
1331 return ss
->idx
< 0 || ss
->idx
== nb_matched
;
1339 int check_stream_specifier(AVFormatContext
*s
, AVStream
*st
, const char *spec
)
1344 ret
= stream_specifier_parse(&ss
, spec
, 0, NULL
);
1348 ret
= stream_specifier_match(&ss
, s
, st
, NULL
);
1349 stream_specifier_uninit(&ss
);
1353 unsigned stream_group_specifier_match(const StreamSpecifier
*ss
,
1354 const AVFormatContext
*s
, const AVStreamGroup
*stg
,
1357 int start_stream_group
= 0, nb_stream_groups
;
1363 switch (ss
->stream_list
) {
1364 case STREAM_LIST_STREAM_ID
:
1365 case STREAM_LIST_ALL
:
1366 case STREAM_LIST_PROGRAM
:
1368 case STREAM_LIST_GROUP_ID
:
1369 // <n-th> stream with given ID makes no sense and should be impossible to request
1370 av_assert0(ss
->idx
< 0);
1371 // return early if we know for sure the stream does not match
1372 if (stg
->id
!= ss
->list_id
)
1374 start_stream_group
= stg
->index
;
1375 nb_stream_groups
= stg
->index
+ 1;
1377 case STREAM_LIST_GROUP_IDX
:
1378 start_stream_group
= ss
->list_id
>= 0 ? 0 : stg
->index
;
1379 nb_stream_groups
= stg
->index
+ 1;
1381 default: av_assert0(0);
1384 for (int i
= start_stream_group
; i
< nb_stream_groups
; i
++) {
1385 const AVStreamGroup
*candidate
= s
->stream_groups
[i
];
1388 const AVDictionaryEntry
*tag
= av_dict_get(candidate
->metadata
,
1389 ss
->meta_key
, NULL
, 0);
1393 if (ss
->meta_val
&& strcmp(tag
->value
, ss
->meta_val
))
1397 if (ss
->usable_only
) {
1398 switch (candidate
->type
) {
1399 case AV_STREAM_GROUP_PARAMS_TILE_GRID
: {
1400 const AVStreamGroupTileGrid
*tg
= candidate
->params
.tile_grid
;
1401 if (!tg
->coded_width
|| !tg
->coded_height
|| !tg
->nb_tiles
||
1402 !tg
->width
|| !tg
->height
|| !tg
->nb_tiles
)
1411 if (ss
->disposition
&&
1412 (candidate
->disposition
& ss
->disposition
) != ss
->disposition
)
1415 if (stg
== candidate
)
1416 return ss
->list_id
< 0 || ss
->list_id
== nb_matched
;
1424 int filter_codec_opts(const AVDictionary
*opts
, enum AVCodecID codec_id
,
1425 AVFormatContext
*s
, AVStream
*st
, const AVCodec
*codec
,
1426 AVDictionary
**dst
, AVDictionary
**opts_used
)
1428 AVDictionary
*ret
= NULL
;
1429 const AVDictionaryEntry
*t
= NULL
;
1430 int flags
= s
->oformat
? AV_OPT_FLAG_ENCODING_PARAM
1431 : AV_OPT_FLAG_DECODING_PARAM
;
1433 const AVClass
*cc
= avcodec_get_class();
1435 switch (st
->codecpar
->codec_type
) {
1436 case AVMEDIA_TYPE_VIDEO
:
1438 flags
|= AV_OPT_FLAG_VIDEO_PARAM
;
1440 case AVMEDIA_TYPE_AUDIO
:
1442 flags
|= AV_OPT_FLAG_AUDIO_PARAM
;
1444 case AVMEDIA_TYPE_SUBTITLE
:
1446 flags
|= AV_OPT_FLAG_SUBTITLE_PARAM
;
1450 while (t
= av_dict_iterate(opts
, t
)) {
1451 const AVClass
*priv_class
;
1452 char *p
= strchr(t
->key
, ':');
1455 /* check stream specification in opt name */
1457 int err
= check_stream_specifier(s
, st
, p
+ 1);
1467 if (av_opt_find(&cc
, t
->key
, NULL
, flags
, AV_OPT_SEARCH_FAKE_OBJ
) ||
1469 ((priv_class
= codec
->priv_class
) &&
1470 av_opt_find(&priv_class
, t
->key
, NULL
, flags
,
1471 AV_OPT_SEARCH_FAKE_OBJ
))) {
1472 av_dict_set(&ret
, t
->key
, t
->value
, 0);
1474 } else if (t
->key
[0] == prefix
&&
1475 av_opt_find(&cc
, t
->key
+ 1, NULL
, flags
,
1476 AV_OPT_SEARCH_FAKE_OBJ
)) {
1477 av_dict_set(&ret
, t
->key
+ 1, t
->value
, 0);
1484 if (used
&& opts_used
)
1485 av_dict_set(opts_used
, t
->key
, "", 0);
1492 int setup_find_stream_info_opts(AVFormatContext
*s
,
1493 AVDictionary
*local_codec_opts
,
1494 AVDictionary
***dst
)
1497 AVDictionary
**opts
;
1504 opts
= av_calloc(s
->nb_streams
, sizeof(*opts
));
1506 return AVERROR(ENOMEM
);
1508 for (int i
= 0; i
< s
->nb_streams
; i
++) {
1509 ret
= filter_codec_opts(local_codec_opts
, s
->streams
[i
]->codecpar
->codec_id
,
1510 s
, s
->streams
[i
], NULL
, &opts
[i
], NULL
);
1517 for (int i
= 0; i
< s
->nb_streams
; i
++)
1518 av_dict_free(&opts
[i
]);
1523 int grow_array(void **array
, int elem_size
, int *size
, int new_size
)
1525 if (new_size
>= INT_MAX
/ elem_size
) {
1526 av_log(NULL
, AV_LOG_ERROR
, "Array too big.\n");
1527 return AVERROR(ERANGE
);
1529 if (*size
< new_size
) {
1530 uint8_t *tmp
= av_realloc_array(*array
, new_size
, elem_size
);
1532 return AVERROR(ENOMEM
);
1533 memset(tmp
+ *size
*elem_size
, 0, (new_size
-*size
) * elem_size
);
1541 void *allocate_array_elem(void *ptr
, size_t elem_size
, int *nb_elems
)
1545 new_elem
= av_mallocz(elem_size
);
1548 if (av_dynarray_add_nofree(ptr
, nb_elems
, new_elem
) < 0)
1549 av_freep(&new_elem
);
1554 double get_rotation(const int32_t *displaymatrix
)
1558 theta
= -round(av_display_rotation_get(displaymatrix
));
1560 theta
-= 360*floor(theta
/360 + 0.9/360);
1562 if (fabs(theta
- 90*round(theta
/90)) > 2)
1563 av_log(NULL
, AV_LOG_WARNING
, "Odd rotation angle.\n"
1564 "If you want to help, upload a sample "
1565 "of this file to https://streams.videolan.org/upload/ "
1566 "and contact the ffmpeg-devel mailing list. (ffmpeg-devel@ffmpeg.org)");
1571 /* read file contents into a string */
1572 char *read_file_to_string(const char *filename
)
1574 AVIOContext
*pb
= NULL
;
1575 int ret
= avio_open(&pb
, filename
, AVIO_FLAG_READ
);
1580 av_log(NULL
, AV_LOG_ERROR
, "Error opening file %s.\n", filename
);
1584 av_bprint_init(&bprint
, 0, AV_BPRINT_SIZE_UNLIMITED
);
1585 ret
= avio_read_to_bprint(pb
, &bprint
, SIZE_MAX
);
1588 av_bprint_finalize(&bprint
, NULL
);
1591 ret
= av_bprint_finalize(&bprint
, &str
);
1597 void remove_avoptions(AVDictionary
**a
, AVDictionary
*b
)
1599 const AVDictionaryEntry
*t
= NULL
;
1601 while ((t
= av_dict_iterate(b
, t
))) {
1602 av_dict_set(a
, t
->key
, NULL
, AV_DICT_MATCH_CASE
);
1606 int check_avoptions(AVDictionary
*m
)
1608 const AVDictionaryEntry
*t
= av_dict_iterate(m
, NULL
);
1610 av_log(NULL
, AV_LOG_FATAL
, "Option %s not found.\n", t
->key
);
1611 return AVERROR_OPTION_NOT_FOUND
;
1617 void dump_dictionary(void *ctx
, const AVDictionary
*m
,
1618 const char *name
, const char *indent
,
1621 const AVDictionaryEntry
*tag
= NULL
;
1626 av_log(ctx
, log_level
, "%s%s:\n", indent
, name
);
1627 while ((tag
= av_dict_iterate(m
, tag
))) {
1628 const char *p
= tag
->value
;
1629 av_log(ctx
, log_level
, "%s %-16s: ", indent
, tag
->key
);
1631 size_t len
= strcspn(p
, "\x8\xa\xb\xc\xd");
1632 av_log(ctx
, log_level
, "%.*s", (int)(FFMIN(255, len
)), p
);
1634 if (*p
== 0xd) av_log(ctx
, log_level
, " ");
1635 if (*p
== 0xa) av_log(ctx
, log_level
, "\n%s %-16s: ", indent
, "");
1638 av_log(ctx
, log_level
, "\n");