FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/fftools/opt_common.c
Date: 2022-10-02 18:56:10
Exec Total Coverage
Lines: 77 744 10.3%
Branches: 83 627 13.2%

Line Branch Exec Source
1 /*
2 * Option handlers shared between the tools.
3 *
4 * This file is part of FFmpeg.
5 *
6 * FFmpeg is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * FFmpeg is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with FFmpeg; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21 #include "config.h"
22
23 #include <stdio.h>
24
25 #include "cmdutils.h"
26 #include "opt_common.h"
27
28 #include "libavutil/avassert.h"
29 #include "libavutil/avstring.h"
30 #include "libavutil/bprint.h"
31 #include "libavutil/channel_layout.h"
32 #include "libavutil/cpu.h"
33 #include "libavutil/dict.h"
34 #include "libavutil/error.h"
35 #include "libavutil/ffversion.h"
36 #include "libavutil/log.h"
37 #include "libavutil/mem.h"
38 #include "libavutil/parseutils.h"
39 #include "libavutil/pixdesc.h"
40 #include "libavutil/version.h"
41
42 #include "libavcodec/avcodec.h"
43 #include "libavcodec/bsf.h"
44 #include "libavcodec/codec.h"
45 #include "libavcodec/codec_desc.h"
46 #include "libavcodec/version.h"
47
48 #include "libavformat/avformat.h"
49 #include "libavformat/version.h"
50
51 #include "libavdevice/avdevice.h"
52 #include "libavdevice/version.h"
53
54 #include "libavfilter/avfilter.h"
55 #include "libavfilter/version.h"
56
57 #include "libswscale/swscale.h"
58 #include "libswscale/version.h"
59
60 #include "libswresample/swresample.h"
61 #include "libswresample/version.h"
62
63 #include "libpostproc/postprocess.h"
64 #include "libpostproc/version.h"
65
66 enum show_muxdemuxers {
67 SHOW_DEFAULT,
68 SHOW_DEMUXERS,
69 SHOW_MUXERS,
70 };
71
72 static FILE *report_file;
73 static int report_file_level = AV_LOG_DEBUG;
74
75 int show_license(void *optctx, const char *opt, const char *arg)
76 {
77 #if CONFIG_NONFREE
78 printf(
79 "This version of %s has nonfree parts compiled in.\n"
80 "Therefore it is not legally redistributable.\n",
81 program_name );
82 #elif CONFIG_GPLV3
83 printf(
84 "%s is free software; you can redistribute it and/or modify\n"
85 "it under the terms of the GNU General Public License as published by\n"
86 "the Free Software Foundation; either version 3 of the License, or\n"
87 "(at your option) any later version.\n"
88 "\n"
89 "%s is distributed in the hope that it will be useful,\n"
90 "but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
91 "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n"
92 "GNU General Public License for more details.\n"
93 "\n"
94 "You should have received a copy of the GNU General Public License\n"
95 "along with %s. If not, see <http://www.gnu.org/licenses/>.\n",
96 program_name, program_name, program_name );
97 #elif CONFIG_GPL
98 printf(
99 "%s is free software; you can redistribute it and/or modify\n"
100 "it under the terms of the GNU General Public License as published by\n"
101 "the Free Software Foundation; either version 2 of the License, or\n"
102 "(at your option) any later version.\n"
103 "\n"
104 "%s is distributed in the hope that it will be useful,\n"
105 "but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
106 "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n"
107 "GNU General Public License for more details.\n"
108 "\n"
109 "You should have received a copy of the GNU General Public License\n"
110 "along with %s; if not, write to the Free Software\n"
111 "Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA\n",
112 program_name, program_name, program_name );
113 #elif CONFIG_LGPLV3
114 printf(
115 "%s is free software; you can redistribute it and/or modify\n"
116 "it under the terms of the GNU Lesser General Public License as published by\n"
117 "the Free Software Foundation; either version 3 of the License, or\n"
118 "(at your option) any later version.\n"
119 "\n"
120 "%s is distributed in the hope that it will be useful,\n"
121 "but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
122 "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n"
123 "GNU Lesser General Public License for more details.\n"
124 "\n"
125 "You should have received a copy of the GNU Lesser General Public License\n"
126 "along with %s. If not, see <http://www.gnu.org/licenses/>.\n",
127 program_name, program_name, program_name );
128 #else
129 printf(
130 "%s is free software; you can redistribute it and/or\n"
131 "modify it under the terms of the GNU Lesser General Public\n"
132 "License as published by the Free Software Foundation; either\n"
133 "version 2.1 of the License, or (at your option) any later version.\n"
134 "\n"
135 "%s is distributed in the hope that it will be useful,\n"
136 "but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
137 "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n"
138 "Lesser General Public License for more details.\n"
139 "\n"
140 "You should have received a copy of the GNU Lesser General Public\n"
141 "License along with %s; if not, write to the Free Software\n"
142 "Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA\n",
143 program_name, program_name, program_name );
144 #endif
145
146 return 0;
147 }
148
149 static int warned_cfg = 0;
150
151 #define INDENT 1
152 #define SHOW_VERSION 2
153 #define SHOW_CONFIG 4
154 #define SHOW_COPYRIGHT 8
155
156 #define PRINT_LIB_INFO(libname, LIBNAME, flags, level) \
157 if (CONFIG_##LIBNAME) { \
158 const char *indent = flags & INDENT? " " : ""; \
159 if (flags & SHOW_VERSION) { \
160 unsigned int version = libname##_version(); \
161 av_log(NULL, level, \
162 "%slib%-11s %2d.%3d.%3d / %2d.%3d.%3d\n", \
163 indent, #libname, \
164 LIB##LIBNAME##_VERSION_MAJOR, \
165 LIB##LIBNAME##_VERSION_MINOR, \
166 LIB##LIBNAME##_VERSION_MICRO, \
167 AV_VERSION_MAJOR(version), AV_VERSION_MINOR(version),\
168 AV_VERSION_MICRO(version)); \
169 } \
170 if (flags & SHOW_CONFIG) { \
171 const char *cfg = libname##_configuration(); \
172 if (strcmp(FFMPEG_CONFIGURATION, cfg)) { \
173 if (!warned_cfg) { \
174 av_log(NULL, level, \
175 "%sWARNING: library configuration mismatch\n", \
176 indent); \
177 warned_cfg = 1; \
178 } \
179 av_log(NULL, level, "%s%-11s configuration: %s\n", \
180 indent, #libname, cfg); \
181 } \
182 } \
183 } \
184
185 13092 static void print_all_libs_info(int flags, int level)
186 {
187
6/10
✓ Branch 0 taken 13092 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6546 times.
✓ Branch 3 taken 6546 times.
✓ Branch 6 taken 6546 times.
✓ Branch 7 taken 6546 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 6546 times.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
13092 PRINT_LIB_INFO(avutil, AVUTIL, flags, level);
188
6/10
✓ Branch 0 taken 13092 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6546 times.
✓ Branch 3 taken 6546 times.
✓ Branch 6 taken 6546 times.
✓ Branch 7 taken 6546 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 6546 times.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
13092 PRINT_LIB_INFO(avcodec, AVCODEC, flags, level);
189
6/10
✓ Branch 0 taken 13092 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6546 times.
✓ Branch 3 taken 6546 times.
✓ Branch 6 taken 6546 times.
✓ Branch 7 taken 6546 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 6546 times.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
13092 PRINT_LIB_INFO(avformat, AVFORMAT, flags, level);
190
6/10
✓ Branch 0 taken 13092 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6546 times.
✓ Branch 3 taken 6546 times.
✓ Branch 6 taken 6546 times.
✓ Branch 7 taken 6546 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 6546 times.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
13092 PRINT_LIB_INFO(avdevice, AVDEVICE, flags, level);
191
6/10
✓ Branch 0 taken 13092 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6546 times.
✓ Branch 3 taken 6546 times.
✓ Branch 6 taken 6546 times.
✓ Branch 7 taken 6546 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 6546 times.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
13092 PRINT_LIB_INFO(avfilter, AVFILTER, flags, level);
192
6/10
✓ Branch 0 taken 13092 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6546 times.
✓ Branch 3 taken 6546 times.
✓ Branch 6 taken 6546 times.
✓ Branch 7 taken 6546 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 6546 times.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
13092 PRINT_LIB_INFO(swscale, SWSCALE, flags, level);
193
6/10
✓ Branch 0 taken 13092 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6546 times.
✓ Branch 3 taken 6546 times.
✓ Branch 6 taken 6546 times.
✓ Branch 7 taken 6546 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 6546 times.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
13092 PRINT_LIB_INFO(swresample, SWRESAMPLE, flags, level);
194
6/10
✓ Branch 0 taken 13092 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6546 times.
✓ Branch 3 taken 6546 times.
✓ Branch 6 taken 6546 times.
✓ Branch 7 taken 6546 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 6546 times.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
13092 PRINT_LIB_INFO(postproc, POSTPROC, flags, level);
195 13092 }
196
197 6546 static void print_program_info(int flags, int level)
198 {
199
1/2
✓ Branch 0 taken 6546 times.
✗ Branch 1 not taken.
6546 const char *indent = flags & INDENT? " " : "";
200
201 6546 av_log(NULL, level, "%s version " FFMPEG_VERSION, program_name);
202
1/2
✓ Branch 0 taken 6546 times.
✗ Branch 1 not taken.
6546 if (flags & SHOW_COPYRIGHT)
203 6546 av_log(NULL, level, " Copyright (c) %d-%d the FFmpeg developers",
204 program_birth_year, CONFIG_THIS_YEAR);
205 6546 av_log(NULL, level, "\n");
206 6546 av_log(NULL, level, "%sbuilt with %s\n", indent, CC_IDENT);
207
208 6546 av_log(NULL, level, "%sconfiguration: " FFMPEG_CONFIGURATION "\n", indent);
209 6546 }
210
211 static void print_buildconf(int flags, int level)
212 {
213 const char *indent = flags & INDENT ? " " : "";
214 char str[] = { FFMPEG_CONFIGURATION };
215 char *conflist, *remove_tilde, *splitconf;
216
217 // Change all the ' --' strings to '~--' so that
218 // they can be identified as tokens.
219 while ((conflist = strstr(str, " --")) != NULL) {
220 conflist[0] = '~';
221 }
222
223 // Compensate for the weirdness this would cause
224 // when passing 'pkg-config --static'.
225 while ((remove_tilde = strstr(str, "pkg-config~")) != NULL) {
226 remove_tilde[sizeof("pkg-config~") - 2] = ' ';
227 }
228
229 splitconf = strtok(str, "~");
230 av_log(NULL, level, "\n%sconfiguration:\n", indent);
231 while (splitconf != NULL) {
232 av_log(NULL, level, "%s%s%s\n", indent, indent, splitconf);
233 splitconf = strtok(NULL, "~");
234 }
235 }
236
237 6546 void show_banner(int argc, char **argv, const OptionDef *options)
238 {
239 6546 int idx = locate_option(argc, argv, options, "version");
240
2/4
✓ Branch 0 taken 6546 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 6546 times.
6546 if (hide_banner || idx)
241 return;
242
243 6546 print_program_info (INDENT|SHOW_COPYRIGHT, AV_LOG_INFO);
244 6546 print_all_libs_info(INDENT|SHOW_CONFIG, AV_LOG_INFO);
245 6546 print_all_libs_info(INDENT|SHOW_VERSION, AV_LOG_INFO);
246 }
247
248 int show_version(void *optctx, const char *opt, const char *arg)
249 {
250 av_log_set_callback(log_callback_help);
251 print_program_info (SHOW_COPYRIGHT, AV_LOG_INFO);
252 print_all_libs_info(SHOW_VERSION, AV_LOG_INFO);
253
254 return 0;
255 }
256
257 int show_buildconf(void *optctx, const char *opt, const char *arg)
258 {
259 av_log_set_callback(log_callback_help);
260 print_buildconf (INDENT|0, AV_LOG_INFO);
261
262 return 0;
263 }
264
265 #define PRINT_CODEC_SUPPORTED(codec, field, type, list_name, term, get_name) \
266 if (codec->field) { \
267 const type *p = codec->field; \
268 \
269 printf(" Supported " list_name ":"); \
270 while (*p != term) { \
271 get_name(*p); \
272 printf(" %s", name); \
273 p++; \
274 } \
275 printf("\n"); \
276 } \
277
278 static void print_codec(const AVCodec *c)
279 {
280 int encoder = av_codec_is_encoder(c);
281
282 printf("%s %s [%s]:\n", encoder ? "Encoder" : "Decoder", c->name,
283 c->long_name ? c->long_name : "");
284
285 printf(" General capabilities: ");
286 if (c->capabilities & AV_CODEC_CAP_DRAW_HORIZ_BAND)
287 printf("horizband ");
288 if (c->capabilities & AV_CODEC_CAP_DR1)
289 printf("dr1 ");
290 if (c->capabilities & AV_CODEC_CAP_DELAY)
291 printf("delay ");
292 if (c->capabilities & AV_CODEC_CAP_SMALL_LAST_FRAME)
293 printf("small ");
294 if (c->capabilities & AV_CODEC_CAP_SUBFRAMES)
295 printf("subframes ");
296 if (c->capabilities & AV_CODEC_CAP_EXPERIMENTAL)
297 printf("exp ");
298 if (c->capabilities & AV_CODEC_CAP_CHANNEL_CONF)
299 printf("chconf ");
300 if (c->capabilities & AV_CODEC_CAP_PARAM_CHANGE)
301 printf("paramchange ");
302 if (c->capabilities & AV_CODEC_CAP_VARIABLE_FRAME_SIZE)
303 printf("variable ");
304 if (c->capabilities & (AV_CODEC_CAP_FRAME_THREADS |
305 AV_CODEC_CAP_SLICE_THREADS |
306 AV_CODEC_CAP_OTHER_THREADS))
307 printf("threads ");
308 if (c->capabilities & AV_CODEC_CAP_AVOID_PROBING)
309 printf("avoidprobe ");
310 if (c->capabilities & AV_CODEC_CAP_HARDWARE)
311 printf("hardware ");
312 if (c->capabilities & AV_CODEC_CAP_HYBRID)
313 printf("hybrid ");
314 if (!c->capabilities)
315 printf("none");
316 printf("\n");
317
318 if (c->type == AVMEDIA_TYPE_VIDEO ||
319 c->type == AVMEDIA_TYPE_AUDIO) {
320 printf(" Threading capabilities: ");
321 switch (c->capabilities & (AV_CODEC_CAP_FRAME_THREADS |
322 AV_CODEC_CAP_SLICE_THREADS |
323 AV_CODEC_CAP_OTHER_THREADS)) {
324 case AV_CODEC_CAP_FRAME_THREADS |
325 AV_CODEC_CAP_SLICE_THREADS: printf("frame and slice"); break;
326 case AV_CODEC_CAP_FRAME_THREADS: printf("frame"); break;
327 case AV_CODEC_CAP_SLICE_THREADS: printf("slice"); break;
328 case AV_CODEC_CAP_OTHER_THREADS: printf("other"); break;
329 default: printf("none"); break;
330 }
331 printf("\n");
332 }
333
334 if (avcodec_get_hw_config(c, 0)) {
335 printf(" Supported hardware devices: ");
336 for (int i = 0;; i++) {
337 const AVCodecHWConfig *config = avcodec_get_hw_config(c, i);
338 const char *name;
339 if (!config)
340 break;
341 name = av_hwdevice_get_type_name(config->device_type);
342 if (name)
343 printf("%s ", name);
344 }
345 printf("\n");
346 }
347
348 if (c->supported_framerates) {
349 const AVRational *fps = c->supported_framerates;
350
351 printf(" Supported framerates:");
352 while (fps->num) {
353 printf(" %d/%d", fps->num, fps->den);
354 fps++;
355 }
356 printf("\n");
357 }
358 PRINT_CODEC_SUPPORTED(c, pix_fmts, enum AVPixelFormat, "pixel formats",
359 AV_PIX_FMT_NONE, GET_PIX_FMT_NAME);
360 PRINT_CODEC_SUPPORTED(c, supported_samplerates, int, "sample rates", 0,
361 GET_SAMPLE_RATE_NAME);
362 PRINT_CODEC_SUPPORTED(c, sample_fmts, enum AVSampleFormat, "sample formats",
363 AV_SAMPLE_FMT_NONE, GET_SAMPLE_FMT_NAME);
364
365 if (c->ch_layouts) {
366 const AVChannelLayout *p = c->ch_layouts;
367
368 printf(" Supported channel layouts:");
369 while (p->nb_channels) {
370 char name[128];
371 av_channel_layout_describe(p, name, sizeof(name));
372 printf(" %s", name);
373 p++;
374 }
375 printf("\n");
376 }
377
378 if (c->priv_class) {
379 show_help_children(c->priv_class,
380 AV_OPT_FLAG_ENCODING_PARAM |
381 AV_OPT_FLAG_DECODING_PARAM);
382 }
383 }
384
385 static const AVCodec *next_codec_for_id(enum AVCodecID id, void **iter,
386 int encoder)
387 {
388 const AVCodec *c;
389 while ((c = av_codec_iterate(iter))) {
390 if (c->id == id &&
391 (encoder ? av_codec_is_encoder(c) : av_codec_is_decoder(c)))
392 return c;
393 }
394 return NULL;
395 }
396
397 static void show_help_codec(const char *name, int encoder)
398 {
399 const AVCodecDescriptor *desc;
400 const AVCodec *codec;
401
402 if (!name) {
403 av_log(NULL, AV_LOG_ERROR, "No codec name specified.\n");
404 return;
405 }
406
407 codec = encoder ? avcodec_find_encoder_by_name(name) :
408 avcodec_find_decoder_by_name(name);
409
410 if (codec)
411 print_codec(codec);
412 else if ((desc = avcodec_descriptor_get_by_name(name))) {
413 void *iter = NULL;
414 int printed = 0;
415
416 while ((codec = next_codec_for_id(desc->id, &iter, encoder))) {
417 printed = 1;
418 print_codec(codec);
419 }
420
421 if (!printed) {
422 av_log(NULL, AV_LOG_ERROR, "Codec '%s' is known to FFmpeg, "
423 "but no %s for it are available. FFmpeg might need to be "
424 "recompiled with additional external libraries.\n",
425 name, encoder ? "encoders" : "decoders");
426 }
427 } else {
428 av_log(NULL, AV_LOG_ERROR, "Codec '%s' is not recognized by FFmpeg.\n",
429 name);
430 }
431 }
432
433 static void show_help_demuxer(const char *name)
434 {
435 const AVInputFormat *fmt = av_find_input_format(name);
436
437 if (!fmt) {
438 av_log(NULL, AV_LOG_ERROR, "Unknown format '%s'.\n", name);
439 return;
440 }
441
442 printf("Demuxer %s [%s]:\n", fmt->name, fmt->long_name);
443
444 if (fmt->extensions)
445 printf(" Common extensions: %s.\n", fmt->extensions);
446
447 if (fmt->priv_class)
448 show_help_children(fmt->priv_class, AV_OPT_FLAG_DECODING_PARAM);
449 }
450
451 static void show_help_protocol(const char *name)
452 {
453 const AVClass *proto_class;
454
455 if (!name) {
456 av_log(NULL, AV_LOG_ERROR, "No protocol name specified.\n");
457 return;
458 }
459
460 proto_class = avio_protocol_get_class(name);
461 if (!proto_class) {
462 av_log(NULL, AV_LOG_ERROR, "Unknown protocol '%s'.\n", name);
463 return;
464 }
465
466 show_help_children(proto_class, AV_OPT_FLAG_DECODING_PARAM | AV_OPT_FLAG_ENCODING_PARAM);
467 }
468
469 static void show_help_muxer(const char *name)
470 {
471 const AVCodecDescriptor *desc;
472 const AVOutputFormat *fmt = av_guess_format(name, NULL, NULL);
473
474 if (!fmt) {
475 av_log(NULL, AV_LOG_ERROR, "Unknown format '%s'.\n", name);
476 return;
477 }
478
479 printf("Muxer %s [%s]:\n", fmt->name, fmt->long_name);
480
481 if (fmt->extensions)
482 printf(" Common extensions: %s.\n", fmt->extensions);
483 if (fmt->mime_type)
484 printf(" Mime type: %s.\n", fmt->mime_type);
485 if (fmt->video_codec != AV_CODEC_ID_NONE &&
486 (desc = avcodec_descriptor_get(fmt->video_codec))) {
487 printf(" Default video codec: %s.\n", desc->name);
488 }
489 if (fmt->audio_codec != AV_CODEC_ID_NONE &&
490 (desc = avcodec_descriptor_get(fmt->audio_codec))) {
491 printf(" Default audio codec: %s.\n", desc->name);
492 }
493 if (fmt->subtitle_codec != AV_CODEC_ID_NONE &&
494 (desc = avcodec_descriptor_get(fmt->subtitle_codec))) {
495 printf(" Default subtitle codec: %s.\n", desc->name);
496 }
497
498 if (fmt->priv_class)
499 show_help_children(fmt->priv_class, AV_OPT_FLAG_ENCODING_PARAM);
500 }
501
502 #if CONFIG_AVFILTER
503 static void show_help_filter(const char *name)
504 {
505 #if CONFIG_AVFILTER
506 const AVFilter *f = avfilter_get_by_name(name);
507 int i, count;
508
509 if (!name) {
510 av_log(NULL, AV_LOG_ERROR, "No filter name specified.\n");
511 return;
512 } else if (!f) {
513 av_log(NULL, AV_LOG_ERROR, "Unknown filter '%s'.\n", name);
514 return;
515 }
516
517 printf("Filter %s\n", f->name);
518 if (f->description)
519 printf(" %s\n", f->description);
520
521 if (f->flags & AVFILTER_FLAG_SLICE_THREADS)
522 printf(" slice threading supported\n");
523
524 printf(" Inputs:\n");
525 count = avfilter_filter_pad_count(f, 0);
526 for (i = 0; i < count; i++) {
527 printf(" #%d: %s (%s)\n", i, avfilter_pad_get_name(f->inputs, i),
528 av_get_media_type_string(avfilter_pad_get_type(f->inputs, i)));
529 }
530 if (f->flags & AVFILTER_FLAG_DYNAMIC_INPUTS)
531 printf(" dynamic (depending on the options)\n");
532 else if (!count)
533 printf(" none (source filter)\n");
534
535 printf(" Outputs:\n");
536 count = avfilter_filter_pad_count(f, 1);
537 for (i = 0; i < count; i++) {
538 printf(" #%d: %s (%s)\n", i, avfilter_pad_get_name(f->outputs, i),
539 av_get_media_type_string(avfilter_pad_get_type(f->outputs, i)));
540 }
541 if (f->flags & AVFILTER_FLAG_DYNAMIC_OUTPUTS)
542 printf(" dynamic (depending on the options)\n");
543 else if (!count)
544 printf(" none (sink filter)\n");
545
546 if (f->priv_class)
547 show_help_children(f->priv_class, AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_FILTERING_PARAM |
548 AV_OPT_FLAG_AUDIO_PARAM);
549 if (f->flags & AVFILTER_FLAG_SUPPORT_TIMELINE)
550 printf("This filter has support for timeline through the 'enable' option.\n");
551 #else
552 av_log(NULL, AV_LOG_ERROR, "Build without libavfilter; "
553 "can not to satisfy request\n");
554 #endif
555 }
556 #endif
557
558 static void show_help_bsf(const char *name)
559 {
560 const AVBitStreamFilter *bsf = av_bsf_get_by_name(name);
561
562 if (!name) {
563 av_log(NULL, AV_LOG_ERROR, "No bitstream filter name specified.\n");
564 return;
565 } else if (!bsf) {
566 av_log(NULL, AV_LOG_ERROR, "Unknown bit stream filter '%s'.\n", name);
567 return;
568 }
569
570 printf("Bit stream filter %s\n", bsf->name);
571 PRINT_CODEC_SUPPORTED(bsf, codec_ids, enum AVCodecID, "codecs",
572 AV_CODEC_ID_NONE, GET_CODEC_NAME);
573 if (bsf->priv_class)
574 show_help_children(bsf->priv_class, AV_OPT_FLAG_BSF_PARAM);
575 }
576
577 int show_help(void *optctx, const char *opt, const char *arg)
578 {
579 char *topic, *par;
580 av_log_set_callback(log_callback_help);
581
582 topic = av_strdup(arg ? arg : "");
583 if (!topic)
584 return AVERROR(ENOMEM);
585 par = strchr(topic, '=');
586 if (par)
587 *par++ = 0;
588
589 if (!*topic) {
590 show_help_default(topic, par);
591 } else if (!strcmp(topic, "decoder")) {
592 show_help_codec(par, 0);
593 } else if (!strcmp(topic, "encoder")) {
594 show_help_codec(par, 1);
595 } else if (!strcmp(topic, "demuxer")) {
596 show_help_demuxer(par);
597 } else if (!strcmp(topic, "muxer")) {
598 show_help_muxer(par);
599 } else if (!strcmp(topic, "protocol")) {
600 show_help_protocol(par);
601 #if CONFIG_AVFILTER
602 } else if (!strcmp(topic, "filter")) {
603 show_help_filter(par);
604 #endif
605 } else if (!strcmp(topic, "bsf")) {
606 show_help_bsf(par);
607 } else {
608 show_help_default(topic, par);
609 }
610
611 av_freep(&topic);
612 return 0;
613 }
614
615 static void print_codecs_for_id(enum AVCodecID id, int encoder)
616 {
617 void *iter = NULL;
618 const AVCodec *codec;
619
620 printf(" (%s: ", encoder ? "encoders" : "decoders");
621
622 while ((codec = next_codec_for_id(id, &iter, encoder)))
623 printf("%s ", codec->name);
624
625 printf(")");
626 }
627
628 static int compare_codec_desc(const void *a, const void *b)
629 {
630 const AVCodecDescriptor * const *da = a;
631 const AVCodecDescriptor * const *db = b;
632
633 return (*da)->type != (*db)->type ? FFDIFFSIGN((*da)->type, (*db)->type) :
634 strcmp((*da)->name, (*db)->name);
635 }
636
637 static unsigned get_codecs_sorted(const AVCodecDescriptor ***rcodecs)
638 {
639 const AVCodecDescriptor *desc = NULL;
640 const AVCodecDescriptor **codecs;
641 unsigned nb_codecs = 0, i = 0;
642
643 while ((desc = avcodec_descriptor_next(desc)))
644 nb_codecs++;
645 if (!(codecs = av_calloc(nb_codecs, sizeof(*codecs))))
646 report_and_exit(AVERROR(ENOMEM));
647 desc = NULL;
648 while ((desc = avcodec_descriptor_next(desc)))
649 codecs[i++] = desc;
650 av_assert0(i == nb_codecs);
651 qsort(codecs, nb_codecs, sizeof(*codecs), compare_codec_desc);
652 *rcodecs = codecs;
653 return nb_codecs;
654 }
655
656 static char get_media_type_char(enum AVMediaType type)
657 {
658 switch (type) {
659 case AVMEDIA_TYPE_VIDEO: return 'V';
660 case AVMEDIA_TYPE_AUDIO: return 'A';
661 case AVMEDIA_TYPE_DATA: return 'D';
662 case AVMEDIA_TYPE_SUBTITLE: return 'S';
663 case AVMEDIA_TYPE_ATTACHMENT:return 'T';
664 default: return '?';
665 }
666 }
667
668 int show_codecs(void *optctx, const char *opt, const char *arg)
669 {
670 const AVCodecDescriptor **codecs;
671 unsigned i, nb_codecs = get_codecs_sorted(&codecs);
672
673 printf("Codecs:\n"
674 " D..... = Decoding supported\n"
675 " .E.... = Encoding supported\n"
676 " ..V... = Video codec\n"
677 " ..A... = Audio codec\n"
678 " ..S... = Subtitle codec\n"
679 " ..D... = Data codec\n"
680 " ..T... = Attachment codec\n"
681 " ...I.. = Intra frame-only codec\n"
682 " ....L. = Lossy compression\n"
683 " .....S = Lossless compression\n"
684 " -------\n");
685 for (i = 0; i < nb_codecs; i++) {
686 const AVCodecDescriptor *desc = codecs[i];
687 const AVCodec *codec;
688 void *iter = NULL;
689
690 if (strstr(desc->name, "_deprecated"))
691 continue;
692
693 printf(" ");
694 printf(avcodec_find_decoder(desc->id) ? "D" : ".");
695 printf(avcodec_find_encoder(desc->id) ? "E" : ".");
696
697 printf("%c", get_media_type_char(desc->type));
698 printf((desc->props & AV_CODEC_PROP_INTRA_ONLY) ? "I" : ".");
699 printf((desc->props & AV_CODEC_PROP_LOSSY) ? "L" : ".");
700 printf((desc->props & AV_CODEC_PROP_LOSSLESS) ? "S" : ".");
701
702 printf(" %-20s %s", desc->name, desc->long_name ? desc->long_name : "");
703
704 /* print decoders/encoders when there's more than one or their
705 * names are different from codec name */
706 while ((codec = next_codec_for_id(desc->id, &iter, 0))) {
707 if (strcmp(codec->name, desc->name)) {
708 print_codecs_for_id(desc->id, 0);
709 break;
710 }
711 }
712 iter = NULL;
713 while ((codec = next_codec_for_id(desc->id, &iter, 1))) {
714 if (strcmp(codec->name, desc->name)) {
715 print_codecs_for_id(desc->id, 1);
716 break;
717 }
718 }
719
720 printf("\n");
721 }
722 av_free(codecs);
723 return 0;
724 }
725
726 static void print_codecs(int encoder)
727 {
728 const AVCodecDescriptor **codecs;
729 unsigned i, nb_codecs = get_codecs_sorted(&codecs);
730
731 printf("%s:\n"
732 " V..... = Video\n"
733 " A..... = Audio\n"
734 " S..... = Subtitle\n"
735 " .F.... = Frame-level multithreading\n"
736 " ..S... = Slice-level multithreading\n"
737 " ...X.. = Codec is experimental\n"
738 " ....B. = Supports draw_horiz_band\n"
739 " .....D = Supports direct rendering method 1\n"
740 " ------\n",
741 encoder ? "Encoders" : "Decoders");
742 for (i = 0; i < nb_codecs; i++) {
743 const AVCodecDescriptor *desc = codecs[i];
744 const AVCodec *codec;
745 void *iter = NULL;
746
747 while ((codec = next_codec_for_id(desc->id, &iter, encoder))) {
748 printf(" %c", get_media_type_char(desc->type));
749 printf((codec->capabilities & AV_CODEC_CAP_FRAME_THREADS) ? "F" : ".");
750 printf((codec->capabilities & AV_CODEC_CAP_SLICE_THREADS) ? "S" : ".");
751 printf((codec->capabilities & AV_CODEC_CAP_EXPERIMENTAL) ? "X" : ".");
752 printf((codec->capabilities & AV_CODEC_CAP_DRAW_HORIZ_BAND)?"B" : ".");
753 printf((codec->capabilities & AV_CODEC_CAP_DR1) ? "D" : ".");
754
755 printf(" %-20s %s", codec->name, codec->long_name ? codec->long_name : "");
756 if (strcmp(codec->name, desc->name))
757 printf(" (codec %s)", desc->name);
758
759 printf("\n");
760 }
761 }
762 av_free(codecs);
763 }
764
765 int show_decoders(void *optctx, const char *opt, const char *arg)
766 {
767 print_codecs(0);
768 return 0;
769 }
770
771 int show_encoders(void *optctx, const char *opt, const char *arg)
772 {
773 print_codecs(1);
774 return 0;
775 }
776
777 int show_bsfs(void *optctx, const char *opt, const char *arg)
778 {
779 const AVBitStreamFilter *bsf = NULL;
780 void *opaque = NULL;
781
782 printf("Bitstream filters:\n");
783 while ((bsf = av_bsf_iterate(&opaque)))
784 printf("%s\n", bsf->name);
785 printf("\n");
786 return 0;
787 }
788
789 int show_filters(void *optctx, const char *opt, const char *arg)
790 {
791 #if CONFIG_AVFILTER
792 const AVFilter *filter = NULL;
793 char descr[64], *descr_cur;
794 void *opaque = NULL;
795 int i, j;
796 const AVFilterPad *pad;
797
798 printf("Filters:\n"
799 " T.. = Timeline support\n"
800 " .S. = Slice threading\n"
801 " ..C = Command support\n"
802 " A = Audio input/output\n"
803 " V = Video input/output\n"
804 " N = Dynamic number and/or type of input/output\n"
805 " | = Source or sink filter\n");
806 while ((filter = av_filter_iterate(&opaque))) {
807 descr_cur = descr;
808 for (i = 0; i < 2; i++) {
809 unsigned nb_pads;
810 if (i) {
811 *(descr_cur++) = '-';
812 *(descr_cur++) = '>';
813 }
814 pad = i ? filter->outputs : filter->inputs;
815 nb_pads = avfilter_filter_pad_count(filter, i);
816 for (j = 0; j < nb_pads; j++) {
817 if (descr_cur >= descr + sizeof(descr) - 4)
818 break;
819 *(descr_cur++) = get_media_type_char(avfilter_pad_get_type(pad, j));
820 }
821 if (!j)
822 *(descr_cur++) = ((!i && (filter->flags & AVFILTER_FLAG_DYNAMIC_INPUTS)) ||
823 ( i && (filter->flags & AVFILTER_FLAG_DYNAMIC_OUTPUTS))) ? 'N' : '|';
824 }
825 *descr_cur = 0;
826 printf(" %c%c%c %-17s %-10s %s\n",
827 filter->flags & AVFILTER_FLAG_SUPPORT_TIMELINE ? 'T' : '.',
828 filter->flags & AVFILTER_FLAG_SLICE_THREADS ? 'S' : '.',
829 filter->process_command ? 'C' : '.',
830 filter->name, descr, filter->description);
831 }
832 #else
833 printf("No filters available: libavfilter disabled\n");
834 #endif
835 return 0;
836 }
837
838 static int is_device(const AVClass *avclass)
839 {
840 if (!avclass)
841 return 0;
842 return AV_IS_INPUT_DEVICE(avclass->category) || AV_IS_OUTPUT_DEVICE(avclass->category);
843 }
844
845 static int show_formats_devices(void *optctx, const char *opt, const char *arg, int device_only, int muxdemuxers)
846 {
847 void *ifmt_opaque = NULL;
848 const AVInputFormat *ifmt = NULL;
849 void *ofmt_opaque = NULL;
850 const AVOutputFormat *ofmt = NULL;
851 const char *last_name;
852 int is_dev;
853
854 printf("%s\n"
855 " D. = Demuxing supported\n"
856 " .E = Muxing supported\n"
857 " --\n", device_only ? "Devices:" : "File formats:");
858 last_name = "000";
859 for (;;) {
860 int decode = 0;
861 int encode = 0;
862 const char *name = NULL;
863 const char *long_name = NULL;
864
865 if (muxdemuxers !=SHOW_DEMUXERS) {
866 ofmt_opaque = NULL;
867 while ((ofmt = av_muxer_iterate(&ofmt_opaque))) {
868 is_dev = is_device(ofmt->priv_class);
869 if (!is_dev && device_only)
870 continue;
871 if ((!name || strcmp(ofmt->name, name) < 0) &&
872 strcmp(ofmt->name, last_name) > 0) {
873 name = ofmt->name;
874 long_name = ofmt->long_name;
875 encode = 1;
876 }
877 }
878 }
879 if (muxdemuxers != SHOW_MUXERS) {
880 ifmt_opaque = NULL;
881 while ((ifmt = av_demuxer_iterate(&ifmt_opaque))) {
882 is_dev = is_device(ifmt->priv_class);
883 if (!is_dev && device_only)
884 continue;
885 if ((!name || strcmp(ifmt->name, name) < 0) &&
886 strcmp(ifmt->name, last_name) > 0) {
887 name = ifmt->name;
888 long_name = ifmt->long_name;
889 encode = 0;
890 }
891 if (name && strcmp(ifmt->name, name) == 0)
892 decode = 1;
893 }
894 }
895 if (!name)
896 break;
897 last_name = name;
898
899 printf(" %c%c %-15s %s\n",
900 decode ? 'D' : ' ',
901 encode ? 'E' : ' ',
902 name,
903 long_name ? long_name:" ");
904 }
905 return 0;
906 }
907
908 int show_formats(void *optctx, const char *opt, const char *arg)
909 {
910 return show_formats_devices(optctx, opt, arg, 0, SHOW_DEFAULT);
911 }
912
913 int show_muxers(void *optctx, const char *opt, const char *arg)
914 {
915 return show_formats_devices(optctx, opt, arg, 0, SHOW_MUXERS);
916 }
917
918 int show_demuxers(void *optctx, const char *opt, const char *arg)
919 {
920 return show_formats_devices(optctx, opt, arg, 0, SHOW_DEMUXERS);
921 }
922
923 int show_devices(void *optctx, const char *opt, const char *arg)
924 {
925 return show_formats_devices(optctx, opt, arg, 1, SHOW_DEFAULT);
926 }
927
928 int show_protocols(void *optctx, const char *opt, const char *arg)
929 {
930 void *opaque = NULL;
931 const char *name;
932
933 printf("Supported file protocols:\n"
934 "Input:\n");
935 while ((name = avio_enum_protocols(&opaque, 0)))
936 printf(" %s\n", name);
937 printf("Output:\n");
938 while ((name = avio_enum_protocols(&opaque, 1)))
939 printf(" %s\n", name);
940 return 0;
941 }
942
943 int show_colors(void *optctx, const char *opt, const char *arg)
944 {
945 const char *name;
946 const uint8_t *rgb;
947 int i;
948
949 printf("%-32s #RRGGBB\n", "name");
950
951 for (i = 0; name = av_get_known_color_name(i, &rgb); i++)
952 printf("%-32s #%02x%02x%02x\n", name, rgb[0], rgb[1], rgb[2]);
953
954 return 0;
955 }
956
957 1 int show_pix_fmts(void *optctx, const char *opt, const char *arg)
958 {
959 1 const AVPixFmtDescriptor *pix_desc = NULL;
960
961 1 printf("Pixel formats:\n"
962 "I.... = Supported Input format for conversion\n"
963 ".O... = Supported Output format for conversion\n"
964 "..H.. = Hardware accelerated format\n"
965 "...P. = Paletted format\n"
966 "....B = Bitstream format\n"
967 "FLAGS NAME NB_COMPONENTS BITS_PER_PIXEL BIT_DEPTHS\n"
968 "-----\n");
969
970 #if !CONFIG_SWSCALE
971 # define sws_isSupportedInput(x) 0
972 # define sws_isSupportedOutput(x) 0
973 #endif
974
975
2/2
✓ Branch 1 taken 222 times.
✓ Branch 2 taken 1 times.
223 while ((pix_desc = av_pix_fmt_desc_next(pix_desc))) {
976 222 enum AVPixelFormat av_unused pix_fmt = av_pix_fmt_desc_get_id(pix_desc);
977
4/4
✓ Branch 0 taken 179 times.
✓ Branch 1 taken 43 times.
✓ Branch 2 taken 192 times.
✓ Branch 3 taken 30 times.
1110 printf("%c%c%c%c%c %-16s %d %3d %d",
978 222 sws_isSupportedInput (pix_fmt) ? 'I' : '.',
979 222 sws_isSupportedOutput(pix_fmt) ? 'O' : '.',
980
2/2
✓ Branch 0 taken 14 times.
✓ Branch 1 taken 208 times.
222 pix_desc->flags & AV_PIX_FMT_FLAG_HWACCEL ? 'H' : '.',
981
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 221 times.
222 pix_desc->flags & AV_PIX_FMT_FLAG_PAL ? 'P' : '.',
982 222 pix_desc->flags & AV_PIX_FMT_FLAG_BITSTREAM ? 'B' : '.',
983 222 pix_desc->name,
984
2/2
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 217 times.
222 pix_desc->nb_components,
985 av_get_bits_per_pixel(pix_desc),
986 222 pix_desc->comp[0].depth);
987
988
2/2
✓ Branch 0 taken 430 times.
✓ Branch 1 taken 222 times.
652 for (unsigned i = 1; i < pix_desc->nb_components; i++)
989 430 printf("-%d", pix_desc->comp[i].depth);
990 222 printf("\n");
991 }
992 1 return 0;
993 }
994
995 int show_layouts(void *optctx, const char *opt, const char *arg)
996 {
997 const AVChannelLayout *ch_layout;
998 void *iter = NULL;
999 char buf[128], buf2[128];
1000 int i = 0;
1001
1002 printf("Individual channels:\n"
1003 "NAME DESCRIPTION\n");
1004 for (i = 0; i < 63; i++) {
1005 av_channel_name(buf, sizeof(buf), i);
1006 if (strstr(buf, "USR"))
1007 continue;
1008 av_channel_description(buf2, sizeof(buf2), i);
1009 printf("%-14s %s\n", buf, buf2);
1010 }
1011 printf("\nStandard channel layouts:\n"
1012 "NAME DECOMPOSITION\n");
1013 while (ch_layout = av_channel_layout_standard(&iter)) {
1014 av_channel_layout_describe(ch_layout, buf, sizeof(buf));
1015 printf("%-14s ", buf);
1016 for (i = 0; i < 63; i++) {
1017 int idx = av_channel_layout_index_from_channel(ch_layout, i);
1018 if (idx >= 0) {
1019 av_channel_name(buf2, sizeof(buf2), i);
1020 printf("%s%s", idx ? "+" : "", buf2);
1021 }
1022 }
1023 printf("\n");
1024 }
1025 return 0;
1026 }
1027
1028 int show_sample_fmts(void *optctx, const char *opt, const char *arg)
1029 {
1030 int i;
1031 char fmt_str[128];
1032 for (i = -1; i < AV_SAMPLE_FMT_NB; i++)
1033 printf("%s\n", av_get_sample_fmt_string(fmt_str, sizeof(fmt_str), i));
1034 return 0;
1035 }
1036
1037 int show_dispositions(void *optctx, const char *opt, const char *arg)
1038 {
1039 for (int i = 0; i < 32; i++) {
1040 const char *str = av_disposition_to_string(1U << i);
1041 if (str)
1042 printf("%s\n", str);
1043 }
1044 return 0;
1045 }
1046
1047 6395 int opt_cpuflags(void *optctx, const char *opt, const char *arg)
1048 {
1049 int ret;
1050 6395 unsigned flags = av_get_cpu_flags();
1051
1052
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 6395 times.
6395 if ((ret = av_parse_cpu_caps(&flags, arg)) < 0)
1053 return ret;
1054
1055 6395 av_force_cpu_flags(flags);
1056 6395 return 0;
1057 }
1058
1059 int opt_cpucount(void *optctx, const char *opt, const char *arg)
1060 {
1061 int ret;
1062 int count;
1063
1064 static const AVOption opts[] = {
1065 {"count", NULL, 0, AV_OPT_TYPE_INT, { .i64 = -1}, -1, INT_MAX},
1066 {NULL},
1067 };
1068 static const AVClass class = {
1069 .class_name = "cpucount",
1070 .item_name = av_default_item_name,
1071 .option = opts,
1072 .version = LIBAVUTIL_VERSION_INT,
1073 };
1074 const AVClass *pclass = &class;
1075
1076 ret = av_opt_eval_int(&pclass, opts, arg, &count);
1077
1078 if (!ret) {
1079 av_cpu_force_count(count);
1080 }
1081
1082 return ret;
1083 }
1084
1085 static void expand_filename_template(AVBPrint *bp, const char *template,
1086 struct tm *tm)
1087 {
1088 int c;
1089
1090 while ((c = *(template++))) {
1091 if (c == '%') {
1092 if (!(c = *(template++)))
1093 break;
1094 switch (c) {
1095 case 'p':
1096 av_bprintf(bp, "%s", program_name);
1097 break;
1098 case 't':
1099 av_bprintf(bp, "%04d%02d%02d-%02d%02d%02d",
1100 tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday,
1101 tm->tm_hour, tm->tm_min, tm->tm_sec);
1102 break;
1103 case '%':
1104 av_bprint_chars(bp, c, 1);
1105 break;
1106 }
1107 } else {
1108 av_bprint_chars(bp, c, 1);
1109 }
1110 }
1111 }
1112
1113 static void log_callback_report(void *ptr, int level, const char *fmt, va_list vl)
1114 {
1115 va_list vl2;
1116 char line[1024];
1117 static int print_prefix = 1;
1118
1119 va_copy(vl2, vl);
1120 av_log_default_callback(ptr, level, fmt, vl);
1121 av_log_format_line(ptr, level, fmt, vl2, line, sizeof(line), &print_prefix);
1122 va_end(vl2);
1123 if (report_file_level >= level) {
1124 fputs(line, report_file);
1125 fflush(report_file);
1126 }
1127 }
1128
1129 int init_report(const char *env, FILE **file)
1130 {
1131 char *filename_template = NULL;
1132 char *key, *val;
1133 int ret, count = 0;
1134 int prog_loglevel, envlevel = 0;
1135 time_t now;
1136 struct tm *tm;
1137 AVBPrint filename;
1138
1139 if (report_file) /* already opened */
1140 return 0;
1141 time(&now);
1142 tm = localtime(&now);
1143
1144 while (env && *env) {
1145 if ((ret = av_opt_get_key_value(&env, "=", ":", 0, &key, &val)) < 0) {
1146 if (count)
1147 av_log(NULL, AV_LOG_ERROR,
1148 "Failed to parse FFREPORT environment variable: %s\n",
1149 av_err2str(ret));
1150 break;
1151 }
1152 if (*env)
1153 env++;
1154 count++;
1155 if (!strcmp(key, "file")) {
1156 av_free(filename_template);
1157 filename_template = val;
1158 val = NULL;
1159 } else if (!strcmp(key, "level")) {
1160 char *tail;
1161 report_file_level = strtol(val, &tail, 10);
1162 if (*tail) {
1163 av_log(NULL, AV_LOG_FATAL, "Invalid report file level\n");
1164 exit_program(1);
1165 }
1166 envlevel = 1;
1167 } else {
1168 av_log(NULL, AV_LOG_ERROR, "Unknown key '%s' in FFREPORT\n", key);
1169 }
1170 av_free(val);
1171 av_free(key);
1172 }
1173
1174 av_bprint_init(&filename, 0, AV_BPRINT_SIZE_AUTOMATIC);
1175 expand_filename_template(&filename,
1176 av_x_if_null(filename_template, "%p-%t.log"), tm);
1177 av_free(filename_template);
1178 if (!av_bprint_is_complete(&filename)) {
1179 av_log(NULL, AV_LOG_ERROR, "Out of memory building report file name\n");
1180 return AVERROR(ENOMEM);
1181 }
1182
1183 prog_loglevel = av_log_get_level();
1184 if (!envlevel)
1185 report_file_level = FFMAX(report_file_level, prog_loglevel);
1186
1187 report_file = fopen(filename.str, "w");
1188 if (!report_file) {
1189 int ret = AVERROR(errno);
1190 av_log(NULL, AV_LOG_ERROR, "Failed to open report \"%s\": %s\n",
1191 filename.str, strerror(errno));
1192 return ret;
1193 }
1194 av_log_set_callback(log_callback_report);
1195 av_log(NULL, AV_LOG_INFO,
1196 "%s started on %04d-%02d-%02d at %02d:%02d:%02d\n"
1197 "Report written to \"%s\"\n"
1198 "Log level: %d\n",
1199 program_name,
1200 tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday,
1201 tm->tm_hour, tm->tm_min, tm->tm_sec,
1202 filename.str, report_file_level);
1203 av_bprint_finalize(&filename, NULL);
1204
1205 if (file)
1206 *file = report_file;
1207
1208 return 0;
1209 }
1210
1211 int opt_report(void *optctx, const char *opt, const char *arg)
1212 {
1213 return init_report(NULL, NULL);
1214 }
1215
1216 int opt_max_alloc(void *optctx, const char *opt, const char *arg)
1217 {
1218 char *tail;
1219 size_t max;
1220
1221 max = strtol(arg, &tail, 10);
1222 if (*tail) {
1223 av_log(NULL, AV_LOG_FATAL, "Invalid max_alloc \"%s\".\n", arg);
1224 exit_program(1);
1225 }
1226 av_max_alloc(max);
1227 return 0;
1228 }
1229
1230 30 int opt_loglevel(void *optctx, const char *opt, const char *arg)
1231 {
1232 30 const struct { const char *name; int level; } log_levels[] = {
1233 { "quiet" , AV_LOG_QUIET },
1234 { "panic" , AV_LOG_PANIC },
1235 { "fatal" , AV_LOG_FATAL },
1236 { "error" , AV_LOG_ERROR },
1237 { "warning", AV_LOG_WARNING },
1238 { "info" , AV_LOG_INFO },
1239 { "verbose", AV_LOG_VERBOSE },
1240 { "debug" , AV_LOG_DEBUG },
1241 { "trace" , AV_LOG_TRACE },
1242 };
1243 const char *token;
1244 char *tail;
1245 30 int flags = av_log_get_flags();
1246 30 int level = av_log_get_level();
1247 30 int cmd, i = 0;
1248
1249
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 30 times.
30 av_assert0(arg);
1250
1/2
✓ Branch 0 taken 30 times.
✗ Branch 1 not taken.
30 while (*arg) {
1251 30 token = arg;
1252
2/4
✓ Branch 0 taken 30 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 30 times.
30 if (*token == '+' || *token == '-') {
1253 cmd = *token++;
1254 } else {
1255 30 cmd = 0;
1256 }
1257
2/4
✓ Branch 0 taken 30 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 30 times.
✗ Branch 3 not taken.
30 if (!i && !cmd) {
1258 30 flags = 0; /* missing relative prefix, build absolute value */
1259 }
1260
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 30 times.
30 if (av_strstart(token, "repeat", &arg)) {
1261 if (cmd == '-') {
1262 flags |= AV_LOG_SKIP_REPEATED;
1263 } else {
1264 flags &= ~AV_LOG_SKIP_REPEATED;
1265 }
1266
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 30 times.
30 } else if (av_strstart(token, "level", &arg)) {
1267 if (cmd == '-') {
1268 flags &= ~AV_LOG_PRINT_LEVEL;
1269 } else {
1270 flags |= AV_LOG_PRINT_LEVEL;
1271 }
1272 } else {
1273 30 break;
1274 }
1275 i++;
1276 }
1277
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 30 times.
30 if (!*arg) {
1278 goto end;
1279
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 30 times.
30 } else if (*arg == '+') {
1280 arg++;
1281
1/2
✓ Branch 0 taken 30 times.
✗ Branch 1 not taken.
30 } else if (!i) {
1282 30 flags = av_log_get_flags(); /* level value without prefix, reset flags */
1283 }
1284
1285
2/2
✓ Branch 0 taken 262 times.
✓ Branch 1 taken 26 times.
288 for (i = 0; i < FF_ARRAY_ELEMS(log_levels); i++) {
1286
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 258 times.
262 if (!strcmp(log_levels[i].name, arg)) {
1287 4 level = log_levels[i].level;
1288 4 goto end;
1289 }
1290 }
1291
1292 26 level = strtol(arg, &tail, 10);
1293
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 26 times.
26 if (*tail) {
1294 av_log(NULL, AV_LOG_FATAL, "Invalid loglevel \"%s\". "
1295 "Possible levels are numbers or:\n", arg);
1296 for (i = 0; i < FF_ARRAY_ELEMS(log_levels); i++)
1297 av_log(NULL, AV_LOG_FATAL, "\"%s\"\n", log_levels[i].name);
1298 exit_program(1);
1299 }
1300
1301 26 end:
1302 30 av_log_set_flags(flags);
1303 30 av_log_set_level(level);
1304 30 return 0;
1305 }
1306
1307 #if CONFIG_AVDEVICE
1308 static void print_device_list(const AVDeviceInfoList *device_list)
1309 {
1310 // print devices
1311 for (int i = 0; i < device_list->nb_devices; i++) {
1312 const AVDeviceInfo *device = device_list->devices[i];
1313 printf("%c %s [%s] (", device_list->default_device == i ? '*' : ' ',
1314 device->device_name, device->device_description);
1315 if (device->nb_media_types > 0) {
1316 for (int j = 0; j < device->nb_media_types; ++j) {
1317 const char* media_type = av_get_media_type_string(device->media_types[j]);
1318 if (j > 0)
1319 printf(", ");
1320 printf("%s", media_type ? media_type : "unknown");
1321 }
1322 } else {
1323 printf("none");
1324 }
1325 printf(")\n");
1326 }
1327 }
1328
1329 static int print_device_sources(const AVInputFormat *fmt, AVDictionary *opts)
1330 {
1331 int ret;
1332 AVDeviceInfoList *device_list = NULL;
1333
1334 if (!fmt || !fmt->priv_class || !AV_IS_INPUT_DEVICE(fmt->priv_class->category))
1335 return AVERROR(EINVAL);
1336
1337 printf("Auto-detected sources for %s:\n", fmt->name);
1338 if ((ret = avdevice_list_input_sources(fmt, NULL, opts, &device_list)) < 0) {
1339 printf("Cannot list sources: %s\n", av_err2str(ret));
1340 goto fail;
1341 }
1342
1343 print_device_list(device_list);
1344
1345 fail:
1346 avdevice_free_list_devices(&device_list);
1347 return ret;
1348 }
1349
1350 static int print_device_sinks(const AVOutputFormat *fmt, AVDictionary *opts)
1351 {
1352 int ret;
1353 AVDeviceInfoList *device_list = NULL;
1354
1355 if (!fmt || !fmt->priv_class || !AV_IS_OUTPUT_DEVICE(fmt->priv_class->category))
1356 return AVERROR(EINVAL);
1357
1358 printf("Auto-detected sinks for %s:\n", fmt->name);
1359 if ((ret = avdevice_list_output_sinks(fmt, NULL, opts, &device_list)) < 0) {
1360 printf("Cannot list sinks: %s\n", av_err2str(ret));
1361 goto fail;
1362 }
1363
1364 print_device_list(device_list);
1365
1366 fail:
1367 avdevice_free_list_devices(&device_list);
1368 return ret;
1369 }
1370
1371 static int show_sinks_sources_parse_arg(const char *arg, char **dev, AVDictionary **opts)
1372 {
1373 int ret;
1374 if (arg) {
1375 char *opts_str = NULL;
1376 av_assert0(dev && opts);
1377 *dev = av_strdup(arg);
1378 if (!*dev)
1379 return AVERROR(ENOMEM);
1380 if ((opts_str = strchr(*dev, ','))) {
1381 *(opts_str++) = '\0';
1382 if (opts_str[0] && ((ret = av_dict_parse_string(opts, opts_str, "=", ":", 0)) < 0)) {
1383 av_freep(dev);
1384 return ret;
1385 }
1386 }
1387 } else
1388 printf("\nDevice name is not provided.\n"
1389 "You can pass devicename[,opt1=val1[,opt2=val2...]] as an argument.\n\n");
1390 return 0;
1391 }
1392
1393 int show_sources(void *optctx, const char *opt, const char *arg)
1394 {
1395 const AVInputFormat *fmt = NULL;
1396 char *dev = NULL;
1397 AVDictionary *opts = NULL;
1398 int ret = 0;
1399 int error_level = av_log_get_level();
1400
1401 av_log_set_level(AV_LOG_WARNING);
1402
1403 if ((ret = show_sinks_sources_parse_arg(arg, &dev, &opts)) < 0)
1404 goto fail;
1405
1406 do {
1407 fmt = av_input_audio_device_next(fmt);
1408 if (fmt) {
1409 if (!strcmp(fmt->name, "lavfi"))
1410 continue; //it's pointless to probe lavfi
1411 if (dev && !av_match_name(dev, fmt->name))
1412 continue;
1413 print_device_sources(fmt, opts);
1414 }
1415 } while (fmt);
1416 do {
1417 fmt = av_input_video_device_next(fmt);
1418 if (fmt) {
1419 if (dev && !av_match_name(dev, fmt->name))
1420 continue;
1421 print_device_sources(fmt, opts);
1422 }
1423 } while (fmt);
1424 fail:
1425 av_dict_free(&opts);
1426 av_free(dev);
1427 av_log_set_level(error_level);
1428 return ret;
1429 }
1430
1431 int show_sinks(void *optctx, const char *opt, const char *arg)
1432 {
1433 const AVOutputFormat *fmt = NULL;
1434 char *dev = NULL;
1435 AVDictionary *opts = NULL;
1436 int ret = 0;
1437 int error_level = av_log_get_level();
1438
1439 av_log_set_level(AV_LOG_WARNING);
1440
1441 if ((ret = show_sinks_sources_parse_arg(arg, &dev, &opts)) < 0)
1442 goto fail;
1443
1444 do {
1445 fmt = av_output_audio_device_next(fmt);
1446 if (fmt) {
1447 if (dev && !av_match_name(dev, fmt->name))
1448 continue;
1449 print_device_sinks(fmt, opts);
1450 }
1451 } while (fmt);
1452 do {
1453 fmt = av_output_video_device_next(fmt);
1454 if (fmt) {
1455 if (dev && !av_match_name(dev, fmt->name))
1456 continue;
1457 print_device_sinks(fmt, opts);
1458 }
1459 } while (fmt);
1460 fail:
1461 av_dict_free(&opts);
1462 av_free(dev);
1463 av_log_set_level(error_level);
1464 return ret;
1465 }
1466 #endif /* CONFIG_AVDEVICE */
1467