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