ffmpeg_opt.c 75 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775
  1. /*
  2. * ffmpeg option parsing
  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. #include "config.h"
  21. #include <stdint.h>
  22. #if HAVE_SYS_RESOURCE_H
  23. #include <sys/time.h>
  24. #include <sys/resource.h>
  25. #endif
  26. #include "ffmpeg.h"
  27. #include "cmdutils.h"
  28. #include "opt_common.h"
  29. #include "sync_queue.h"
  30. #include "libavformat/avformat.h"
  31. #include "libavcodec/avcodec.h"
  32. #include "libavcodec/bsf.h"
  33. #include "libavfilter/avfilter.h"
  34. #include "libavutil/avassert.h"
  35. #include "libavutil/avstring.h"
  36. #include "libavutil/avutil.h"
  37. #include "libavutil/bprint.h"
  38. #include "libavutil/channel_layout.h"
  39. #include "libavutil/display.h"
  40. #include "libavutil/intreadwrite.h"
  41. #include "libavutil/fifo.h"
  42. #include "libavutil/mathematics.h"
  43. #include "libavutil/opt.h"
  44. #include "libavutil/parseutils.h"
  45. #include "libavutil/pixdesc.h"
  46. #include "libavutil/pixfmt.h"
  47. const char *const opt_name_codec_names[] = {"c", "codec", "acodec", "vcodec", "scodec", "dcodec", NULL};
  48. const char *const opt_name_frame_rates[] = {"r", NULL};
  49. const char *const opt_name_codec_tags[] = {"tag", "atag", "vtag", "stag", NULL};
  50. const char *const opt_name_top_field_first[] = {"top", NULL};
  51. HWDevice *filter_hw_device;
  52. char *vstats_filename;
  53. char *sdp_filename;
  54. float audio_drift_threshold = 0.1;
  55. float dts_delta_threshold = 10;
  56. float dts_error_threshold = 3600*30;
  57. enum VideoSyncMethod video_sync_method = VSYNC_AUTO;
  58. float frame_drop_threshold = 0;
  59. int do_benchmark = 0;
  60. int do_benchmark_all = 0;
  61. int do_hex_dump = 0;
  62. int do_pkt_dump = 0;
  63. int copy_ts = 0;
  64. int start_at_zero = 0;
  65. int copy_tb = -1;
  66. int debug_ts = 0;
  67. int exit_on_error = 0;
  68. int abort_on_flags = 0;
  69. int print_stats = -1;
  70. int qp_hist = 0;
  71. int stdin_interaction = 1;
  72. float max_error_rate = 2.0/3;
  73. char *filter_nbthreads;
  74. int filter_complex_nbthreads = 0;
  75. int vstats_version = 2;
  76. int auto_conversion_filters = 1;
  77. int64_t stats_period = 500000;
  78. static int file_overwrite = 0;
  79. static int no_file_overwrite = 0;
  80. #if FFMPEG_OPT_PSNR
  81. int do_psnr = 0;
  82. #endif
  83. int ignore_unknown_streams = 0;
  84. int copy_unknown_streams = 0;
  85. int recast_media = 0;
  86. static void uninit_options(OptionsContext *o)
  87. {
  88. const OptionDef *po = options;
  89. int i;
  90. /* all OPT_SPEC and OPT_STRING can be freed in generic way */
  91. while (po->name) {
  92. void *dst = (uint8_t*)o + po->u.off;
  93. if (po->flags & OPT_SPEC) {
  94. SpecifierOpt **so = dst;
  95. int i, *count = (int*)(so + 1);
  96. for (i = 0; i < *count; i++) {
  97. av_freep(&(*so)[i].specifier);
  98. if (po->flags & OPT_STRING)
  99. av_freep(&(*so)[i].u.str);
  100. }
  101. av_freep(so);
  102. *count = 0;
  103. } else if (po->flags & OPT_OFFSET && po->flags & OPT_STRING)
  104. av_freep(dst);
  105. po++;
  106. }
  107. for (i = 0; i < o->nb_stream_maps; i++)
  108. av_freep(&o->stream_maps[i].linklabel);
  109. av_freep(&o->stream_maps);
  110. #if FFMPEG_OPT_MAP_CHANNEL
  111. av_freep(&o->audio_channel_maps);
  112. #endif
  113. av_freep(&o->streamid_map);
  114. av_freep(&o->attachments);
  115. }
  116. static void init_options(OptionsContext *o)
  117. {
  118. memset(o, 0, sizeof(*o));
  119. o->stop_time = INT64_MAX;
  120. o->mux_max_delay = 0.7;
  121. o->start_time = AV_NOPTS_VALUE;
  122. o->start_time_eof = AV_NOPTS_VALUE;
  123. o->recording_time = INT64_MAX;
  124. o->limit_filesize = INT64_MAX;
  125. o->chapters_input_file = INT_MAX;
  126. o->accurate_seek = 1;
  127. o->thread_queue_size = -1;
  128. o->input_sync_ref = -1;
  129. o->find_stream_info = 1;
  130. o->shortest_buf_duration = 10.f;
  131. }
  132. static int show_hwaccels(void *optctx, const char *opt, const char *arg)
  133. {
  134. enum AVHWDeviceType type = AV_HWDEVICE_TYPE_NONE;
  135. printf("Hardware acceleration methods:\n");
  136. while ((type = av_hwdevice_iterate_types(type)) !=
  137. AV_HWDEVICE_TYPE_NONE)
  138. printf("%s\n", av_hwdevice_get_type_name(type));
  139. printf("\n");
  140. return 0;
  141. }
  142. /* return a copy of the input with the stream specifiers removed from the keys */
  143. AVDictionary *strip_specifiers(const AVDictionary *dict)
  144. {
  145. const AVDictionaryEntry *e = NULL;
  146. AVDictionary *ret = NULL;
  147. while ((e = av_dict_iterate(dict, e))) {
  148. char *p = strchr(e->key, ':');
  149. if (p)
  150. *p = 0;
  151. av_dict_set(&ret, e->key, e->value, 0);
  152. if (p)
  153. *p = ':';
  154. }
  155. return ret;
  156. }
  157. int parse_and_set_vsync(const char *arg, int *vsync_var, int file_idx, int st_idx, int is_global)
  158. {
  159. if (!av_strcasecmp(arg, "cfr")) *vsync_var = VSYNC_CFR;
  160. else if (!av_strcasecmp(arg, "vfr")) *vsync_var = VSYNC_VFR;
  161. else if (!av_strcasecmp(arg, "passthrough")) *vsync_var = VSYNC_PASSTHROUGH;
  162. else if (!av_strcasecmp(arg, "drop")) *vsync_var = VSYNC_DROP;
  163. else if (!is_global && !av_strcasecmp(arg, "auto")) *vsync_var = VSYNC_AUTO;
  164. else if (!is_global) {
  165. av_log(NULL, AV_LOG_FATAL, "Invalid value %s specified for fps_mode of #%d:%d.\n", arg, file_idx, st_idx);
  166. exit_program(1);
  167. }
  168. if (is_global && *vsync_var == VSYNC_AUTO) {
  169. video_sync_method = parse_number_or_die("vsync", arg, OPT_INT, VSYNC_AUTO, VSYNC_VFR);
  170. av_log(NULL, AV_LOG_WARNING, "Passing a number to -vsync is deprecated,"
  171. " use a string argument as described in the manual.\n");
  172. }
  173. return 0;
  174. }
  175. /* Correct input file start times based on enabled streams */
  176. static void correct_input_start_times(void)
  177. {
  178. for (int i = 0; i < nb_input_files; i++) {
  179. InputFile *ifile = input_files[i];
  180. AVFormatContext *is = ifile->ctx;
  181. int64_t new_start_time = INT64_MAX, diff, abs_start_seek;
  182. ifile->start_time_effective = is->start_time;
  183. if (is->start_time == AV_NOPTS_VALUE ||
  184. !(is->iformat->flags & AVFMT_TS_DISCONT))
  185. continue;
  186. for (int j = 0; j < is->nb_streams; j++) {
  187. AVStream *st = is->streams[j];
  188. if(st->discard == AVDISCARD_ALL || st->start_time == AV_NOPTS_VALUE)
  189. continue;
  190. new_start_time = FFMIN(new_start_time, av_rescale_q(st->start_time, st->time_base, AV_TIME_BASE_Q));
  191. }
  192. diff = new_start_time - is->start_time;
  193. if (diff) {
  194. av_log(NULL, AV_LOG_VERBOSE, "Correcting start time of Input #%d by %"PRId64" us.\n", i, diff);
  195. ifile->start_time_effective = new_start_time;
  196. if (copy_ts && start_at_zero)
  197. ifile->ts_offset = -new_start_time;
  198. else if (!copy_ts) {
  199. abs_start_seek = is->start_time + (ifile->start_time != AV_NOPTS_VALUE) ? ifile->start_time : 0;
  200. ifile->ts_offset = abs_start_seek > new_start_time ? -abs_start_seek : -new_start_time;
  201. } else if (copy_ts)
  202. ifile->ts_offset = 0;
  203. ifile->ts_offset += ifile->input_ts_offset;
  204. }
  205. }
  206. }
  207. static int apply_sync_offsets(void)
  208. {
  209. for (int i = 0; i < nb_input_files; i++) {
  210. InputFile *ref, *self = input_files[i];
  211. int64_t adjustment;
  212. int64_t self_start_time, ref_start_time, self_seek_start, ref_seek_start;
  213. int start_times_set = 1;
  214. if (self->input_sync_ref == -1 || self->input_sync_ref == i) continue;
  215. if (self->input_sync_ref >= nb_input_files || self->input_sync_ref < -1) {
  216. av_log(NULL, AV_LOG_FATAL, "-isync for input %d references non-existent input %d.\n", i, self->input_sync_ref);
  217. exit_program(1);
  218. }
  219. if (copy_ts && !start_at_zero) {
  220. av_log(NULL, AV_LOG_FATAL, "Use of -isync requires that start_at_zero be set if copyts is set.\n");
  221. exit_program(1);
  222. }
  223. ref = input_files[self->input_sync_ref];
  224. if (ref->input_sync_ref != -1 && ref->input_sync_ref != self->input_sync_ref) {
  225. av_log(NULL, AV_LOG_ERROR, "-isync for input %d references a resynced input %d. Sync not set.\n", i, self->input_sync_ref);
  226. continue;
  227. }
  228. if (self->ctx->start_time_realtime != AV_NOPTS_VALUE && ref->ctx->start_time_realtime != AV_NOPTS_VALUE) {
  229. self_start_time = self->ctx->start_time_realtime;
  230. ref_start_time = ref->ctx->start_time_realtime;
  231. } else if (self->start_time_effective != AV_NOPTS_VALUE && ref->start_time_effective != AV_NOPTS_VALUE) {
  232. self_start_time = self->start_time_effective;
  233. ref_start_time = ref->start_time_effective;
  234. } else {
  235. start_times_set = 0;
  236. }
  237. if (start_times_set) {
  238. self_seek_start = self->start_time == AV_NOPTS_VALUE ? 0 : self->start_time;
  239. ref_seek_start = ref->start_time == AV_NOPTS_VALUE ? 0 : ref->start_time;
  240. adjustment = (self_start_time - ref_start_time) + !copy_ts*(self_seek_start - ref_seek_start) + ref->input_ts_offset;
  241. self->ts_offset += adjustment;
  242. av_log(NULL, AV_LOG_INFO, "Adjusted ts offset for Input #%d by %"PRId64" us to sync with Input #%d.\n", i, adjustment, self->input_sync_ref);
  243. } else {
  244. av_log(NULL, AV_LOG_INFO, "Unable to identify start times for Inputs #%d and %d both. No sync adjustment made.\n", i, self->input_sync_ref);
  245. }
  246. }
  247. return 0;
  248. }
  249. static int opt_filter_threads(void *optctx, const char *opt, const char *arg)
  250. {
  251. av_free(filter_nbthreads);
  252. filter_nbthreads = av_strdup(arg);
  253. return 0;
  254. }
  255. static int opt_abort_on(void *optctx, const char *opt, const char *arg)
  256. {
  257. static const AVOption opts[] = {
  258. { "abort_on" , NULL, 0, AV_OPT_TYPE_FLAGS, { .i64 = 0 }, INT64_MIN, INT64_MAX, .unit = "flags" },
  259. { "empty_output" , NULL, 0, AV_OPT_TYPE_CONST, { .i64 = ABORT_ON_FLAG_EMPTY_OUTPUT }, .unit = "flags" },
  260. { "empty_output_stream", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = ABORT_ON_FLAG_EMPTY_OUTPUT_STREAM }, .unit = "flags" },
  261. { NULL },
  262. };
  263. static const AVClass class = {
  264. .class_name = "",
  265. .item_name = av_default_item_name,
  266. .option = opts,
  267. .version = LIBAVUTIL_VERSION_INT,
  268. };
  269. const AVClass *pclass = &class;
  270. return av_opt_eval_flags(&pclass, &opts[0], arg, &abort_on_flags);
  271. }
  272. static int opt_stats_period(void *optctx, const char *opt, const char *arg)
  273. {
  274. int64_t user_stats_period = parse_time_or_die(opt, arg, 1);
  275. if (user_stats_period <= 0) {
  276. av_log(NULL, AV_LOG_ERROR, "stats_period %s must be positive.\n", arg);
  277. return AVERROR(EINVAL);
  278. }
  279. stats_period = user_stats_period;
  280. av_log(NULL, AV_LOG_INFO, "ffmpeg stats and -progress period set to %s.\n", arg);
  281. return 0;
  282. }
  283. static int opt_audio_codec(void *optctx, const char *opt, const char *arg)
  284. {
  285. OptionsContext *o = optctx;
  286. return parse_option(o, "codec:a", arg, options);
  287. }
  288. static int opt_video_codec(void *optctx, const char *opt, const char *arg)
  289. {
  290. OptionsContext *o = optctx;
  291. return parse_option(o, "codec:v", arg, options);
  292. }
  293. static int opt_subtitle_codec(void *optctx, const char *opt, const char *arg)
  294. {
  295. OptionsContext *o = optctx;
  296. return parse_option(o, "codec:s", arg, options);
  297. }
  298. static int opt_data_codec(void *optctx, const char *opt, const char *arg)
  299. {
  300. OptionsContext *o = optctx;
  301. return parse_option(o, "codec:d", arg, options);
  302. }
  303. static int opt_map(void *optctx, const char *opt, const char *arg)
  304. {
  305. OptionsContext *o = optctx;
  306. StreamMap *m = NULL;
  307. int i, negative = 0, file_idx, disabled = 0;
  308. #if FFMPEG_OPT_MAP_SYNC
  309. char *sync;
  310. #endif
  311. char *map, *p;
  312. char *allow_unused;
  313. if (*arg == '-') {
  314. negative = 1;
  315. arg++;
  316. }
  317. map = av_strdup(arg);
  318. if (!map)
  319. return AVERROR(ENOMEM);
  320. #if FFMPEG_OPT_MAP_SYNC
  321. /* parse sync stream first, just pick first matching stream */
  322. if (sync = strchr(map, ',')) {
  323. *sync = 0;
  324. av_log(NULL, AV_LOG_WARNING, "Specifying a sync stream is deprecated and has no effect\n");
  325. }
  326. #endif
  327. if (map[0] == '[') {
  328. /* this mapping refers to lavfi output */
  329. const char *c = map + 1;
  330. GROW_ARRAY(o->stream_maps, o->nb_stream_maps);
  331. m = &o->stream_maps[o->nb_stream_maps - 1];
  332. m->linklabel = av_get_token(&c, "]");
  333. if (!m->linklabel) {
  334. av_log(NULL, AV_LOG_ERROR, "Invalid output link label: %s.\n", map);
  335. exit_program(1);
  336. }
  337. } else {
  338. if (allow_unused = strchr(map, '?'))
  339. *allow_unused = 0;
  340. file_idx = strtol(map, &p, 0);
  341. if (file_idx >= nb_input_files || file_idx < 0) {
  342. av_log(NULL, AV_LOG_FATAL, "Invalid input file index: %d.\n", file_idx);
  343. exit_program(1);
  344. }
  345. if (negative)
  346. /* disable some already defined maps */
  347. for (i = 0; i < o->nb_stream_maps; i++) {
  348. m = &o->stream_maps[i];
  349. if (file_idx == m->file_index &&
  350. check_stream_specifier(input_files[m->file_index]->ctx,
  351. input_files[m->file_index]->ctx->streams[m->stream_index],
  352. *p == ':' ? p + 1 : p) > 0)
  353. m->disabled = 1;
  354. }
  355. else
  356. for (i = 0; i < input_files[file_idx]->nb_streams; i++) {
  357. if (check_stream_specifier(input_files[file_idx]->ctx, input_files[file_idx]->ctx->streams[i],
  358. *p == ':' ? p + 1 : p) <= 0)
  359. continue;
  360. if (input_files[file_idx]->streams[i]->user_set_discard == AVDISCARD_ALL) {
  361. disabled = 1;
  362. continue;
  363. }
  364. GROW_ARRAY(o->stream_maps, o->nb_stream_maps);
  365. m = &o->stream_maps[o->nb_stream_maps - 1];
  366. m->file_index = file_idx;
  367. m->stream_index = i;
  368. }
  369. }
  370. if (!m) {
  371. if (allow_unused) {
  372. av_log(NULL, AV_LOG_VERBOSE, "Stream map '%s' matches no streams; ignoring.\n", arg);
  373. } else if (disabled) {
  374. av_log(NULL, AV_LOG_FATAL, "Stream map '%s' matches disabled streams.\n"
  375. "To ignore this, add a trailing '?' to the map.\n", arg);
  376. exit_program(1);
  377. } else {
  378. av_log(NULL, AV_LOG_FATAL, "Stream map '%s' matches no streams.\n"
  379. "To ignore this, add a trailing '?' to the map.\n", arg);
  380. exit_program(1);
  381. }
  382. }
  383. av_freep(&map);
  384. return 0;
  385. }
  386. static int opt_attach(void *optctx, const char *opt, const char *arg)
  387. {
  388. OptionsContext *o = optctx;
  389. GROW_ARRAY(o->attachments, o->nb_attachments);
  390. o->attachments[o->nb_attachments - 1] = arg;
  391. return 0;
  392. }
  393. #if FFMPEG_OPT_MAP_CHANNEL
  394. static int opt_map_channel(void *optctx, const char *opt, const char *arg)
  395. {
  396. OptionsContext *o = optctx;
  397. int n;
  398. AVStream *st;
  399. AudioChannelMap *m;
  400. char *allow_unused;
  401. char *mapchan;
  402. av_log(NULL, AV_LOG_WARNING,
  403. "The -%s option is deprecated and will be removed. "
  404. "It can be replaced by the 'pan' filter, or in some cases by "
  405. "combinations of 'channelsplit', 'channelmap', 'amerge' filters.\n", opt);
  406. mapchan = av_strdup(arg);
  407. if (!mapchan)
  408. return AVERROR(ENOMEM);
  409. GROW_ARRAY(o->audio_channel_maps, o->nb_audio_channel_maps);
  410. m = &o->audio_channel_maps[o->nb_audio_channel_maps - 1];
  411. /* muted channel syntax */
  412. n = sscanf(arg, "%d:%d.%d", &m->channel_idx, &m->ofile_idx, &m->ostream_idx);
  413. if ((n == 1 || n == 3) && m->channel_idx == -1) {
  414. m->file_idx = m->stream_idx = -1;
  415. if (n == 1)
  416. m->ofile_idx = m->ostream_idx = -1;
  417. av_free(mapchan);
  418. return 0;
  419. }
  420. /* normal syntax */
  421. n = sscanf(arg, "%d.%d.%d:%d.%d",
  422. &m->file_idx, &m->stream_idx, &m->channel_idx,
  423. &m->ofile_idx, &m->ostream_idx);
  424. if (n != 3 && n != 5) {
  425. av_log(NULL, AV_LOG_FATAL, "Syntax error, mapchan usage: "
  426. "[file.stream.channel|-1][:syncfile:syncstream]\n");
  427. exit_program(1);
  428. }
  429. if (n != 5) // only file.stream.channel specified
  430. m->ofile_idx = m->ostream_idx = -1;
  431. /* check input */
  432. if (m->file_idx < 0 || m->file_idx >= nb_input_files) {
  433. av_log(NULL, AV_LOG_FATAL, "mapchan: invalid input file index: %d\n",
  434. m->file_idx);
  435. exit_program(1);
  436. }
  437. if (m->stream_idx < 0 ||
  438. m->stream_idx >= input_files[m->file_idx]->nb_streams) {
  439. av_log(NULL, AV_LOG_FATAL, "mapchan: invalid input file stream index #%d.%d\n",
  440. m->file_idx, m->stream_idx);
  441. exit_program(1);
  442. }
  443. st = input_files[m->file_idx]->ctx->streams[m->stream_idx];
  444. if (st->codecpar->codec_type != AVMEDIA_TYPE_AUDIO) {
  445. av_log(NULL, AV_LOG_FATAL, "mapchan: stream #%d.%d is not an audio stream.\n",
  446. m->file_idx, m->stream_idx);
  447. exit_program(1);
  448. }
  449. /* allow trailing ? to map_channel */
  450. if (allow_unused = strchr(mapchan, '?'))
  451. *allow_unused = 0;
  452. if (m->channel_idx < 0 || m->channel_idx >= st->codecpar->ch_layout.nb_channels ||
  453. input_files[m->file_idx]->streams[m->stream_idx]->user_set_discard == AVDISCARD_ALL) {
  454. if (allow_unused) {
  455. av_log(NULL, AV_LOG_VERBOSE, "mapchan: invalid audio channel #%d.%d.%d\n",
  456. m->file_idx, m->stream_idx, m->channel_idx);
  457. } else {
  458. av_log(NULL, AV_LOG_FATAL, "mapchan: invalid audio channel #%d.%d.%d\n"
  459. "To ignore this, add a trailing '?' to the map_channel.\n",
  460. m->file_idx, m->stream_idx, m->channel_idx);
  461. exit_program(1);
  462. }
  463. }
  464. av_free(mapchan);
  465. return 0;
  466. }
  467. #endif
  468. static int opt_sdp_file(void *optctx, const char *opt, const char *arg)
  469. {
  470. av_free(sdp_filename);
  471. sdp_filename = av_strdup(arg);
  472. return 0;
  473. }
  474. #if CONFIG_VAAPI
  475. static int opt_vaapi_device(void *optctx, const char *opt, const char *arg)
  476. {
  477. const char *prefix = "vaapi:";
  478. char *tmp;
  479. int err;
  480. tmp = av_asprintf("%s%s", prefix, arg);
  481. if (!tmp)
  482. return AVERROR(ENOMEM);
  483. err = hw_device_init_from_string(tmp, NULL);
  484. av_free(tmp);
  485. return err;
  486. }
  487. #endif
  488. #if CONFIG_QSV
  489. static int opt_qsv_device(void *optctx, const char *opt, const char *arg)
  490. {
  491. const char *prefix = "qsv=__qsv_device:hw_any,child_device=";
  492. int err;
  493. char *tmp = av_asprintf("%s%s", prefix, arg);
  494. if (!tmp)
  495. return AVERROR(ENOMEM);
  496. err = hw_device_init_from_string(tmp, NULL);
  497. av_free(tmp);
  498. return err;
  499. }
  500. #endif
  501. static int opt_init_hw_device(void *optctx, const char *opt, const char *arg)
  502. {
  503. if (!strcmp(arg, "list")) {
  504. enum AVHWDeviceType type = AV_HWDEVICE_TYPE_NONE;
  505. printf("Supported hardware device types:\n");
  506. while ((type = av_hwdevice_iterate_types(type)) !=
  507. AV_HWDEVICE_TYPE_NONE)
  508. printf("%s\n", av_hwdevice_get_type_name(type));
  509. printf("\n");
  510. exit_program(0);
  511. } else {
  512. return hw_device_init_from_string(arg, NULL);
  513. }
  514. }
  515. static int opt_filter_hw_device(void *optctx, const char *opt, const char *arg)
  516. {
  517. if (filter_hw_device) {
  518. av_log(NULL, AV_LOG_ERROR, "Only one filter device can be used.\n");
  519. return AVERROR(EINVAL);
  520. }
  521. filter_hw_device = hw_device_get_by_name(arg);
  522. if (!filter_hw_device) {
  523. av_log(NULL, AV_LOG_ERROR, "Invalid filter device %s.\n", arg);
  524. return AVERROR(EINVAL);
  525. }
  526. return 0;
  527. }
  528. static int opt_recording_timestamp(void *optctx, const char *opt, const char *arg)
  529. {
  530. OptionsContext *o = optctx;
  531. char buf[128];
  532. int64_t recording_timestamp = parse_time_or_die(opt, arg, 0) / 1E6;
  533. struct tm time = *gmtime((time_t*)&recording_timestamp);
  534. if (!strftime(buf, sizeof(buf), "creation_time=%Y-%m-%dT%H:%M:%S%z", &time))
  535. return -1;
  536. parse_option(o, "metadata", buf, options);
  537. av_log(NULL, AV_LOG_WARNING, "%s is deprecated, set the 'creation_time' metadata "
  538. "tag instead.\n", opt);
  539. return 0;
  540. }
  541. const AVCodec *find_codec_or_die(void *logctx, const char *name,
  542. enum AVMediaType type, int encoder)
  543. {
  544. const AVCodecDescriptor *desc;
  545. const char *codec_string = encoder ? "encoder" : "decoder";
  546. const AVCodec *codec;
  547. codec = encoder ?
  548. avcodec_find_encoder_by_name(name) :
  549. avcodec_find_decoder_by_name(name);
  550. if (!codec && (desc = avcodec_descriptor_get_by_name(name))) {
  551. codec = encoder ? avcodec_find_encoder(desc->id) :
  552. avcodec_find_decoder(desc->id);
  553. if (codec)
  554. av_log(logctx, AV_LOG_VERBOSE, "Matched %s '%s' for codec '%s'.\n",
  555. codec_string, codec->name, desc->name);
  556. }
  557. if (!codec) {
  558. av_log(logctx, AV_LOG_FATAL, "Unknown %s '%s'\n", codec_string, name);
  559. exit_program(1);
  560. }
  561. if (codec->type != type && !recast_media) {
  562. av_log(logctx, AV_LOG_FATAL, "Invalid %s type '%s'\n", codec_string, name);
  563. exit_program(1);
  564. }
  565. return codec;
  566. }
  567. void assert_file_overwrite(const char *filename)
  568. {
  569. const char *proto_name = avio_find_protocol_name(filename);
  570. if (file_overwrite && no_file_overwrite) {
  571. fprintf(stderr, "Error, both -y and -n supplied. Exiting.\n");
  572. exit_program(1);
  573. }
  574. if (!file_overwrite) {
  575. if (proto_name && !strcmp(proto_name, "file") && avio_check(filename, 0) == 0) {
  576. if (stdin_interaction && !no_file_overwrite) {
  577. fprintf(stderr,"File '%s' already exists. Overwrite? [y/N] ", filename);
  578. fflush(stderr);
  579. term_exit();
  580. signal(SIGINT, SIG_DFL);
  581. if (!read_yesno()) {
  582. av_log(NULL, AV_LOG_FATAL, "Not overwriting - exiting\n");
  583. exit_program(1);
  584. }
  585. term_init();
  586. }
  587. else {
  588. av_log(NULL, AV_LOG_FATAL, "File '%s' already exists. Exiting.\n", filename);
  589. exit_program(1);
  590. }
  591. }
  592. }
  593. if (proto_name && !strcmp(proto_name, "file")) {
  594. for (int i = 0; i < nb_input_files; i++) {
  595. InputFile *file = input_files[i];
  596. if (file->ctx->iformat->flags & AVFMT_NOFILE)
  597. continue;
  598. if (!strcmp(filename, file->ctx->url)) {
  599. av_log(NULL, AV_LOG_FATAL, "Output %s same as Input #%d - exiting\n", filename, i);
  600. av_log(NULL, AV_LOG_WARNING, "FFmpeg cannot edit existing files in-place.\n");
  601. exit_program(1);
  602. }
  603. }
  604. }
  605. }
  606. /* read file contents into a string */
  607. char *file_read(const char *filename)
  608. {
  609. AVIOContext *pb = NULL;
  610. int ret = avio_open(&pb, filename, AVIO_FLAG_READ);
  611. AVBPrint bprint;
  612. char *str;
  613. if (ret < 0) {
  614. av_log(NULL, AV_LOG_ERROR, "Error opening file %s.\n", filename);
  615. return NULL;
  616. }
  617. av_bprint_init(&bprint, 0, AV_BPRINT_SIZE_UNLIMITED);
  618. ret = avio_read_to_bprint(pb, &bprint, SIZE_MAX);
  619. avio_closep(&pb);
  620. if (ret < 0) {
  621. av_bprint_finalize(&bprint, NULL);
  622. return NULL;
  623. }
  624. ret = av_bprint_finalize(&bprint, &str);
  625. if (ret < 0)
  626. return NULL;
  627. return str;
  628. }
  629. /* arg format is "output-stream-index:streamid-value". */
  630. static int opt_streamid(void *optctx, const char *opt, const char *arg)
  631. {
  632. OptionsContext *o = optctx;
  633. int idx;
  634. char *p;
  635. char idx_str[16];
  636. av_strlcpy(idx_str, arg, sizeof(idx_str));
  637. p = strchr(idx_str, ':');
  638. if (!p) {
  639. av_log(NULL, AV_LOG_FATAL,
  640. "Invalid value '%s' for option '%s', required syntax is 'index:value'\n",
  641. arg, opt);
  642. exit_program(1);
  643. }
  644. *p++ = '\0';
  645. idx = parse_number_or_die(opt, idx_str, OPT_INT, 0, MAX_STREAMS-1);
  646. o->streamid_map = grow_array(o->streamid_map, sizeof(*o->streamid_map), &o->nb_streamid_map, idx+1);
  647. o->streamid_map[idx] = parse_number_or_die(opt, p, OPT_INT, 0, INT_MAX);
  648. return 0;
  649. }
  650. static int init_complex_filters(void)
  651. {
  652. int i, ret = 0;
  653. for (i = 0; i < nb_filtergraphs; i++) {
  654. ret = init_complex_filtergraph(filtergraphs[i]);
  655. if (ret < 0)
  656. return ret;
  657. }
  658. return 0;
  659. }
  660. static int opt_target(void *optctx, const char *opt, const char *arg)
  661. {
  662. OptionsContext *o = optctx;
  663. enum { PAL, NTSC, FILM, UNKNOWN } norm = UNKNOWN;
  664. static const char *const frame_rates[] = { "25", "30000/1001", "24000/1001" };
  665. if (!strncmp(arg, "pal-", 4)) {
  666. norm = PAL;
  667. arg += 4;
  668. } else if (!strncmp(arg, "ntsc-", 5)) {
  669. norm = NTSC;
  670. arg += 5;
  671. } else if (!strncmp(arg, "film-", 5)) {
  672. norm = FILM;
  673. arg += 5;
  674. } else {
  675. /* Try to determine PAL/NTSC by peeking in the input files */
  676. if (nb_input_files) {
  677. int i, j;
  678. for (j = 0; j < nb_input_files; j++) {
  679. for (i = 0; i < input_files[j]->nb_streams; i++) {
  680. AVStream *st = input_files[j]->ctx->streams[i];
  681. int64_t fr;
  682. if (st->codecpar->codec_type != AVMEDIA_TYPE_VIDEO)
  683. continue;
  684. fr = st->time_base.den * 1000LL / st->time_base.num;
  685. if (fr == 25000) {
  686. norm = PAL;
  687. break;
  688. } else if ((fr == 29970) || (fr == 23976)) {
  689. norm = NTSC;
  690. break;
  691. }
  692. }
  693. if (norm != UNKNOWN)
  694. break;
  695. }
  696. }
  697. if (norm != UNKNOWN)
  698. av_log(NULL, AV_LOG_INFO, "Assuming %s for target.\n", norm == PAL ? "PAL" : "NTSC");
  699. }
  700. if (norm == UNKNOWN) {
  701. av_log(NULL, AV_LOG_FATAL, "Could not determine norm (PAL/NTSC/NTSC-Film) for target.\n");
  702. av_log(NULL, AV_LOG_FATAL, "Please prefix target with \"pal-\", \"ntsc-\" or \"film-\",\n");
  703. av_log(NULL, AV_LOG_FATAL, "or set a framerate with \"-r xxx\".\n");
  704. exit_program(1);
  705. }
  706. if (!strcmp(arg, "vcd")) {
  707. opt_video_codec(o, "c:v", "mpeg1video");
  708. opt_audio_codec(o, "c:a", "mp2");
  709. parse_option(o, "f", "vcd", options);
  710. parse_option(o, "s", norm == PAL ? "352x288" : "352x240", options);
  711. parse_option(o, "r", frame_rates[norm], options);
  712. opt_default(NULL, "g", norm == PAL ? "15" : "18");
  713. opt_default(NULL, "b:v", "1150000");
  714. opt_default(NULL, "maxrate:v", "1150000");
  715. opt_default(NULL, "minrate:v", "1150000");
  716. opt_default(NULL, "bufsize:v", "327680"); // 40*1024*8;
  717. opt_default(NULL, "b:a", "224000");
  718. parse_option(o, "ar", "44100", options);
  719. parse_option(o, "ac", "2", options);
  720. opt_default(NULL, "packetsize", "2324");
  721. opt_default(NULL, "muxrate", "1411200"); // 2352 * 75 * 8;
  722. /* We have to offset the PTS, so that it is consistent with the SCR.
  723. SCR starts at 36000, but the first two packs contain only padding
  724. and the first pack from the other stream, respectively, may also have
  725. been written before.
  726. So the real data starts at SCR 36000+3*1200. */
  727. o->mux_preload = (36000 + 3 * 1200) / 90000.0; // 0.44
  728. } else if (!strcmp(arg, "svcd")) {
  729. opt_video_codec(o, "c:v", "mpeg2video");
  730. opt_audio_codec(o, "c:a", "mp2");
  731. parse_option(o, "f", "svcd", options);
  732. parse_option(o, "s", norm == PAL ? "480x576" : "480x480", options);
  733. parse_option(o, "r", frame_rates[norm], options);
  734. parse_option(o, "pix_fmt", "yuv420p", options);
  735. opt_default(NULL, "g", norm == PAL ? "15" : "18");
  736. opt_default(NULL, "b:v", "2040000");
  737. opt_default(NULL, "maxrate:v", "2516000");
  738. opt_default(NULL, "minrate:v", "0"); // 1145000;
  739. opt_default(NULL, "bufsize:v", "1835008"); // 224*1024*8;
  740. opt_default(NULL, "scan_offset", "1");
  741. opt_default(NULL, "b:a", "224000");
  742. parse_option(o, "ar", "44100", options);
  743. opt_default(NULL, "packetsize", "2324");
  744. } else if (!strcmp(arg, "dvd")) {
  745. opt_video_codec(o, "c:v", "mpeg2video");
  746. opt_audio_codec(o, "c:a", "ac3");
  747. parse_option(o, "f", "dvd", options);
  748. parse_option(o, "s", norm == PAL ? "720x576" : "720x480", options);
  749. parse_option(o, "r", frame_rates[norm], options);
  750. parse_option(o, "pix_fmt", "yuv420p", options);
  751. opt_default(NULL, "g", norm == PAL ? "15" : "18");
  752. opt_default(NULL, "b:v", "6000000");
  753. opt_default(NULL, "maxrate:v", "9000000");
  754. opt_default(NULL, "minrate:v", "0"); // 1500000;
  755. opt_default(NULL, "bufsize:v", "1835008"); // 224*1024*8;
  756. opt_default(NULL, "packetsize", "2048"); // from www.mpucoder.com: DVD sectors contain 2048 bytes of data, this is also the size of one pack.
  757. opt_default(NULL, "muxrate", "10080000"); // from mplex project: data_rate = 1260000. mux_rate = data_rate * 8
  758. opt_default(NULL, "b:a", "448000");
  759. parse_option(o, "ar", "48000", options);
  760. } else if (!strncmp(arg, "dv", 2)) {
  761. parse_option(o, "f", "dv", options);
  762. parse_option(o, "s", norm == PAL ? "720x576" : "720x480", options);
  763. parse_option(o, "pix_fmt", !strncmp(arg, "dv50", 4) ? "yuv422p" :
  764. norm == PAL ? "yuv420p" : "yuv411p", options);
  765. parse_option(o, "r", frame_rates[norm], options);
  766. parse_option(o, "ar", "48000", options);
  767. parse_option(o, "ac", "2", options);
  768. } else {
  769. av_log(NULL, AV_LOG_ERROR, "Unknown target: %s\n", arg);
  770. return AVERROR(EINVAL);
  771. }
  772. av_dict_copy(&o->g->codec_opts, codec_opts, AV_DICT_DONT_OVERWRITE);
  773. av_dict_copy(&o->g->format_opts, format_opts, AV_DICT_DONT_OVERWRITE);
  774. return 0;
  775. }
  776. static int opt_vstats_file(void *optctx, const char *opt, const char *arg)
  777. {
  778. av_free (vstats_filename);
  779. vstats_filename = av_strdup (arg);
  780. return 0;
  781. }
  782. static int opt_vstats(void *optctx, const char *opt, const char *arg)
  783. {
  784. char filename[40];
  785. time_t today2 = time(NULL);
  786. struct tm *today = localtime(&today2);
  787. if (!today) { // maybe tomorrow
  788. av_log(NULL, AV_LOG_FATAL, "Unable to get current time: %s\n", strerror(errno));
  789. exit_program(1);
  790. }
  791. snprintf(filename, sizeof(filename), "vstats_%02d%02d%02d.log", today->tm_hour, today->tm_min,
  792. today->tm_sec);
  793. return opt_vstats_file(NULL, opt, filename);
  794. }
  795. static int opt_video_frames(void *optctx, const char *opt, const char *arg)
  796. {
  797. OptionsContext *o = optctx;
  798. return parse_option(o, "frames:v", arg, options);
  799. }
  800. static int opt_audio_frames(void *optctx, const char *opt, const char *arg)
  801. {
  802. OptionsContext *o = optctx;
  803. return parse_option(o, "frames:a", arg, options);
  804. }
  805. static int opt_data_frames(void *optctx, const char *opt, const char *arg)
  806. {
  807. OptionsContext *o = optctx;
  808. return parse_option(o, "frames:d", arg, options);
  809. }
  810. static int opt_default_new(OptionsContext *o, const char *opt, const char *arg)
  811. {
  812. int ret;
  813. AVDictionary *cbak = codec_opts;
  814. AVDictionary *fbak = format_opts;
  815. codec_opts = NULL;
  816. format_opts = NULL;
  817. ret = opt_default(NULL, opt, arg);
  818. av_dict_copy(&o->g->codec_opts , codec_opts, 0);
  819. av_dict_copy(&o->g->format_opts, format_opts, 0);
  820. av_dict_free(&codec_opts);
  821. av_dict_free(&format_opts);
  822. codec_opts = cbak;
  823. format_opts = fbak;
  824. return ret;
  825. }
  826. static int opt_preset(void *optctx, const char *opt, const char *arg)
  827. {
  828. OptionsContext *o = optctx;
  829. FILE *f=NULL;
  830. char filename[1000], line[1000], tmp_line[1000];
  831. const char *codec_name = NULL;
  832. tmp_line[0] = *opt;
  833. tmp_line[1] = 0;
  834. MATCH_PER_TYPE_OPT(codec_names, str, codec_name, NULL, tmp_line);
  835. if (!(f = get_preset_file(filename, sizeof(filename), arg, *opt == 'f', codec_name))) {
  836. if(!strncmp(arg, "libx264-lossless", strlen("libx264-lossless"))){
  837. av_log(NULL, AV_LOG_FATAL, "Please use -preset <speed> -qp 0\n");
  838. }else
  839. av_log(NULL, AV_LOG_FATAL, "File for preset '%s' not found\n", arg);
  840. exit_program(1);
  841. }
  842. while (fgets(line, sizeof(line), f)) {
  843. char *key = tmp_line, *value, *endptr;
  844. if (strcspn(line, "#\n\r") == 0)
  845. continue;
  846. av_strlcpy(tmp_line, line, sizeof(tmp_line));
  847. if (!av_strtok(key, "=", &value) ||
  848. !av_strtok(value, "\r\n", &endptr)) {
  849. av_log(NULL, AV_LOG_FATAL, "%s: Invalid syntax: '%s'\n", filename, line);
  850. exit_program(1);
  851. }
  852. av_log(NULL, AV_LOG_DEBUG, "ffpreset[%s]: set '%s' = '%s'\n", filename, key, value);
  853. if (!strcmp(key, "acodec")) opt_audio_codec (o, key, value);
  854. else if (!strcmp(key, "vcodec")) opt_video_codec (o, key, value);
  855. else if (!strcmp(key, "scodec")) opt_subtitle_codec(o, key, value);
  856. else if (!strcmp(key, "dcodec")) opt_data_codec (o, key, value);
  857. else if (opt_default_new(o, key, value) < 0) {
  858. av_log(NULL, AV_LOG_FATAL, "%s: Invalid option or argument: '%s', parsed as '%s' = '%s'\n",
  859. filename, line, key, value);
  860. exit_program(1);
  861. }
  862. }
  863. fclose(f);
  864. return 0;
  865. }
  866. static int opt_old2new(void *optctx, const char *opt, const char *arg)
  867. {
  868. OptionsContext *o = optctx;
  869. int ret;
  870. char *s = av_asprintf("%s:%c", opt + 1, *opt);
  871. if (!s)
  872. return AVERROR(ENOMEM);
  873. ret = parse_option(o, s, arg, options);
  874. av_free(s);
  875. return ret;
  876. }
  877. static int opt_bitrate(void *optctx, const char *opt, const char *arg)
  878. {
  879. OptionsContext *o = optctx;
  880. if(!strcmp(opt, "ab")){
  881. av_dict_set(&o->g->codec_opts, "b:a", arg, 0);
  882. return 0;
  883. } else if(!strcmp(opt, "b")){
  884. av_log(NULL, AV_LOG_WARNING, "Please use -b:a or -b:v, -b is ambiguous\n");
  885. av_dict_set(&o->g->codec_opts, "b:v", arg, 0);
  886. return 0;
  887. }
  888. av_dict_set(&o->g->codec_opts, opt, arg, 0);
  889. return 0;
  890. }
  891. static int opt_qscale(void *optctx, const char *opt, const char *arg)
  892. {
  893. OptionsContext *o = optctx;
  894. char *s;
  895. int ret;
  896. if(!strcmp(opt, "qscale")){
  897. av_log(NULL, AV_LOG_WARNING, "Please use -q:a or -q:v, -qscale is ambiguous\n");
  898. return parse_option(o, "q:v", arg, options);
  899. }
  900. s = av_asprintf("q%s", opt + 6);
  901. if (!s)
  902. return AVERROR(ENOMEM);
  903. ret = parse_option(o, s, arg, options);
  904. av_free(s);
  905. return ret;
  906. }
  907. static int opt_profile(void *optctx, const char *opt, const char *arg)
  908. {
  909. OptionsContext *o = optctx;
  910. if(!strcmp(opt, "profile")){
  911. av_log(NULL, AV_LOG_WARNING, "Please use -profile:a or -profile:v, -profile is ambiguous\n");
  912. av_dict_set(&o->g->codec_opts, "profile:v", arg, 0);
  913. return 0;
  914. }
  915. av_dict_set(&o->g->codec_opts, opt, arg, 0);
  916. return 0;
  917. }
  918. static int opt_video_filters(void *optctx, const char *opt, const char *arg)
  919. {
  920. OptionsContext *o = optctx;
  921. return parse_option(o, "filter:v", arg, options);
  922. }
  923. static int opt_audio_filters(void *optctx, const char *opt, const char *arg)
  924. {
  925. OptionsContext *o = optctx;
  926. return parse_option(o, "filter:a", arg, options);
  927. }
  928. static int opt_vsync(void *optctx, const char *opt, const char *arg)
  929. {
  930. av_log(NULL, AV_LOG_WARNING, "-vsync is deprecated. Use -fps_mode\n");
  931. parse_and_set_vsync(arg, &video_sync_method, -1, -1, 1);
  932. return 0;
  933. }
  934. static int opt_timecode(void *optctx, const char *opt, const char *arg)
  935. {
  936. OptionsContext *o = optctx;
  937. int ret;
  938. char *tcr = av_asprintf("timecode=%s", arg);
  939. if (!tcr)
  940. return AVERROR(ENOMEM);
  941. ret = parse_option(o, "metadata:g", tcr, options);
  942. if (ret >= 0)
  943. ret = av_dict_set(&o->g->codec_opts, "gop_timecode", arg, 0);
  944. av_free(tcr);
  945. return ret;
  946. }
  947. static int opt_audio_qscale(void *optctx, const char *opt, const char *arg)
  948. {
  949. OptionsContext *o = optctx;
  950. return parse_option(o, "q:a", arg, options);
  951. }
  952. static int opt_filter_complex(void *optctx, const char *opt, const char *arg)
  953. {
  954. FilterGraph *fg = ALLOC_ARRAY_ELEM(filtergraphs, nb_filtergraphs);
  955. fg->index = nb_filtergraphs - 1;
  956. fg->graph_desc = av_strdup(arg);
  957. if (!fg->graph_desc)
  958. return AVERROR(ENOMEM);
  959. return 0;
  960. }
  961. static int opt_filter_complex_script(void *optctx, const char *opt, const char *arg)
  962. {
  963. FilterGraph *fg;
  964. char *graph_desc = file_read(arg);
  965. if (!graph_desc)
  966. return AVERROR(EINVAL);
  967. fg = ALLOC_ARRAY_ELEM(filtergraphs, nb_filtergraphs);
  968. fg->index = nb_filtergraphs - 1;
  969. fg->graph_desc = graph_desc;
  970. return 0;
  971. }
  972. void show_help_default(const char *opt, const char *arg)
  973. {
  974. /* per-file options have at least one of those set */
  975. const int per_file = OPT_SPEC | OPT_OFFSET | OPT_PERFILE;
  976. int show_advanced = 0, show_avoptions = 0;
  977. if (opt && *opt) {
  978. if (!strcmp(opt, "long"))
  979. show_advanced = 1;
  980. else if (!strcmp(opt, "full"))
  981. show_advanced = show_avoptions = 1;
  982. else
  983. av_log(NULL, AV_LOG_ERROR, "Unknown help option '%s'.\n", opt);
  984. }
  985. show_usage();
  986. printf("Getting help:\n"
  987. " -h -- print basic options\n"
  988. " -h long -- print more options\n"
  989. " -h full -- print all options (including all format and codec specific options, very long)\n"
  990. " -h type=name -- print all options for the named decoder/encoder/demuxer/muxer/filter/bsf/protocol\n"
  991. " See man %s for detailed description of the options.\n"
  992. "\n", program_name);
  993. show_help_options(options, "Print help / information / capabilities:",
  994. OPT_EXIT, 0, 0);
  995. show_help_options(options, "Global options (affect whole program "
  996. "instead of just one file):",
  997. 0, per_file | OPT_EXIT | OPT_EXPERT, 0);
  998. if (show_advanced)
  999. show_help_options(options, "Advanced global options:", OPT_EXPERT,
  1000. per_file | OPT_EXIT, 0);
  1001. show_help_options(options, "Per-file main options:", 0,
  1002. OPT_EXPERT | OPT_AUDIO | OPT_VIDEO | OPT_SUBTITLE |
  1003. OPT_EXIT, per_file);
  1004. if (show_advanced)
  1005. show_help_options(options, "Advanced per-file options:",
  1006. OPT_EXPERT, OPT_AUDIO | OPT_VIDEO | OPT_SUBTITLE, per_file);
  1007. show_help_options(options, "Video options:",
  1008. OPT_VIDEO, OPT_EXPERT | OPT_AUDIO, 0);
  1009. if (show_advanced)
  1010. show_help_options(options, "Advanced Video options:",
  1011. OPT_EXPERT | OPT_VIDEO, OPT_AUDIO, 0);
  1012. show_help_options(options, "Audio options:",
  1013. OPT_AUDIO, OPT_EXPERT | OPT_VIDEO, 0);
  1014. if (show_advanced)
  1015. show_help_options(options, "Advanced Audio options:",
  1016. OPT_EXPERT | OPT_AUDIO, OPT_VIDEO, 0);
  1017. show_help_options(options, "Subtitle options:",
  1018. OPT_SUBTITLE, 0, 0);
  1019. printf("\n");
  1020. if (show_avoptions) {
  1021. int flags = AV_OPT_FLAG_DECODING_PARAM | AV_OPT_FLAG_ENCODING_PARAM;
  1022. show_help_children(avcodec_get_class(), flags);
  1023. show_help_children(avformat_get_class(), flags);
  1024. #if CONFIG_SWSCALE
  1025. show_help_children(sws_get_class(), flags);
  1026. #endif
  1027. #if CONFIG_SWRESAMPLE
  1028. show_help_children(swr_get_class(), AV_OPT_FLAG_AUDIO_PARAM);
  1029. #endif
  1030. show_help_children(avfilter_get_class(), AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_AUDIO_PARAM | AV_OPT_FLAG_FILTERING_PARAM);
  1031. show_help_children(av_bsf_get_class(), AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_AUDIO_PARAM | AV_OPT_FLAG_BSF_PARAM);
  1032. }
  1033. }
  1034. void show_usage(void)
  1035. {
  1036. av_log(NULL, AV_LOG_INFO, "Hyper fast Audio and Video encoder\n");
  1037. av_log(NULL, AV_LOG_INFO, "usage: %s [options] [[infile options] -i infile]... {[outfile options] outfile}...\n", program_name);
  1038. av_log(NULL, AV_LOG_INFO, "\n");
  1039. }
  1040. enum OptGroup {
  1041. GROUP_OUTFILE,
  1042. GROUP_INFILE,
  1043. };
  1044. static const OptionGroupDef groups[] = {
  1045. [GROUP_OUTFILE] = { "output url", NULL, OPT_OUTPUT },
  1046. [GROUP_INFILE] = { "input url", "i", OPT_INPUT },
  1047. };
  1048. static int open_files(OptionGroupList *l, const char *inout,
  1049. int (*open_file)(const OptionsContext*, const char*))
  1050. {
  1051. int i, ret;
  1052. for (i = 0; i < l->nb_groups; i++) {
  1053. OptionGroup *g = &l->groups[i];
  1054. OptionsContext o;
  1055. init_options(&o);
  1056. o.g = g;
  1057. ret = parse_optgroup(&o, g);
  1058. if (ret < 0) {
  1059. av_log(NULL, AV_LOG_ERROR, "Error parsing options for %s file "
  1060. "%s.\n", inout, g->arg);
  1061. uninit_options(&o);
  1062. return ret;
  1063. }
  1064. av_log(NULL, AV_LOG_DEBUG, "Opening an %s file: %s.\n", inout, g->arg);
  1065. ret = open_file(&o, g->arg);
  1066. uninit_options(&o);
  1067. if (ret < 0) {
  1068. av_log(NULL, AV_LOG_ERROR, "Error opening %s file %s.\n",
  1069. inout, g->arg);
  1070. return ret;
  1071. }
  1072. av_log(NULL, AV_LOG_DEBUG, "Successfully opened the file.\n");
  1073. }
  1074. return 0;
  1075. }
  1076. int ffmpeg_parse_options(int argc, char **argv)
  1077. {
  1078. OptionParseContext octx;
  1079. int ret;
  1080. memset(&octx, 0, sizeof(octx));
  1081. /* split the commandline into an internal representation */
  1082. ret = split_commandline(&octx, argc, argv, options, groups,
  1083. FF_ARRAY_ELEMS(groups));
  1084. if (ret < 0) {
  1085. av_log(NULL, AV_LOG_FATAL, "Error splitting the argument list: ");
  1086. goto fail;
  1087. }
  1088. /* apply global options */
  1089. ret = parse_optgroup(NULL, &octx.global_opts);
  1090. if (ret < 0) {
  1091. av_log(NULL, AV_LOG_FATAL, "Error parsing global options: ");
  1092. goto fail;
  1093. }
  1094. /* configure terminal and setup signal handlers */
  1095. term_init();
  1096. /* open input files */
  1097. ret = open_files(&octx.groups[GROUP_INFILE], "input", ifile_open);
  1098. if (ret < 0) {
  1099. av_log(NULL, AV_LOG_FATAL, "Error opening input files: ");
  1100. goto fail;
  1101. }
  1102. /* create the complex filtergraphs */
  1103. ret = init_complex_filters();
  1104. if (ret < 0) {
  1105. av_log(NULL, AV_LOG_FATAL, "Error initializing complex filters.\n");
  1106. goto fail;
  1107. }
  1108. /* open output files */
  1109. ret = open_files(&octx.groups[GROUP_OUTFILE], "output", of_open);
  1110. if (ret < 0) {
  1111. av_log(NULL, AV_LOG_FATAL, "Error opening output files: ");
  1112. goto fail;
  1113. }
  1114. correct_input_start_times();
  1115. apply_sync_offsets();
  1116. check_filter_outputs();
  1117. fail:
  1118. uninit_parse_context(&octx);
  1119. if (ret < 0) {
  1120. av_log(NULL, AV_LOG_FATAL, "%s\n", av_err2str(ret));
  1121. }
  1122. return ret;
  1123. }
  1124. static int opt_progress(void *optctx, const char *opt, const char *arg)
  1125. {
  1126. AVIOContext *avio = NULL;
  1127. int ret;
  1128. if (!strcmp(arg, "-"))
  1129. arg = "pipe:";
  1130. ret = avio_open2(&avio, arg, AVIO_FLAG_WRITE, &int_cb, NULL);
  1131. if (ret < 0) {
  1132. av_log(NULL, AV_LOG_ERROR, "Failed to open progress URL \"%s\": %s\n",
  1133. arg, av_err2str(ret));
  1134. return ret;
  1135. }
  1136. progress_avio = avio;
  1137. return 0;
  1138. }
  1139. int opt_timelimit(void *optctx, const char *opt, const char *arg)
  1140. {
  1141. #if HAVE_SETRLIMIT
  1142. int lim = parse_number_or_die(opt, arg, OPT_INT64, 0, INT_MAX);
  1143. struct rlimit rl = { lim, lim + 1 };
  1144. if (setrlimit(RLIMIT_CPU, &rl))
  1145. perror("setrlimit");
  1146. #else
  1147. av_log(NULL, AV_LOG_WARNING, "-%s not implemented on this OS\n", opt);
  1148. #endif
  1149. return 0;
  1150. }
  1151. #define OFFSET(x) offsetof(OptionsContext, x)
  1152. const OptionDef options[] = {
  1153. /* main options */
  1154. CMDUTILS_COMMON_OPTIONS
  1155. { "f", HAS_ARG | OPT_STRING | OPT_OFFSET |
  1156. OPT_INPUT | OPT_OUTPUT, { .off = OFFSET(format) },
  1157. "force format", "fmt" },
  1158. { "y", OPT_BOOL, { &file_overwrite },
  1159. "overwrite output files" },
  1160. { "n", OPT_BOOL, { &no_file_overwrite },
  1161. "never overwrite output files" },
  1162. { "ignore_unknown", OPT_BOOL, { &ignore_unknown_streams },
  1163. "Ignore unknown stream types" },
  1164. { "copy_unknown", OPT_BOOL | OPT_EXPERT, { &copy_unknown_streams },
  1165. "Copy unknown stream types" },
  1166. { "recast_media", OPT_BOOL | OPT_EXPERT, { &recast_media },
  1167. "allow recasting stream type in order to force a decoder of different media type" },
  1168. { "c", HAS_ARG | OPT_STRING | OPT_SPEC |
  1169. OPT_INPUT | OPT_OUTPUT, { .off = OFFSET(codec_names) },
  1170. "codec name", "codec" },
  1171. { "codec", HAS_ARG | OPT_STRING | OPT_SPEC |
  1172. OPT_INPUT | OPT_OUTPUT, { .off = OFFSET(codec_names) },
  1173. "codec name", "codec" },
  1174. { "pre", HAS_ARG | OPT_STRING | OPT_SPEC |
  1175. OPT_OUTPUT, { .off = OFFSET(presets) },
  1176. "preset name", "preset" },
  1177. { "map", HAS_ARG | OPT_EXPERT | OPT_PERFILE |
  1178. OPT_OUTPUT, { .func_arg = opt_map },
  1179. "set input stream mapping",
  1180. "[-]input_file_id[:stream_specifier][,sync_file_id[:stream_specifier]]" },
  1181. #if FFMPEG_OPT_MAP_CHANNEL
  1182. { "map_channel", HAS_ARG | OPT_EXPERT | OPT_PERFILE | OPT_OUTPUT, { .func_arg = opt_map_channel },
  1183. "map an audio channel from one stream to another (deprecated)", "file.stream.channel[:syncfile.syncstream]" },
  1184. #endif
  1185. { "map_metadata", HAS_ARG | OPT_STRING | OPT_SPEC |
  1186. OPT_OUTPUT, { .off = OFFSET(metadata_map) },
  1187. "set metadata information of outfile from infile",
  1188. "outfile[,metadata]:infile[,metadata]" },
  1189. { "map_chapters", HAS_ARG | OPT_INT | OPT_EXPERT | OPT_OFFSET |
  1190. OPT_OUTPUT, { .off = OFFSET(chapters_input_file) },
  1191. "set chapters mapping", "input_file_index" },
  1192. { "t", HAS_ARG | OPT_TIME | OPT_OFFSET |
  1193. OPT_INPUT | OPT_OUTPUT, { .off = OFFSET(recording_time) },
  1194. "record or transcode \"duration\" seconds of audio/video",
  1195. "duration" },
  1196. { "to", HAS_ARG | OPT_TIME | OPT_OFFSET | OPT_INPUT | OPT_OUTPUT, { .off = OFFSET(stop_time) },
  1197. "record or transcode stop time", "time_stop" },
  1198. { "fs", HAS_ARG | OPT_INT64 | OPT_OFFSET | OPT_OUTPUT, { .off = OFFSET(limit_filesize) },
  1199. "set the limit file size in bytes", "limit_size" },
  1200. { "ss", HAS_ARG | OPT_TIME | OPT_OFFSET |
  1201. OPT_INPUT | OPT_OUTPUT, { .off = OFFSET(start_time) },
  1202. "set the start time offset", "time_off" },
  1203. { "sseof", HAS_ARG | OPT_TIME | OPT_OFFSET |
  1204. OPT_INPUT, { .off = OFFSET(start_time_eof) },
  1205. "set the start time offset relative to EOF", "time_off" },
  1206. { "seek_timestamp", HAS_ARG | OPT_INT | OPT_OFFSET |
  1207. OPT_INPUT, { .off = OFFSET(seek_timestamp) },
  1208. "enable/disable seeking by timestamp with -ss" },
  1209. { "accurate_seek", OPT_BOOL | OPT_OFFSET | OPT_EXPERT |
  1210. OPT_INPUT, { .off = OFFSET(accurate_seek) },
  1211. "enable/disable accurate seeking with -ss" },
  1212. { "isync", HAS_ARG | OPT_INT | OPT_OFFSET |
  1213. OPT_EXPERT | OPT_INPUT, { .off = OFFSET(input_sync_ref) },
  1214. "Indicate the input index for sync reference", "sync ref" },
  1215. { "itsoffset", HAS_ARG | OPT_TIME | OPT_OFFSET |
  1216. OPT_EXPERT | OPT_INPUT, { .off = OFFSET(input_ts_offset) },
  1217. "set the input ts offset", "time_off" },
  1218. { "itsscale", HAS_ARG | OPT_DOUBLE | OPT_SPEC |
  1219. OPT_EXPERT | OPT_INPUT, { .off = OFFSET(ts_scale) },
  1220. "set the input ts scale", "scale" },
  1221. { "timestamp", HAS_ARG | OPT_PERFILE | OPT_OUTPUT, { .func_arg = opt_recording_timestamp },
  1222. "set the recording timestamp ('now' to set the current time)", "time" },
  1223. { "metadata", HAS_ARG | OPT_STRING | OPT_SPEC | OPT_OUTPUT, { .off = OFFSET(metadata) },
  1224. "add metadata", "string=string" },
  1225. { "program", HAS_ARG | OPT_STRING | OPT_SPEC | OPT_OUTPUT, { .off = OFFSET(program) },
  1226. "add program with specified streams", "title=string:st=number..." },
  1227. { "dframes", HAS_ARG | OPT_PERFILE | OPT_EXPERT |
  1228. OPT_OUTPUT, { .func_arg = opt_data_frames },
  1229. "set the number of data frames to output", "number" },
  1230. { "benchmark", OPT_BOOL | OPT_EXPERT, { &do_benchmark },
  1231. "add timings for benchmarking" },
  1232. { "benchmark_all", OPT_BOOL | OPT_EXPERT, { &do_benchmark_all },
  1233. "add timings for each task" },
  1234. { "progress", HAS_ARG | OPT_EXPERT, { .func_arg = opt_progress },
  1235. "write program-readable progress information", "url" },
  1236. { "stdin", OPT_BOOL | OPT_EXPERT, { &stdin_interaction },
  1237. "enable or disable interaction on standard input" },
  1238. { "timelimit", HAS_ARG | OPT_EXPERT, { .func_arg = opt_timelimit },
  1239. "set max runtime in seconds in CPU user time", "limit" },
  1240. { "dump", OPT_BOOL | OPT_EXPERT, { &do_pkt_dump },
  1241. "dump each input packet" },
  1242. { "hex", OPT_BOOL | OPT_EXPERT, { &do_hex_dump },
  1243. "when dumping packets, also dump the payload" },
  1244. { "re", OPT_BOOL | OPT_EXPERT | OPT_OFFSET |
  1245. OPT_INPUT, { .off = OFFSET(rate_emu) },
  1246. "read input at native frame rate; equivalent to -readrate 1", "" },
  1247. { "readrate", HAS_ARG | OPT_FLOAT | OPT_OFFSET |
  1248. OPT_EXPERT | OPT_INPUT, { .off = OFFSET(readrate) },
  1249. "read input at specified rate", "speed" },
  1250. { "target", HAS_ARG | OPT_PERFILE | OPT_OUTPUT, { .func_arg = opt_target },
  1251. "specify target file type (\"vcd\", \"svcd\", \"dvd\", \"dv\" or \"dv50\" "
  1252. "with optional prefixes \"pal-\", \"ntsc-\" or \"film-\")", "type" },
  1253. { "vsync", HAS_ARG | OPT_EXPERT, { .func_arg = opt_vsync },
  1254. "set video sync method globally; deprecated, use -fps_mode", "" },
  1255. { "frame_drop_threshold", HAS_ARG | OPT_FLOAT | OPT_EXPERT, { &frame_drop_threshold },
  1256. "frame drop threshold", "" },
  1257. { "adrift_threshold", HAS_ARG | OPT_FLOAT | OPT_EXPERT, { &audio_drift_threshold },
  1258. "audio drift threshold", "threshold" },
  1259. { "copyts", OPT_BOOL | OPT_EXPERT, { &copy_ts },
  1260. "copy timestamps" },
  1261. { "start_at_zero", OPT_BOOL | OPT_EXPERT, { &start_at_zero },
  1262. "shift input timestamps to start at 0 when using copyts" },
  1263. { "copytb", HAS_ARG | OPT_INT | OPT_EXPERT, { &copy_tb },
  1264. "copy input stream time base when stream copying", "mode" },
  1265. { "shortest", OPT_BOOL | OPT_EXPERT | OPT_OFFSET |
  1266. OPT_OUTPUT, { .off = OFFSET(shortest) },
  1267. "finish encoding within shortest input" },
  1268. { "shortest_buf_duration", HAS_ARG | OPT_FLOAT | OPT_EXPERT | OPT_OFFSET | OPT_OUTPUT, { .off = OFFSET(shortest_buf_duration) },
  1269. "maximum buffering duration (in seconds) for the -shortest option" },
  1270. { "bitexact", OPT_BOOL | OPT_EXPERT | OPT_OFFSET |
  1271. OPT_OUTPUT | OPT_INPUT, { .off = OFFSET(bitexact) },
  1272. "bitexact mode" },
  1273. { "apad", OPT_STRING | HAS_ARG | OPT_SPEC |
  1274. OPT_OUTPUT, { .off = OFFSET(apad) },
  1275. "audio pad", "" },
  1276. { "dts_delta_threshold", HAS_ARG | OPT_FLOAT | OPT_EXPERT, { &dts_delta_threshold },
  1277. "timestamp discontinuity delta threshold", "threshold" },
  1278. { "dts_error_threshold", HAS_ARG | OPT_FLOAT | OPT_EXPERT, { &dts_error_threshold },
  1279. "timestamp error delta threshold", "threshold" },
  1280. { "xerror", OPT_BOOL | OPT_EXPERT, { &exit_on_error },
  1281. "exit on error", "error" },
  1282. { "abort_on", HAS_ARG | OPT_EXPERT, { .func_arg = opt_abort_on },
  1283. "abort on the specified condition flags", "flags" },
  1284. { "copyinkf", OPT_BOOL | OPT_EXPERT | OPT_SPEC |
  1285. OPT_OUTPUT, { .off = OFFSET(copy_initial_nonkeyframes) },
  1286. "copy initial non-keyframes" },
  1287. { "copypriorss", OPT_INT | HAS_ARG | OPT_EXPERT | OPT_SPEC | OPT_OUTPUT, { .off = OFFSET(copy_prior_start) },
  1288. "copy or discard frames before start time" },
  1289. { "frames", OPT_INT64 | HAS_ARG | OPT_SPEC | OPT_OUTPUT, { .off = OFFSET(max_frames) },
  1290. "set the number of frames to output", "number" },
  1291. { "tag", OPT_STRING | HAS_ARG | OPT_SPEC |
  1292. OPT_EXPERT | OPT_OUTPUT | OPT_INPUT, { .off = OFFSET(codec_tags) },
  1293. "force codec tag/fourcc", "fourcc/tag" },
  1294. { "q", HAS_ARG | OPT_EXPERT | OPT_DOUBLE |
  1295. OPT_SPEC | OPT_OUTPUT, { .off = OFFSET(qscale) },
  1296. "use fixed quality scale (VBR)", "q" },
  1297. { "qscale", HAS_ARG | OPT_EXPERT | OPT_PERFILE |
  1298. OPT_OUTPUT, { .func_arg = opt_qscale },
  1299. "use fixed quality scale (VBR)", "q" },
  1300. { "profile", HAS_ARG | OPT_EXPERT | OPT_PERFILE | OPT_OUTPUT, { .func_arg = opt_profile },
  1301. "set profile", "profile" },
  1302. { "filter", HAS_ARG | OPT_STRING | OPT_SPEC | OPT_OUTPUT, { .off = OFFSET(filters) },
  1303. "set stream filtergraph", "filter_graph" },
  1304. { "filter_threads", HAS_ARG, { .func_arg = opt_filter_threads },
  1305. "number of non-complex filter threads" },
  1306. { "filter_script", HAS_ARG | OPT_STRING | OPT_SPEC | OPT_OUTPUT, { .off = OFFSET(filter_scripts) },
  1307. "read stream filtergraph description from a file", "filename" },
  1308. { "reinit_filter", HAS_ARG | OPT_INT | OPT_SPEC | OPT_INPUT, { .off = OFFSET(reinit_filters) },
  1309. "reinit filtergraph on input parameter changes", "" },
  1310. { "filter_complex", HAS_ARG | OPT_EXPERT, { .func_arg = opt_filter_complex },
  1311. "create a complex filtergraph", "graph_description" },
  1312. { "filter_complex_threads", HAS_ARG | OPT_INT, { &filter_complex_nbthreads },
  1313. "number of threads for -filter_complex" },
  1314. { "lavfi", HAS_ARG | OPT_EXPERT, { .func_arg = opt_filter_complex },
  1315. "create a complex filtergraph", "graph_description" },
  1316. { "filter_complex_script", HAS_ARG | OPT_EXPERT, { .func_arg = opt_filter_complex_script },
  1317. "read complex filtergraph description from a file", "filename" },
  1318. { "auto_conversion_filters", OPT_BOOL | OPT_EXPERT, { &auto_conversion_filters },
  1319. "enable automatic conversion filters globally" },
  1320. { "stats", OPT_BOOL, { &print_stats },
  1321. "print progress report during encoding", },
  1322. { "stats_period", HAS_ARG | OPT_EXPERT, { .func_arg = opt_stats_period },
  1323. "set the period at which ffmpeg updates stats and -progress output", "time" },
  1324. { "attach", HAS_ARG | OPT_PERFILE | OPT_EXPERT |
  1325. OPT_OUTPUT, { .func_arg = opt_attach },
  1326. "add an attachment to the output file", "filename" },
  1327. { "dump_attachment", HAS_ARG | OPT_STRING | OPT_SPEC |
  1328. OPT_EXPERT | OPT_INPUT, { .off = OFFSET(dump_attachment) },
  1329. "extract an attachment into a file", "filename" },
  1330. { "stream_loop", OPT_INT | HAS_ARG | OPT_EXPERT | OPT_INPUT |
  1331. OPT_OFFSET, { .off = OFFSET(loop) }, "set number of times input stream shall be looped", "loop count" },
  1332. { "debug_ts", OPT_BOOL | OPT_EXPERT, { &debug_ts },
  1333. "print timestamp debugging info" },
  1334. { "max_error_rate", HAS_ARG | OPT_FLOAT, { &max_error_rate },
  1335. "ratio of decoding errors (0.0: no errors, 1.0: 100% errors) above which ffmpeg returns an error instead of success.", "maximum error rate" },
  1336. { "discard", OPT_STRING | HAS_ARG | OPT_SPEC |
  1337. OPT_INPUT, { .off = OFFSET(discard) },
  1338. "discard", "" },
  1339. { "disposition", OPT_STRING | HAS_ARG | OPT_SPEC |
  1340. OPT_OUTPUT, { .off = OFFSET(disposition) },
  1341. "disposition", "" },
  1342. { "thread_queue_size", HAS_ARG | OPT_INT | OPT_OFFSET | OPT_EXPERT | OPT_INPUT | OPT_OUTPUT,
  1343. { .off = OFFSET(thread_queue_size) },
  1344. "set the maximum number of queued packets from the demuxer" },
  1345. { "find_stream_info", OPT_BOOL | OPT_INPUT | OPT_EXPERT | OPT_OFFSET, { .off = OFFSET(find_stream_info) },
  1346. "read and decode the streams to fill missing information with heuristics" },
  1347. { "bits_per_raw_sample", OPT_INT | HAS_ARG | OPT_EXPERT | OPT_SPEC | OPT_OUTPUT,
  1348. { .off = OFFSET(bits_per_raw_sample) },
  1349. "set the number of bits per raw sample", "number" },
  1350. { "stats_enc_pre", HAS_ARG | OPT_SPEC | OPT_EXPERT | OPT_OUTPUT | OPT_STRING, { .off = OFFSET(enc_stats_pre) },
  1351. "write encoding stats before encoding" },
  1352. { "stats_enc_post", HAS_ARG | OPT_SPEC | OPT_EXPERT | OPT_OUTPUT | OPT_STRING, { .off = OFFSET(enc_stats_post) },
  1353. "write encoding stats after encoding" },
  1354. { "stats_mux_pre", HAS_ARG | OPT_SPEC | OPT_EXPERT | OPT_OUTPUT | OPT_STRING, { .off = OFFSET(mux_stats) },
  1355. "write packets stats before muxing" },
  1356. { "stats_enc_pre_fmt", HAS_ARG | OPT_SPEC | OPT_EXPERT | OPT_OUTPUT | OPT_STRING, { .off = OFFSET(enc_stats_pre_fmt) },
  1357. "format of the stats written with -stats_enc_pre" },
  1358. { "stats_enc_post_fmt", HAS_ARG | OPT_SPEC | OPT_EXPERT | OPT_OUTPUT | OPT_STRING, { .off = OFFSET(enc_stats_post_fmt) },
  1359. "format of the stats written with -stats_enc_post" },
  1360. { "stats_mux_pre_fmt", HAS_ARG | OPT_SPEC | OPT_EXPERT | OPT_OUTPUT | OPT_STRING, { .off = OFFSET(mux_stats_fmt) },
  1361. "format of the stats written with -stats_mux_pre" },
  1362. /* video options */
  1363. { "vframes", OPT_VIDEO | HAS_ARG | OPT_PERFILE | OPT_OUTPUT, { .func_arg = opt_video_frames },
  1364. "set the number of video frames to output", "number" },
  1365. { "r", OPT_VIDEO | HAS_ARG | OPT_STRING | OPT_SPEC |
  1366. OPT_INPUT | OPT_OUTPUT, { .off = OFFSET(frame_rates) },
  1367. "set frame rate (Hz value, fraction or abbreviation)", "rate" },
  1368. { "fpsmax", OPT_VIDEO | HAS_ARG | OPT_STRING | OPT_SPEC |
  1369. OPT_OUTPUT, { .off = OFFSET(max_frame_rates) },
  1370. "set max frame rate (Hz value, fraction or abbreviation)", "rate" },
  1371. { "s", OPT_VIDEO | HAS_ARG | OPT_SUBTITLE | OPT_STRING | OPT_SPEC |
  1372. OPT_INPUT | OPT_OUTPUT, { .off = OFFSET(frame_sizes) },
  1373. "set frame size (WxH or abbreviation)", "size" },
  1374. { "aspect", OPT_VIDEO | HAS_ARG | OPT_STRING | OPT_SPEC |
  1375. OPT_OUTPUT, { .off = OFFSET(frame_aspect_ratios) },
  1376. "set aspect ratio (4:3, 16:9 or 1.3333, 1.7777)", "aspect" },
  1377. { "pix_fmt", OPT_VIDEO | HAS_ARG | OPT_EXPERT | OPT_STRING | OPT_SPEC |
  1378. OPT_INPUT | OPT_OUTPUT, { .off = OFFSET(frame_pix_fmts) },
  1379. "set pixel format", "format" },
  1380. { "display_rotation", OPT_VIDEO | HAS_ARG | OPT_DOUBLE | OPT_SPEC |
  1381. OPT_INPUT, { .off = OFFSET(display_rotations) },
  1382. "set pure counter-clockwise rotation in degrees for stream(s)",
  1383. "angle" },
  1384. { "display_hflip", OPT_VIDEO | OPT_BOOL | OPT_SPEC | OPT_INPUT, { .off = OFFSET(display_hflips) },
  1385. "set display horizontal flip for stream(s) "
  1386. "(overrides any display rotation if it is not set)"},
  1387. { "display_vflip", OPT_VIDEO | OPT_BOOL | OPT_SPEC | OPT_INPUT, { .off = OFFSET(display_vflips) },
  1388. "set display vertical flip for stream(s) "
  1389. "(overrides any display rotation if it is not set)"},
  1390. { "vn", OPT_VIDEO | OPT_BOOL | OPT_OFFSET | OPT_INPUT | OPT_OUTPUT,{ .off = OFFSET(video_disable) },
  1391. "disable video" },
  1392. { "rc_override", OPT_VIDEO | HAS_ARG | OPT_EXPERT | OPT_STRING | OPT_SPEC |
  1393. OPT_OUTPUT, { .off = OFFSET(rc_overrides) },
  1394. "rate control override for specific intervals", "override" },
  1395. { "vcodec", OPT_VIDEO | HAS_ARG | OPT_PERFILE | OPT_INPUT |
  1396. OPT_OUTPUT, { .func_arg = opt_video_codec },
  1397. "force video codec ('copy' to copy stream)", "codec" },
  1398. { "timecode", OPT_VIDEO | HAS_ARG | OPT_PERFILE | OPT_OUTPUT, { .func_arg = opt_timecode },
  1399. "set initial TimeCode value.", "hh:mm:ss[:;.]ff" },
  1400. { "pass", OPT_VIDEO | HAS_ARG | OPT_SPEC | OPT_INT | OPT_OUTPUT, { .off = OFFSET(pass) },
  1401. "select the pass number (1 to 3)", "n" },
  1402. { "passlogfile", OPT_VIDEO | HAS_ARG | OPT_STRING | OPT_EXPERT | OPT_SPEC |
  1403. OPT_OUTPUT, { .off = OFFSET(passlogfiles) },
  1404. "select two pass log file name prefix", "prefix" },
  1405. #if FFMPEG_OPT_PSNR
  1406. { "psnr", OPT_VIDEO | OPT_BOOL | OPT_EXPERT, { &do_psnr },
  1407. "calculate PSNR of compressed frames (deprecated, use -flags +psnr)" },
  1408. #endif
  1409. { "vstats", OPT_VIDEO | OPT_EXPERT , { .func_arg = opt_vstats },
  1410. "dump video coding statistics to file" },
  1411. { "vstats_file", OPT_VIDEO | HAS_ARG | OPT_EXPERT , { .func_arg = opt_vstats_file },
  1412. "dump video coding statistics to file", "file" },
  1413. { "vstats_version", OPT_VIDEO | OPT_INT | HAS_ARG | OPT_EXPERT , { &vstats_version },
  1414. "Version of the vstats format to use."},
  1415. { "vf", OPT_VIDEO | HAS_ARG | OPT_PERFILE | OPT_OUTPUT, { .func_arg = opt_video_filters },
  1416. "set video filters", "filter_graph" },
  1417. { "intra_matrix", OPT_VIDEO | HAS_ARG | OPT_EXPERT | OPT_STRING | OPT_SPEC |
  1418. OPT_OUTPUT, { .off = OFFSET(intra_matrices) },
  1419. "specify intra matrix coeffs", "matrix" },
  1420. { "inter_matrix", OPT_VIDEO | HAS_ARG | OPT_EXPERT | OPT_STRING | OPT_SPEC |
  1421. OPT_OUTPUT, { .off = OFFSET(inter_matrices) },
  1422. "specify inter matrix coeffs", "matrix" },
  1423. { "chroma_intra_matrix", OPT_VIDEO | HAS_ARG | OPT_EXPERT | OPT_STRING | OPT_SPEC |
  1424. OPT_OUTPUT, { .off = OFFSET(chroma_intra_matrices) },
  1425. "specify intra matrix coeffs", "matrix" },
  1426. { "top", OPT_VIDEO | HAS_ARG | OPT_EXPERT | OPT_INT| OPT_SPEC |
  1427. OPT_INPUT | OPT_OUTPUT, { .off = OFFSET(top_field_first) },
  1428. "top=1/bottom=0/auto=-1 field first", "" },
  1429. { "vtag", OPT_VIDEO | HAS_ARG | OPT_EXPERT | OPT_PERFILE |
  1430. OPT_INPUT | OPT_OUTPUT, { .func_arg = opt_old2new },
  1431. "force video tag/fourcc", "fourcc/tag" },
  1432. { "qphist", OPT_VIDEO | OPT_BOOL | OPT_EXPERT , { &qp_hist },
  1433. "show QP histogram" },
  1434. { "fps_mode", OPT_VIDEO | HAS_ARG | OPT_STRING | OPT_EXPERT |
  1435. OPT_SPEC | OPT_OUTPUT, { .off = OFFSET(fps_mode) },
  1436. "set framerate mode for matching video streams; overrides vsync" },
  1437. { "force_fps", OPT_VIDEO | OPT_BOOL | OPT_EXPERT | OPT_SPEC |
  1438. OPT_OUTPUT, { .off = OFFSET(force_fps) },
  1439. "force the selected framerate, disable the best supported framerate selection" },
  1440. { "streamid", OPT_VIDEO | HAS_ARG | OPT_EXPERT | OPT_PERFILE |
  1441. OPT_OUTPUT, { .func_arg = opt_streamid },
  1442. "set the value of an outfile streamid", "streamIndex:value" },
  1443. { "force_key_frames", OPT_VIDEO | OPT_STRING | HAS_ARG | OPT_EXPERT |
  1444. OPT_SPEC | OPT_OUTPUT, { .off = OFFSET(forced_key_frames) },
  1445. "force key frames at specified timestamps", "timestamps" },
  1446. { "b", OPT_VIDEO | HAS_ARG | OPT_PERFILE | OPT_OUTPUT, { .func_arg = opt_bitrate },
  1447. "video bitrate (please use -b:v)", "bitrate" },
  1448. { "hwaccel", OPT_VIDEO | OPT_STRING | HAS_ARG | OPT_EXPERT |
  1449. OPT_SPEC | OPT_INPUT, { .off = OFFSET(hwaccels) },
  1450. "use HW accelerated decoding", "hwaccel name" },
  1451. { "hwaccel_device", OPT_VIDEO | OPT_STRING | HAS_ARG | OPT_EXPERT |
  1452. OPT_SPEC | OPT_INPUT, { .off = OFFSET(hwaccel_devices) },
  1453. "select a device for HW acceleration", "devicename" },
  1454. { "hwaccel_output_format", OPT_VIDEO | OPT_STRING | HAS_ARG | OPT_EXPERT |
  1455. OPT_SPEC | OPT_INPUT, { .off = OFFSET(hwaccel_output_formats) },
  1456. "select output format used with HW accelerated decoding", "format" },
  1457. { "hwaccels", OPT_EXIT, { .func_arg = show_hwaccels },
  1458. "show available HW acceleration methods" },
  1459. { "autorotate", HAS_ARG | OPT_BOOL | OPT_SPEC |
  1460. OPT_EXPERT | OPT_INPUT, { .off = OFFSET(autorotate) },
  1461. "automatically insert correct rotate filters" },
  1462. { "autoscale", HAS_ARG | OPT_BOOL | OPT_SPEC |
  1463. OPT_EXPERT | OPT_OUTPUT, { .off = OFFSET(autoscale) },
  1464. "automatically insert a scale filter at the end of the filter graph" },
  1465. { "fix_sub_duration_heartbeat", OPT_VIDEO | OPT_BOOL | OPT_EXPERT |
  1466. OPT_SPEC | OPT_OUTPUT, { .off = OFFSET(fix_sub_duration_heartbeat) },
  1467. "set this video output stream to be a heartbeat stream for "
  1468. "fix_sub_duration, according to which subtitles should be split at "
  1469. "random access points" },
  1470. /* audio options */
  1471. { "aframes", OPT_AUDIO | HAS_ARG | OPT_PERFILE | OPT_OUTPUT, { .func_arg = opt_audio_frames },
  1472. "set the number of audio frames to output", "number" },
  1473. { "aq", OPT_AUDIO | HAS_ARG | OPT_PERFILE | OPT_OUTPUT, { .func_arg = opt_audio_qscale },
  1474. "set audio quality (codec-specific)", "quality", },
  1475. { "ar", OPT_AUDIO | HAS_ARG | OPT_INT | OPT_SPEC |
  1476. OPT_INPUT | OPT_OUTPUT, { .off = OFFSET(audio_sample_rate) },
  1477. "set audio sampling rate (in Hz)", "rate" },
  1478. { "ac", OPT_AUDIO | HAS_ARG | OPT_INT | OPT_SPEC |
  1479. OPT_INPUT | OPT_OUTPUT, { .off = OFFSET(audio_channels) },
  1480. "set number of audio channels", "channels" },
  1481. { "an", OPT_AUDIO | OPT_BOOL | OPT_OFFSET | OPT_INPUT | OPT_OUTPUT,{ .off = OFFSET(audio_disable) },
  1482. "disable audio" },
  1483. { "acodec", OPT_AUDIO | HAS_ARG | OPT_PERFILE |
  1484. OPT_INPUT | OPT_OUTPUT, { .func_arg = opt_audio_codec },
  1485. "force audio codec ('copy' to copy stream)", "codec" },
  1486. { "ab", OPT_AUDIO | HAS_ARG | OPT_PERFILE | OPT_OUTPUT, { .func_arg = opt_bitrate },
  1487. "audio bitrate (please use -b:a)", "bitrate" },
  1488. { "atag", OPT_AUDIO | HAS_ARG | OPT_EXPERT | OPT_PERFILE |
  1489. OPT_OUTPUT, { .func_arg = opt_old2new },
  1490. "force audio tag/fourcc", "fourcc/tag" },
  1491. { "sample_fmt", OPT_AUDIO | HAS_ARG | OPT_EXPERT | OPT_SPEC |
  1492. OPT_STRING | OPT_INPUT | OPT_OUTPUT, { .off = OFFSET(sample_fmts) },
  1493. "set sample format", "format" },
  1494. { "channel_layout", OPT_AUDIO | HAS_ARG | OPT_EXPERT | OPT_SPEC |
  1495. OPT_STRING | OPT_INPUT | OPT_OUTPUT, { .off = OFFSET(audio_ch_layouts) },
  1496. "set channel layout", "layout" },
  1497. { "ch_layout", OPT_AUDIO | HAS_ARG | OPT_EXPERT | OPT_SPEC |
  1498. OPT_STRING | OPT_INPUT | OPT_OUTPUT, { .off = OFFSET(audio_ch_layouts) },
  1499. "set channel layout", "layout" },
  1500. { "af", OPT_AUDIO | HAS_ARG | OPT_PERFILE | OPT_OUTPUT, { .func_arg = opt_audio_filters },
  1501. "set audio filters", "filter_graph" },
  1502. { "guess_layout_max", OPT_AUDIO | HAS_ARG | OPT_INT | OPT_SPEC | OPT_EXPERT | OPT_INPUT, { .off = OFFSET(guess_layout_max) },
  1503. "set the maximum number of channels to try to guess the channel layout" },
  1504. /* subtitle options */
  1505. { "sn", OPT_SUBTITLE | OPT_BOOL | OPT_OFFSET | OPT_INPUT | OPT_OUTPUT, { .off = OFFSET(subtitle_disable) },
  1506. "disable subtitle" },
  1507. { "scodec", OPT_SUBTITLE | HAS_ARG | OPT_PERFILE | OPT_INPUT | OPT_OUTPUT, { .func_arg = opt_subtitle_codec },
  1508. "force subtitle codec ('copy' to copy stream)", "codec" },
  1509. { "stag", OPT_SUBTITLE | HAS_ARG | OPT_EXPERT | OPT_PERFILE | OPT_OUTPUT, { .func_arg = opt_old2new }
  1510. , "force subtitle tag/fourcc", "fourcc/tag" },
  1511. { "fix_sub_duration", OPT_BOOL | OPT_EXPERT | OPT_SUBTITLE | OPT_SPEC | OPT_INPUT, { .off = OFFSET(fix_sub_duration) },
  1512. "fix subtitles duration" },
  1513. { "canvas_size", OPT_SUBTITLE | HAS_ARG | OPT_STRING | OPT_SPEC | OPT_INPUT, { .off = OFFSET(canvas_sizes) },
  1514. "set canvas size (WxH or abbreviation)", "size" },
  1515. /* muxer options */
  1516. { "muxdelay", OPT_FLOAT | HAS_ARG | OPT_EXPERT | OPT_OFFSET | OPT_OUTPUT, { .off = OFFSET(mux_max_delay) },
  1517. "set the maximum demux-decode delay", "seconds" },
  1518. { "muxpreload", OPT_FLOAT | HAS_ARG | OPT_EXPERT | OPT_OFFSET | OPT_OUTPUT, { .off = OFFSET(mux_preload) },
  1519. "set the initial demux-decode delay", "seconds" },
  1520. { "sdp_file", HAS_ARG | OPT_EXPERT | OPT_OUTPUT, { .func_arg = opt_sdp_file },
  1521. "specify a file in which to print sdp information", "file" },
  1522. { "time_base", HAS_ARG | OPT_STRING | OPT_EXPERT | OPT_SPEC | OPT_OUTPUT, { .off = OFFSET(time_bases) },
  1523. "set the desired time base hint for output stream (1:24, 1:48000 or 0.04166, 2.0833e-5)", "ratio" },
  1524. { "enc_time_base", HAS_ARG | OPT_STRING | OPT_EXPERT | OPT_SPEC | OPT_OUTPUT, { .off = OFFSET(enc_time_bases) },
  1525. "set the desired time base for the encoder (1:24, 1:48000 or 0.04166, 2.0833e-5). "
  1526. "two special values are defined - "
  1527. "0 = use frame rate (video) or sample rate (audio),"
  1528. "-1 = match source time base", "ratio" },
  1529. { "bsf", HAS_ARG | OPT_STRING | OPT_SPEC | OPT_EXPERT | OPT_OUTPUT, { .off = OFFSET(bitstream_filters) },
  1530. "A comma-separated list of bitstream filters", "bitstream_filters" },
  1531. { "absf", HAS_ARG | OPT_AUDIO | OPT_EXPERT| OPT_PERFILE | OPT_OUTPUT, { .func_arg = opt_old2new },
  1532. "deprecated", "audio bitstream_filters" },
  1533. { "vbsf", OPT_VIDEO | HAS_ARG | OPT_EXPERT| OPT_PERFILE | OPT_OUTPUT, { .func_arg = opt_old2new },
  1534. "deprecated", "video bitstream_filters" },
  1535. { "apre", HAS_ARG | OPT_AUDIO | OPT_EXPERT| OPT_PERFILE | OPT_OUTPUT, { .func_arg = opt_preset },
  1536. "set the audio options to the indicated preset", "preset" },
  1537. { "vpre", OPT_VIDEO | HAS_ARG | OPT_EXPERT| OPT_PERFILE | OPT_OUTPUT, { .func_arg = opt_preset },
  1538. "set the video options to the indicated preset", "preset" },
  1539. { "spre", HAS_ARG | OPT_SUBTITLE | OPT_EXPERT| OPT_PERFILE | OPT_OUTPUT, { .func_arg = opt_preset },
  1540. "set the subtitle options to the indicated preset", "preset" },
  1541. { "fpre", HAS_ARG | OPT_EXPERT| OPT_PERFILE | OPT_OUTPUT, { .func_arg = opt_preset },
  1542. "set options from indicated preset file", "filename" },
  1543. { "max_muxing_queue_size", HAS_ARG | OPT_INT | OPT_SPEC | OPT_EXPERT | OPT_OUTPUT, { .off = OFFSET(max_muxing_queue_size) },
  1544. "maximum number of packets that can be buffered while waiting for all streams to initialize", "packets" },
  1545. { "muxing_queue_data_threshold", HAS_ARG | OPT_INT | OPT_SPEC | OPT_EXPERT | OPT_OUTPUT, { .off = OFFSET(muxing_queue_data_threshold) },
  1546. "set the threshold after which max_muxing_queue_size is taken into account", "bytes" },
  1547. /* data codec support */
  1548. { "dcodec", HAS_ARG | OPT_DATA | OPT_PERFILE | OPT_EXPERT | OPT_INPUT | OPT_OUTPUT, { .func_arg = opt_data_codec },
  1549. "force data codec ('copy' to copy stream)", "codec" },
  1550. { "dn", OPT_BOOL | OPT_VIDEO | OPT_OFFSET | OPT_INPUT | OPT_OUTPUT, { .off = OFFSET(data_disable) },
  1551. "disable data" },
  1552. #if CONFIG_VAAPI
  1553. { "vaapi_device", HAS_ARG | OPT_EXPERT, { .func_arg = opt_vaapi_device },
  1554. "set VAAPI hardware device (DRM path or X11 display name)", "device" },
  1555. #endif
  1556. #if CONFIG_QSV
  1557. { "qsv_device", HAS_ARG | OPT_EXPERT, { .func_arg = opt_qsv_device },
  1558. "set QSV hardware device (DirectX adapter index, DRM path or X11 display name)", "device"},
  1559. #endif
  1560. { "init_hw_device", HAS_ARG | OPT_EXPERT, { .func_arg = opt_init_hw_device },
  1561. "initialise hardware device", "args" },
  1562. { "filter_hw_device", HAS_ARG | OPT_EXPERT, { .func_arg = opt_filter_hw_device },
  1563. "set hardware device used when filtering", "device" },
  1564. { NULL, },
  1565. };