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