cmdutils.c 74 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351
  1. /*
  2. * Various utilities for command line tools
  3. * Copyright (c) 2000-2003 Fabrice Bellard
  4. *
  5. * This file is part of FFmpeg.
  6. *
  7. * FFmpeg is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU Lesser General Public
  9. * License as published by the Free Software Foundation; either
  10. * version 2.1 of the License, or (at your option) any later version.
  11. *
  12. * FFmpeg is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * Lesser General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public
  18. * License along with FFmpeg; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  20. */
  21. #include <string.h>
  22. #include <stdint.h>
  23. #include <stdlib.h>
  24. #include <errno.h>
  25. #include <math.h>
  26. /* Include only the enabled headers since some compilers (namely, Sun
  27. Studio) will not omit unused inline functions and create undefined
  28. references to libraries that are not being built. */
  29. #include "config.h"
  30. #include "compat/va_copy.h"
  31. #include "libavformat/avformat.h"
  32. #include "libavfilter/avfilter.h"
  33. #include "libavdevice/avdevice.h"
  34. #include "libavresample/avresample.h"
  35. #include "libswscale/swscale.h"
  36. #include "libswresample/swresample.h"
  37. #include "libpostproc/postprocess.h"
  38. #include "libavutil/attributes.h"
  39. #include "libavutil/avassert.h"
  40. #include "libavutil/avstring.h"
  41. #include "libavutil/bprint.h"
  42. #include "libavutil/display.h"
  43. #include "libavutil/mathematics.h"
  44. #include "libavutil/imgutils.h"
  45. #include "libavutil/libm.h"
  46. #include "libavutil/parseutils.h"
  47. #include "libavutil/pixdesc.h"
  48. #include "libavutil/eval.h"
  49. #include "libavutil/dict.h"
  50. #include "libavutil/opt.h"
  51. #include "libavutil/cpu.h"
  52. #include "libavutil/ffversion.h"
  53. #include "libavutil/version.h"
  54. #include "cmdutils.h"
  55. #if CONFIG_NETWORK
  56. #include "libavformat/network.h"
  57. #endif
  58. #if HAVE_SYS_RESOURCE_H
  59. #include <sys/time.h>
  60. #include <sys/resource.h>
  61. #endif
  62. #ifdef _WIN32
  63. #include <windows.h>
  64. #endif
  65. static int init_report(const char *env);
  66. AVDictionary *sws_dict;
  67. AVDictionary *swr_opts;
  68. AVDictionary *format_opts, *codec_opts, *resample_opts;
  69. static FILE *report_file;
  70. static int report_file_level = AV_LOG_DEBUG;
  71. int hide_banner = 0;
  72. enum show_muxdemuxers {
  73. SHOW_DEFAULT,
  74. SHOW_DEMUXERS,
  75. SHOW_MUXERS,
  76. };
  77. void init_opts(void)
  78. {
  79. av_dict_set(&sws_dict, "flags", "bicubic", 0);
  80. }
  81. void uninit_opts(void)
  82. {
  83. av_dict_free(&swr_opts);
  84. av_dict_free(&sws_dict);
  85. av_dict_free(&format_opts);
  86. av_dict_free(&codec_opts);
  87. av_dict_free(&resample_opts);
  88. }
  89. void log_callback_help(void *ptr, int level, const char *fmt, va_list vl)
  90. {
  91. vfprintf(stdout, fmt, vl);
  92. }
  93. static void log_callback_report(void *ptr, int level, const char *fmt, va_list vl)
  94. {
  95. va_list vl2;
  96. char line[1024];
  97. static int print_prefix = 1;
  98. va_copy(vl2, vl);
  99. av_log_default_callback(ptr, level, fmt, vl);
  100. av_log_format_line(ptr, level, fmt, vl2, line, sizeof(line), &print_prefix);
  101. va_end(vl2);
  102. if (report_file_level >= level) {
  103. fputs(line, report_file);
  104. fflush(report_file);
  105. }
  106. }
  107. void init_dynload(void)
  108. {
  109. #ifdef _WIN32
  110. /* Calling SetDllDirectory with the empty string (but not NULL) removes the
  111. * current working directory from the DLL search path as a security pre-caution. */
  112. SetDllDirectory("");
  113. #endif
  114. }
  115. static void (*program_exit)(int ret);
  116. void register_exit(void (*cb)(int ret))
  117. {
  118. program_exit = cb;
  119. }
  120. void exit_program(int ret)
  121. {
  122. if (program_exit)
  123. program_exit(ret);
  124. exit(ret);
  125. }
  126. double parse_number_or_die(const char *context, const char *numstr, int type,
  127. double min, double max)
  128. {
  129. char *tail;
  130. const char *error;
  131. double d = av_strtod(numstr, &tail);
  132. if (*tail)
  133. error = "Expected number for %s but found: %s\n";
  134. else if (d < min || d > max)
  135. error = "The value for %s was %s which is not within %f - %f\n";
  136. else if (type == OPT_INT64 && (int64_t)d != d)
  137. error = "Expected int64 for %s but found %s\n";
  138. else if (type == OPT_INT && (int)d != d)
  139. error = "Expected int for %s but found %s\n";
  140. else
  141. return d;
  142. av_log(NULL, AV_LOG_FATAL, error, context, numstr, min, max);
  143. exit_program(1);
  144. return 0;
  145. }
  146. int64_t parse_time_or_die(const char *context, const char *timestr,
  147. int is_duration)
  148. {
  149. int64_t us;
  150. if (av_parse_time(&us, timestr, is_duration) < 0) {
  151. av_log(NULL, AV_LOG_FATAL, "Invalid %s specification for %s: %s\n",
  152. is_duration ? "duration" : "date", context, timestr);
  153. exit_program(1);
  154. }
  155. return us;
  156. }
  157. void show_help_options(const OptionDef *options, const char *msg, int req_flags,
  158. int rej_flags, int alt_flags)
  159. {
  160. const OptionDef *po;
  161. int first;
  162. first = 1;
  163. for (po = options; po->name; po++) {
  164. char buf[64];
  165. if (((po->flags & req_flags) != req_flags) ||
  166. (alt_flags && !(po->flags & alt_flags)) ||
  167. (po->flags & rej_flags))
  168. continue;
  169. if (first) {
  170. printf("%s\n", msg);
  171. first = 0;
  172. }
  173. av_strlcpy(buf, po->name, sizeof(buf));
  174. if (po->argname) {
  175. av_strlcat(buf, " ", sizeof(buf));
  176. av_strlcat(buf, po->argname, sizeof(buf));
  177. }
  178. printf("-%-17s %s\n", buf, po->help);
  179. }
  180. printf("\n");
  181. }
  182. void show_help_children(const AVClass *class, int flags)
  183. {
  184. const AVClass *child = NULL;
  185. if (class->option) {
  186. av_opt_show2(&class, NULL, flags, 0);
  187. printf("\n");
  188. }
  189. while (child = av_opt_child_class_next(class, child))
  190. show_help_children(child, flags);
  191. }
  192. static const OptionDef *find_option(const OptionDef *po, const char *name)
  193. {
  194. const char *p = strchr(name, ':');
  195. int len = p ? p - name : strlen(name);
  196. while (po->name) {
  197. if (!strncmp(name, po->name, len) && strlen(po->name) == len)
  198. break;
  199. po++;
  200. }
  201. return po;
  202. }
  203. /* _WIN32 means using the windows libc - cygwin doesn't define that
  204. * by default. HAVE_COMMANDLINETOARGVW is true on cygwin, while
  205. * it doesn't provide the actual command line via GetCommandLineW(). */
  206. #if HAVE_COMMANDLINETOARGVW && defined(_WIN32)
  207. #include <shellapi.h>
  208. /* Will be leaked on exit */
  209. static char** win32_argv_utf8 = NULL;
  210. static int win32_argc = 0;
  211. /**
  212. * Prepare command line arguments for executable.
  213. * For Windows - perform wide-char to UTF-8 conversion.
  214. * Input arguments should be main() function arguments.
  215. * @param argc_ptr Arguments number (including executable)
  216. * @param argv_ptr Arguments list.
  217. */
  218. static void prepare_app_arguments(int *argc_ptr, char ***argv_ptr)
  219. {
  220. char *argstr_flat;
  221. wchar_t **argv_w;
  222. int i, buffsize = 0, offset = 0;
  223. if (win32_argv_utf8) {
  224. *argc_ptr = win32_argc;
  225. *argv_ptr = win32_argv_utf8;
  226. return;
  227. }
  228. win32_argc = 0;
  229. argv_w = CommandLineToArgvW(GetCommandLineW(), &win32_argc);
  230. if (win32_argc <= 0 || !argv_w)
  231. return;
  232. /* determine the UTF-8 buffer size (including NULL-termination symbols) */
  233. for (i = 0; i < win32_argc; i++)
  234. buffsize += WideCharToMultiByte(CP_UTF8, 0, argv_w[i], -1,
  235. NULL, 0, NULL, NULL);
  236. win32_argv_utf8 = av_mallocz(sizeof(char *) * (win32_argc + 1) + buffsize);
  237. argstr_flat = (char *)win32_argv_utf8 + sizeof(char *) * (win32_argc + 1);
  238. if (!win32_argv_utf8) {
  239. LocalFree(argv_w);
  240. return;
  241. }
  242. for (i = 0; i < win32_argc; i++) {
  243. win32_argv_utf8[i] = &argstr_flat[offset];
  244. offset += WideCharToMultiByte(CP_UTF8, 0, argv_w[i], -1,
  245. &argstr_flat[offset],
  246. buffsize - offset, NULL, NULL);
  247. }
  248. win32_argv_utf8[i] = NULL;
  249. LocalFree(argv_w);
  250. *argc_ptr = win32_argc;
  251. *argv_ptr = win32_argv_utf8;
  252. }
  253. #else
  254. static inline void prepare_app_arguments(int *argc_ptr, char ***argv_ptr)
  255. {
  256. /* nothing to do */
  257. }
  258. #endif /* HAVE_COMMANDLINETOARGVW */
  259. static int write_option(void *optctx, const OptionDef *po, const char *opt,
  260. const char *arg)
  261. {
  262. /* new-style options contain an offset into optctx, old-style address of
  263. * a global var*/
  264. void *dst = po->flags & (OPT_OFFSET | OPT_SPEC) ?
  265. (uint8_t *)optctx + po->u.off : po->u.dst_ptr;
  266. int *dstcount;
  267. if (po->flags & OPT_SPEC) {
  268. SpecifierOpt **so = dst;
  269. char *p = strchr(opt, ':');
  270. char *str;
  271. dstcount = (int *)(so + 1);
  272. *so = grow_array(*so, sizeof(**so), dstcount, *dstcount + 1);
  273. str = av_strdup(p ? p + 1 : "");
  274. if (!str)
  275. return AVERROR(ENOMEM);
  276. (*so)[*dstcount - 1].specifier = str;
  277. dst = &(*so)[*dstcount - 1].u;
  278. }
  279. if (po->flags & OPT_STRING) {
  280. char *str;
  281. str = av_strdup(arg);
  282. av_freep(dst);
  283. if (!str)
  284. return AVERROR(ENOMEM);
  285. *(char **)dst = str;
  286. } else if (po->flags & OPT_BOOL || po->flags & OPT_INT) {
  287. *(int *)dst = parse_number_or_die(opt, arg, OPT_INT64, INT_MIN, INT_MAX);
  288. } else if (po->flags & OPT_INT64) {
  289. *(int64_t *)dst = parse_number_or_die(opt, arg, OPT_INT64, INT64_MIN, INT64_MAX);
  290. } else if (po->flags & OPT_TIME) {
  291. *(int64_t *)dst = parse_time_or_die(opt, arg, 1);
  292. } else if (po->flags & OPT_FLOAT) {
  293. *(float *)dst = parse_number_or_die(opt, arg, OPT_FLOAT, -INFINITY, INFINITY);
  294. } else if (po->flags & OPT_DOUBLE) {
  295. *(double *)dst = parse_number_or_die(opt, arg, OPT_DOUBLE, -INFINITY, INFINITY);
  296. } else if (po->u.func_arg) {
  297. int ret = po->u.func_arg(optctx, opt, arg);
  298. if (ret < 0) {
  299. av_log(NULL, AV_LOG_ERROR,
  300. "Failed to set value '%s' for option '%s': %s\n",
  301. arg, opt, av_err2str(ret));
  302. return ret;
  303. }
  304. }
  305. if (po->flags & OPT_EXIT)
  306. exit_program(0);
  307. return 0;
  308. }
  309. int parse_option(void *optctx, const char *opt, const char *arg,
  310. const OptionDef *options)
  311. {
  312. const OptionDef *po;
  313. int ret;
  314. po = find_option(options, opt);
  315. if (!po->name && opt[0] == 'n' && opt[1] == 'o') {
  316. /* handle 'no' bool option */
  317. po = find_option(options, opt + 2);
  318. if ((po->name && (po->flags & OPT_BOOL)))
  319. arg = "0";
  320. } else if (po->flags & OPT_BOOL)
  321. arg = "1";
  322. if (!po->name)
  323. po = find_option(options, "default");
  324. if (!po->name) {
  325. av_log(NULL, AV_LOG_ERROR, "Unrecognized option '%s'\n", opt);
  326. return AVERROR(EINVAL);
  327. }
  328. if (po->flags & HAS_ARG && !arg) {
  329. av_log(NULL, AV_LOG_ERROR, "Missing argument for option '%s'\n", opt);
  330. return AVERROR(EINVAL);
  331. }
  332. ret = write_option(optctx, po, opt, arg);
  333. if (ret < 0)
  334. return ret;
  335. return !!(po->flags & HAS_ARG);
  336. }
  337. void parse_options(void *optctx, int argc, char **argv, const OptionDef *options,
  338. void (*parse_arg_function)(void *, const char*))
  339. {
  340. const char *opt;
  341. int optindex, handleoptions = 1, ret;
  342. /* perform system-dependent conversions for arguments list */
  343. prepare_app_arguments(&argc, &argv);
  344. /* parse options */
  345. optindex = 1;
  346. while (optindex < argc) {
  347. opt = argv[optindex++];
  348. if (handleoptions && opt[0] == '-' && opt[1] != '\0') {
  349. if (opt[1] == '-' && opt[2] == '\0') {
  350. handleoptions = 0;
  351. continue;
  352. }
  353. opt++;
  354. if ((ret = parse_option(optctx, opt, argv[optindex], options)) < 0)
  355. exit_program(1);
  356. optindex += ret;
  357. } else {
  358. if (parse_arg_function)
  359. parse_arg_function(optctx, opt);
  360. }
  361. }
  362. }
  363. int parse_optgroup(void *optctx, OptionGroup *g)
  364. {
  365. int i, ret;
  366. av_log(NULL, AV_LOG_DEBUG, "Parsing a group of options: %s %s.\n",
  367. g->group_def->name, g->arg);
  368. for (i = 0; i < g->nb_opts; i++) {
  369. Option *o = &g->opts[i];
  370. if (g->group_def->flags &&
  371. !(g->group_def->flags & o->opt->flags)) {
  372. av_log(NULL, AV_LOG_ERROR, "Option %s (%s) cannot be applied to "
  373. "%s %s -- you are trying to apply an input option to an "
  374. "output file or vice versa. Move this option before the "
  375. "file it belongs to.\n", o->key, o->opt->help,
  376. g->group_def->name, g->arg);
  377. return AVERROR(EINVAL);
  378. }
  379. av_log(NULL, AV_LOG_DEBUG, "Applying option %s (%s) with argument %s.\n",
  380. o->key, o->opt->help, o->val);
  381. ret = write_option(optctx, o->opt, o->key, o->val);
  382. if (ret < 0)
  383. return ret;
  384. }
  385. av_log(NULL, AV_LOG_DEBUG, "Successfully parsed a group of options.\n");
  386. return 0;
  387. }
  388. int locate_option(int argc, char **argv, const OptionDef *options,
  389. const char *optname)
  390. {
  391. const OptionDef *po;
  392. int i;
  393. for (i = 1; i < argc; i++) {
  394. const char *cur_opt = argv[i];
  395. if (*cur_opt++ != '-')
  396. continue;
  397. po = find_option(options, cur_opt);
  398. if (!po->name && cur_opt[0] == 'n' && cur_opt[1] == 'o')
  399. po = find_option(options, cur_opt + 2);
  400. if ((!po->name && !strcmp(cur_opt, optname)) ||
  401. (po->name && !strcmp(optname, po->name)))
  402. return i;
  403. if (!po->name || po->flags & HAS_ARG)
  404. i++;
  405. }
  406. return 0;
  407. }
  408. static void dump_argument(const char *a)
  409. {
  410. const unsigned char *p;
  411. for (p = a; *p; p++)
  412. if (!((*p >= '+' && *p <= ':') || (*p >= '@' && *p <= 'Z') ||
  413. *p == '_' || (*p >= 'a' && *p <= 'z')))
  414. break;
  415. if (!*p) {
  416. fputs(a, report_file);
  417. return;
  418. }
  419. fputc('"', report_file);
  420. for (p = a; *p; p++) {
  421. if (*p == '\\' || *p == '"' || *p == '$' || *p == '`')
  422. fprintf(report_file, "\\%c", *p);
  423. else if (*p < ' ' || *p > '~')
  424. fprintf(report_file, "\\x%02x", *p);
  425. else
  426. fputc(*p, report_file);
  427. }
  428. fputc('"', report_file);
  429. }
  430. static void check_options(const OptionDef *po)
  431. {
  432. while (po->name) {
  433. if (po->flags & OPT_PERFILE)
  434. av_assert0(po->flags & (OPT_INPUT | OPT_OUTPUT));
  435. po++;
  436. }
  437. }
  438. void parse_loglevel(int argc, char **argv, const OptionDef *options)
  439. {
  440. int idx = locate_option(argc, argv, options, "loglevel");
  441. const char *env;
  442. check_options(options);
  443. if (!idx)
  444. idx = locate_option(argc, argv, options, "v");
  445. if (idx && argv[idx + 1])
  446. opt_loglevel(NULL, "loglevel", argv[idx + 1]);
  447. idx = locate_option(argc, argv, options, "report");
  448. if ((env = getenv("FFREPORT")) || idx) {
  449. init_report(env);
  450. if (report_file) {
  451. int i;
  452. fprintf(report_file, "Command line:\n");
  453. for (i = 0; i < argc; i++) {
  454. dump_argument(argv[i]);
  455. fputc(i < argc - 1 ? ' ' : '\n', report_file);
  456. }
  457. fflush(report_file);
  458. }
  459. }
  460. idx = locate_option(argc, argv, options, "hide_banner");
  461. if (idx)
  462. hide_banner = 1;
  463. }
  464. static const AVOption *opt_find(void *obj, const char *name, const char *unit,
  465. int opt_flags, int search_flags)
  466. {
  467. const AVOption *o = av_opt_find(obj, name, unit, opt_flags, search_flags);
  468. if(o && !o->flags)
  469. return NULL;
  470. return o;
  471. }
  472. #define FLAGS (o->type == AV_OPT_TYPE_FLAGS && (arg[0]=='-' || arg[0]=='+')) ? AV_DICT_APPEND : 0
  473. int opt_default(void *optctx, const char *opt, const char *arg)
  474. {
  475. const AVOption *o;
  476. int consumed = 0;
  477. char opt_stripped[128];
  478. const char *p;
  479. const AVClass *cc = avcodec_get_class(), *fc = avformat_get_class();
  480. #if CONFIG_AVRESAMPLE
  481. const AVClass *rc = avresample_get_class();
  482. #endif
  483. #if CONFIG_SWSCALE
  484. const AVClass *sc = sws_get_class();
  485. #endif
  486. #if CONFIG_SWRESAMPLE
  487. const AVClass *swr_class = swr_get_class();
  488. #endif
  489. if (!strcmp(opt, "debug") || !strcmp(opt, "fdebug"))
  490. av_log_set_level(AV_LOG_DEBUG);
  491. if (!(p = strchr(opt, ':')))
  492. p = opt + strlen(opt);
  493. av_strlcpy(opt_stripped, opt, FFMIN(sizeof(opt_stripped), p - opt + 1));
  494. if ((o = opt_find(&cc, opt_stripped, NULL, 0,
  495. AV_OPT_SEARCH_CHILDREN | AV_OPT_SEARCH_FAKE_OBJ)) ||
  496. ((opt[0] == 'v' || opt[0] == 'a' || opt[0] == 's') &&
  497. (o = opt_find(&cc, opt + 1, NULL, 0, AV_OPT_SEARCH_FAKE_OBJ)))) {
  498. av_dict_set(&codec_opts, opt, arg, FLAGS);
  499. consumed = 1;
  500. }
  501. if ((o = opt_find(&fc, opt, NULL, 0,
  502. AV_OPT_SEARCH_CHILDREN | AV_OPT_SEARCH_FAKE_OBJ))) {
  503. av_dict_set(&format_opts, opt, arg, FLAGS);
  504. if (consumed)
  505. av_log(NULL, AV_LOG_VERBOSE, "Routing option %s to both codec and muxer layer\n", opt);
  506. consumed = 1;
  507. }
  508. #if CONFIG_SWSCALE
  509. if (!consumed && (o = opt_find(&sc, opt, NULL, 0,
  510. AV_OPT_SEARCH_CHILDREN | AV_OPT_SEARCH_FAKE_OBJ))) {
  511. struct SwsContext *sws = sws_alloc_context();
  512. int ret = av_opt_set(sws, opt, arg, 0);
  513. sws_freeContext(sws);
  514. if (!strcmp(opt, "srcw") || !strcmp(opt, "srch") ||
  515. !strcmp(opt, "dstw") || !strcmp(opt, "dsth") ||
  516. !strcmp(opt, "src_format") || !strcmp(opt, "dst_format")) {
  517. av_log(NULL, AV_LOG_ERROR, "Directly using swscale dimensions/format options is not supported, please use the -s or -pix_fmt options\n");
  518. return AVERROR(EINVAL);
  519. }
  520. if (ret < 0) {
  521. av_log(NULL, AV_LOG_ERROR, "Error setting option %s.\n", opt);
  522. return ret;
  523. }
  524. av_dict_set(&sws_dict, opt, arg, FLAGS);
  525. consumed = 1;
  526. }
  527. #else
  528. if (!consumed && !strcmp(opt, "sws_flags")) {
  529. av_log(NULL, AV_LOG_WARNING, "Ignoring %s %s, due to disabled swscale\n", opt, arg);
  530. consumed = 1;
  531. }
  532. #endif
  533. #if CONFIG_SWRESAMPLE
  534. if (!consumed && (o=opt_find(&swr_class, opt, NULL, 0,
  535. AV_OPT_SEARCH_CHILDREN | AV_OPT_SEARCH_FAKE_OBJ))) {
  536. struct SwrContext *swr = swr_alloc();
  537. int ret = av_opt_set(swr, opt, arg, 0);
  538. swr_free(&swr);
  539. if (ret < 0) {
  540. av_log(NULL, AV_LOG_ERROR, "Error setting option %s.\n", opt);
  541. return ret;
  542. }
  543. av_dict_set(&swr_opts, opt, arg, FLAGS);
  544. consumed = 1;
  545. }
  546. #endif
  547. #if CONFIG_AVRESAMPLE
  548. if ((o=opt_find(&rc, opt, NULL, 0,
  549. AV_OPT_SEARCH_CHILDREN | AV_OPT_SEARCH_FAKE_OBJ))) {
  550. av_dict_set(&resample_opts, opt, arg, FLAGS);
  551. consumed = 1;
  552. }
  553. #endif
  554. if (consumed)
  555. return 0;
  556. return AVERROR_OPTION_NOT_FOUND;
  557. }
  558. /*
  559. * Check whether given option is a group separator.
  560. *
  561. * @return index of the group definition that matched or -1 if none
  562. */
  563. static int match_group_separator(const OptionGroupDef *groups, int nb_groups,
  564. const char *opt)
  565. {
  566. int i;
  567. for (i = 0; i < nb_groups; i++) {
  568. const OptionGroupDef *p = &groups[i];
  569. if (p->sep && !strcmp(p->sep, opt))
  570. return i;
  571. }
  572. return -1;
  573. }
  574. /*
  575. * Finish parsing an option group.
  576. *
  577. * @param group_idx which group definition should this group belong to
  578. * @param arg argument of the group delimiting option
  579. */
  580. static void finish_group(OptionParseContext *octx, int group_idx,
  581. const char *arg)
  582. {
  583. OptionGroupList *l = &octx->groups[group_idx];
  584. OptionGroup *g;
  585. GROW_ARRAY(l->groups, l->nb_groups);
  586. g = &l->groups[l->nb_groups - 1];
  587. *g = octx->cur_group;
  588. g->arg = arg;
  589. g->group_def = l->group_def;
  590. g->sws_dict = sws_dict;
  591. g->swr_opts = swr_opts;
  592. g->codec_opts = codec_opts;
  593. g->format_opts = format_opts;
  594. g->resample_opts = resample_opts;
  595. codec_opts = NULL;
  596. format_opts = NULL;
  597. resample_opts = NULL;
  598. sws_dict = NULL;
  599. swr_opts = NULL;
  600. init_opts();
  601. memset(&octx->cur_group, 0, sizeof(octx->cur_group));
  602. }
  603. /*
  604. * Add an option instance to currently parsed group.
  605. */
  606. static void add_opt(OptionParseContext *octx, const OptionDef *opt,
  607. const char *key, const char *val)
  608. {
  609. int global = !(opt->flags & (OPT_PERFILE | OPT_SPEC | OPT_OFFSET));
  610. OptionGroup *g = global ? &octx->global_opts : &octx->cur_group;
  611. GROW_ARRAY(g->opts, g->nb_opts);
  612. g->opts[g->nb_opts - 1].opt = opt;
  613. g->opts[g->nb_opts - 1].key = key;
  614. g->opts[g->nb_opts - 1].val = val;
  615. }
  616. static void init_parse_context(OptionParseContext *octx,
  617. const OptionGroupDef *groups, int nb_groups)
  618. {
  619. static const OptionGroupDef global_group = { "global" };
  620. int i;
  621. memset(octx, 0, sizeof(*octx));
  622. octx->nb_groups = nb_groups;
  623. octx->groups = av_mallocz_array(octx->nb_groups, sizeof(*octx->groups));
  624. if (!octx->groups)
  625. exit_program(1);
  626. for (i = 0; i < octx->nb_groups; i++)
  627. octx->groups[i].group_def = &groups[i];
  628. octx->global_opts.group_def = &global_group;
  629. octx->global_opts.arg = "";
  630. init_opts();
  631. }
  632. void uninit_parse_context(OptionParseContext *octx)
  633. {
  634. int i, j;
  635. for (i = 0; i < octx->nb_groups; i++) {
  636. OptionGroupList *l = &octx->groups[i];
  637. for (j = 0; j < l->nb_groups; j++) {
  638. av_freep(&l->groups[j].opts);
  639. av_dict_free(&l->groups[j].codec_opts);
  640. av_dict_free(&l->groups[j].format_opts);
  641. av_dict_free(&l->groups[j].resample_opts);
  642. av_dict_free(&l->groups[j].sws_dict);
  643. av_dict_free(&l->groups[j].swr_opts);
  644. }
  645. av_freep(&l->groups);
  646. }
  647. av_freep(&octx->groups);
  648. av_freep(&octx->cur_group.opts);
  649. av_freep(&octx->global_opts.opts);
  650. uninit_opts();
  651. }
  652. int split_commandline(OptionParseContext *octx, int argc, char *argv[],
  653. const OptionDef *options,
  654. const OptionGroupDef *groups, int nb_groups)
  655. {
  656. int optindex = 1;
  657. int dashdash = -2;
  658. /* perform system-dependent conversions for arguments list */
  659. prepare_app_arguments(&argc, &argv);
  660. init_parse_context(octx, groups, nb_groups);
  661. av_log(NULL, AV_LOG_DEBUG, "Splitting the commandline.\n");
  662. while (optindex < argc) {
  663. const char *opt = argv[optindex++], *arg;
  664. const OptionDef *po;
  665. int ret;
  666. av_log(NULL, AV_LOG_DEBUG, "Reading option '%s' ...", opt);
  667. if (opt[0] == '-' && opt[1] == '-' && !opt[2]) {
  668. dashdash = optindex;
  669. continue;
  670. }
  671. /* unnamed group separators, e.g. output filename */
  672. if (opt[0] != '-' || !opt[1] || dashdash+1 == optindex) {
  673. finish_group(octx, 0, opt);
  674. av_log(NULL, AV_LOG_DEBUG, " matched as %s.\n", groups[0].name);
  675. continue;
  676. }
  677. opt++;
  678. #define GET_ARG(arg) \
  679. do { \
  680. arg = argv[optindex++]; \
  681. if (!arg) { \
  682. av_log(NULL, AV_LOG_ERROR, "Missing argument for option '%s'.\n", opt);\
  683. return AVERROR(EINVAL); \
  684. } \
  685. } while (0)
  686. /* named group separators, e.g. -i */
  687. if ((ret = match_group_separator(groups, nb_groups, opt)) >= 0) {
  688. GET_ARG(arg);
  689. finish_group(octx, ret, arg);
  690. av_log(NULL, AV_LOG_DEBUG, " matched as %s with argument '%s'.\n",
  691. groups[ret].name, arg);
  692. continue;
  693. }
  694. /* normal options */
  695. po = find_option(options, opt);
  696. if (po->name) {
  697. if (po->flags & OPT_EXIT) {
  698. /* optional argument, e.g. -h */
  699. arg = argv[optindex++];
  700. } else if (po->flags & HAS_ARG) {
  701. GET_ARG(arg);
  702. } else {
  703. arg = "1";
  704. }
  705. add_opt(octx, po, opt, arg);
  706. av_log(NULL, AV_LOG_DEBUG, " matched as option '%s' (%s) with "
  707. "argument '%s'.\n", po->name, po->help, arg);
  708. continue;
  709. }
  710. /* AVOptions */
  711. if (argv[optindex]) {
  712. ret = opt_default(NULL, opt, argv[optindex]);
  713. if (ret >= 0) {
  714. av_log(NULL, AV_LOG_DEBUG, " matched as AVOption '%s' with "
  715. "argument '%s'.\n", opt, argv[optindex]);
  716. optindex++;
  717. continue;
  718. } else if (ret != AVERROR_OPTION_NOT_FOUND) {
  719. av_log(NULL, AV_LOG_ERROR, "Error parsing option '%s' "
  720. "with argument '%s'.\n", opt, argv[optindex]);
  721. return ret;
  722. }
  723. }
  724. /* boolean -nofoo options */
  725. if (opt[0] == 'n' && opt[1] == 'o' &&
  726. (po = find_option(options, opt + 2)) &&
  727. po->name && po->flags & OPT_BOOL) {
  728. add_opt(octx, po, opt, "0");
  729. av_log(NULL, AV_LOG_DEBUG, " matched as option '%s' (%s) with "
  730. "argument 0.\n", po->name, po->help);
  731. continue;
  732. }
  733. av_log(NULL, AV_LOG_ERROR, "Unrecognized option '%s'.\n", opt);
  734. return AVERROR_OPTION_NOT_FOUND;
  735. }
  736. if (octx->cur_group.nb_opts || codec_opts || format_opts || resample_opts)
  737. av_log(NULL, AV_LOG_WARNING, "Trailing options were found on the "
  738. "commandline.\n");
  739. av_log(NULL, AV_LOG_DEBUG, "Finished splitting the commandline.\n");
  740. return 0;
  741. }
  742. int opt_cpuflags(void *optctx, const char *opt, const char *arg)
  743. {
  744. int ret;
  745. unsigned flags = av_get_cpu_flags();
  746. if ((ret = av_parse_cpu_caps(&flags, arg)) < 0)
  747. return ret;
  748. av_force_cpu_flags(flags);
  749. return 0;
  750. }
  751. int opt_loglevel(void *optctx, const char *opt, const char *arg)
  752. {
  753. const struct { const char *name; int level; } log_levels[] = {
  754. { "quiet" , AV_LOG_QUIET },
  755. { "panic" , AV_LOG_PANIC },
  756. { "fatal" , AV_LOG_FATAL },
  757. { "error" , AV_LOG_ERROR },
  758. { "warning", AV_LOG_WARNING },
  759. { "info" , AV_LOG_INFO },
  760. { "verbose", AV_LOG_VERBOSE },
  761. { "debug" , AV_LOG_DEBUG },
  762. { "trace" , AV_LOG_TRACE },
  763. };
  764. const char *token;
  765. char *tail;
  766. int flags = av_log_get_flags();
  767. int level = av_log_get_level();
  768. int cmd, i = 0;
  769. av_assert0(arg);
  770. while (*arg) {
  771. token = arg;
  772. if (*token == '+' || *token == '-') {
  773. cmd = *token++;
  774. } else {
  775. cmd = 0;
  776. }
  777. if (!i && !cmd) {
  778. flags = 0; /* missing relative prefix, build absolute value */
  779. }
  780. if (!strncmp(token, "repeat", 6)) {
  781. if (cmd == '-') {
  782. flags |= AV_LOG_SKIP_REPEATED;
  783. } else {
  784. flags &= ~AV_LOG_SKIP_REPEATED;
  785. }
  786. arg = token + 6;
  787. } else if (!strncmp(token, "level", 5)) {
  788. if (cmd == '-') {
  789. flags &= ~AV_LOG_PRINT_LEVEL;
  790. } else {
  791. flags |= AV_LOG_PRINT_LEVEL;
  792. }
  793. arg = token + 5;
  794. } else {
  795. break;
  796. }
  797. i++;
  798. }
  799. if (!*arg) {
  800. goto end;
  801. } else if (*arg == '+') {
  802. arg++;
  803. } else if (!i) {
  804. flags = av_log_get_flags(); /* level value without prefix, reset flags */
  805. }
  806. for (i = 0; i < FF_ARRAY_ELEMS(log_levels); i++) {
  807. if (!strcmp(log_levels[i].name, arg)) {
  808. level = log_levels[i].level;
  809. goto end;
  810. }
  811. }
  812. level = strtol(arg, &tail, 10);
  813. if (*tail) {
  814. av_log(NULL, AV_LOG_FATAL, "Invalid loglevel \"%s\". "
  815. "Possible levels are numbers or:\n", arg);
  816. for (i = 0; i < FF_ARRAY_ELEMS(log_levels); i++)
  817. av_log(NULL, AV_LOG_FATAL, "\"%s\"\n", log_levels[i].name);
  818. exit_program(1);
  819. }
  820. end:
  821. av_log_set_flags(flags);
  822. av_log_set_level(level);
  823. return 0;
  824. }
  825. static void expand_filename_template(AVBPrint *bp, const char *template,
  826. struct tm *tm)
  827. {
  828. int c;
  829. while ((c = *(template++))) {
  830. if (c == '%') {
  831. if (!(c = *(template++)))
  832. break;
  833. switch (c) {
  834. case 'p':
  835. av_bprintf(bp, "%s", program_name);
  836. break;
  837. case 't':
  838. av_bprintf(bp, "%04d%02d%02d-%02d%02d%02d",
  839. tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday,
  840. tm->tm_hour, tm->tm_min, tm->tm_sec);
  841. break;
  842. case '%':
  843. av_bprint_chars(bp, c, 1);
  844. break;
  845. }
  846. } else {
  847. av_bprint_chars(bp, c, 1);
  848. }
  849. }
  850. }
  851. static int init_report(const char *env)
  852. {
  853. char *filename_template = NULL;
  854. char *key, *val;
  855. int ret, count = 0;
  856. time_t now;
  857. struct tm *tm;
  858. AVBPrint filename;
  859. if (report_file) /* already opened */
  860. return 0;
  861. time(&now);
  862. tm = localtime(&now);
  863. while (env && *env) {
  864. if ((ret = av_opt_get_key_value(&env, "=", ":", 0, &key, &val)) < 0) {
  865. if (count)
  866. av_log(NULL, AV_LOG_ERROR,
  867. "Failed to parse FFREPORT environment variable: %s\n",
  868. av_err2str(ret));
  869. break;
  870. }
  871. if (*env)
  872. env++;
  873. count++;
  874. if (!strcmp(key, "file")) {
  875. av_free(filename_template);
  876. filename_template = val;
  877. val = NULL;
  878. } else if (!strcmp(key, "level")) {
  879. char *tail;
  880. report_file_level = strtol(val, &tail, 10);
  881. if (*tail) {
  882. av_log(NULL, AV_LOG_FATAL, "Invalid report file level\n");
  883. exit_program(1);
  884. }
  885. } else {
  886. av_log(NULL, AV_LOG_ERROR, "Unknown key '%s' in FFREPORT\n", key);
  887. }
  888. av_free(val);
  889. av_free(key);
  890. }
  891. av_bprint_init(&filename, 0, AV_BPRINT_SIZE_AUTOMATIC);
  892. expand_filename_template(&filename,
  893. av_x_if_null(filename_template, "%p-%t.log"), tm);
  894. av_free(filename_template);
  895. if (!av_bprint_is_complete(&filename)) {
  896. av_log(NULL, AV_LOG_ERROR, "Out of memory building report file name\n");
  897. return AVERROR(ENOMEM);
  898. }
  899. report_file = fopen(filename.str, "w");
  900. if (!report_file) {
  901. int ret = AVERROR(errno);
  902. av_log(NULL, AV_LOG_ERROR, "Failed to open report \"%s\": %s\n",
  903. filename.str, strerror(errno));
  904. return ret;
  905. }
  906. av_log_set_callback(log_callback_report);
  907. av_log(NULL, AV_LOG_INFO,
  908. "%s started on %04d-%02d-%02d at %02d:%02d:%02d\n"
  909. "Report written to \"%s\"\n",
  910. program_name,
  911. tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday,
  912. tm->tm_hour, tm->tm_min, tm->tm_sec,
  913. filename.str);
  914. av_bprint_finalize(&filename, NULL);
  915. return 0;
  916. }
  917. int opt_report(const char *opt)
  918. {
  919. return init_report(NULL);
  920. }
  921. int opt_max_alloc(void *optctx, const char *opt, const char *arg)
  922. {
  923. char *tail;
  924. size_t max;
  925. max = strtol(arg, &tail, 10);
  926. if (*tail) {
  927. av_log(NULL, AV_LOG_FATAL, "Invalid max_alloc \"%s\".\n", arg);
  928. exit_program(1);
  929. }
  930. av_max_alloc(max);
  931. return 0;
  932. }
  933. int opt_timelimit(void *optctx, const char *opt, const char *arg)
  934. {
  935. #if HAVE_SETRLIMIT
  936. int lim = parse_number_or_die(opt, arg, OPT_INT64, 0, INT_MAX);
  937. struct rlimit rl = { lim, lim + 1 };
  938. if (setrlimit(RLIMIT_CPU, &rl))
  939. perror("setrlimit");
  940. #else
  941. av_log(NULL, AV_LOG_WARNING, "-%s not implemented on this OS\n", opt);
  942. #endif
  943. return 0;
  944. }
  945. void print_error(const char *filename, int err)
  946. {
  947. char errbuf[128];
  948. const char *errbuf_ptr = errbuf;
  949. if (av_strerror(err, errbuf, sizeof(errbuf)) < 0)
  950. errbuf_ptr = strerror(AVUNERROR(err));
  951. av_log(NULL, AV_LOG_ERROR, "%s: %s\n", filename, errbuf_ptr);
  952. }
  953. static int warned_cfg = 0;
  954. #define INDENT 1
  955. #define SHOW_VERSION 2
  956. #define SHOW_CONFIG 4
  957. #define SHOW_COPYRIGHT 8
  958. #define PRINT_LIB_INFO(libname, LIBNAME, flags, level) \
  959. if (CONFIG_##LIBNAME) { \
  960. const char *indent = flags & INDENT? " " : ""; \
  961. if (flags & SHOW_VERSION) { \
  962. unsigned int version = libname##_version(); \
  963. av_log(NULL, level, \
  964. "%slib%-11s %2d.%3d.%3d / %2d.%3d.%3d\n", \
  965. indent, #libname, \
  966. LIB##LIBNAME##_VERSION_MAJOR, \
  967. LIB##LIBNAME##_VERSION_MINOR, \
  968. LIB##LIBNAME##_VERSION_MICRO, \
  969. AV_VERSION_MAJOR(version), AV_VERSION_MINOR(version),\
  970. AV_VERSION_MICRO(version)); \
  971. } \
  972. if (flags & SHOW_CONFIG) { \
  973. const char *cfg = libname##_configuration(); \
  974. if (strcmp(FFMPEG_CONFIGURATION, cfg)) { \
  975. if (!warned_cfg) { \
  976. av_log(NULL, level, \
  977. "%sWARNING: library configuration mismatch\n", \
  978. indent); \
  979. warned_cfg = 1; \
  980. } \
  981. av_log(NULL, level, "%s%-11s configuration: %s\n", \
  982. indent, #libname, cfg); \
  983. } \
  984. } \
  985. } \
  986. static void print_all_libs_info(int flags, int level)
  987. {
  988. PRINT_LIB_INFO(avutil, AVUTIL, flags, level);
  989. PRINT_LIB_INFO(avcodec, AVCODEC, flags, level);
  990. PRINT_LIB_INFO(avformat, AVFORMAT, flags, level);
  991. PRINT_LIB_INFO(avdevice, AVDEVICE, flags, level);
  992. PRINT_LIB_INFO(avfilter, AVFILTER, flags, level);
  993. PRINT_LIB_INFO(avresample, AVRESAMPLE, flags, level);
  994. PRINT_LIB_INFO(swscale, SWSCALE, flags, level);
  995. PRINT_LIB_INFO(swresample, SWRESAMPLE, flags, level);
  996. PRINT_LIB_INFO(postproc, POSTPROC, flags, level);
  997. }
  998. static void print_program_info(int flags, int level)
  999. {
  1000. const char *indent = flags & INDENT? " " : "";
  1001. av_log(NULL, level, "%s version " FFMPEG_VERSION, program_name);
  1002. if (flags & SHOW_COPYRIGHT)
  1003. av_log(NULL, level, " Copyright (c) %d-%d the FFmpeg developers",
  1004. program_birth_year, CONFIG_THIS_YEAR);
  1005. av_log(NULL, level, "\n");
  1006. av_log(NULL, level, "%sbuilt with %s\n", indent, CC_IDENT);
  1007. av_log(NULL, level, "%sconfiguration: " FFMPEG_CONFIGURATION "\n", indent);
  1008. }
  1009. static void print_buildconf(int flags, int level)
  1010. {
  1011. const char *indent = flags & INDENT ? " " : "";
  1012. char str[] = { FFMPEG_CONFIGURATION };
  1013. char *conflist, *remove_tilde, *splitconf;
  1014. // Change all the ' --' strings to '~--' so that
  1015. // they can be identified as tokens.
  1016. while ((conflist = strstr(str, " --")) != NULL) {
  1017. strncpy(conflist, "~--", 3);
  1018. }
  1019. // Compensate for the weirdness this would cause
  1020. // when passing 'pkg-config --static'.
  1021. while ((remove_tilde = strstr(str, "pkg-config~")) != NULL) {
  1022. strncpy(remove_tilde, "pkg-config ", 11);
  1023. }
  1024. splitconf = strtok(str, "~");
  1025. av_log(NULL, level, "\n%sconfiguration:\n", indent);
  1026. while (splitconf != NULL) {
  1027. av_log(NULL, level, "%s%s%s\n", indent, indent, splitconf);
  1028. splitconf = strtok(NULL, "~");
  1029. }
  1030. }
  1031. void show_banner(int argc, char **argv, const OptionDef *options)
  1032. {
  1033. int idx = locate_option(argc, argv, options, "version");
  1034. if (hide_banner || idx)
  1035. return;
  1036. print_program_info (INDENT|SHOW_COPYRIGHT, AV_LOG_INFO);
  1037. print_all_libs_info(INDENT|SHOW_CONFIG, AV_LOG_INFO);
  1038. print_all_libs_info(INDENT|SHOW_VERSION, AV_LOG_INFO);
  1039. }
  1040. int show_version(void *optctx, const char *opt, const char *arg)
  1041. {
  1042. av_log_set_callback(log_callback_help);
  1043. print_program_info (SHOW_COPYRIGHT, AV_LOG_INFO);
  1044. print_all_libs_info(SHOW_VERSION, AV_LOG_INFO);
  1045. return 0;
  1046. }
  1047. int show_buildconf(void *optctx, const char *opt, const char *arg)
  1048. {
  1049. av_log_set_callback(log_callback_help);
  1050. print_buildconf (INDENT|0, AV_LOG_INFO);
  1051. return 0;
  1052. }
  1053. int show_license(void *optctx, const char *opt, const char *arg)
  1054. {
  1055. #if CONFIG_NONFREE
  1056. printf(
  1057. "This version of %s has nonfree parts compiled in.\n"
  1058. "Therefore it is not legally redistributable.\n",
  1059. program_name );
  1060. #elif CONFIG_GPLV3
  1061. printf(
  1062. "%s is free software; you can redistribute it and/or modify\n"
  1063. "it under the terms of the GNU General Public License as published by\n"
  1064. "the Free Software Foundation; either version 3 of the License, or\n"
  1065. "(at your option) any later version.\n"
  1066. "\n"
  1067. "%s is distributed in the hope that it will be useful,\n"
  1068. "but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
  1069. "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n"
  1070. "GNU General Public License for more details.\n"
  1071. "\n"
  1072. "You should have received a copy of the GNU General Public License\n"
  1073. "along with %s. If not, see <http://www.gnu.org/licenses/>.\n",
  1074. program_name, program_name, program_name );
  1075. #elif CONFIG_GPL
  1076. printf(
  1077. "%s is free software; you can redistribute it and/or modify\n"
  1078. "it under the terms of the GNU General Public License as published by\n"
  1079. "the Free Software Foundation; either version 2 of the License, or\n"
  1080. "(at your option) any later version.\n"
  1081. "\n"
  1082. "%s is distributed in the hope that it will be useful,\n"
  1083. "but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
  1084. "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n"
  1085. "GNU General Public License for more details.\n"
  1086. "\n"
  1087. "You should have received a copy of the GNU General Public License\n"
  1088. "along with %s; if not, write to the Free Software\n"
  1089. "Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA\n",
  1090. program_name, program_name, program_name );
  1091. #elif CONFIG_LGPLV3
  1092. printf(
  1093. "%s is free software; you can redistribute it and/or modify\n"
  1094. "it under the terms of the GNU Lesser General Public License as published by\n"
  1095. "the Free Software Foundation; either version 3 of the License, or\n"
  1096. "(at your option) any later version.\n"
  1097. "\n"
  1098. "%s is distributed in the hope that it will be useful,\n"
  1099. "but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
  1100. "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n"
  1101. "GNU Lesser General Public License for more details.\n"
  1102. "\n"
  1103. "You should have received a copy of the GNU Lesser General Public License\n"
  1104. "along with %s. If not, see <http://www.gnu.org/licenses/>.\n",
  1105. program_name, program_name, program_name );
  1106. #else
  1107. printf(
  1108. "%s is free software; you can redistribute it and/or\n"
  1109. "modify it under the terms of the GNU Lesser General Public\n"
  1110. "License as published by the Free Software Foundation; either\n"
  1111. "version 2.1 of the License, or (at your option) any later version.\n"
  1112. "\n"
  1113. "%s is distributed in the hope that it will be useful,\n"
  1114. "but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
  1115. "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n"
  1116. "Lesser General Public License for more details.\n"
  1117. "\n"
  1118. "You should have received a copy of the GNU Lesser General Public\n"
  1119. "License along with %s; if not, write to the Free Software\n"
  1120. "Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA\n",
  1121. program_name, program_name, program_name );
  1122. #endif
  1123. return 0;
  1124. }
  1125. static int is_device(const AVClass *avclass)
  1126. {
  1127. if (!avclass)
  1128. return 0;
  1129. return AV_IS_INPUT_DEVICE(avclass->category) || AV_IS_OUTPUT_DEVICE(avclass->category);
  1130. }
  1131. static int show_formats_devices(void *optctx, const char *opt, const char *arg, int device_only, int muxdemuxers)
  1132. {
  1133. void *ifmt_opaque = NULL;
  1134. const AVInputFormat *ifmt = NULL;
  1135. void *ofmt_opaque = NULL;
  1136. const AVOutputFormat *ofmt = NULL;
  1137. const char *last_name;
  1138. int is_dev;
  1139. printf("%s\n"
  1140. " D. = Demuxing supported\n"
  1141. " .E = Muxing supported\n"
  1142. " --\n", device_only ? "Devices:" : "File formats:");
  1143. last_name = "000";
  1144. for (;;) {
  1145. int decode = 0;
  1146. int encode = 0;
  1147. const char *name = NULL;
  1148. const char *long_name = NULL;
  1149. if (muxdemuxers !=SHOW_DEMUXERS) {
  1150. ofmt_opaque = NULL;
  1151. while ((ofmt = av_muxer_iterate(&ofmt_opaque))) {
  1152. is_dev = is_device(ofmt->priv_class);
  1153. if (!is_dev && device_only)
  1154. continue;
  1155. if ((!name || strcmp(ofmt->name, name) < 0) &&
  1156. strcmp(ofmt->name, last_name) > 0) {
  1157. name = ofmt->name;
  1158. long_name = ofmt->long_name;
  1159. encode = 1;
  1160. }
  1161. }
  1162. }
  1163. if (muxdemuxers != SHOW_MUXERS) {
  1164. ifmt_opaque = NULL;
  1165. while ((ifmt = av_demuxer_iterate(&ifmt_opaque))) {
  1166. is_dev = is_device(ifmt->priv_class);
  1167. if (!is_dev && device_only)
  1168. continue;
  1169. if ((!name || strcmp(ifmt->name, name) < 0) &&
  1170. strcmp(ifmt->name, last_name) > 0) {
  1171. name = ifmt->name;
  1172. long_name = ifmt->long_name;
  1173. encode = 0;
  1174. }
  1175. if (name && strcmp(ifmt->name, name) == 0)
  1176. decode = 1;
  1177. }
  1178. }
  1179. if (!name)
  1180. break;
  1181. last_name = name;
  1182. printf(" %s%s %-15s %s\n",
  1183. decode ? "D" : " ",
  1184. encode ? "E" : " ",
  1185. name,
  1186. long_name ? long_name:" ");
  1187. }
  1188. return 0;
  1189. }
  1190. int show_formats(void *optctx, const char *opt, const char *arg)
  1191. {
  1192. return show_formats_devices(optctx, opt, arg, 0, SHOW_DEFAULT);
  1193. }
  1194. int show_muxers(void *optctx, const char *opt, const char *arg)
  1195. {
  1196. return show_formats_devices(optctx, opt, arg, 0, SHOW_MUXERS);
  1197. }
  1198. int show_demuxers(void *optctx, const char *opt, const char *arg)
  1199. {
  1200. return show_formats_devices(optctx, opt, arg, 0, SHOW_DEMUXERS);
  1201. }
  1202. int show_devices(void *optctx, const char *opt, const char *arg)
  1203. {
  1204. return show_formats_devices(optctx, opt, arg, 1, SHOW_DEFAULT);
  1205. }
  1206. #define PRINT_CODEC_SUPPORTED(codec, field, type, list_name, term, get_name) \
  1207. if (codec->field) { \
  1208. const type *p = codec->field; \
  1209. \
  1210. printf(" Supported " list_name ":"); \
  1211. while (*p != term) { \
  1212. get_name(*p); \
  1213. printf(" %s", name); \
  1214. p++; \
  1215. } \
  1216. printf("\n"); \
  1217. } \
  1218. static void print_codec(const AVCodec *c)
  1219. {
  1220. int encoder = av_codec_is_encoder(c);
  1221. printf("%s %s [%s]:\n", encoder ? "Encoder" : "Decoder", c->name,
  1222. c->long_name ? c->long_name : "");
  1223. printf(" General capabilities: ");
  1224. if (c->capabilities & AV_CODEC_CAP_DRAW_HORIZ_BAND)
  1225. printf("horizband ");
  1226. if (c->capabilities & AV_CODEC_CAP_DR1)
  1227. printf("dr1 ");
  1228. if (c->capabilities & AV_CODEC_CAP_TRUNCATED)
  1229. printf("trunc ");
  1230. if (c->capabilities & AV_CODEC_CAP_DELAY)
  1231. printf("delay ");
  1232. if (c->capabilities & AV_CODEC_CAP_SMALL_LAST_FRAME)
  1233. printf("small ");
  1234. if (c->capabilities & AV_CODEC_CAP_SUBFRAMES)
  1235. printf("subframes ");
  1236. if (c->capabilities & AV_CODEC_CAP_EXPERIMENTAL)
  1237. printf("exp ");
  1238. if (c->capabilities & AV_CODEC_CAP_CHANNEL_CONF)
  1239. printf("chconf ");
  1240. if (c->capabilities & AV_CODEC_CAP_PARAM_CHANGE)
  1241. printf("paramchange ");
  1242. if (c->capabilities & AV_CODEC_CAP_VARIABLE_FRAME_SIZE)
  1243. printf("variable ");
  1244. if (c->capabilities & (AV_CODEC_CAP_FRAME_THREADS |
  1245. AV_CODEC_CAP_SLICE_THREADS |
  1246. AV_CODEC_CAP_AUTO_THREADS))
  1247. printf("threads ");
  1248. if (c->capabilities & AV_CODEC_CAP_AVOID_PROBING)
  1249. printf("avoidprobe ");
  1250. if (c->capabilities & AV_CODEC_CAP_INTRA_ONLY)
  1251. printf("intraonly ");
  1252. if (c->capabilities & AV_CODEC_CAP_LOSSLESS)
  1253. printf("lossless ");
  1254. if (c->capabilities & AV_CODEC_CAP_HARDWARE)
  1255. printf("hardware ");
  1256. if (c->capabilities & AV_CODEC_CAP_HYBRID)
  1257. printf("hybrid ");
  1258. if (!c->capabilities)
  1259. printf("none");
  1260. printf("\n");
  1261. if (c->type == AVMEDIA_TYPE_VIDEO ||
  1262. c->type == AVMEDIA_TYPE_AUDIO) {
  1263. printf(" Threading capabilities: ");
  1264. switch (c->capabilities & (AV_CODEC_CAP_FRAME_THREADS |
  1265. AV_CODEC_CAP_SLICE_THREADS |
  1266. AV_CODEC_CAP_AUTO_THREADS)) {
  1267. case AV_CODEC_CAP_FRAME_THREADS |
  1268. AV_CODEC_CAP_SLICE_THREADS: printf("frame and slice"); break;
  1269. case AV_CODEC_CAP_FRAME_THREADS: printf("frame"); break;
  1270. case AV_CODEC_CAP_SLICE_THREADS: printf("slice"); break;
  1271. case AV_CODEC_CAP_AUTO_THREADS : printf("auto"); break;
  1272. default: printf("none"); break;
  1273. }
  1274. printf("\n");
  1275. }
  1276. if (avcodec_get_hw_config(c, 0)) {
  1277. printf(" Supported hardware devices: ");
  1278. for (int i = 0;; i++) {
  1279. const AVCodecHWConfig *config = avcodec_get_hw_config(c, i);
  1280. if (!config)
  1281. break;
  1282. printf("%s ", av_hwdevice_get_type_name(config->device_type));
  1283. }
  1284. printf("\n");
  1285. }
  1286. if (c->supported_framerates) {
  1287. const AVRational *fps = c->supported_framerates;
  1288. printf(" Supported framerates:");
  1289. while (fps->num) {
  1290. printf(" %d/%d", fps->num, fps->den);
  1291. fps++;
  1292. }
  1293. printf("\n");
  1294. }
  1295. PRINT_CODEC_SUPPORTED(c, pix_fmts, enum AVPixelFormat, "pixel formats",
  1296. AV_PIX_FMT_NONE, GET_PIX_FMT_NAME);
  1297. PRINT_CODEC_SUPPORTED(c, supported_samplerates, int, "sample rates", 0,
  1298. GET_SAMPLE_RATE_NAME);
  1299. PRINT_CODEC_SUPPORTED(c, sample_fmts, enum AVSampleFormat, "sample formats",
  1300. AV_SAMPLE_FMT_NONE, GET_SAMPLE_FMT_NAME);
  1301. PRINT_CODEC_SUPPORTED(c, channel_layouts, uint64_t, "channel layouts",
  1302. 0, GET_CH_LAYOUT_DESC);
  1303. if (c->priv_class) {
  1304. show_help_children(c->priv_class,
  1305. AV_OPT_FLAG_ENCODING_PARAM |
  1306. AV_OPT_FLAG_DECODING_PARAM);
  1307. }
  1308. }
  1309. static char get_media_type_char(enum AVMediaType type)
  1310. {
  1311. switch (type) {
  1312. case AVMEDIA_TYPE_VIDEO: return 'V';
  1313. case AVMEDIA_TYPE_AUDIO: return 'A';
  1314. case AVMEDIA_TYPE_DATA: return 'D';
  1315. case AVMEDIA_TYPE_SUBTITLE: return 'S';
  1316. case AVMEDIA_TYPE_ATTACHMENT:return 'T';
  1317. default: return '?';
  1318. }
  1319. }
  1320. static const AVCodec *next_codec_for_id(enum AVCodecID id, const AVCodec *prev,
  1321. int encoder)
  1322. {
  1323. while ((prev = av_codec_next(prev))) {
  1324. if (prev->id == id &&
  1325. (encoder ? av_codec_is_encoder(prev) : av_codec_is_decoder(prev)))
  1326. return prev;
  1327. }
  1328. return NULL;
  1329. }
  1330. static int compare_codec_desc(const void *a, const void *b)
  1331. {
  1332. const AVCodecDescriptor * const *da = a;
  1333. const AVCodecDescriptor * const *db = b;
  1334. return (*da)->type != (*db)->type ? FFDIFFSIGN((*da)->type, (*db)->type) :
  1335. strcmp((*da)->name, (*db)->name);
  1336. }
  1337. static unsigned get_codecs_sorted(const AVCodecDescriptor ***rcodecs)
  1338. {
  1339. const AVCodecDescriptor *desc = NULL;
  1340. const AVCodecDescriptor **codecs;
  1341. unsigned nb_codecs = 0, i = 0;
  1342. while ((desc = avcodec_descriptor_next(desc)))
  1343. nb_codecs++;
  1344. if (!(codecs = av_calloc(nb_codecs, sizeof(*codecs)))) {
  1345. av_log(NULL, AV_LOG_ERROR, "Out of memory\n");
  1346. exit_program(1);
  1347. }
  1348. desc = NULL;
  1349. while ((desc = avcodec_descriptor_next(desc)))
  1350. codecs[i++] = desc;
  1351. av_assert0(i == nb_codecs);
  1352. qsort(codecs, nb_codecs, sizeof(*codecs), compare_codec_desc);
  1353. *rcodecs = codecs;
  1354. return nb_codecs;
  1355. }
  1356. static void print_codecs_for_id(enum AVCodecID id, int encoder)
  1357. {
  1358. const AVCodec *codec = NULL;
  1359. printf(" (%s: ", encoder ? "encoders" : "decoders");
  1360. while ((codec = next_codec_for_id(id, codec, encoder)))
  1361. printf("%s ", codec->name);
  1362. printf(")");
  1363. }
  1364. int show_codecs(void *optctx, const char *opt, const char *arg)
  1365. {
  1366. const AVCodecDescriptor **codecs;
  1367. unsigned i, nb_codecs = get_codecs_sorted(&codecs);
  1368. printf("Codecs:\n"
  1369. " D..... = Decoding supported\n"
  1370. " .E.... = Encoding supported\n"
  1371. " ..V... = Video codec\n"
  1372. " ..A... = Audio codec\n"
  1373. " ..S... = Subtitle codec\n"
  1374. " ...I.. = Intra frame-only codec\n"
  1375. " ....L. = Lossy compression\n"
  1376. " .....S = Lossless compression\n"
  1377. " -------\n");
  1378. for (i = 0; i < nb_codecs; i++) {
  1379. const AVCodecDescriptor *desc = codecs[i];
  1380. const AVCodec *codec = NULL;
  1381. if (strstr(desc->name, "_deprecated"))
  1382. continue;
  1383. printf(" ");
  1384. printf(avcodec_find_decoder(desc->id) ? "D" : ".");
  1385. printf(avcodec_find_encoder(desc->id) ? "E" : ".");
  1386. printf("%c", get_media_type_char(desc->type));
  1387. printf((desc->props & AV_CODEC_PROP_INTRA_ONLY) ? "I" : ".");
  1388. printf((desc->props & AV_CODEC_PROP_LOSSY) ? "L" : ".");
  1389. printf((desc->props & AV_CODEC_PROP_LOSSLESS) ? "S" : ".");
  1390. printf(" %-20s %s", desc->name, desc->long_name ? desc->long_name : "");
  1391. /* print decoders/encoders when there's more than one or their
  1392. * names are different from codec name */
  1393. while ((codec = next_codec_for_id(desc->id, codec, 0))) {
  1394. if (strcmp(codec->name, desc->name)) {
  1395. print_codecs_for_id(desc->id, 0);
  1396. break;
  1397. }
  1398. }
  1399. codec = NULL;
  1400. while ((codec = next_codec_for_id(desc->id, codec, 1))) {
  1401. if (strcmp(codec->name, desc->name)) {
  1402. print_codecs_for_id(desc->id, 1);
  1403. break;
  1404. }
  1405. }
  1406. printf("\n");
  1407. }
  1408. av_free(codecs);
  1409. return 0;
  1410. }
  1411. static void print_codecs(int encoder)
  1412. {
  1413. const AVCodecDescriptor **codecs;
  1414. unsigned i, nb_codecs = get_codecs_sorted(&codecs);
  1415. printf("%s:\n"
  1416. " V..... = Video\n"
  1417. " A..... = Audio\n"
  1418. " S..... = Subtitle\n"
  1419. " .F.... = Frame-level multithreading\n"
  1420. " ..S... = Slice-level multithreading\n"
  1421. " ...X.. = Codec is experimental\n"
  1422. " ....B. = Supports draw_horiz_band\n"
  1423. " .....D = Supports direct rendering method 1\n"
  1424. " ------\n",
  1425. encoder ? "Encoders" : "Decoders");
  1426. for (i = 0; i < nb_codecs; i++) {
  1427. const AVCodecDescriptor *desc = codecs[i];
  1428. const AVCodec *codec = NULL;
  1429. while ((codec = next_codec_for_id(desc->id, codec, encoder))) {
  1430. printf(" %c", get_media_type_char(desc->type));
  1431. printf((codec->capabilities & AV_CODEC_CAP_FRAME_THREADS) ? "F" : ".");
  1432. printf((codec->capabilities & AV_CODEC_CAP_SLICE_THREADS) ? "S" : ".");
  1433. printf((codec->capabilities & AV_CODEC_CAP_EXPERIMENTAL) ? "X" : ".");
  1434. printf((codec->capabilities & AV_CODEC_CAP_DRAW_HORIZ_BAND)?"B" : ".");
  1435. printf((codec->capabilities & AV_CODEC_CAP_DR1) ? "D" : ".");
  1436. printf(" %-20s %s", codec->name, codec->long_name ? codec->long_name : "");
  1437. if (strcmp(codec->name, desc->name))
  1438. printf(" (codec %s)", desc->name);
  1439. printf("\n");
  1440. }
  1441. }
  1442. av_free(codecs);
  1443. }
  1444. int show_decoders(void *optctx, const char *opt, const char *arg)
  1445. {
  1446. print_codecs(0);
  1447. return 0;
  1448. }
  1449. int show_encoders(void *optctx, const char *opt, const char *arg)
  1450. {
  1451. print_codecs(1);
  1452. return 0;
  1453. }
  1454. int show_bsfs(void *optctx, const char *opt, const char *arg)
  1455. {
  1456. const AVBitStreamFilter *bsf = NULL;
  1457. void *opaque = NULL;
  1458. printf("Bitstream filters:\n");
  1459. while ((bsf = av_bsf_iterate(&opaque)))
  1460. printf("%s\n", bsf->name);
  1461. printf("\n");
  1462. return 0;
  1463. }
  1464. int show_protocols(void *optctx, const char *opt, const char *arg)
  1465. {
  1466. void *opaque = NULL;
  1467. const char *name;
  1468. printf("Supported file protocols:\n"
  1469. "Input:\n");
  1470. while ((name = avio_enum_protocols(&opaque, 0)))
  1471. printf(" %s\n", name);
  1472. printf("Output:\n");
  1473. while ((name = avio_enum_protocols(&opaque, 1)))
  1474. printf(" %s\n", name);
  1475. return 0;
  1476. }
  1477. int show_filters(void *optctx, const char *opt, const char *arg)
  1478. {
  1479. #if CONFIG_AVFILTER
  1480. const AVFilter *filter = NULL;
  1481. char descr[64], *descr_cur;
  1482. void *opaque = NULL;
  1483. int i, j;
  1484. const AVFilterPad *pad;
  1485. printf("Filters:\n"
  1486. " T.. = Timeline support\n"
  1487. " .S. = Slice threading\n"
  1488. " ..C = Command support\n"
  1489. " A = Audio input/output\n"
  1490. " V = Video input/output\n"
  1491. " N = Dynamic number and/or type of input/output\n"
  1492. " | = Source or sink filter\n");
  1493. while ((filter = av_filter_iterate(&opaque))) {
  1494. descr_cur = descr;
  1495. for (i = 0; i < 2; i++) {
  1496. if (i) {
  1497. *(descr_cur++) = '-';
  1498. *(descr_cur++) = '>';
  1499. }
  1500. pad = i ? filter->outputs : filter->inputs;
  1501. for (j = 0; pad && avfilter_pad_get_name(pad, j); j++) {
  1502. if (descr_cur >= descr + sizeof(descr) - 4)
  1503. break;
  1504. *(descr_cur++) = get_media_type_char(avfilter_pad_get_type(pad, j));
  1505. }
  1506. if (!j)
  1507. *(descr_cur++) = ((!i && (filter->flags & AVFILTER_FLAG_DYNAMIC_INPUTS)) ||
  1508. ( i && (filter->flags & AVFILTER_FLAG_DYNAMIC_OUTPUTS))) ? 'N' : '|';
  1509. }
  1510. *descr_cur = 0;
  1511. printf(" %c%c%c %-17s %-10s %s\n",
  1512. filter->flags & AVFILTER_FLAG_SUPPORT_TIMELINE ? 'T' : '.',
  1513. filter->flags & AVFILTER_FLAG_SLICE_THREADS ? 'S' : '.',
  1514. filter->process_command ? 'C' : '.',
  1515. filter->name, descr, filter->description);
  1516. }
  1517. #else
  1518. printf("No filters available: libavfilter disabled\n");
  1519. #endif
  1520. return 0;
  1521. }
  1522. int show_colors(void *optctx, const char *opt, const char *arg)
  1523. {
  1524. const char *name;
  1525. const uint8_t *rgb;
  1526. int i;
  1527. printf("%-32s #RRGGBB\n", "name");
  1528. for (i = 0; name = av_get_known_color_name(i, &rgb); i++)
  1529. printf("%-32s #%02x%02x%02x\n", name, rgb[0], rgb[1], rgb[2]);
  1530. return 0;
  1531. }
  1532. int show_pix_fmts(void *optctx, const char *opt, const char *arg)
  1533. {
  1534. const AVPixFmtDescriptor *pix_desc = NULL;
  1535. printf("Pixel formats:\n"
  1536. "I.... = Supported Input format for conversion\n"
  1537. ".O... = Supported Output format for conversion\n"
  1538. "..H.. = Hardware accelerated format\n"
  1539. "...P. = Paletted format\n"
  1540. "....B = Bitstream format\n"
  1541. "FLAGS NAME NB_COMPONENTS BITS_PER_PIXEL\n"
  1542. "-----\n");
  1543. #if !CONFIG_SWSCALE
  1544. # define sws_isSupportedInput(x) 0
  1545. # define sws_isSupportedOutput(x) 0
  1546. #endif
  1547. while ((pix_desc = av_pix_fmt_desc_next(pix_desc))) {
  1548. enum AVPixelFormat av_unused pix_fmt = av_pix_fmt_desc_get_id(pix_desc);
  1549. printf("%c%c%c%c%c %-16s %d %2d\n",
  1550. sws_isSupportedInput (pix_fmt) ? 'I' : '.',
  1551. sws_isSupportedOutput(pix_fmt) ? 'O' : '.',
  1552. pix_desc->flags & AV_PIX_FMT_FLAG_HWACCEL ? 'H' : '.',
  1553. pix_desc->flags & AV_PIX_FMT_FLAG_PAL ? 'P' : '.',
  1554. pix_desc->flags & AV_PIX_FMT_FLAG_BITSTREAM ? 'B' : '.',
  1555. pix_desc->name,
  1556. pix_desc->nb_components,
  1557. av_get_bits_per_pixel(pix_desc));
  1558. }
  1559. return 0;
  1560. }
  1561. int show_layouts(void *optctx, const char *opt, const char *arg)
  1562. {
  1563. int i = 0;
  1564. uint64_t layout, j;
  1565. const char *name, *descr;
  1566. printf("Individual channels:\n"
  1567. "NAME DESCRIPTION\n");
  1568. for (i = 0; i < 63; i++) {
  1569. name = av_get_channel_name((uint64_t)1 << i);
  1570. if (!name)
  1571. continue;
  1572. descr = av_get_channel_description((uint64_t)1 << i);
  1573. printf("%-14s %s\n", name, descr);
  1574. }
  1575. printf("\nStandard channel layouts:\n"
  1576. "NAME DECOMPOSITION\n");
  1577. for (i = 0; !av_get_standard_channel_layout(i, &layout, &name); i++) {
  1578. if (name) {
  1579. printf("%-14s ", name);
  1580. for (j = 1; j; j <<= 1)
  1581. if ((layout & j))
  1582. printf("%s%s", (layout & (j - 1)) ? "+" : "", av_get_channel_name(j));
  1583. printf("\n");
  1584. }
  1585. }
  1586. return 0;
  1587. }
  1588. int show_sample_fmts(void *optctx, const char *opt, const char *arg)
  1589. {
  1590. int i;
  1591. char fmt_str[128];
  1592. for (i = -1; i < AV_SAMPLE_FMT_NB; i++)
  1593. printf("%s\n", av_get_sample_fmt_string(fmt_str, sizeof(fmt_str), i));
  1594. return 0;
  1595. }
  1596. static void show_help_codec(const char *name, int encoder)
  1597. {
  1598. const AVCodecDescriptor *desc;
  1599. const AVCodec *codec;
  1600. if (!name) {
  1601. av_log(NULL, AV_LOG_ERROR, "No codec name specified.\n");
  1602. return;
  1603. }
  1604. codec = encoder ? avcodec_find_encoder_by_name(name) :
  1605. avcodec_find_decoder_by_name(name);
  1606. if (codec)
  1607. print_codec(codec);
  1608. else if ((desc = avcodec_descriptor_get_by_name(name))) {
  1609. int printed = 0;
  1610. while ((codec = next_codec_for_id(desc->id, codec, encoder))) {
  1611. printed = 1;
  1612. print_codec(codec);
  1613. }
  1614. if (!printed) {
  1615. av_log(NULL, AV_LOG_ERROR, "Codec '%s' is known to FFmpeg, "
  1616. "but no %s for it are available. FFmpeg might need to be "
  1617. "recompiled with additional external libraries.\n",
  1618. name, encoder ? "encoders" : "decoders");
  1619. }
  1620. } else {
  1621. av_log(NULL, AV_LOG_ERROR, "Codec '%s' is not recognized by FFmpeg.\n",
  1622. name);
  1623. }
  1624. }
  1625. static void show_help_demuxer(const char *name)
  1626. {
  1627. const AVInputFormat *fmt = av_find_input_format(name);
  1628. if (!fmt) {
  1629. av_log(NULL, AV_LOG_ERROR, "Unknown format '%s'.\n", name);
  1630. return;
  1631. }
  1632. printf("Demuxer %s [%s]:\n", fmt->name, fmt->long_name);
  1633. if (fmt->extensions)
  1634. printf(" Common extensions: %s.\n", fmt->extensions);
  1635. if (fmt->priv_class)
  1636. show_help_children(fmt->priv_class, AV_OPT_FLAG_DECODING_PARAM);
  1637. }
  1638. static void show_help_muxer(const char *name)
  1639. {
  1640. const AVCodecDescriptor *desc;
  1641. const AVOutputFormat *fmt = av_guess_format(name, NULL, NULL);
  1642. if (!fmt) {
  1643. av_log(NULL, AV_LOG_ERROR, "Unknown format '%s'.\n", name);
  1644. return;
  1645. }
  1646. printf("Muxer %s [%s]:\n", fmt->name, fmt->long_name);
  1647. if (fmt->extensions)
  1648. printf(" Common extensions: %s.\n", fmt->extensions);
  1649. if (fmt->mime_type)
  1650. printf(" Mime type: %s.\n", fmt->mime_type);
  1651. if (fmt->video_codec != AV_CODEC_ID_NONE &&
  1652. (desc = avcodec_descriptor_get(fmt->video_codec))) {
  1653. printf(" Default video codec: %s.\n", desc->name);
  1654. }
  1655. if (fmt->audio_codec != AV_CODEC_ID_NONE &&
  1656. (desc = avcodec_descriptor_get(fmt->audio_codec))) {
  1657. printf(" Default audio codec: %s.\n", desc->name);
  1658. }
  1659. if (fmt->subtitle_codec != AV_CODEC_ID_NONE &&
  1660. (desc = avcodec_descriptor_get(fmt->subtitle_codec))) {
  1661. printf(" Default subtitle codec: %s.\n", desc->name);
  1662. }
  1663. if (fmt->priv_class)
  1664. show_help_children(fmt->priv_class, AV_OPT_FLAG_ENCODING_PARAM);
  1665. }
  1666. #if CONFIG_AVFILTER
  1667. static void show_help_filter(const char *name)
  1668. {
  1669. #if CONFIG_AVFILTER
  1670. const AVFilter *f = avfilter_get_by_name(name);
  1671. int i, count;
  1672. if (!name) {
  1673. av_log(NULL, AV_LOG_ERROR, "No filter name specified.\n");
  1674. return;
  1675. } else if (!f) {
  1676. av_log(NULL, AV_LOG_ERROR, "Unknown filter '%s'.\n", name);
  1677. return;
  1678. }
  1679. printf("Filter %s\n", f->name);
  1680. if (f->description)
  1681. printf(" %s\n", f->description);
  1682. if (f->flags & AVFILTER_FLAG_SLICE_THREADS)
  1683. printf(" slice threading supported\n");
  1684. printf(" Inputs:\n");
  1685. count = avfilter_pad_count(f->inputs);
  1686. for (i = 0; i < count; i++) {
  1687. printf(" #%d: %s (%s)\n", i, avfilter_pad_get_name(f->inputs, i),
  1688. media_type_string(avfilter_pad_get_type(f->inputs, i)));
  1689. }
  1690. if (f->flags & AVFILTER_FLAG_DYNAMIC_INPUTS)
  1691. printf(" dynamic (depending on the options)\n");
  1692. else if (!count)
  1693. printf(" none (source filter)\n");
  1694. printf(" Outputs:\n");
  1695. count = avfilter_pad_count(f->outputs);
  1696. for (i = 0; i < count; i++) {
  1697. printf(" #%d: %s (%s)\n", i, avfilter_pad_get_name(f->outputs, i),
  1698. media_type_string(avfilter_pad_get_type(f->outputs, i)));
  1699. }
  1700. if (f->flags & AVFILTER_FLAG_DYNAMIC_OUTPUTS)
  1701. printf(" dynamic (depending on the options)\n");
  1702. else if (!count)
  1703. printf(" none (sink filter)\n");
  1704. if (f->priv_class)
  1705. show_help_children(f->priv_class, AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_FILTERING_PARAM |
  1706. AV_OPT_FLAG_AUDIO_PARAM);
  1707. if (f->flags & AVFILTER_FLAG_SUPPORT_TIMELINE)
  1708. printf("This filter has support for timeline through the 'enable' option.\n");
  1709. #else
  1710. av_log(NULL, AV_LOG_ERROR, "Build without libavfilter; "
  1711. "can not to satisfy request\n");
  1712. #endif
  1713. }
  1714. #endif
  1715. static void show_help_bsf(const char *name)
  1716. {
  1717. const AVBitStreamFilter *bsf = av_bsf_get_by_name(name);
  1718. if (!name) {
  1719. av_log(NULL, AV_LOG_ERROR, "No bitstream filter name specified.\n");
  1720. return;
  1721. } else if (!bsf) {
  1722. av_log(NULL, AV_LOG_ERROR, "Unknown bit stream filter '%s'.\n", name);
  1723. return;
  1724. }
  1725. printf("Bit stream filter %s\n", bsf->name);
  1726. PRINT_CODEC_SUPPORTED(bsf, codec_ids, enum AVCodecID, "codecs",
  1727. AV_CODEC_ID_NONE, GET_CODEC_NAME);
  1728. if (bsf->priv_class)
  1729. show_help_children(bsf->priv_class, AV_OPT_FLAG_BSF_PARAM);
  1730. }
  1731. int show_help(void *optctx, const char *opt, const char *arg)
  1732. {
  1733. char *topic, *par;
  1734. av_log_set_callback(log_callback_help);
  1735. topic = av_strdup(arg ? arg : "");
  1736. if (!topic)
  1737. return AVERROR(ENOMEM);
  1738. par = strchr(topic, '=');
  1739. if (par)
  1740. *par++ = 0;
  1741. if (!*topic) {
  1742. show_help_default(topic, par);
  1743. } else if (!strcmp(topic, "decoder")) {
  1744. show_help_codec(par, 0);
  1745. } else if (!strcmp(topic, "encoder")) {
  1746. show_help_codec(par, 1);
  1747. } else if (!strcmp(topic, "demuxer")) {
  1748. show_help_demuxer(par);
  1749. } else if (!strcmp(topic, "muxer")) {
  1750. show_help_muxer(par);
  1751. #if CONFIG_AVFILTER
  1752. } else if (!strcmp(topic, "filter")) {
  1753. show_help_filter(par);
  1754. #endif
  1755. } else if (!strcmp(topic, "bsf")) {
  1756. show_help_bsf(par);
  1757. } else {
  1758. show_help_default(topic, par);
  1759. }
  1760. av_freep(&topic);
  1761. return 0;
  1762. }
  1763. int read_yesno(void)
  1764. {
  1765. int c = getchar();
  1766. int yesno = (av_toupper(c) == 'Y');
  1767. while (c != '\n' && c != EOF)
  1768. c = getchar();
  1769. return yesno;
  1770. }
  1771. FILE *get_preset_file(char *filename, size_t filename_size,
  1772. const char *preset_name, int is_path,
  1773. const char *codec_name)
  1774. {
  1775. FILE *f = NULL;
  1776. int i;
  1777. const char *base[3] = { getenv("FFMPEG_DATADIR"),
  1778. getenv("HOME"),
  1779. FFMPEG_DATADIR, };
  1780. if (is_path) {
  1781. av_strlcpy(filename, preset_name, filename_size);
  1782. f = fopen(filename, "r");
  1783. } else {
  1784. #ifdef _WIN32
  1785. char datadir[MAX_PATH], *ls;
  1786. base[2] = NULL;
  1787. if (GetModuleFileNameA(GetModuleHandleA(NULL), datadir, sizeof(datadir) - 1))
  1788. {
  1789. for (ls = datadir; ls < datadir + strlen(datadir); ls++)
  1790. if (*ls == '\\') *ls = '/';
  1791. if (ls = strrchr(datadir, '/'))
  1792. {
  1793. *ls = 0;
  1794. strncat(datadir, "/ffpresets", sizeof(datadir) - 1 - strlen(datadir));
  1795. base[2] = datadir;
  1796. }
  1797. }
  1798. #endif
  1799. for (i = 0; i < 3 && !f; i++) {
  1800. if (!base[i])
  1801. continue;
  1802. snprintf(filename, filename_size, "%s%s/%s.ffpreset", base[i],
  1803. i != 1 ? "" : "/.ffmpeg", preset_name);
  1804. f = fopen(filename, "r");
  1805. if (!f && codec_name) {
  1806. snprintf(filename, filename_size,
  1807. "%s%s/%s-%s.ffpreset",
  1808. base[i], i != 1 ? "" : "/.ffmpeg", codec_name,
  1809. preset_name);
  1810. f = fopen(filename, "r");
  1811. }
  1812. }
  1813. }
  1814. return f;
  1815. }
  1816. int check_stream_specifier(AVFormatContext *s, AVStream *st, const char *spec)
  1817. {
  1818. int ret = avformat_match_stream_specifier(s, st, spec);
  1819. if (ret < 0)
  1820. av_log(s, AV_LOG_ERROR, "Invalid stream specifier: %s.\n", spec);
  1821. return ret;
  1822. }
  1823. AVDictionary *filter_codec_opts(AVDictionary *opts, enum AVCodecID codec_id,
  1824. AVFormatContext *s, AVStream *st, AVCodec *codec)
  1825. {
  1826. AVDictionary *ret = NULL;
  1827. AVDictionaryEntry *t = NULL;
  1828. int flags = s->oformat ? AV_OPT_FLAG_ENCODING_PARAM
  1829. : AV_OPT_FLAG_DECODING_PARAM;
  1830. char prefix = 0;
  1831. const AVClass *cc = avcodec_get_class();
  1832. if (!codec)
  1833. codec = s->oformat ? avcodec_find_encoder(codec_id)
  1834. : avcodec_find_decoder(codec_id);
  1835. switch (st->codecpar->codec_type) {
  1836. case AVMEDIA_TYPE_VIDEO:
  1837. prefix = 'v';
  1838. flags |= AV_OPT_FLAG_VIDEO_PARAM;
  1839. break;
  1840. case AVMEDIA_TYPE_AUDIO:
  1841. prefix = 'a';
  1842. flags |= AV_OPT_FLAG_AUDIO_PARAM;
  1843. break;
  1844. case AVMEDIA_TYPE_SUBTITLE:
  1845. prefix = 's';
  1846. flags |= AV_OPT_FLAG_SUBTITLE_PARAM;
  1847. break;
  1848. }
  1849. while (t = av_dict_get(opts, "", t, AV_DICT_IGNORE_SUFFIX)) {
  1850. char *p = strchr(t->key, ':');
  1851. /* check stream specification in opt name */
  1852. if (p)
  1853. switch (check_stream_specifier(s, st, p + 1)) {
  1854. case 1: *p = 0; break;
  1855. case 0: continue;
  1856. default: exit_program(1);
  1857. }
  1858. if (av_opt_find(&cc, t->key, NULL, flags, AV_OPT_SEARCH_FAKE_OBJ) ||
  1859. !codec ||
  1860. (codec->priv_class &&
  1861. av_opt_find(&codec->priv_class, t->key, NULL, flags,
  1862. AV_OPT_SEARCH_FAKE_OBJ)))
  1863. av_dict_set(&ret, t->key, t->value, 0);
  1864. else if (t->key[0] == prefix &&
  1865. av_opt_find(&cc, t->key + 1, NULL, flags,
  1866. AV_OPT_SEARCH_FAKE_OBJ))
  1867. av_dict_set(&ret, t->key + 1, t->value, 0);
  1868. if (p)
  1869. *p = ':';
  1870. }
  1871. return ret;
  1872. }
  1873. AVDictionary **setup_find_stream_info_opts(AVFormatContext *s,
  1874. AVDictionary *codec_opts)
  1875. {
  1876. int i;
  1877. AVDictionary **opts;
  1878. if (!s->nb_streams)
  1879. return NULL;
  1880. opts = av_mallocz_array(s->nb_streams, sizeof(*opts));
  1881. if (!opts) {
  1882. av_log(NULL, AV_LOG_ERROR,
  1883. "Could not alloc memory for stream options.\n");
  1884. return NULL;
  1885. }
  1886. for (i = 0; i < s->nb_streams; i++)
  1887. opts[i] = filter_codec_opts(codec_opts, s->streams[i]->codecpar->codec_id,
  1888. s, s->streams[i], NULL);
  1889. return opts;
  1890. }
  1891. void *grow_array(void *array, int elem_size, int *size, int new_size)
  1892. {
  1893. if (new_size >= INT_MAX / elem_size) {
  1894. av_log(NULL, AV_LOG_ERROR, "Array too big.\n");
  1895. exit_program(1);
  1896. }
  1897. if (*size < new_size) {
  1898. uint8_t *tmp = av_realloc_array(array, new_size, elem_size);
  1899. if (!tmp) {
  1900. av_log(NULL, AV_LOG_ERROR, "Could not alloc buffer.\n");
  1901. exit_program(1);
  1902. }
  1903. memset(tmp + *size*elem_size, 0, (new_size-*size) * elem_size);
  1904. *size = new_size;
  1905. return tmp;
  1906. }
  1907. return array;
  1908. }
  1909. double get_rotation(AVStream *st)
  1910. {
  1911. uint8_t* displaymatrix = av_stream_get_side_data(st,
  1912. AV_PKT_DATA_DISPLAYMATRIX, NULL);
  1913. double theta = 0;
  1914. if (displaymatrix)
  1915. theta = -av_display_rotation_get((int32_t*) displaymatrix);
  1916. theta -= 360*floor(theta/360 + 0.9/360);
  1917. if (fabs(theta - 90*round(theta/90)) > 2)
  1918. av_log(NULL, AV_LOG_WARNING, "Odd rotation angle.\n"
  1919. "If you want to help, upload a sample "
  1920. "of this file to ftp://upload.ffmpeg.org/incoming/ "
  1921. "and contact the ffmpeg-devel mailing list. (ffmpeg-devel@ffmpeg.org)");
  1922. return theta;
  1923. }
  1924. #if CONFIG_AVDEVICE
  1925. static int print_device_sources(AVInputFormat *fmt, AVDictionary *opts)
  1926. {
  1927. int ret, i;
  1928. AVDeviceInfoList *device_list = NULL;
  1929. if (!fmt || !fmt->priv_class || !AV_IS_INPUT_DEVICE(fmt->priv_class->category))
  1930. return AVERROR(EINVAL);
  1931. printf("Auto-detected sources for %s:\n", fmt->name);
  1932. if (!fmt->get_device_list) {
  1933. ret = AVERROR(ENOSYS);
  1934. printf("Cannot list sources. Not implemented.\n");
  1935. goto fail;
  1936. }
  1937. if ((ret = avdevice_list_input_sources(fmt, NULL, opts, &device_list)) < 0) {
  1938. printf("Cannot list sources.\n");
  1939. goto fail;
  1940. }
  1941. for (i = 0; i < device_list->nb_devices; i++) {
  1942. printf("%s %s [%s]\n", device_list->default_device == i ? "*" : " ",
  1943. device_list->devices[i]->device_name, device_list->devices[i]->device_description);
  1944. }
  1945. fail:
  1946. avdevice_free_list_devices(&device_list);
  1947. return ret;
  1948. }
  1949. static int print_device_sinks(AVOutputFormat *fmt, AVDictionary *opts)
  1950. {
  1951. int ret, i;
  1952. AVDeviceInfoList *device_list = NULL;
  1953. if (!fmt || !fmt->priv_class || !AV_IS_OUTPUT_DEVICE(fmt->priv_class->category))
  1954. return AVERROR(EINVAL);
  1955. printf("Auto-detected sinks for %s:\n", fmt->name);
  1956. if (!fmt->get_device_list) {
  1957. ret = AVERROR(ENOSYS);
  1958. printf("Cannot list sinks. Not implemented.\n");
  1959. goto fail;
  1960. }
  1961. if ((ret = avdevice_list_output_sinks(fmt, NULL, opts, &device_list)) < 0) {
  1962. printf("Cannot list sinks.\n");
  1963. goto fail;
  1964. }
  1965. for (i = 0; i < device_list->nb_devices; i++) {
  1966. printf("%s %s [%s]\n", device_list->default_device == i ? "*" : " ",
  1967. device_list->devices[i]->device_name, device_list->devices[i]->device_description);
  1968. }
  1969. fail:
  1970. avdevice_free_list_devices(&device_list);
  1971. return ret;
  1972. }
  1973. static int show_sinks_sources_parse_arg(const char *arg, char **dev, AVDictionary **opts)
  1974. {
  1975. int ret;
  1976. if (arg) {
  1977. char *opts_str = NULL;
  1978. av_assert0(dev && opts);
  1979. *dev = av_strdup(arg);
  1980. if (!*dev)
  1981. return AVERROR(ENOMEM);
  1982. if ((opts_str = strchr(*dev, ','))) {
  1983. *(opts_str++) = '\0';
  1984. if (opts_str[0] && ((ret = av_dict_parse_string(opts, opts_str, "=", ":", 0)) < 0)) {
  1985. av_freep(dev);
  1986. return ret;
  1987. }
  1988. }
  1989. } else
  1990. printf("\nDevice name is not provided.\n"
  1991. "You can pass devicename[,opt1=val1[,opt2=val2...]] as an argument.\n\n");
  1992. return 0;
  1993. }
  1994. int show_sources(void *optctx, const char *opt, const char *arg)
  1995. {
  1996. AVInputFormat *fmt = NULL;
  1997. char *dev = NULL;
  1998. AVDictionary *opts = NULL;
  1999. int ret = 0;
  2000. int error_level = av_log_get_level();
  2001. av_log_set_level(AV_LOG_ERROR);
  2002. if ((ret = show_sinks_sources_parse_arg(arg, &dev, &opts)) < 0)
  2003. goto fail;
  2004. do {
  2005. fmt = av_input_audio_device_next(fmt);
  2006. if (fmt) {
  2007. if (!strcmp(fmt->name, "lavfi"))
  2008. continue; //it's pointless to probe lavfi
  2009. if (dev && !av_match_name(dev, fmt->name))
  2010. continue;
  2011. print_device_sources(fmt, opts);
  2012. }
  2013. } while (fmt);
  2014. do {
  2015. fmt = av_input_video_device_next(fmt);
  2016. if (fmt) {
  2017. if (dev && !av_match_name(dev, fmt->name))
  2018. continue;
  2019. print_device_sources(fmt, opts);
  2020. }
  2021. } while (fmt);
  2022. fail:
  2023. av_dict_free(&opts);
  2024. av_free(dev);
  2025. av_log_set_level(error_level);
  2026. return ret;
  2027. }
  2028. int show_sinks(void *optctx, const char *opt, const char *arg)
  2029. {
  2030. AVOutputFormat *fmt = NULL;
  2031. char *dev = NULL;
  2032. AVDictionary *opts = NULL;
  2033. int ret = 0;
  2034. int error_level = av_log_get_level();
  2035. av_log_set_level(AV_LOG_ERROR);
  2036. if ((ret = show_sinks_sources_parse_arg(arg, &dev, &opts)) < 0)
  2037. goto fail;
  2038. do {
  2039. fmt = av_output_audio_device_next(fmt);
  2040. if (fmt) {
  2041. if (dev && !av_match_name(dev, fmt->name))
  2042. continue;
  2043. print_device_sinks(fmt, opts);
  2044. }
  2045. } while (fmt);
  2046. do {
  2047. fmt = av_output_video_device_next(fmt);
  2048. if (fmt) {
  2049. if (dev && !av_match_name(dev, fmt->name))
  2050. continue;
  2051. print_device_sinks(fmt, opts);
  2052. }
  2053. } while (fmt);
  2054. fail:
  2055. av_dict_free(&opts);
  2056. av_free(dev);
  2057. av_log_set_level(error_level);
  2058. return ret;
  2059. }
  2060. #endif