FFmpeg
ffmpeg_opt.c
Go to the documentation of this file.
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 
21 #include "config.h"
22 
23 #include <stdint.h>
24 
25 #if HAVE_SYS_RESOURCE_H
26 #include <sys/time.h>
27 #include <sys/resource.h>
28 #endif
29 
30 #include "ffmpeg.h"
31 #include "fopen_utf8.h"
32 #include "cmdutils.h"
33 #include "opt_common.h"
34 
35 #include "libavformat/avformat.h"
36 
37 #include "libavcodec/avcodec.h"
38 #include "libavcodec/bsf.h"
39 
40 #include "libavfilter/avfilter.h"
41 
42 #include "libavutil/avassert.h"
43 #include "libavutil/avstring.h"
44 #include "libavutil/avutil.h"
45 #include "libavutil/bprint.h"
47 #include "libavutil/getenv_utf8.h"
48 #include "libavutil/intreadwrite.h"
49 #include "libavutil/fifo.h"
50 #include "libavutil/mathematics.h"
51 #include "libavutil/opt.h"
52 #include "libavutil/parseutils.h"
53 #include "libavutil/pixdesc.h"
54 #include "libavutil/pixfmt.h"
55 
56 #define DEFAULT_PASS_LOGFILENAME_PREFIX "ffmpeg2pass"
57 
58 #define SPECIFIER_OPT_FMT_str "%s"
59 #define SPECIFIER_OPT_FMT_i "%i"
60 #define SPECIFIER_OPT_FMT_i64 "%"PRId64
61 #define SPECIFIER_OPT_FMT_ui64 "%"PRIu64
62 #define SPECIFIER_OPT_FMT_f "%f"
63 #define SPECIFIER_OPT_FMT_dbl "%lf"
64 
65 static const char *const opt_name_codec_names[] = {"c", "codec", "acodec", "vcodec", "scodec", "dcodec", NULL};
66 static const char *const opt_name_audio_channels[] = {"ac", NULL};
67 static const char *const opt_name_audio_ch_layouts[] = {"channel_layout", "ch_layout", NULL};
68 static const char *const opt_name_audio_sample_rate[] = {"ar", NULL};
69 static const char *const opt_name_frame_rates[] = {"r", NULL};
70 static const char *const opt_name_max_frame_rates[] = {"fpsmax", NULL};
71 static const char *const opt_name_frame_sizes[] = {"s", NULL};
72 static const char *const opt_name_frame_pix_fmts[] = {"pix_fmt", NULL};
73 static const char *const opt_name_ts_scale[] = {"itsscale", NULL};
74 static const char *const opt_name_hwaccels[] = {"hwaccel", NULL};
75 static const char *const opt_name_hwaccel_devices[] = {"hwaccel_device", NULL};
76 static const char *const opt_name_hwaccel_output_formats[] = {"hwaccel_output_format", NULL};
77 static const char *const opt_name_autorotate[] = {"autorotate", NULL};
78 static const char *const opt_name_autoscale[] = {"autoscale", NULL};
79 static const char *const opt_name_max_frames[] = {"frames", "aframes", "vframes", "dframes", NULL};
80 static const char *const opt_name_bitstream_filters[] = {"bsf", "absf", "vbsf", NULL};
81 static const char *const opt_name_codec_tags[] = {"tag", "atag", "vtag", "stag", NULL};
82 static const char *const opt_name_sample_fmts[] = {"sample_fmt", NULL};
83 static const char *const opt_name_qscale[] = {"q", "qscale", NULL};
84 static const char *const opt_name_forced_key_frames[] = {"forced_key_frames", NULL};
85 static const char *const opt_name_fps_mode[] = {"fps_mode", NULL};
86 static const char *const opt_name_force_fps[] = {"force_fps", NULL};
87 static const char *const opt_name_frame_aspect_ratios[] = {"aspect", NULL};
88 static const char *const opt_name_rc_overrides[] = {"rc_override", NULL};
89 static const char *const opt_name_intra_matrices[] = {"intra_matrix", NULL};
90 static const char *const opt_name_inter_matrices[] = {"inter_matrix", NULL};
91 static const char *const opt_name_chroma_intra_matrices[] = {"chroma_intra_matrix", NULL};
92 static const char *const opt_name_top_field_first[] = {"top", NULL};
93 static const char *const opt_name_presets[] = {"pre", "apre", "vpre", "spre", NULL};
94 static const char *const opt_name_copy_initial_nonkeyframes[] = {"copyinkf", NULL};
95 static const char *const opt_name_copy_prior_start[] = {"copypriorss", NULL};
96 static const char *const opt_name_filters[] = {"filter", "af", "vf", NULL};
97 static const char *const opt_name_filter_scripts[] = {"filter_script", NULL};
98 static const char *const opt_name_reinit_filters[] = {"reinit_filter", NULL};
99 static const char *const opt_name_fix_sub_duration[] = {"fix_sub_duration", NULL};
100 static const char *const opt_name_canvas_sizes[] = {"canvas_size", NULL};
101 static const char *const opt_name_pass[] = {"pass", NULL};
102 static const char *const opt_name_passlogfiles[] = {"passlogfile", NULL};
103 static const char *const opt_name_max_muxing_queue_size[] = {"max_muxing_queue_size", NULL};
104 static const char *const opt_name_muxing_queue_data_threshold[] = {"muxing_queue_data_threshold", NULL};
105 static const char *const opt_name_guess_layout_max[] = {"guess_layout_max", NULL};
106 static const char *const opt_name_apad[] = {"apad", NULL};
107 static const char *const opt_name_discard[] = {"discard", NULL};
108 static const char *const opt_name_disposition[] = {"disposition", NULL};
109 static const char *const opt_name_time_bases[] = {"time_base", NULL};
110 static const char *const opt_name_enc_time_bases[] = {"enc_time_base", NULL};
111 static const char *const opt_name_bits_per_raw_sample[] = {"bits_per_raw_sample", NULL};
112 
113 #define WARN_MULTIPLE_OPT_USAGE(name, type, so, st)\
114 {\
115  char namestr[128] = "";\
116  const char *spec = so->specifier && so->specifier[0] ? so->specifier : "";\
117  for (i = 0; opt_name_##name[i]; i++)\
118  av_strlcatf(namestr, sizeof(namestr), "-%s%s", opt_name_##name[i], opt_name_##name[i+1] ? (opt_name_##name[i+2] ? ", " : " or ") : "");\
119  av_log(NULL, AV_LOG_WARNING, "Multiple %s options specified for stream %d, only the last option '-%s%s%s "SPECIFIER_OPT_FMT_##type"' will be used.\n",\
120  namestr, st->index, opt_name_##name[0], spec[0] ? ":" : "", spec, so->u.type);\
121 }
122 
123 #define MATCH_PER_STREAM_OPT(name, type, outvar, fmtctx, st)\
124 {\
125  int i, ret, matches = 0;\
126  SpecifierOpt *so;\
127  for (i = 0; i < o->nb_ ## name; i++) {\
128  char *spec = o->name[i].specifier;\
129  if ((ret = check_stream_specifier(fmtctx, st, spec)) > 0) {\
130  outvar = o->name[i].u.type;\
131  so = &o->name[i];\
132  matches++;\
133  } else if (ret < 0)\
134  exit_program(1);\
135  }\
136  if (matches > 1)\
137  WARN_MULTIPLE_OPT_USAGE(name, type, so, st);\
138 }
139 
140 #define MATCH_PER_TYPE_OPT(name, type, outvar, fmtctx, mediatype)\
141 {\
142  int i;\
143  for (i = 0; i < o->nb_ ## name; i++) {\
144  char *spec = o->name[i].specifier;\
145  if (!strcmp(spec, mediatype))\
146  outvar = o->name[i].u.type;\
147  }\
148 }
149 
151 
154 
157 float dts_error_threshold = 3600*30;
158 
159 int audio_volume = 256;
163 int do_benchmark = 0;
165 int do_hex_dump = 0;
166 int do_pkt_dump = 0;
167 int copy_ts = 0;
169 int copy_tb = -1;
170 int debug_ts = 0;
173 int print_stats = -1;
174 int qp_hist = 0;
176 float max_error_rate = 2.0/3;
181 int64_t stats_period = 500000;
182 
183 
184 static int file_overwrite = 0;
185 static int no_file_overwrite = 0;
186 static int do_psnr = 0;
188 static int ignore_unknown_streams = 0;
189 static int copy_unknown_streams = 0;
190 static int recast_media = 0;
191 static int find_stream_info = 1;
192 
194 {
195  const OptionDef *po = options;
196  int i;
197 
198  /* all OPT_SPEC and OPT_STRING can be freed in generic way */
199  while (po->name) {
200  void *dst = (uint8_t*)o + po->u.off;
201 
202  if (po->flags & OPT_SPEC) {
203  SpecifierOpt **so = dst;
204  int i, *count = (int*)(so + 1);
205  for (i = 0; i < *count; i++) {
206  av_freep(&(*so)[i].specifier);
207  if (po->flags & OPT_STRING)
208  av_freep(&(*so)[i].u.str);
209  }
210  av_freep(so);
211  *count = 0;
212  } else if (po->flags & OPT_OFFSET && po->flags & OPT_STRING)
213  av_freep(dst);
214  po++;
215  }
216 
217  for (i = 0; i < o->nb_stream_maps; i++)
219  av_freep(&o->stream_maps);
221  av_freep(&o->streamid_map);
222  av_freep(&o->attachments);
223 }
224 
226 {
227  memset(o, 0, sizeof(*o));
228 
229  o->stop_time = INT64_MAX;
230  o->mux_max_delay = 0.7;
233  o->recording_time = INT64_MAX;
234  o->limit_filesize = UINT64_MAX;
235  o->chapters_input_file = INT_MAX;
236  o->accurate_seek = 1;
237  o->thread_queue_size = -1;
238  o->input_sync_ref = -1;
239 }
240 
241 static int show_hwaccels(void *optctx, const char *opt, const char *arg)
242 {
244 
245  printf("Hardware acceleration methods:\n");
246  while ((type = av_hwdevice_iterate_types(type)) !=
249  printf("\n");
250  return 0;
251 }
252 
253 /* return a copy of the input with the stream specifiers removed from the keys */
255 {
256  const AVDictionaryEntry *e = NULL;
257  AVDictionary *ret = NULL;
258 
259  while ((e = av_dict_get(dict, "", e, AV_DICT_IGNORE_SUFFIX))) {
260  char *p = strchr(e->key, ':');
261 
262  if (p)
263  *p = 0;
264  av_dict_set(&ret, e->key, e->value, 0);
265  if (p)
266  *p = ':';
267  }
268  return ret;
269 }
270 
271 static int parse_and_set_vsync(const char *arg, int *vsync_var, int file_idx, int st_idx, int is_global)
272 {
273  if (!av_strcasecmp(arg, "cfr")) *vsync_var = VSYNC_CFR;
274  else if (!av_strcasecmp(arg, "vfr")) *vsync_var = VSYNC_VFR;
275  else if (!av_strcasecmp(arg, "passthrough")) *vsync_var = VSYNC_PASSTHROUGH;
276  else if (!av_strcasecmp(arg, "drop")) *vsync_var = VSYNC_DROP;
277  else if (!is_global && !av_strcasecmp(arg, "auto")) *vsync_var = VSYNC_AUTO;
278  else if (!is_global) {
279  av_log(NULL, AV_LOG_FATAL, "Invalid value %s specified for fps_mode of #%d:%d.\n", arg, file_idx, st_idx);
280  exit_program(1);
281  }
282 
283  if (is_global && *vsync_var == VSYNC_AUTO) {
285  av_log(NULL, AV_LOG_WARNING, "Passing a number to -vsync is deprecated,"
286  " use a string argument as described in the manual.\n");
287  }
288  return 0;
289 }
290 
291 static int apply_sync_offsets(void)
292 {
293  for (int i = 0; i < nb_input_files; i++) {
294  InputFile *ref, *self = input_files[i];
295  int64_t adjustment;
296  int64_t self_start_time, ref_start_time, self_seek_start, ref_seek_start;
297  int start_times_set = 1;
298 
299  if (self->input_sync_ref == -1 || self->input_sync_ref == i) continue;
300  if (self->input_sync_ref >= nb_input_files || self->input_sync_ref < -1) {
301  av_log(NULL, AV_LOG_FATAL, "-isync for input %d references non-existent input %d.\n", i, self->input_sync_ref);
302  exit_program(1);
303  }
304 
305  if (copy_ts && !start_at_zero) {
306  av_log(NULL, AV_LOG_FATAL, "Use of -isync requires that start_at_zero be set if copyts is set.\n");
307  exit_program(1);
308  }
309 
310  ref = input_files[self->input_sync_ref];
311  if (ref->input_sync_ref != -1 && ref->input_sync_ref != self->input_sync_ref) {
312  av_log(NULL, AV_LOG_ERROR, "-isync for input %d references a resynced input %d. Sync not set.\n", i, self->input_sync_ref);
313  continue;
314  }
315 
316  if (self->ctx->start_time_realtime != AV_NOPTS_VALUE && ref->ctx->start_time_realtime != AV_NOPTS_VALUE) {
317  self_start_time = self->ctx->start_time_realtime;
318  ref_start_time = ref->ctx->start_time_realtime;
319  } else if (self->ctx->start_time != AV_NOPTS_VALUE && ref->ctx->start_time != AV_NOPTS_VALUE) {
320  self_start_time = self->ctx->start_time;
321  ref_start_time = ref->ctx->start_time;
322  } else {
323  start_times_set = 0;
324  }
325 
326  if (start_times_set) {
327  self_seek_start = self->start_time == AV_NOPTS_VALUE ? 0 : self->start_time;
328  ref_seek_start = ref->start_time == AV_NOPTS_VALUE ? 0 : ref->start_time;
329 
330  adjustment = (self_start_time - ref_start_time) + !copy_ts*(self_seek_start - ref_seek_start) + ref->input_ts_offset;
331 
332  self->ts_offset += adjustment;
333 
334  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);
335  } else {
336  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);
337  }
338  }
339 
340  return 0;
341 }
342 
343 static int opt_filter_threads(void *optctx, const char *opt, const char *arg)
344 {
347  return 0;
348 }
349 
350 static int opt_abort_on(void *optctx, const char *opt, const char *arg)
351 {
352  static const AVOption opts[] = {
353  { "abort_on" , NULL, 0, AV_OPT_TYPE_FLAGS, { .i64 = 0 }, INT64_MIN, INT64_MAX, .unit = "flags" },
354  { "empty_output" , NULL, 0, AV_OPT_TYPE_CONST, { .i64 = ABORT_ON_FLAG_EMPTY_OUTPUT }, .unit = "flags" },
355  { "empty_output_stream", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = ABORT_ON_FLAG_EMPTY_OUTPUT_STREAM }, .unit = "flags" },
356  { NULL },
357  };
358  static const AVClass class = {
359  .class_name = "",
360  .item_name = av_default_item_name,
361  .option = opts,
362  .version = LIBAVUTIL_VERSION_INT,
363  };
364  const AVClass *pclass = &class;
365 
366  return av_opt_eval_flags(&pclass, &opts[0], arg, &abort_on_flags);
367 }
368 
369 static int opt_stats_period(void *optctx, const char *opt, const char *arg)
370 {
371  int64_t user_stats_period = parse_time_or_die(opt, arg, 1);
372 
373  if (user_stats_period <= 0) {
374  av_log(NULL, AV_LOG_ERROR, "stats_period %s must be positive.\n", arg);
375  return AVERROR(EINVAL);
376  }
377 
378  stats_period = user_stats_period;
379  av_log(NULL, AV_LOG_INFO, "ffmpeg stats and -progress period set to %s.\n", arg);
380 
381  return 0;
382 }
383 
384 static int opt_audio_codec(void *optctx, const char *opt, const char *arg)
385 {
386  OptionsContext *o = optctx;
387  return parse_option(o, "codec:a", arg, options);
388 }
389 
390 static int opt_video_codec(void *optctx, const char *opt, const char *arg)
391 {
392  OptionsContext *o = optctx;
393  return parse_option(o, "codec:v", arg, options);
394 }
395 
396 static int opt_subtitle_codec(void *optctx, const char *opt, const char *arg)
397 {
398  OptionsContext *o = optctx;
399  return parse_option(o, "codec:s", arg, options);
400 }
401 
402 static int opt_data_codec(void *optctx, const char *opt, const char *arg)
403 {
404  OptionsContext *o = optctx;
405  return parse_option(o, "codec:d", arg, options);
406 }
407 
408 static int opt_map(void *optctx, const char *opt, const char *arg)
409 {
410  OptionsContext *o = optctx;
411  StreamMap *m = NULL;
412  int i, negative = 0, file_idx, disabled = 0;
413  int sync_file_idx = -1, sync_stream_idx = 0;
414  char *p, *sync;
415  char *map;
416  char *allow_unused;
417 
418  if (*arg == '-') {
419  negative = 1;
420  arg++;
421  }
422  map = av_strdup(arg);
423  if (!map)
424  return AVERROR(ENOMEM);
425 
426  /* parse sync stream first, just pick first matching stream */
427  if (sync = strchr(map, ',')) {
428  *sync = 0;
429  sync_file_idx = strtol(sync + 1, &sync, 0);
430  if (sync_file_idx >= nb_input_files || sync_file_idx < 0) {
431  av_log(NULL, AV_LOG_FATAL, "Invalid sync file index: %d.\n", sync_file_idx);
432  exit_program(1);
433  }
434  if (*sync)
435  sync++;
436  for (i = 0; i < input_files[sync_file_idx]->nb_streams; i++)
437  if (check_stream_specifier(input_files[sync_file_idx]->ctx,
438  input_files[sync_file_idx]->ctx->streams[i], sync) == 1) {
439  sync_stream_idx = i;
440  break;
441  }
442  if (i == input_files[sync_file_idx]->nb_streams) {
443  av_log(NULL, AV_LOG_FATAL, "Sync stream specification in map %s does not "
444  "match any streams.\n", arg);
445  exit_program(1);
446  }
447  if (input_streams[input_files[sync_file_idx]->ist_index + sync_stream_idx]->user_set_discard == AVDISCARD_ALL) {
448  av_log(NULL, AV_LOG_FATAL, "Sync stream specification in map %s matches a disabled input "
449  "stream.\n", arg);
450  exit_program(1);
451  }
452  }
453 
454 
455  if (map[0] == '[') {
456  /* this mapping refers to lavfi output */
457  const char *c = map + 1;
459  m = &o->stream_maps[o->nb_stream_maps - 1];
460  m->linklabel = av_get_token(&c, "]");
461  if (!m->linklabel) {
462  av_log(NULL, AV_LOG_ERROR, "Invalid output link label: %s.\n", map);
463  exit_program(1);
464  }
465  } else {
466  if (allow_unused = strchr(map, '?'))
467  *allow_unused = 0;
468  file_idx = strtol(map, &p, 0);
469  if (file_idx >= nb_input_files || file_idx < 0) {
470  av_log(NULL, AV_LOG_FATAL, "Invalid input file index: %d.\n", file_idx);
471  exit_program(1);
472  }
473  if (negative)
474  /* disable some already defined maps */
475  for (i = 0; i < o->nb_stream_maps; i++) {
476  m = &o->stream_maps[i];
477  if (file_idx == m->file_index &&
480  *p == ':' ? p + 1 : p) > 0)
481  m->disabled = 1;
482  }
483  else
484  for (i = 0; i < input_files[file_idx]->nb_streams; i++) {
485  if (check_stream_specifier(input_files[file_idx]->ctx, input_files[file_idx]->ctx->streams[i],
486  *p == ':' ? p + 1 : p) <= 0)
487  continue;
488  if (input_streams[input_files[file_idx]->ist_index + i]->user_set_discard == AVDISCARD_ALL) {
489  disabled = 1;
490  continue;
491  }
493  m = &o->stream_maps[o->nb_stream_maps - 1];
494 
495  m->file_index = file_idx;
496  m->stream_index = i;
497 
498  if (sync_file_idx >= 0) {
499  m->sync_file_index = sync_file_idx;
500  m->sync_stream_index = sync_stream_idx;
501  } else {
502  m->sync_file_index = file_idx;
503  m->sync_stream_index = i;
504  }
505  }
506  }
507 
508  if (!m) {
509  if (allow_unused) {
510  av_log(NULL, AV_LOG_VERBOSE, "Stream map '%s' matches no streams; ignoring.\n", arg);
511  } else if (disabled) {
512  av_log(NULL, AV_LOG_FATAL, "Stream map '%s' matches disabled streams.\n"
513  "To ignore this, add a trailing '?' to the map.\n", arg);
514  exit_program(1);
515  } else {
516  av_log(NULL, AV_LOG_FATAL, "Stream map '%s' matches no streams.\n"
517  "To ignore this, add a trailing '?' to the map.\n", arg);
518  exit_program(1);
519  }
520  }
521 
522  av_freep(&map);
523  return 0;
524 }
525 
526 static int opt_attach(void *optctx, const char *opt, const char *arg)
527 {
528  OptionsContext *o = optctx;
530  o->attachments[o->nb_attachments - 1] = arg;
531  return 0;
532 }
533 
534 static int opt_map_channel(void *optctx, const char *opt, const char *arg)
535 {
536  OptionsContext *o = optctx;
537  int n;
538  AVStream *st;
539  AudioChannelMap *m;
540  char *allow_unused;
541  char *mapchan;
542  mapchan = av_strdup(arg);
543  if (!mapchan)
544  return AVERROR(ENOMEM);
545 
548 
549  /* muted channel syntax */
550  n = sscanf(arg, "%d:%d.%d", &m->channel_idx, &m->ofile_idx, &m->ostream_idx);
551  if ((n == 1 || n == 3) && m->channel_idx == -1) {
552  m->file_idx = m->stream_idx = -1;
553  if (n == 1)
554  m->ofile_idx = m->ostream_idx = -1;
555  av_free(mapchan);
556  return 0;
557  }
558 
559  /* normal syntax */
560  n = sscanf(arg, "%d.%d.%d:%d.%d",
561  &m->file_idx, &m->stream_idx, &m->channel_idx,
562  &m->ofile_idx, &m->ostream_idx);
563 
564  if (n != 3 && n != 5) {
565  av_log(NULL, AV_LOG_FATAL, "Syntax error, mapchan usage: "
566  "[file.stream.channel|-1][:syncfile:syncstream]\n");
567  exit_program(1);
568  }
569 
570  if (n != 5) // only file.stream.channel specified
571  m->ofile_idx = m->ostream_idx = -1;
572 
573  /* check input */
574  if (m->file_idx < 0 || m->file_idx >= nb_input_files) {
575  av_log(NULL, AV_LOG_FATAL, "mapchan: invalid input file index: %d\n",
576  m->file_idx);
577  exit_program(1);
578  }
579  if (m->stream_idx < 0 ||
581  av_log(NULL, AV_LOG_FATAL, "mapchan: invalid input file stream index #%d.%d\n",
582  m->file_idx, m->stream_idx);
583  exit_program(1);
584  }
585  st = input_files[m->file_idx]->ctx->streams[m->stream_idx];
586  if (st->codecpar->codec_type != AVMEDIA_TYPE_AUDIO) {
587  av_log(NULL, AV_LOG_FATAL, "mapchan: stream #%d.%d is not an audio stream.\n",
588  m->file_idx, m->stream_idx);
589  exit_program(1);
590  }
591  /* allow trailing ? to map_channel */
592  if (allow_unused = strchr(mapchan, '?'))
593  *allow_unused = 0;
594  if (m->channel_idx < 0 || m->channel_idx >= st->codecpar->ch_layout.nb_channels ||
596  if (allow_unused) {
597  av_log(NULL, AV_LOG_VERBOSE, "mapchan: invalid audio channel #%d.%d.%d\n",
598  m->file_idx, m->stream_idx, m->channel_idx);
599  } else {
600  av_log(NULL, AV_LOG_FATAL, "mapchan: invalid audio channel #%d.%d.%d\n"
601  "To ignore this, add a trailing '?' to the map_channel.\n",
602  m->file_idx, m->stream_idx, m->channel_idx);
603  exit_program(1);
604  }
605 
606  }
607  av_free(mapchan);
608  return 0;
609 }
610 
611 static int opt_sdp_file(void *optctx, const char *opt, const char *arg)
612 {
615  return 0;
616 }
617 
618 #if CONFIG_VAAPI
619 static int opt_vaapi_device(void *optctx, const char *opt, const char *arg)
620 {
621  const char *prefix = "vaapi:";
622  char *tmp;
623  int err;
624  tmp = av_asprintf("%s%s", prefix, arg);
625  if (!tmp)
626  return AVERROR(ENOMEM);
628  av_free(tmp);
629  return err;
630 }
631 #endif
632 
633 #if CONFIG_QSV
634 static int opt_qsv_device(void *optctx, const char *opt, const char *arg)
635 {
636  const char *prefix = "qsv=__qsv_device:hw_any,child_device=";
637  int err;
638  char *tmp = av_asprintf("%s%s", prefix, arg);
639 
640  if (!tmp)
641  return AVERROR(ENOMEM);
642 
644  av_free(tmp);
645 
646  return err;
647 }
648 #endif
649 
650 static int opt_init_hw_device(void *optctx, const char *opt, const char *arg)
651 {
652  if (!strcmp(arg, "list")) {
654  printf("Supported hardware device types:\n");
655  while ((type = av_hwdevice_iterate_types(type)) !=
658  printf("\n");
659  exit_program(0);
660  } else {
662  }
663 }
664 
665 static int opt_filter_hw_device(void *optctx, const char *opt, const char *arg)
666 {
667  if (filter_hw_device) {
668  av_log(NULL, AV_LOG_ERROR, "Only one filter device can be used.\n");
669  return AVERROR(EINVAL);
670  }
672  if (!filter_hw_device) {
673  av_log(NULL, AV_LOG_ERROR, "Invalid filter device %s.\n", arg);
674  return AVERROR(EINVAL);
675  }
676  return 0;
677 }
678 
679 /**
680  * Parse a metadata specifier passed as 'arg' parameter.
681  * @param arg metadata string to parse
682  * @param type metadata type is written here -- g(lobal)/s(tream)/c(hapter)/p(rogram)
683  * @param index for type c/p, chapter/program index is written here
684  * @param stream_spec for type s, the stream specifier is written here
685  */
686 static void parse_meta_type(char *arg, char *type, int *index, const char **stream_spec)
687 {
688  if (*arg) {
689  *type = *arg;
690  switch (*arg) {
691  case 'g':
692  break;
693  case 's':
694  if (*(++arg) && *arg != ':') {
695  av_log(NULL, AV_LOG_FATAL, "Invalid metadata specifier %s.\n", arg);
696  exit_program(1);
697  }
698  *stream_spec = *arg == ':' ? arg + 1 : "";
699  break;
700  case 'c':
701  case 'p':
702  if (*(++arg) == ':')
703  *index = strtol(++arg, NULL, 0);
704  break;
705  default:
706  av_log(NULL, AV_LOG_FATAL, "Invalid metadata type %c.\n", *arg);
707  exit_program(1);
708  }
709  } else
710  *type = 'g';
711 }
712 
713 static int copy_metadata(char *outspec, char *inspec, AVFormatContext *oc, AVFormatContext *ic, OptionsContext *o)
714 {
715  AVDictionary **meta_in = NULL;
716  AVDictionary **meta_out = NULL;
717  int i, ret = 0;
718  char type_in, type_out;
719  const char *istream_spec = NULL, *ostream_spec = NULL;
720  int idx_in = 0, idx_out = 0;
721 
722  parse_meta_type(inspec, &type_in, &idx_in, &istream_spec);
723  parse_meta_type(outspec, &type_out, &idx_out, &ostream_spec);
724 
725  if (!ic) {
726  if (type_out == 'g' || !*outspec)
727  o->metadata_global_manual = 1;
728  if (type_out == 's' || !*outspec)
730  if (type_out == 'c' || !*outspec)
732  return 0;
733  }
734 
735  if (type_in == 'g' || type_out == 'g')
736  o->metadata_global_manual = 1;
737  if (type_in == 's' || type_out == 's')
739  if (type_in == 'c' || type_out == 'c')
741 
742  /* ic is NULL when just disabling automatic mappings */
743  if (!ic)
744  return 0;
745 
746 #define METADATA_CHECK_INDEX(index, nb_elems, desc)\
747  if ((index) < 0 || (index) >= (nb_elems)) {\
748  av_log(NULL, AV_LOG_FATAL, "Invalid %s index %d while processing metadata maps.\n",\
749  (desc), (index));\
750  exit_program(1);\
751  }
752 
753 #define SET_DICT(type, meta, context, index)\
754  switch (type) {\
755  case 'g':\
756  meta = &context->metadata;\
757  break;\
758  case 'c':\
759  METADATA_CHECK_INDEX(index, context->nb_chapters, "chapter")\
760  meta = &context->chapters[index]->metadata;\
761  break;\
762  case 'p':\
763  METADATA_CHECK_INDEX(index, context->nb_programs, "program")\
764  meta = &context->programs[index]->metadata;\
765  break;\
766  case 's':\
767  break; /* handled separately below */ \
768  default: av_assert0(0);\
769  }\
770 
771  SET_DICT(type_in, meta_in, ic, idx_in);
772  SET_DICT(type_out, meta_out, oc, idx_out);
773 
774  /* for input streams choose first matching stream */
775  if (type_in == 's') {
776  for (i = 0; i < ic->nb_streams; i++) {
777  if ((ret = check_stream_specifier(ic, ic->streams[i], istream_spec)) > 0) {
778  meta_in = &ic->streams[i]->metadata;
779  break;
780  } else if (ret < 0)
781  exit_program(1);
782  }
783  if (!meta_in) {
784  av_log(NULL, AV_LOG_FATAL, "Stream specifier %s does not match any streams.\n", istream_spec);
785  exit_program(1);
786  }
787  }
788 
789  if (type_out == 's') {
790  for (i = 0; i < oc->nb_streams; i++) {
791  if ((ret = check_stream_specifier(oc, oc->streams[i], ostream_spec)) > 0) {
792  meta_out = &oc->streams[i]->metadata;
793  av_dict_copy(meta_out, *meta_in, AV_DICT_DONT_OVERWRITE);
794  } else if (ret < 0)
795  exit_program(1);
796  }
797  } else
798  av_dict_copy(meta_out, *meta_in, AV_DICT_DONT_OVERWRITE);
799 
800  return 0;
801 }
802 
803 static int opt_recording_timestamp(void *optctx, const char *opt, const char *arg)
804 {
805  OptionsContext *o = optctx;
806  char buf[128];
807  int64_t recording_timestamp = parse_time_or_die(opt, arg, 0) / 1E6;
808  struct tm time = *gmtime((time_t*)&recording_timestamp);
809  if (!strftime(buf, sizeof(buf), "creation_time=%Y-%m-%dT%H:%M:%S%z", &time))
810  return -1;
811  parse_option(o, "metadata", buf, options);
812 
813  av_log(NULL, AV_LOG_WARNING, "%s is deprecated, set the 'creation_time' metadata "
814  "tag instead.\n", opt);
815  return 0;
816 }
817 
818 static const AVCodec *find_codec_or_die(const char *name, enum AVMediaType type, int encoder)
819 {
820  const AVCodecDescriptor *desc;
821  const char *codec_string = encoder ? "encoder" : "decoder";
822  const AVCodec *codec;
823 
824  codec = encoder ?
827 
828  if (!codec && (desc = avcodec_descriptor_get_by_name(name))) {
829  codec = encoder ? avcodec_find_encoder(desc->id) :
831  if (codec)
832  av_log(NULL, AV_LOG_VERBOSE, "Matched %s '%s' for codec '%s'.\n",
833  codec_string, codec->name, desc->name);
834  }
835 
836  if (!codec) {
837  av_log(NULL, AV_LOG_FATAL, "Unknown %s '%s'\n", codec_string, name);
838  exit_program(1);
839  }
840  if (codec->type != type && !recast_media) {
841  av_log(NULL, AV_LOG_FATAL, "Invalid %s type '%s'\n", codec_string, name);
842  exit_program(1);
843  }
844  return codec;
845 }
846 
848 {
849  char *codec_name = NULL;
850 
851  MATCH_PER_STREAM_OPT(codec_names, str, codec_name, s, st);
852  if (codec_name) {
853  const AVCodec *codec = find_codec_or_die(codec_name, st->codecpar->codec_type, 0);
854  st->codecpar->codec_id = codec->id;
855  if (recast_media && st->codecpar->codec_type != codec->type)
856  st->codecpar->codec_type = codec->type;
857  return codec;
858  } else
860 }
861 
862 /* Add all the streams from the given input file to the global
863  * list of input streams. */
865 {
866  int i, ret;
867 
868  for (i = 0; i < ic->nb_streams; i++) {
869  AVStream *st = ic->streams[i];
870  AVCodecParameters *par = st->codecpar;
871  InputStream *ist;
872  char *framerate = NULL, *hwaccel_device = NULL;
873  const char *hwaccel = NULL;
874  char *hwaccel_output_format = NULL;
875  char *codec_tag = NULL;
876  char *next;
877  char *discard_str = NULL;
878  const AVClass *cc = avcodec_get_class();
879  const AVOption *discard_opt = av_opt_find(&cc, "skip_frame", NULL,
881 
883  ist->st = st;
884  ist->file_index = nb_input_files;
885  ist->discard = 1;
886  st->discard = AVDISCARD_ALL;
887  ist->nb_samples = 0;
888  ist->first_dts = AV_NOPTS_VALUE;
889  ist->min_pts = INT64_MAX;
890  ist->max_pts = INT64_MIN;
891 
892  ist->ts_scale = 1.0;
893  MATCH_PER_STREAM_OPT(ts_scale, dbl, ist->ts_scale, ic, st);
894 
895  ist->autorotate = 1;
897 
898  MATCH_PER_STREAM_OPT(codec_tags, str, codec_tag, ic, st);
899  if (codec_tag) {
900  uint32_t tag = strtol(codec_tag, &next, 0);
901  if (*next)
902  tag = AV_RL32(codec_tag);
903  st->codecpar->codec_tag = tag;
904  }
905 
906  ist->dec = choose_decoder(o, ic, st);
907  ist->decoder_opts = filter_codec_opts(o->g->codec_opts, ist->st->codecpar->codec_id, ic, st, ist->dec);
908 
909  ist->reinit_filters = -1;
910  MATCH_PER_STREAM_OPT(reinit_filters, i, ist->reinit_filters, ic, st);
911 
912  MATCH_PER_STREAM_OPT(discard, str, discard_str, ic, st);
914 
915  if ((o->video_disable && ist->st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) ||
920 
921  if (discard_str && av_opt_eval_int(&cc, discard_opt, discard_str, &ist->user_set_discard) < 0) {
922  av_log(NULL, AV_LOG_ERROR, "Error parsing discard %s.\n",
923  discard_str);
924  exit_program(1);
925  }
926 
929 
930  ist->dec_ctx = avcodec_alloc_context3(ist->dec);
931  if (!ist->dec_ctx) {
932  av_log(NULL, AV_LOG_ERROR, "Error allocating the decoder context.\n");
933  exit_program(1);
934  }
935 
937  if (ret < 0) {
938  av_log(NULL, AV_LOG_ERROR, "Error initializing the decoder context.\n");
939  exit_program(1);
940  }
941 
942  ist->decoded_frame = av_frame_alloc();
943  if (!ist->decoded_frame)
944  exit_program(1);
945 
946  ist->pkt = av_packet_alloc();
947  if (!ist->pkt)
948  exit_program(1);
949 
950  if (o->bitexact)
952 
953  switch (par->codec_type) {
954  case AVMEDIA_TYPE_VIDEO:
955  if(!ist->dec)
956  ist->dec = avcodec_find_decoder(par->codec_id);
957 
958  // avformat_find_stream_info() doesn't set this for us anymore.
959  ist->dec_ctx->framerate = st->avg_frame_rate;
960 
961  MATCH_PER_STREAM_OPT(frame_rates, str, framerate, ic, st);
963  framerate) < 0) {
964  av_log(NULL, AV_LOG_ERROR, "Error parsing framerate %s.\n",
965  framerate);
966  exit_program(1);
967  }
968 
969  ist->top_field_first = -1;
970  MATCH_PER_STREAM_OPT(top_field_first, i, ist->top_field_first, ic, st);
971 
972  MATCH_PER_STREAM_OPT(hwaccels, str, hwaccel, ic, st);
973  MATCH_PER_STREAM_OPT(hwaccel_output_formats, str,
974  hwaccel_output_format, ic, st);
975 
976  if (!hwaccel_output_format && hwaccel && !strcmp(hwaccel, "cuvid")) {
978  "WARNING: defaulting hwaccel_output_format to cuda for compatibility "
979  "with old commandlines. This behaviour is DEPRECATED and will be removed "
980  "in the future. Please explicitly set \"-hwaccel_output_format cuda\".\n");
982  } else if (!hwaccel_output_format && hwaccel && !strcmp(hwaccel, "qsv")) {
984  "WARNING: defaulting hwaccel_output_format to qsv for compatibility "
985  "with old commandlines. This behaviour is DEPRECATED and will be removed "
986  "in the future. Please explicitly set \"-hwaccel_output_format qsv\".\n");
988  } else if (hwaccel_output_format) {
989  ist->hwaccel_output_format = av_get_pix_fmt(hwaccel_output_format);
991  av_log(NULL, AV_LOG_FATAL, "Unrecognised hwaccel output "
992  "format: %s", hwaccel_output_format);
993  }
994  } else {
996  }
997 
998  if (hwaccel) {
999  // The NVDEC hwaccels use a CUDA device, so remap the name here.
1000  if (!strcmp(hwaccel, "nvdec") || !strcmp(hwaccel, "cuvid"))
1001  hwaccel = "cuda";
1002 
1003  if (!strcmp(hwaccel, "none"))
1004  ist->hwaccel_id = HWACCEL_NONE;
1005  else if (!strcmp(hwaccel, "auto"))
1006  ist->hwaccel_id = HWACCEL_AUTO;
1007  else {
1009  if (type != AV_HWDEVICE_TYPE_NONE) {
1010  ist->hwaccel_id = HWACCEL_GENERIC;
1011  ist->hwaccel_device_type = type;
1012  }
1013 
1014  if (!ist->hwaccel_id) {
1015  av_log(NULL, AV_LOG_FATAL, "Unrecognized hwaccel: %s.\n",
1016  hwaccel);
1017  av_log(NULL, AV_LOG_FATAL, "Supported hwaccels: ");
1019  while ((type = av_hwdevice_iterate_types(type)) !=
1021  av_log(NULL, AV_LOG_FATAL, "%s ",
1023  av_log(NULL, AV_LOG_FATAL, "\n");
1024  exit_program(1);
1025  }
1026  }
1027  }
1028 
1029  MATCH_PER_STREAM_OPT(hwaccel_devices, str, hwaccel_device, ic, st);
1030  if (hwaccel_device) {
1031  ist->hwaccel_device = av_strdup(hwaccel_device);
1032  if (!ist->hwaccel_device)
1033  exit_program(1);
1034  }
1035 
1037 
1038  break;
1039  case AVMEDIA_TYPE_AUDIO:
1040  ist->guess_layout_max = INT_MAX;
1041  MATCH_PER_STREAM_OPT(guess_layout_max, i, ist->guess_layout_max, ic, st);
1043  break;
1044  case AVMEDIA_TYPE_DATA:
1045  case AVMEDIA_TYPE_SUBTITLE: {
1046  char *canvas_size = NULL;
1047  if(!ist->dec)
1048  ist->dec = avcodec_find_decoder(par->codec_id);
1049  MATCH_PER_STREAM_OPT(fix_sub_duration, i, ist->fix_sub_duration, ic, st);
1050  MATCH_PER_STREAM_OPT(canvas_sizes, str, canvas_size, ic, st);
1051  if (canvas_size &&
1052  av_parse_video_size(&ist->dec_ctx->width, &ist->dec_ctx->height, canvas_size) < 0) {
1053  av_log(NULL, AV_LOG_FATAL, "Invalid canvas size: %s.\n", canvas_size);
1054  exit_program(1);
1055  }
1056  break;
1057  }
1059  case AVMEDIA_TYPE_UNKNOWN:
1060  break;
1061  default:
1062  abort();
1063  }
1064 
1066  if (ret < 0) {
1067  av_log(NULL, AV_LOG_ERROR, "Error initializing the decoder context.\n");
1068  exit_program(1);
1069  }
1070  }
1071 }
1072 
1073 static void assert_file_overwrite(const char *filename)
1074 {
1075  const char *proto_name = avio_find_protocol_name(filename);
1076 
1078  fprintf(stderr, "Error, both -y and -n supplied. Exiting.\n");
1079  exit_program(1);
1080  }
1081 
1082  if (!file_overwrite) {
1083  if (proto_name && !strcmp(proto_name, "file") && avio_check(filename, 0) == 0) {
1085  fprintf(stderr,"File '%s' already exists. Overwrite? [y/N] ", filename);
1086  fflush(stderr);
1087  term_exit();
1088  signal(SIGINT, SIG_DFL);
1089  if (!read_yesno()) {
1090  av_log(NULL, AV_LOG_FATAL, "Not overwriting - exiting\n");
1091  exit_program(1);
1092  }
1093  term_init();
1094  }
1095  else {
1096  av_log(NULL, AV_LOG_FATAL, "File '%s' already exists. Exiting.\n", filename);
1097  exit_program(1);
1098  }
1099  }
1100  }
1101 
1102  if (proto_name && !strcmp(proto_name, "file")) {
1103  for (int i = 0; i < nb_input_files; i++) {
1104  InputFile *file = input_files[i];
1105  if (file->ctx->iformat->flags & AVFMT_NOFILE)
1106  continue;
1107  if (!strcmp(filename, file->ctx->url)) {
1108  av_log(NULL, AV_LOG_FATAL, "Output %s same as Input #%d - exiting\n", filename, i);
1109  av_log(NULL, AV_LOG_WARNING, "FFmpeg cannot edit existing files in-place.\n");
1110  exit_program(1);
1111  }
1112  }
1113  }
1114 }
1115 
1116 static void dump_attachment(AVStream *st, const char *filename)
1117 {
1118  int ret;
1119  AVIOContext *out = NULL;
1120  const AVDictionaryEntry *e;
1121 
1122  if (!st->codecpar->extradata_size) {
1123  av_log(NULL, AV_LOG_WARNING, "No extradata to dump in stream #%d:%d.\n",
1124  nb_input_files - 1, st->index);
1125  return;
1126  }
1127  if (!*filename && (e = av_dict_get(st->metadata, "filename", NULL, 0)))
1128  filename = e->value;
1129  if (!*filename) {
1130  av_log(NULL, AV_LOG_FATAL, "No filename specified and no 'filename' tag"
1131  "in stream #%d:%d.\n", nb_input_files - 1, st->index);
1132  exit_program(1);
1133  }
1134 
1135  assert_file_overwrite(filename);
1136 
1137  if ((ret = avio_open2(&out, filename, AVIO_FLAG_WRITE, &int_cb, NULL)) < 0) {
1138  av_log(NULL, AV_LOG_FATAL, "Could not open file %s for writing.\n",
1139  filename);
1140  exit_program(1);
1141  }
1142 
1144  avio_flush(out);
1145  avio_close(out);
1146 }
1147 
1148 static int open_input_file(OptionsContext *o, const char *filename)
1149 {
1150  InputFile *f;
1151  AVFormatContext *ic;
1152  const AVInputFormat *file_iformat = NULL;
1153  int err, i, ret;
1154  int64_t timestamp;
1155  AVDictionary *unused_opts = NULL;
1156  const AVDictionaryEntry *e = NULL;
1157  char * video_codec_name = NULL;
1158  char * audio_codec_name = NULL;
1159  char *subtitle_codec_name = NULL;
1160  char * data_codec_name = NULL;
1161  int scan_all_pmts_set = 0;
1162 
1163  if (o->stop_time != INT64_MAX && o->recording_time != INT64_MAX) {
1164  o->stop_time = INT64_MAX;
1165  av_log(NULL, AV_LOG_WARNING, "-t and -to cannot be used together; using -t.\n");
1166  }
1167 
1168  if (o->stop_time != INT64_MAX && o->recording_time == INT64_MAX) {
1169  int64_t start_time = o->start_time == AV_NOPTS_VALUE ? 0 : o->start_time;
1170  if (o->stop_time <= start_time) {
1171  av_log(NULL, AV_LOG_ERROR, "-to value smaller than -ss; aborting.\n");
1172  exit_program(1);
1173  } else {
1175  }
1176  }
1177 
1178  if (o->format) {
1179  if (!(file_iformat = av_find_input_format(o->format))) {
1180  av_log(NULL, AV_LOG_FATAL, "Unknown input format: '%s'\n", o->format);
1181  exit_program(1);
1182  }
1183  }
1184 
1185  if (!strcmp(filename, "-"))
1186  filename = "pipe:";
1187 
1188  stdin_interaction &= strncmp(filename, "pipe:", 5) &&
1189  strcmp(filename, "/dev/stdin");
1190 
1191  /* get default parameters from command line */
1192  ic = avformat_alloc_context();
1193  if (!ic) {
1194  print_error(filename, AVERROR(ENOMEM));
1195  exit_program(1);
1196  }
1197  if (o->nb_audio_sample_rate) {
1198  av_dict_set_int(&o->g->format_opts, "sample_rate", o->audio_sample_rate[o->nb_audio_sample_rate - 1].u.i, 0);
1199  }
1200  if (o->nb_audio_channels) {
1201  const AVClass *priv_class;
1202  if (file_iformat && (priv_class = file_iformat->priv_class) &&
1203  av_opt_find(&priv_class, "ch_layout", NULL, 0,
1205  char buf[32];
1206  snprintf(buf, sizeof(buf), "%dC", o->audio_channels[o->nb_audio_channels - 1].u.i);
1207  av_dict_set(&o->g->format_opts, "ch_layout", buf, 0);
1208  }
1209  }
1210  if (o->nb_audio_ch_layouts) {
1211  const AVClass *priv_class;
1212  if (file_iformat && (priv_class = file_iformat->priv_class) &&
1213  av_opt_find(&priv_class, "ch_layout", NULL, 0,
1215  av_dict_set(&o->g->format_opts, "ch_layout", o->audio_ch_layouts[o->nb_audio_ch_layouts - 1].u.str, 0);
1216  }
1217  }
1218  if (o->nb_frame_rates) {
1219  const AVClass *priv_class;
1220  /* set the format-level framerate option;
1221  * this is important for video grabbers, e.g. x11 */
1222  if (file_iformat && (priv_class = file_iformat->priv_class) &&
1223  av_opt_find(&priv_class, "framerate", NULL, 0,
1225  av_dict_set(&o->g->format_opts, "framerate",
1226  o->frame_rates[o->nb_frame_rates - 1].u.str, 0);
1227  }
1228  }
1229  if (o->nb_frame_sizes) {
1230  av_dict_set(&o->g->format_opts, "video_size", o->frame_sizes[o->nb_frame_sizes - 1].u.str, 0);
1231  }
1232  if (o->nb_frame_pix_fmts)
1233  av_dict_set(&o->g->format_opts, "pixel_format", o->frame_pix_fmts[o->nb_frame_pix_fmts - 1].u.str, 0);
1234 
1235  MATCH_PER_TYPE_OPT(codec_names, str, video_codec_name, ic, "v");
1236  MATCH_PER_TYPE_OPT(codec_names, str, audio_codec_name, ic, "a");
1237  MATCH_PER_TYPE_OPT(codec_names, str, subtitle_codec_name, ic, "s");
1238  MATCH_PER_TYPE_OPT(codec_names, str, data_codec_name, ic, "d");
1239 
1240  if (video_codec_name)
1242  if (audio_codec_name)
1244  if (subtitle_codec_name)
1246  if (data_codec_name)
1247  ic->data_codec = find_codec_or_die(data_codec_name , AVMEDIA_TYPE_DATA , 0);
1248 
1252  ic->data_codec_id = data_codec_name ? ic->data_codec->id : AV_CODEC_ID_NONE;
1253 
1254  ic->flags |= AVFMT_FLAG_NONBLOCK;
1255  if (o->bitexact)
1256  ic->flags |= AVFMT_FLAG_BITEXACT;
1257  ic->interrupt_callback = int_cb;
1258 
1259  if (!av_dict_get(o->g->format_opts, "scan_all_pmts", NULL, AV_DICT_MATCH_CASE)) {
1260  av_dict_set(&o->g->format_opts, "scan_all_pmts", "1", AV_DICT_DONT_OVERWRITE);
1261  scan_all_pmts_set = 1;
1262  }
1263  /* open the input file with generic avformat function */
1264  err = avformat_open_input(&ic, filename, file_iformat, &o->g->format_opts);
1265  if (err < 0) {
1266  print_error(filename, err);
1267  if (err == AVERROR_PROTOCOL_NOT_FOUND)
1268  av_log(NULL, AV_LOG_ERROR, "Did you mean file:%s?\n", filename);
1269  exit_program(1);
1270  }
1271  if (scan_all_pmts_set)
1272  av_dict_set(&o->g->format_opts, "scan_all_pmts", NULL, AV_DICT_MATCH_CASE);
1275 
1276  /* apply forced codec ids */
1277  for (i = 0; i < ic->nb_streams; i++)
1278  choose_decoder(o, ic, ic->streams[i]);
1279 
1280  if (find_stream_info) {
1282  int orig_nb_streams = ic->nb_streams;
1283 
1284  /* If not enough info to get the stream parameters, we decode the
1285  first frames to get it. (used in mpeg case for example) */
1287 
1288  for (i = 0; i < orig_nb_streams; i++)
1289  av_dict_free(&opts[i]);
1290  av_freep(&opts);
1291 
1292  if (ret < 0) {
1293  av_log(NULL, AV_LOG_FATAL, "%s: could not find codec parameters\n", filename);
1294  if (ic->nb_streams == 0) {
1295  avformat_close_input(&ic);
1296  exit_program(1);
1297  }
1298  }
1299  }
1300 
1302  av_log(NULL, AV_LOG_WARNING, "Cannot use -ss and -sseof both, using -ss for %s\n", filename);
1304  }
1305 
1306  if (o->start_time_eof != AV_NOPTS_VALUE) {
1307  if (o->start_time_eof >= 0) {
1308  av_log(NULL, AV_LOG_ERROR, "-sseof value must be negative; aborting\n");
1309  exit_program(1);
1310  }
1311  if (ic->duration > 0) {
1312  o->start_time = o->start_time_eof + ic->duration;
1313  if (o->start_time < 0) {
1314  av_log(NULL, AV_LOG_WARNING, "-sseof value seeks to before start of file %s; ignored\n", filename);
1316  }
1317  } else
1318  av_log(NULL, AV_LOG_WARNING, "Cannot use -sseof, duration of %s not known\n", filename);
1319  }
1320  timestamp = (o->start_time == AV_NOPTS_VALUE) ? 0 : o->start_time;
1321  /* add the stream start time */
1322  if (!o->seek_timestamp && ic->start_time != AV_NOPTS_VALUE)
1323  timestamp += ic->start_time;
1324 
1325  /* if seeking requested, we execute it */
1326  if (o->start_time != AV_NOPTS_VALUE) {
1327  int64_t seek_timestamp = timestamp;
1328 
1329  if (!(ic->iformat->flags & AVFMT_SEEK_TO_PTS)) {
1330  int dts_heuristic = 0;
1331  for (i=0; i<ic->nb_streams; i++) {
1332  const AVCodecParameters *par = ic->streams[i]->codecpar;
1333  if (par->video_delay) {
1334  dts_heuristic = 1;
1335  break;
1336  }
1337  }
1338  if (dts_heuristic) {
1339  seek_timestamp -= 3*AV_TIME_BASE / 23;
1340  }
1341  }
1342  ret = avformat_seek_file(ic, -1, INT64_MIN, seek_timestamp, seek_timestamp, 0);
1343  if (ret < 0) {
1344  av_log(NULL, AV_LOG_WARNING, "%s: could not seek to position %0.3f\n",
1345  filename, (double)timestamp / AV_TIME_BASE);
1346  }
1347  }
1348 
1349  /* update the current parameters so that they match the one of the input stream */
1350  add_input_streams(o, ic);
1351 
1352  /* dump the file content */
1353  av_dump_format(ic, nb_input_files, filename, 0);
1354 
1356 
1357  f->ctx = ic;
1358  f->ist_index = nb_input_streams - ic->nb_streams;
1359  f->start_time = o->start_time;
1360  f->recording_time = o->recording_time;
1361  f->input_sync_ref = o->input_sync_ref;
1362  f->input_ts_offset = o->input_ts_offset;
1363  f->ts_offset = o->input_ts_offset - (copy_ts ? (start_at_zero && ic->start_time != AV_NOPTS_VALUE ? ic->start_time : 0) : timestamp);
1364  f->nb_streams = ic->nb_streams;
1365  f->rate_emu = o->rate_emu;
1366  f->accurate_seek = o->accurate_seek;
1367  f->loop = o->loop;
1368  f->duration = 0;
1369  f->time_base = (AVRational){ 1, 1 };
1370 
1371  f->readrate = o->readrate ? o->readrate : 0.0;
1372  if (f->readrate < 0.0f) {
1373  av_log(NULL, AV_LOG_ERROR, "Option -readrate for Input #%d is %0.3f; it must be non-negative.\n", nb_input_files, f->readrate);
1374  exit_program(1);
1375  }
1376  if (f->readrate && f->rate_emu) {
1377  av_log(NULL, AV_LOG_WARNING, "Both -readrate and -re set for Input #%d. Using -readrate %0.3f.\n", nb_input_files, f->readrate);
1378  f->rate_emu = 0;
1379  }
1380 
1381  f->pkt = av_packet_alloc();
1382  if (!f->pkt)
1383  exit_program(1);
1384 #if HAVE_THREADS
1385  f->thread_queue_size = o->thread_queue_size;
1386 #endif
1387 
1388  /* check if all codec options have been used */
1389  unused_opts = strip_specifiers(o->g->codec_opts);
1390  for (i = f->ist_index; i < nb_input_streams; i++) {
1391  e = NULL;
1392  while ((e = av_dict_get(input_streams[i]->decoder_opts, "", e,
1394  av_dict_set(&unused_opts, e->key, NULL, 0);
1395  }
1396 
1397  e = NULL;
1398  while ((e = av_dict_get(unused_opts, "", e, AV_DICT_IGNORE_SUFFIX))) {
1399  const AVClass *class = avcodec_get_class();
1400  const AVOption *option = av_opt_find(&class, e->key, NULL, 0,
1402  const AVClass *fclass = avformat_get_class();
1403  const AVOption *foption = av_opt_find(&fclass, e->key, NULL, 0,
1405  if (!option || foption)
1406  continue;
1407 
1408 
1409  if (!(option->flags & AV_OPT_FLAG_DECODING_PARAM)) {
1410  av_log(NULL, AV_LOG_ERROR, "Codec AVOption %s (%s) specified for "
1411  "input file #%d (%s) is not a decoding option.\n", e->key,
1412  option->help ? option->help : "", nb_input_files - 1,
1413  filename);
1414  exit_program(1);
1415  }
1416 
1417  av_log(NULL, AV_LOG_WARNING, "Codec AVOption %s (%s) specified for "
1418  "input file #%d (%s) has not been used for any stream. The most "
1419  "likely reason is either wrong type (e.g. a video option with "
1420  "no video streams) or that it is a private option of some decoder "
1421  "which was not actually used for any stream.\n", e->key,
1422  option->help ? option->help : "", nb_input_files - 1, filename);
1423  }
1424  av_dict_free(&unused_opts);
1425 
1426  for (i = 0; i < o->nb_dump_attachment; i++) {
1427  int j;
1428 
1429  for (j = 0; j < ic->nb_streams; j++) {
1430  AVStream *st = ic->streams[j];
1431 
1432  if (check_stream_specifier(ic, st, o->dump_attachment[i].specifier) == 1)
1434  }
1435  }
1436 
1438 
1439  return 0;
1440 }
1441 
1442 static char *get_line(AVIOContext *s, AVBPrint *bprint)
1443 {
1444  char c;
1445 
1446  while ((c = avio_r8(s)) && c != '\n')
1447  av_bprint_chars(bprint, c, 1);
1448 
1449  if (!av_bprint_is_complete(bprint)) {
1450  av_log(NULL, AV_LOG_FATAL, "Could not alloc buffer for reading preset.\n");
1451  exit_program(1);
1452  }
1453  return bprint->str;
1454 }
1455 
1456 static int get_preset_file_2(const char *preset_name, const char *codec_name, AVIOContext **s)
1457 {
1458  int i, ret = -1;
1459  char filename[1000];
1460  char *env_avconv_datadir = getenv_utf8("AVCONV_DATADIR");
1461  char *env_home = getenv_utf8("HOME");
1462  const char *base[3] = { env_avconv_datadir,
1463  env_home,
1464  AVCONV_DATADIR,
1465  };
1466 
1467  for (i = 0; i < FF_ARRAY_ELEMS(base) && ret < 0; i++) {
1468  if (!base[i])
1469  continue;
1470  if (codec_name) {
1471  snprintf(filename, sizeof(filename), "%s%s/%s-%s.avpreset", base[i],
1472  i != 1 ? "" : "/.avconv", codec_name, preset_name);
1473  ret = avio_open2(s, filename, AVIO_FLAG_READ, &int_cb, NULL);
1474  }
1475  if (ret < 0) {
1476  snprintf(filename, sizeof(filename), "%s%s/%s.avpreset", base[i],
1477  i != 1 ? "" : "/.avconv", preset_name);
1478  ret = avio_open2(s, filename, AVIO_FLAG_READ, &int_cb, NULL);
1479  }
1480  }
1481  freeenv_utf8(env_home);
1482  freeenv_utf8(env_avconv_datadir);
1483  return ret;
1484 }
1485 
1487 {
1488  enum AVMediaType type = ost->st->codecpar->codec_type;
1489  char *codec_name = NULL;
1490 
1492  MATCH_PER_STREAM_OPT(codec_names, str, codec_name, s, ost->st);
1493  if (!codec_name) {
1494  ost->st->codecpar->codec_id = av_guess_codec(s->oformat, NULL, s->url,
1495  NULL, ost->st->codecpar->codec_type);
1497  if (!ost->enc) {
1498  av_log(NULL, AV_LOG_FATAL, "Automatic encoder selection failed for "
1499  "output stream #%d:%d. Default encoder for format %s (codec %s) is "
1500  "probably disabled. Please choose an encoder manually.\n",
1501  ost->file_index, ost->index, s->oformat->name,
1504  }
1505  } else if (!strcmp(codec_name, "copy"))
1506  ost->stream_copy = 1;
1507  else {
1508  ost->enc = find_codec_or_die(codec_name, ost->st->codecpar->codec_type, 1);
1509  ost->st->codecpar->codec_id = ost->enc->id;
1510  }
1511  ost->encoding_needed = !ost->stream_copy;
1512  } else {
1513  /* no encoding supported for other media types */
1514  ost->stream_copy = 1;
1515  ost->encoding_needed = 0;
1516  }
1517 
1518  return 0;
1519 }
1520 
1522 {
1523  OutputStream *ost;
1524  AVStream *st = avformat_new_stream(oc, NULL);
1525  int idx = oc->nb_streams - 1, ret = 0;
1526  const char *bsfs = NULL, *time_base = NULL;
1527  char *next, *codec_tag = NULL;
1528  double qscale = -1;
1529  int i;
1530 
1531  if (!st) {
1532  av_log(NULL, AV_LOG_FATAL, "Could not alloc stream.\n");
1533  exit_program(1);
1534  }
1535 
1536  if (oc->nb_streams - 1 < o->nb_streamid_map)
1537  st->id = o->streamid_map[oc->nb_streams - 1];
1538 
1540 
1541  ost->file_index = nb_output_files - 1;
1542  ost->index = idx;
1543  ost->st = st;
1544  ost->forced_kf_ref_pts = AV_NOPTS_VALUE;
1545  st->codecpar->codec_type = type;
1546 
1547  ret = choose_encoder(o, oc, ost);
1548  if (ret < 0) {
1549  av_log(NULL, AV_LOG_FATAL, "Error selecting an encoder for stream "
1550  "%d:%d\n", ost->file_index, ost->index);
1551  exit_program(1);
1552  }
1553 
1554  ost->enc_ctx = avcodec_alloc_context3(ost->enc);
1555  if (!ost->enc_ctx) {
1556  av_log(NULL, AV_LOG_ERROR, "Error allocating the encoding context.\n");
1557  exit_program(1);
1558  }
1559  ost->enc_ctx->codec_type = type;
1560 
1561  ost->ref_par = avcodec_parameters_alloc();
1562  if (!ost->ref_par) {
1563  av_log(NULL, AV_LOG_ERROR, "Error allocating the encoding parameters.\n");
1564  exit_program(1);
1565  }
1566 
1567  ost->filtered_frame = av_frame_alloc();
1568  if (!ost->filtered_frame)
1569  exit_program(1);
1570 
1571  ost->pkt = av_packet_alloc();
1572  if (!ost->pkt)
1573  exit_program(1);
1574 
1575  if (ost->enc) {
1576  AVIOContext *s = NULL;
1577  char *buf = NULL, *arg = NULL, *preset = NULL;
1578 
1579  ost->encoder_opts = filter_codec_opts(o->g->codec_opts, ost->enc->id, oc, st, ost->enc);
1580 
1582  ost->autoscale = 1;
1583  MATCH_PER_STREAM_OPT(autoscale, i, ost->autoscale, oc, st);
1584  if (preset && (!(ret = get_preset_file_2(preset, ost->enc->name, &s)))) {
1585  AVBPrint bprint;
1587  do {
1588  av_bprint_clear(&bprint);
1589  buf = get_line(s, &bprint);
1590  if (!buf[0] || buf[0] == '#')
1591  continue;
1592  if (!(arg = strchr(buf, '='))) {
1593  av_log(NULL, AV_LOG_FATAL, "Invalid line found in the preset file.\n");
1594  exit_program(1);
1595  }
1596  *arg++ = 0;
1597  av_dict_set(&ost->encoder_opts, buf, arg, AV_DICT_DONT_OVERWRITE);
1598  } while (!s->eof_reached);
1599  av_bprint_finalize(&bprint, NULL);
1600  avio_closep(&s);
1601  }
1602  if (ret) {
1604  "Preset %s specified for stream %d:%d, but could not be opened.\n",
1605  preset, ost->file_index, ost->index);
1606  exit_program(1);
1607  }
1608  } else {
1609  ost->encoder_opts = filter_codec_opts(o->g->codec_opts, AV_CODEC_ID_NONE, oc, st, NULL);
1610  }
1611 
1612 
1613  if (o->bitexact)
1614  ost->enc_ctx->flags |= AV_CODEC_FLAG_BITEXACT;
1615 
1616  MATCH_PER_STREAM_OPT(time_bases, str, time_base, oc, st);
1617  if (time_base) {
1618  AVRational q;
1619  if (av_parse_ratio(&q, time_base, INT_MAX, 0, NULL) < 0 ||
1620  q.num <= 0 || q.den <= 0) {
1621  av_log(NULL, AV_LOG_FATAL, "Invalid time base: %s\n", time_base);
1622  exit_program(1);
1623  }
1624  st->time_base = q;
1625  }
1626 
1627  MATCH_PER_STREAM_OPT(enc_time_bases, str, time_base, oc, st);
1628  if (time_base) {
1629  AVRational q;
1630  if (av_parse_ratio(&q, time_base, INT_MAX, 0, NULL) < 0 ||
1631  q.den <= 0) {
1632  av_log(NULL, AV_LOG_FATAL, "Invalid time base: %s\n", time_base);
1633  exit_program(1);
1634  }
1635  ost->enc_timebase = q;
1636  }
1637 
1638  ost->max_frames = INT64_MAX;
1639  MATCH_PER_STREAM_OPT(max_frames, i64, ost->max_frames, oc, st);
1640  for (i = 0; i<o->nb_max_frames; i++) {
1641  char *p = o->max_frames[i].specifier;
1642  if (!*p && type != AVMEDIA_TYPE_VIDEO) {
1643  av_log(NULL, AV_LOG_WARNING, "Applying unspecific -frames to non video streams, maybe you meant -vframes ?\n");
1644  break;
1645  }
1646  }
1647 
1648  ost->copy_prior_start = -1;
1649  MATCH_PER_STREAM_OPT(copy_prior_start, i, ost->copy_prior_start, oc ,st);
1650 
1651  MATCH_PER_STREAM_OPT(bitstream_filters, str, bsfs, oc, st);
1652  if (bsfs && *bsfs) {
1653  ret = av_bsf_list_parse_str(bsfs, &ost->bsf_ctx);
1654  if (ret < 0) {
1655  av_log(NULL, AV_LOG_ERROR, "Error parsing bitstream filter sequence '%s': %s\n", bsfs, av_err2str(ret));
1656  exit_program(1);
1657  }
1658  }
1659 
1660  MATCH_PER_STREAM_OPT(codec_tags, str, codec_tag, oc, st);
1661  if (codec_tag) {
1662  uint32_t tag = strtol(codec_tag, &next, 0);
1663  if (*next)
1664  tag = AV_RL32(codec_tag);
1665  ost->st->codecpar->codec_tag =
1666  ost->enc_ctx->codec_tag = tag;
1667  }
1668 
1669  MATCH_PER_STREAM_OPT(qscale, dbl, qscale, oc, st);
1670  if (qscale >= 0) {
1671  ost->enc_ctx->flags |= AV_CODEC_FLAG_QSCALE;
1672  ost->enc_ctx->global_quality = FF_QP2LAMBDA * qscale;
1673  }
1674 
1675  MATCH_PER_STREAM_OPT(disposition, str, ost->disposition, oc, st);
1677 
1678  ost->max_muxing_queue_size = 128;
1679  MATCH_PER_STREAM_OPT(max_muxing_queue_size, i, ost->max_muxing_queue_size, oc, st);
1680 
1681  ost->muxing_queue_data_size = 0;
1682 
1683  ost->muxing_queue_data_threshold = 50*1024*1024;
1684  MATCH_PER_STREAM_OPT(muxing_queue_data_threshold, i, ost->muxing_queue_data_threshold, oc, st);
1685 
1686  MATCH_PER_STREAM_OPT(bits_per_raw_sample, i, ost->bits_per_raw_sample,
1687  oc, st);
1688 
1689  if (oc->oformat->flags & AVFMT_GLOBALHEADER)
1690  ost->enc_ctx->flags |= AV_CODEC_FLAG_GLOBAL_HEADER;
1691 
1692  av_dict_copy(&ost->sws_dict, o->g->sws_dict, 0);
1693 
1694  av_dict_copy(&ost->swr_opts, o->g->swr_opts, 0);
1695  if (ost->enc && av_get_exact_bits_per_sample(ost->enc->id) == 24)
1696  av_dict_set(&ost->swr_opts, "output_sample_bits", "24", 0);
1697 
1698  ost->source_index = source_index;
1699  if (source_index >= 0) {
1700  ost->sync_ist = input_streams[source_index];
1701  input_streams[source_index]->discard = 0;
1702  input_streams[source_index]->st->discard = input_streams[source_index]->user_set_discard;
1703  }
1704  ost->last_mux_dts = AV_NOPTS_VALUE;
1705 
1706  ost->muxing_queue = av_fifo_alloc2(8, sizeof(AVPacket*), 0);
1707  if (!ost->muxing_queue)
1708  exit_program(1);
1709 
1710  MATCH_PER_STREAM_OPT(copy_initial_nonkeyframes, i,
1711  ost->copy_initial_nonkeyframes, oc, st);
1712 
1713  return ost;
1714 }
1715 
1716 static void parse_matrix_coeffs(uint16_t *dest, const char *str)
1717 {
1718  int i;
1719  const char *p = str;
1720  for (i = 0;; i++) {
1721  dest[i] = atoi(p);
1722  if (i == 63)
1723  break;
1724  p = strchr(p, ',');
1725  if (!p) {
1726  av_log(NULL, AV_LOG_FATAL, "Syntax error in matrix \"%s\" at coeff %d\n", str, i);
1727  exit_program(1);
1728  }
1729  p++;
1730  }
1731 }
1732 
1733 /* read file contents into a string */
1734 static char *read_file(const char *filename)
1735 {
1736  AVIOContext *pb = NULL;
1737  int ret = avio_open(&pb, filename, AVIO_FLAG_READ);
1738  AVBPrint bprint;
1739  char *str;
1740 
1741  if (ret < 0) {
1742  av_log(NULL, AV_LOG_ERROR, "Error opening file %s.\n", filename);
1743  return NULL;
1744  }
1745 
1747  ret = avio_read_to_bprint(pb, &bprint, SIZE_MAX);
1748  avio_closep(&pb);
1749  if (ret < 0) {
1750  av_bprint_finalize(&bprint, NULL);
1751  return NULL;
1752  }
1753  ret = av_bprint_finalize(&bprint, &str);
1754  if (ret < 0)
1755  return NULL;
1756  return str;
1757 }
1758 
1760  OutputStream *ost)
1761 {
1762  AVStream *st = ost->st;
1763 
1764  if (ost->filters_script && ost->filters) {
1765  av_log(NULL, AV_LOG_ERROR, "Both -filter and -filter_script set for "
1766  "output stream #%d:%d.\n", nb_output_files, st->index);
1767  exit_program(1);
1768  }
1769 
1770  if (ost->filters_script)
1771  return read_file(ost->filters_script);
1772  else if (ost->filters)
1773  return av_strdup(ost->filters);
1774 
1776  "null" : "anull");
1777 }
1778 
1780  const OutputStream *ost, enum AVMediaType type)
1781 {
1782  if (ost->filters_script || ost->filters) {
1784  "%s '%s' was defined for %s output stream %d:%d but codec copy was selected.\n"
1785  "Filtering and streamcopy cannot be used together.\n",
1786  ost->filters ? "Filtergraph" : "Filtergraph script",
1787  ost->filters ? ost->filters : ost->filters_script,
1788  av_get_media_type_string(type), ost->file_index, ost->index);
1789  exit_program(1);
1790  }
1791 }
1792 
1794 {
1795  AVStream *st;
1796  OutputStream *ost;
1797  AVCodecContext *video_enc;
1798  char *frame_rate = NULL, *max_frame_rate = NULL, *frame_aspect_ratio = NULL;
1799 
1800  ost = new_output_stream(o, oc, AVMEDIA_TYPE_VIDEO, source_index);
1801  st = ost->st;
1802  video_enc = ost->enc_ctx;
1803 
1804  MATCH_PER_STREAM_OPT(frame_rates, str, frame_rate, oc, st);
1805  if (frame_rate && av_parse_video_rate(&ost->frame_rate, frame_rate) < 0) {
1806  av_log(NULL, AV_LOG_FATAL, "Invalid framerate value: %s\n", frame_rate);
1807  exit_program(1);
1808  }
1809 
1810  MATCH_PER_STREAM_OPT(max_frame_rates, str, max_frame_rate, oc, st);
1811  if (max_frame_rate && av_parse_video_rate(&ost->max_frame_rate, max_frame_rate) < 0) {
1812  av_log(NULL, AV_LOG_FATAL, "Invalid maximum framerate value: %s\n", max_frame_rate);
1813  exit_program(1);
1814  }
1815 
1816  if (frame_rate && max_frame_rate) {
1817  av_log(NULL, AV_LOG_ERROR, "Only one of -fpsmax and -r can be set for a stream.\n");
1818  exit_program(1);
1819  }
1820 
1821  if ((frame_rate || max_frame_rate) &&
1823  av_log(NULL, AV_LOG_ERROR, "Using -vsync passthrough and -r/-fpsmax can produce invalid output files\n");
1824 
1825  MATCH_PER_STREAM_OPT(frame_aspect_ratios, str, frame_aspect_ratio, oc, st);
1826  if (frame_aspect_ratio) {
1827  AVRational q;
1828  if (av_parse_ratio(&q, frame_aspect_ratio, 255, 0, NULL) < 0 ||
1829  q.num <= 0 || q.den <= 0) {
1830  av_log(NULL, AV_LOG_FATAL, "Invalid aspect ratio: %s\n", frame_aspect_ratio);
1831  exit_program(1);
1832  }
1833  ost->frame_aspect_ratio = q;
1834  }
1835 
1836  MATCH_PER_STREAM_OPT(filter_scripts, str, ost->filters_script, oc, st);
1837  MATCH_PER_STREAM_OPT(filters, str, ost->filters, oc, st);
1838 
1839  if (!ost->stream_copy) {
1840  const char *p = NULL;
1841  char *frame_size = NULL;
1842  char *frame_pix_fmt = NULL;
1843  char *intra_matrix = NULL, *inter_matrix = NULL;
1844  char *chroma_intra_matrix = NULL;
1845  int do_pass = 0;
1846  int i;
1847 
1849  if (frame_size && av_parse_video_size(&video_enc->width, &video_enc->height, frame_size) < 0) {
1850  av_log(NULL, AV_LOG_FATAL, "Invalid frame size: %s.\n", frame_size);
1851  exit_program(1);
1852  }
1853 
1854  MATCH_PER_STREAM_OPT(frame_pix_fmts, str, frame_pix_fmt, oc, st);
1855  if (frame_pix_fmt && *frame_pix_fmt == '+') {
1856  ost->keep_pix_fmt = 1;
1857  if (!*++frame_pix_fmt)
1858  frame_pix_fmt = NULL;
1859  }
1860  if (frame_pix_fmt && (video_enc->pix_fmt = av_get_pix_fmt(frame_pix_fmt)) == AV_PIX_FMT_NONE) {
1861  av_log(NULL, AV_LOG_FATAL, "Unknown pixel format requested: %s.\n", frame_pix_fmt);
1862  exit_program(1);
1863  }
1864  st->sample_aspect_ratio = video_enc->sample_aspect_ratio;
1865 
1866  MATCH_PER_STREAM_OPT(intra_matrices, str, intra_matrix, oc, st);
1867  if (intra_matrix) {
1868  if (!(video_enc->intra_matrix = av_mallocz(sizeof(*video_enc->intra_matrix) * 64))) {
1869  av_log(NULL, AV_LOG_FATAL, "Could not allocate memory for intra matrix.\n");
1870  exit_program(1);
1871  }
1872  parse_matrix_coeffs(video_enc->intra_matrix, intra_matrix);
1873  }
1874  MATCH_PER_STREAM_OPT(chroma_intra_matrices, str, chroma_intra_matrix, oc, st);
1875  if (chroma_intra_matrix) {
1876  uint16_t *p = av_mallocz(sizeof(*video_enc->chroma_intra_matrix) * 64);
1877  if (!p) {
1878  av_log(NULL, AV_LOG_FATAL, "Could not allocate memory for intra matrix.\n");
1879  exit_program(1);
1880  }
1881  video_enc->chroma_intra_matrix = p;
1882  parse_matrix_coeffs(p, chroma_intra_matrix);
1883  }
1884  MATCH_PER_STREAM_OPT(inter_matrices, str, inter_matrix, oc, st);
1885  if (inter_matrix) {
1886  if (!(video_enc->inter_matrix = av_mallocz(sizeof(*video_enc->inter_matrix) * 64))) {
1887  av_log(NULL, AV_LOG_FATAL, "Could not allocate memory for inter matrix.\n");
1888  exit_program(1);
1889  }
1890  parse_matrix_coeffs(video_enc->inter_matrix, inter_matrix);
1891  }
1892 
1893  MATCH_PER_STREAM_OPT(rc_overrides, str, p, oc, st);
1894  for (i = 0; p; i++) {
1895  int start, end, q;
1896  int e = sscanf(p, "%d,%d,%d", &start, &end, &q);
1897  if (e != 3) {
1898  av_log(NULL, AV_LOG_FATAL, "error parsing rc_override\n");
1899  exit_program(1);
1900  }
1901  video_enc->rc_override =
1902  av_realloc_array(video_enc->rc_override,
1903  i + 1, sizeof(RcOverride));
1904  if (!video_enc->rc_override) {
1905  av_log(NULL, AV_LOG_FATAL, "Could not (re)allocate memory for rc_override.\n");
1906  exit_program(1);
1907  }
1908  video_enc->rc_override[i].start_frame = start;
1909  video_enc->rc_override[i].end_frame = end;
1910  if (q > 0) {
1911  video_enc->rc_override[i].qscale = q;
1912  video_enc->rc_override[i].quality_factor = 1.0;
1913  }
1914  else {
1915  video_enc->rc_override[i].qscale = 0;
1916  video_enc->rc_override[i].quality_factor = -q/100.0;
1917  }
1918  p = strchr(p, '/');
1919  if (p) p++;
1920  }
1921  video_enc->rc_override_count = i;
1922 
1923  if (do_psnr)
1924  video_enc->flags|= AV_CODEC_FLAG_PSNR;
1925 
1926  /* two pass mode */
1927  MATCH_PER_STREAM_OPT(pass, i, do_pass, oc, st);
1928  if (do_pass) {
1929  if (do_pass & 1) {
1930  video_enc->flags |= AV_CODEC_FLAG_PASS1;
1931  av_dict_set(&ost->encoder_opts, "flags", "+pass1", AV_DICT_APPEND);
1932  }
1933  if (do_pass & 2) {
1934  video_enc->flags |= AV_CODEC_FLAG_PASS2;
1935  av_dict_set(&ost->encoder_opts, "flags", "+pass2", AV_DICT_APPEND);
1936  }
1937  }
1938 
1939  MATCH_PER_STREAM_OPT(passlogfiles, str, ost->logfile_prefix, oc, st);
1940  if (ost->logfile_prefix &&
1941  !(ost->logfile_prefix = av_strdup(ost->logfile_prefix)))
1942  exit_program(1);
1943 
1944  if (do_pass) {
1945  char logfilename[1024];
1946  FILE *f;
1947 
1948  snprintf(logfilename, sizeof(logfilename), "%s-%d.log",
1949  ost->logfile_prefix ? ost->logfile_prefix :
1951  nb_output_streams - 1);
1952  if (!strcmp(ost->enc->name, "libx264")) {
1953  av_dict_set(&ost->encoder_opts, "stats", logfilename, AV_DICT_DONT_OVERWRITE);
1954  } else {
1955  if (video_enc->flags & AV_CODEC_FLAG_PASS2) {
1956  char *logbuffer = read_file(logfilename);
1957 
1958  if (!logbuffer) {
1959  av_log(NULL, AV_LOG_FATAL, "Error reading log file '%s' for pass-2 encoding\n",
1960  logfilename);
1961  exit_program(1);
1962  }
1963  video_enc->stats_in = logbuffer;
1964  }
1965  if (video_enc->flags & AV_CODEC_FLAG_PASS1) {
1966  f = fopen_utf8(logfilename, "wb");
1967  if (!f) {
1969  "Cannot write log file '%s' for pass-1 encoding: %s\n",
1970  logfilename, strerror(errno));
1971  exit_program(1);
1972  }
1973  ost->logfile = f;
1974  }
1975  }
1976  }
1977 
1978  MATCH_PER_STREAM_OPT(forced_key_frames, str, ost->forced_keyframes, oc, st);
1979  if (ost->forced_keyframes)
1980  ost->forced_keyframes = av_strdup(ost->forced_keyframes);
1981 
1982  MATCH_PER_STREAM_OPT(force_fps, i, ost->force_fps, oc, st);
1983 
1984  ost->top_field_first = -1;
1985  MATCH_PER_STREAM_OPT(top_field_first, i, ost->top_field_first, oc, st);
1986 
1987  ost->vsync_method = video_sync_method;
1988  MATCH_PER_STREAM_OPT(fps_mode, str, ost->fps_mode, oc, st);
1989  if (ost->fps_mode)
1990  parse_and_set_vsync(ost->fps_mode, &ost->vsync_method, ost->file_index, ost->index, 0);
1991 
1992  if (ost->vsync_method == VSYNC_AUTO) {
1993  if (!strcmp(oc->oformat->name, "avi")) {
1994  ost->vsync_method = VSYNC_VFR;
1995  } else {
1996  ost->vsync_method = (oc->oformat->flags & AVFMT_VARIABLE_FPS) ?
1997  ((oc->oformat->flags & AVFMT_NOTIMESTAMPS) ?
1999  VSYNC_CFR;
2000  }
2001 
2002  if (ost->source_index >= 0 && ost->vsync_method == VSYNC_CFR) {
2003  const InputStream *ist = input_streams[ost->source_index];
2004  const InputFile *ifile = input_files[ist->file_index];
2005 
2006  if (ifile->nb_streams == 1 && ifile->input_ts_offset == 0)
2007  ost->vsync_method = VSYNC_VSCFR;
2008  }
2009 
2010  if (ost->vsync_method == VSYNC_CFR && copy_ts) {
2011  ost->vsync_method = VSYNC_VSCFR;
2012  }
2013  }
2014  ost->is_cfr = (ost->vsync_method == VSYNC_CFR || ost->vsync_method == VSYNC_VSCFR);
2015 
2016  ost->avfilter = get_ost_filters(o, oc, ost);
2017  if (!ost->avfilter)
2018  exit_program(1);
2019 
2020  ost->last_frame = av_frame_alloc();
2021  if (!ost->last_frame)
2022  exit_program(1);
2023  }
2024 
2025  if (ost->stream_copy)
2027 
2028  return ost;
2029 }
2030 
2032 {
2033  int n;
2034  AVStream *st;
2035  OutputStream *ost;
2036  AVCodecContext *audio_enc;
2037 
2038  ost = new_output_stream(o, oc, AVMEDIA_TYPE_AUDIO, source_index);
2039  st = ost->st;
2040 
2041  audio_enc = ost->enc_ctx;
2042  audio_enc->codec_type = AVMEDIA_TYPE_AUDIO;
2043 
2044  MATCH_PER_STREAM_OPT(filter_scripts, str, ost->filters_script, oc, st);
2045  MATCH_PER_STREAM_OPT(filters, str, ost->filters, oc, st);
2046 
2047  if (!ost->stream_copy) {
2048  int channels = 0;
2049  char *layout = NULL;
2050  char *sample_fmt = NULL;
2051 
2053  if (channels) {
2055  audio_enc->ch_layout.nb_channels = channels;
2056  }
2057 
2058  MATCH_PER_STREAM_OPT(audio_ch_layouts, str, layout, oc, st);
2059  if (layout) {
2060  if (av_channel_layout_from_string(&audio_enc->ch_layout, layout) < 0) {
2061 #if FF_API_OLD_CHANNEL_LAYOUT
2062  uint64_t mask;
2065  })
2066  if (!mask) {
2067 #endif
2068  av_log(NULL, AV_LOG_FATAL, "Unknown channel layout: %s\n", layout);
2069  exit_program(1);
2070 #if FF_API_OLD_CHANNEL_LAYOUT
2071  }
2072  av_log(NULL, AV_LOG_WARNING, "Channel layout '%s' uses a deprecated syntax.\n",
2073  layout);
2075 #endif
2076  }
2077  }
2078 
2079  MATCH_PER_STREAM_OPT(sample_fmts, str, sample_fmt, oc, st);
2080  if (sample_fmt &&
2081  (audio_enc->sample_fmt = av_get_sample_fmt(sample_fmt)) == AV_SAMPLE_FMT_NONE) {
2082  av_log(NULL, AV_LOG_FATAL, "Invalid sample format '%s'\n", sample_fmt);
2083  exit_program(1);
2084  }
2085 
2086  MATCH_PER_STREAM_OPT(audio_sample_rate, i, audio_enc->sample_rate, oc, st);
2087 
2088  MATCH_PER_STREAM_OPT(apad, str, ost->apad, oc, st);
2089  ost->apad = av_strdup(ost->apad);
2090 
2091  ost->avfilter = get_ost_filters(o, oc, ost);
2092  if (!ost->avfilter)
2093  exit_program(1);
2094 
2095  /* check for channel mapping for this audio stream */
2096  for (n = 0; n < o->nb_audio_channel_maps; n++) {
2098  if ((map->ofile_idx == -1 || ost->file_index == map->ofile_idx) &&
2099  (map->ostream_idx == -1 || ost->st->index == map->ostream_idx)) {
2100  InputStream *ist;
2101 
2102  if (map->channel_idx == -1) {
2103  ist = NULL;
2104  } else if (ost->source_index < 0) {
2105  av_log(NULL, AV_LOG_FATAL, "Cannot determine input stream for channel mapping %d.%d\n",
2106  ost->file_index, ost->st->index);
2107  continue;
2108  } else {
2109  ist = input_streams[ost->source_index];
2110  }
2111 
2112  if (!ist || (ist->file_index == map->file_idx && ist->st->index == map->stream_idx)) {
2113  if (av_reallocp_array(&ost->audio_channels_map,
2114  ost->audio_channels_mapped + 1,
2115  sizeof(*ost->audio_channels_map)
2116  ) < 0 )
2117  exit_program(1);
2118 
2119  ost->audio_channels_map[ost->audio_channels_mapped++] = map->channel_idx;
2120  }
2121  }
2122  }
2123  }
2124 
2125  if (ost->stream_copy)
2127 
2128  return ost;
2129 }
2130 
2132 {
2133  OutputStream *ost;
2134 
2135  ost = new_output_stream(o, oc, AVMEDIA_TYPE_DATA, source_index);
2136  if (!ost->stream_copy) {
2137  av_log(NULL, AV_LOG_FATAL, "Data stream encoding not supported yet (only streamcopy)\n");
2138  exit_program(1);
2139  }
2140 
2141  return ost;
2142 }
2143 
2145 {
2146  OutputStream *ost;
2147 
2148  ost = new_output_stream(o, oc, AVMEDIA_TYPE_UNKNOWN, source_index);
2149  if (!ost->stream_copy) {
2150  av_log(NULL, AV_LOG_FATAL, "Unknown stream encoding not supported yet (only streamcopy)\n");
2151  exit_program(1);
2152  }
2153 
2154  return ost;
2155 }
2156 
2158 {
2159  OutputStream *ost = new_output_stream(o, oc, AVMEDIA_TYPE_ATTACHMENT, source_index);
2160  ost->stream_copy = 1;
2161  ost->finished = 1;
2162  return ost;
2163 }
2164 
2166 {
2167  AVStream *st;
2168  OutputStream *ost;
2169  AVCodecContext *subtitle_enc;
2170 
2171  ost = new_output_stream(o, oc, AVMEDIA_TYPE_SUBTITLE, source_index);
2172  st = ost->st;
2173  subtitle_enc = ost->enc_ctx;
2174 
2175  subtitle_enc->codec_type = AVMEDIA_TYPE_SUBTITLE;
2176 
2177  if (!ost->stream_copy) {
2178  char *frame_size = NULL;
2179 
2181  if (frame_size && av_parse_video_size(&subtitle_enc->width, &subtitle_enc->height, frame_size) < 0) {
2182  av_log(NULL, AV_LOG_FATAL, "Invalid frame size: %s.\n", frame_size);
2183  exit_program(1);
2184  }
2185  }
2186 
2187  return ost;
2188 }
2189 
2190 /* arg format is "output-stream-index:streamid-value". */
2191 static int opt_streamid(void *optctx, const char *opt, const char *arg)
2192 {
2193  OptionsContext *o = optctx;
2194  int idx;
2195  char *p;
2196  char idx_str[16];
2197 
2198  av_strlcpy(idx_str, arg, sizeof(idx_str));
2199  p = strchr(idx_str, ':');
2200  if (!p) {
2202  "Invalid value '%s' for option '%s', required syntax is 'index:value'\n",
2203  arg, opt);
2204  exit_program(1);
2205  }
2206  *p++ = '\0';
2207  idx = parse_number_or_die(opt, idx_str, OPT_INT, 0, MAX_STREAMS-1);
2208  o->streamid_map = grow_array(o->streamid_map, sizeof(*o->streamid_map), &o->nb_streamid_map, idx+1);
2209  o->streamid_map[idx] = parse_number_or_die(opt, p, OPT_INT, 0, INT_MAX);
2210  return 0;
2211 }
2212 
2214  int copy_metadata)
2215 {
2216  AVFormatContext *is = ifile->ctx;
2217  AVChapter **tmp;
2218  int i;
2219 
2220  tmp = av_realloc_f(os->chapters, is->nb_chapters + os->nb_chapters, sizeof(*os->chapters));
2221  if (!tmp)
2222  return AVERROR(ENOMEM);
2223  os->chapters = tmp;
2224 
2225  for (i = 0; i < is->nb_chapters; i++) {
2226  AVChapter *in_ch = is->chapters[i], *out_ch;
2227  int64_t start_time = (ofile->start_time == AV_NOPTS_VALUE) ? 0 : ofile->start_time;
2228  int64_t ts_off = av_rescale_q(start_time - ifile->ts_offset,
2229  AV_TIME_BASE_Q, in_ch->time_base);
2230  int64_t rt = (ofile->recording_time == INT64_MAX) ? INT64_MAX :
2231  av_rescale_q(ofile->recording_time, AV_TIME_BASE_Q, in_ch->time_base);
2232 
2233 
2234  if (in_ch->end < ts_off)
2235  continue;
2236  if (rt != INT64_MAX && in_ch->start > rt + ts_off)
2237  break;
2238 
2239  out_ch = av_mallocz(sizeof(AVChapter));
2240  if (!out_ch)
2241  return AVERROR(ENOMEM);
2242 
2243  out_ch->id = in_ch->id;
2244  out_ch->time_base = in_ch->time_base;
2245  out_ch->start = FFMAX(0, in_ch->start - ts_off);
2246  out_ch->end = FFMIN(rt, in_ch->end - ts_off);
2247 
2248  if (copy_metadata)
2249  av_dict_copy(&out_ch->metadata, in_ch->metadata, 0);
2250 
2251  os->chapters[os->nb_chapters++] = out_ch;
2252  }
2253  return 0;
2254 }
2255 
2257 {
2258  int nb_streams[AVMEDIA_TYPE_NB] = { 0 };
2259  int have_default[AVMEDIA_TYPE_NB] = { 0 };
2260  int have_manual = 0;
2261 
2262  // first, copy the input dispositions
2263  for (int i = 0; i < ctx->nb_streams; i++) {
2265 
2266  nb_streams[ost->st->codecpar->codec_type]++;
2267 
2268  have_manual |= !!ost->disposition;
2269 
2270  if (ost->source_index >= 0) {
2271  ost->st->disposition = input_streams[ost->source_index]->st->disposition;
2272 
2274  have_default[ost->st->codecpar->codec_type] = 1;
2275  }
2276  }
2277 
2278  if (have_manual) {
2279  // process manually set dispositions - they override the above copy
2280  for (int i = 0; i < ctx->nb_streams; i++) {
2282  int ret;
2283 
2284  if (!ost->disposition)
2285  continue;
2286 
2287 #if LIBAVFORMAT_VERSION_MAJOR >= 60
2288  ret = av_opt_set(ost->st, "disposition", ost->disposition, 0);
2289 #else
2290  {
2291  const AVClass *class = av_stream_get_class();
2292  const AVOption *o = av_opt_find(&class, "disposition", NULL, 0, AV_OPT_SEARCH_FAKE_OBJ);
2293 
2294  av_assert0(o);
2295  ret = av_opt_eval_flags(&class, o, ost->disposition, &ost->st->disposition);
2296  }
2297 #endif
2298 
2299  if (ret < 0)
2300  return ret;
2301  }
2302  } else {
2303  // For each media type with more than one stream, find a suitable stream to
2304  // mark as default, unless one is already marked default.
2305  // "Suitable" means the first of that type, skipping attached pictures.
2306  for (int i = 0; i < ctx->nb_streams; i++) {
2308  enum AVMediaType type = ost->st->codecpar->codec_type;
2309 
2310  if (nb_streams[type] < 2 || have_default[type] ||
2312  continue;
2313 
2315  have_default[type] = 1;
2316  }
2317  }
2318 
2319  return 0;
2320 }
2321 
2323  AVFormatContext *oc)
2324 {
2325  OutputStream *ost;
2326 
2327  switch (ofilter->type) {
2328  case AVMEDIA_TYPE_VIDEO: ost = new_video_stream(o, oc, -1); break;
2329  case AVMEDIA_TYPE_AUDIO: ost = new_audio_stream(o, oc, -1); break;
2330  default:
2331  av_log(NULL, AV_LOG_FATAL, "Only video and audio filters are supported "
2332  "currently.\n");
2333  exit_program(1);
2334  }
2335 
2336  ost->filter = ofilter;
2337 
2338  ofilter->ost = ost;
2339  ofilter->format = -1;
2340 
2341  if (ost->stream_copy) {
2342  av_log(NULL, AV_LOG_ERROR, "Streamcopy requested for output stream %d:%d, "
2343  "which is fed from a complex filtergraph. Filtering and streamcopy "
2344  "cannot be used together.\n", ost->file_index, ost->index);
2345  exit_program(1);
2346  }
2347 
2348  if (ost->avfilter && (ost->filters || ost->filters_script)) {
2349  const char *opt = ost->filters ? "-vf/-af/-filter" : "-filter_script";
2351  "%s '%s' was specified through the %s option "
2352  "for output stream %d:%d, which is fed from a complex filtergraph.\n"
2353  "%s and -filter_complex cannot be used together for the same stream.\n",
2354  ost->filters ? "Filtergraph" : "Filtergraph script",
2355  ost->filters ? ost->filters : ost->filters_script,
2356  opt, ost->file_index, ost->index, opt);
2357  exit_program(1);
2358  }
2359 
2360  avfilter_inout_free(&ofilter->out_tmp);
2361 }
2362 
2363 static int init_complex_filters(void)
2364 {
2365  int i, ret = 0;
2366 
2367  for (i = 0; i < nb_filtergraphs; i++) {
2369  if (ret < 0)
2370  return ret;
2371  }
2372  return 0;
2373 }
2374 
2376 {
2377  int i, err;
2378 
2379  if (ost->enc_ctx->ch_layout.order != AV_CHANNEL_ORDER_UNSPEC) {
2380  /* Pass the layout through for all orders but UNSPEC */
2381  err = av_channel_layout_copy(&f->ch_layout, &ost->enc_ctx->ch_layout);
2382  if (err < 0)
2383  exit_program(1);
2384  return;
2385  }
2386 
2387  /* Requested layout is of order UNSPEC */
2388  if (!ost->enc->ch_layouts) {
2389  /* Use the default native layout for the requested amount of channels when the
2390  encoder doesn't have a list of supported layouts */
2391  av_channel_layout_default(&f->ch_layout, ost->enc_ctx->ch_layout.nb_channels);
2392  return;
2393  }
2394  /* Encoder has a list of supported layouts. Pick the first layout in it with the
2395  same amount of channels as the requested layout */
2396  for (i = 0; ost->enc->ch_layouts[i].nb_channels; i++) {
2397  if (ost->enc->ch_layouts[i].nb_channels == ost->enc_ctx->ch_layout.nb_channels)
2398  break;
2399  }
2400  if (ost->enc->ch_layouts[i].nb_channels) {
2401  /* Use it if one is found */
2402  err = av_channel_layout_copy(&f->ch_layout, &ost->enc->ch_layouts[i]);
2403  if (err < 0)
2404  exit_program(1);
2405  return;
2406  }
2407  /* If no layout for the amount of channels requested was found, use the default
2408  native layout for it. */
2409  av_channel_layout_default(&f->ch_layout, ost->enc_ctx->ch_layout.nb_channels);
2410 }
2411 
2412 static int open_output_file(OptionsContext *o, const char *filename)
2413 {
2414  AVFormatContext *oc;
2415  int i, j, err;
2416  OutputFile *of;
2417  OutputStream *ost;
2418  InputStream *ist;
2419  AVDictionary *unused_opts = NULL;
2420  const AVDictionaryEntry *e = NULL;
2421 
2422  if (o->stop_time != INT64_MAX && o->recording_time != INT64_MAX) {
2423  o->stop_time = INT64_MAX;
2424  av_log(NULL, AV_LOG_WARNING, "-t and -to cannot be used together; using -t.\n");
2425  }
2426 
2427  if (o->stop_time != INT64_MAX && o->recording_time == INT64_MAX) {
2428  int64_t start_time = o->start_time == AV_NOPTS_VALUE ? 0 : o->start_time;
2429  if (o->stop_time <= start_time) {
2430  av_log(NULL, AV_LOG_ERROR, "-to value smaller than -ss; aborting.\n");
2431  exit_program(1);
2432  } else {
2434  }
2435  }
2436 
2438 
2439  of->index = nb_output_files - 1;
2441  of->recording_time = o->recording_time;
2442  of->start_time = o->start_time;
2443  of->limit_filesize = o->limit_filesize;
2444  of->shortest = o->shortest;
2445  av_dict_copy(&of->opts, o->g->format_opts, 0);
2446 
2447  if (!strcmp(filename, "-"))
2448  filename = "pipe:";
2449 
2450  err = avformat_alloc_output_context2(&oc, NULL, o->format, filename);
2451  if (!oc) {
2452  print_error(filename, err);
2453  exit_program(1);
2454  }
2455 
2456  of->ctx = oc;
2457  of->format = oc->oformat;
2458  if (o->recording_time != INT64_MAX)
2459  oc->duration = o->recording_time;
2460 
2461  oc->interrupt_callback = int_cb;
2462 
2463  if (o->bitexact) {
2464  oc->flags |= AVFMT_FLAG_BITEXACT;
2465  }
2466 
2467  /* create streams for all unlabeled output pads */
2468  for (i = 0; i < nb_filtergraphs; i++) {
2469  FilterGraph *fg = filtergraphs[i];
2470  for (j = 0; j < fg->nb_outputs; j++) {
2471  OutputFilter *ofilter = fg->outputs[j];
2472 
2473  if (!ofilter->out_tmp || ofilter->out_tmp->name)
2474  continue;
2475 
2476  switch (ofilter->type) {
2477  case AVMEDIA_TYPE_VIDEO: o->video_disable = 1; break;
2478  case AVMEDIA_TYPE_AUDIO: o->audio_disable = 1; break;
2479  case AVMEDIA_TYPE_SUBTITLE: o->subtitle_disable = 1; break;
2480  }
2481  init_output_filter(ofilter, o, oc);
2482  }
2483  }
2484 
2485  if (!o->nb_stream_maps) {
2486  char *subtitle_codec_name = NULL;
2487  /* pick the "best" stream of each type */
2488 
2489  /* video: highest resolution */
2491  int best_score = 0, idx = -1;
2492  int qcr = avformat_query_codec(oc->oformat, oc->oformat->video_codec, 0);
2493  for (j = 0; j < nb_input_files; j++) {
2494  InputFile *ifile = input_files[j];
2495  int file_best_score = 0, file_best_idx = -1;
2496  for (i = 0; i < ifile->nb_streams; i++) {
2497  int score;
2498  ist = input_streams[ifile->ist_index + i];
2499  score = ist->st->codecpar->width * ist->st->codecpar->height
2500  + 100000000 * !!(ist->st->event_flags & AVSTREAM_EVENT_FLAG_NEW_PACKETS)
2501  + 5000000*!!(ist->st->disposition & AV_DISPOSITION_DEFAULT);
2502  if (ist->user_set_discard == AVDISCARD_ALL)
2503  continue;
2504  if((qcr!=MKTAG('A', 'P', 'I', 'C')) && (ist->st->disposition & AV_DISPOSITION_ATTACHED_PIC))
2505  score = 1;
2506  if (ist->st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO &&
2507  score > file_best_score) {
2508  if((qcr==MKTAG('A', 'P', 'I', 'C')) && !(ist->st->disposition & AV_DISPOSITION_ATTACHED_PIC))
2509  continue;
2510  file_best_score = score;
2511  file_best_idx = ifile->ist_index + i;
2512  }
2513  }
2514  if (file_best_idx >= 0) {
2515  if((qcr == MKTAG('A', 'P', 'I', 'C')) || !(ist->st->disposition & AV_DISPOSITION_ATTACHED_PIC))
2516  file_best_score -= 5000000*!!(input_streams[file_best_idx]->st->disposition & AV_DISPOSITION_DEFAULT);
2517  if (file_best_score > best_score) {
2518  best_score = file_best_score;
2519  idx = file_best_idx;
2520  }
2521  }
2522  }
2523  if (idx >= 0)
2524  new_video_stream(o, oc, idx);
2525  }
2526 
2527  /* audio: most channels */
2529  int best_score = 0, idx = -1;
2530  for (j = 0; j < nb_input_files; j++) {
2531  InputFile *ifile = input_files[j];
2532  int file_best_score = 0, file_best_idx = -1;
2533  for (i = 0; i < ifile->nb_streams; i++) {
2534  int score;
2535  ist = input_streams[ifile->ist_index + i];
2536  score = ist->st->codecpar->ch_layout.nb_channels
2537  + 100000000 * !!(ist->st->event_flags & AVSTREAM_EVENT_FLAG_NEW_PACKETS)
2538  + 5000000*!!(ist->st->disposition & AV_DISPOSITION_DEFAULT);
2539  if (ist->user_set_discard == AVDISCARD_ALL)
2540  continue;
2541  if (ist->st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO &&
2542  score > file_best_score) {
2543  file_best_score = score;
2544  file_best_idx = ifile->ist_index + i;
2545  }
2546  }
2547  if (file_best_idx >= 0) {
2548  file_best_score -= 5000000*!!(input_streams[file_best_idx]->st->disposition & AV_DISPOSITION_DEFAULT);
2549  if (file_best_score > best_score) {
2550  best_score = file_best_score;
2551  idx = file_best_idx;
2552  }
2553  }
2554  }
2555  if (idx >= 0)
2556  new_audio_stream(o, oc, idx);
2557  }
2558 
2559  /* subtitles: pick first */
2560  MATCH_PER_TYPE_OPT(codec_names, str, subtitle_codec_name, oc, "s");
2562  for (i = 0; i < nb_input_streams; i++)
2563  if (input_streams[i]->st->codecpar->codec_type == AVMEDIA_TYPE_SUBTITLE) {
2564  AVCodecDescriptor const *input_descriptor =
2565  avcodec_descriptor_get(input_streams[i]->st->codecpar->codec_id);
2566  AVCodecDescriptor const *output_descriptor = NULL;
2567  AVCodec const *output_codec =
2569  int input_props = 0, output_props = 0;
2570  if (input_streams[i]->user_set_discard == AVDISCARD_ALL)
2571  continue;
2572  if (output_codec)
2573  output_descriptor = avcodec_descriptor_get(output_codec->id);
2574  if (input_descriptor)
2575  input_props = input_descriptor->props & (AV_CODEC_PROP_TEXT_SUB | AV_CODEC_PROP_BITMAP_SUB);
2576  if (output_descriptor)
2577  output_props = output_descriptor->props & (AV_CODEC_PROP_TEXT_SUB | AV_CODEC_PROP_BITMAP_SUB);
2578  if (subtitle_codec_name ||
2579  input_props & output_props ||
2580  // Map dvb teletext which has neither property to any output subtitle encoder
2581  input_descriptor && output_descriptor &&
2582  (!input_descriptor->props ||
2583  !output_descriptor->props)) {
2584  new_subtitle_stream(o, oc, i);
2585  break;
2586  }
2587  }
2588  }
2589  /* Data only if codec id match */
2590  if (!o->data_disable ) {
2592  for (i = 0; codec_id != AV_CODEC_ID_NONE && i < nb_input_streams; i++) {
2593  if (input_streams[i]->user_set_discard == AVDISCARD_ALL)
2594  continue;
2595  if (input_streams[i]->st->codecpar->codec_type == AVMEDIA_TYPE_DATA
2597  new_data_stream(o, oc, i);
2598  }
2599  }
2600  } else {
2601  for (i = 0; i < o->nb_stream_maps; i++) {
2602  StreamMap *map = &o->stream_maps[i];
2603 
2604  if (map->disabled)
2605  continue;
2606 
2607  if (map->linklabel) {
2608  FilterGraph *fg;
2609  OutputFilter *ofilter = NULL;
2610  int j, k;
2611 
2612  for (j = 0; j < nb_filtergraphs; j++) {
2613  fg = filtergraphs[j];
2614  for (k = 0; k < fg->nb_outputs; k++) {
2615  AVFilterInOut *out = fg->outputs[k]->out_tmp;
2616  if (out && !strcmp(out->name, map->linklabel)) {
2617  ofilter = fg->outputs[k];
2618  goto loop_end;
2619  }
2620  }
2621  }
2622 loop_end:
2623  if (!ofilter) {
2624  av_log(NULL, AV_LOG_FATAL, "Output with label '%s' does not exist "
2625  "in any defined filter graph, or was already used elsewhere.\n", map->linklabel);
2626  exit_program(1);
2627  }
2628  init_output_filter(ofilter, o, oc);
2629  } else {
2630  int src_idx = input_files[map->file_index]->ist_index + map->stream_index;
2631 
2632  ist = input_streams[input_files[map->file_index]->ist_index + map->stream_index];
2633  if (ist->user_set_discard == AVDISCARD_ALL) {
2634  av_log(NULL, AV_LOG_FATAL, "Stream #%d:%d is disabled and cannot be mapped.\n",
2635  map->file_index, map->stream_index);
2636  exit_program(1);
2637  }
2639  continue;
2641  continue;
2643  continue;
2644  if(o-> data_disable && ist->st->codecpar->codec_type == AVMEDIA_TYPE_DATA)
2645  continue;
2646 
2647  ost = NULL;
2648  switch (ist->st->codecpar->codec_type) {
2649  case AVMEDIA_TYPE_VIDEO: ost = new_video_stream (o, oc, src_idx); break;
2650  case AVMEDIA_TYPE_AUDIO: ost = new_audio_stream (o, oc, src_idx); break;
2651  case AVMEDIA_TYPE_SUBTITLE: ost = new_subtitle_stream (o, oc, src_idx); break;
2652  case AVMEDIA_TYPE_DATA: ost = new_data_stream (o, oc, src_idx); break;
2653  case AVMEDIA_TYPE_ATTACHMENT: ost = new_attachment_stream(o, oc, src_idx); break;
2654  case AVMEDIA_TYPE_UNKNOWN:
2655  if (copy_unknown_streams) {
2656  ost = new_unknown_stream (o, oc, src_idx);
2657  break;
2658  }
2659  default:
2661  "Cannot map stream #%d:%d - unsupported type.\n",
2662  map->file_index, map->stream_index);
2663  if (!ignore_unknown_streams) {
2665  "If you want unsupported types ignored instead "
2666  "of failing, please use the -ignore_unknown option\n"
2667  "If you want them copied, please use -copy_unknown\n");
2668  exit_program(1);
2669  }
2670  }
2671  if (ost)
2672  ost->sync_ist = input_streams[ input_files[map->sync_file_index]->ist_index
2673  + map->sync_stream_index];
2674  }
2675  }
2676  }
2677 
2678  /* handle attached files */
2679  for (i = 0; i < o->nb_attachments; i++) {
2680  AVIOContext *pb;
2681  uint8_t *attachment;
2682  const char *p;
2683  int64_t len;
2684 
2685  if ((err = avio_open2(&pb, o->attachments[i], AVIO_FLAG_READ, &int_cb, NULL)) < 0) {
2686  av_log(NULL, AV_LOG_FATAL, "Could not open attachment file %s.\n",
2687  o->attachments[i]);
2688  exit_program(1);
2689  }
2690  if ((len = avio_size(pb)) <= 0) {
2691  av_log(NULL, AV_LOG_FATAL, "Could not get size of the attachment %s.\n",
2692  o->attachments[i]);
2693  exit_program(1);
2694  }
2695  if (len > INT_MAX - AV_INPUT_BUFFER_PADDING_SIZE ||
2696  !(attachment = av_malloc(len + AV_INPUT_BUFFER_PADDING_SIZE))) {
2697  av_log(NULL, AV_LOG_FATAL, "Attachment %s too large.\n",
2698  o->attachments[i]);
2699  exit_program(1);
2700  }
2701  avio_read(pb, attachment, len);
2702  memset(attachment + len, 0, AV_INPUT_BUFFER_PADDING_SIZE);
2703 
2704  ost = new_attachment_stream(o, oc, -1);
2705  ost->stream_copy = 0;
2706  ost->attachment_filename = o->attachments[i];
2707  ost->st->codecpar->extradata = attachment;
2708  ost->st->codecpar->extradata_size = len;
2709 
2710  p = strrchr(o->attachments[i], '/');
2711  av_dict_set(&ost->st->metadata, "filename", (p && *p) ? p + 1 : o->attachments[i], AV_DICT_DONT_OVERWRITE);
2712  avio_closep(&pb);
2713  }
2714 
2715  if (!oc->nb_streams && !(oc->oformat->flags & AVFMT_NOSTREAMS)) {
2716  av_dump_format(oc, nb_output_files - 1, oc->url, 1);
2717  av_log(NULL, AV_LOG_ERROR, "Output file #%d does not contain any stream\n", nb_output_files - 1);
2718  exit_program(1);
2719  }
2720 
2721  /* check if all codec options have been used */
2722  unused_opts = strip_specifiers(o->g->codec_opts);
2723  for (i = of->ost_index; i < nb_output_streams; i++) {
2724  e = NULL;
2725  while ((e = av_dict_get(output_streams[i]->encoder_opts, "", e,
2727  av_dict_set(&unused_opts, e->key, NULL, 0);
2728  }
2729 
2730  e = NULL;
2731  while ((e = av_dict_get(unused_opts, "", e, AV_DICT_IGNORE_SUFFIX))) {
2732  const AVClass *class = avcodec_get_class();
2733  const AVOption *option = av_opt_find(&class, e->key, NULL, 0,
2735  const AVClass *fclass = avformat_get_class();
2736  const AVOption *foption = av_opt_find(&fclass, e->key, NULL, 0,
2738  if (!option || foption)
2739  continue;
2740 
2741 
2742  if (!(option->flags & AV_OPT_FLAG_ENCODING_PARAM)) {
2743  av_log(NULL, AV_LOG_ERROR, "Codec AVOption %s (%s) specified for "
2744  "output file #%d (%s) is not an encoding option.\n", e->key,
2745  option->help ? option->help : "", nb_output_files - 1,
2746  filename);
2747  exit_program(1);
2748  }
2749 
2750  // gop_timecode is injected by generic code but not always used
2751  if (!strcmp(e->key, "gop_timecode"))
2752  continue;
2753 
2754  av_log(NULL, AV_LOG_WARNING, "Codec AVOption %s (%s) specified for "
2755  "output file #%d (%s) has not been used for any stream. The most "
2756  "likely reason is either wrong type (e.g. a video option with "
2757  "no video streams) or that it is a private option of some encoder "
2758  "which was not actually used for any stream.\n", e->key,
2759  option->help ? option->help : "", nb_output_files - 1, filename);
2760  }
2761  av_dict_free(&unused_opts);
2762 
2763  /* set the decoding_needed flags and create simple filtergraphs */
2764  for (i = of->ost_index; i < nb_output_streams; i++) {
2766 
2767  if (ost->encoding_needed && ost->source_index >= 0) {
2768  InputStream *ist = input_streams[ost->source_index];
2770  ist->processing_needed = 1;
2771 
2772  if (ost->st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO ||
2774  err = init_simple_filtergraph(ist, ost);
2775  if (err < 0) {
2777  "Error initializing a simple filtergraph between streams "
2778  "%d:%d->%d:%d\n", ist->file_index, ost->source_index,
2779  nb_output_files - 1, ost->st->index);
2780  exit_program(1);
2781  }
2782  }
2783  } else if (ost->stream_copy && ost->source_index >= 0) {
2784  InputStream *ist = input_streams[ost->source_index];
2785  ist->processing_needed = 1;
2786  }
2787 
2788  /* set the filter output constraints */
2789  if (ost->filter) {
2790  OutputFilter *f = ost->filter;
2791  switch (ost->enc_ctx->codec_type) {
2792  case AVMEDIA_TYPE_VIDEO:
2793  f->frame_rate = ost->frame_rate;
2794  f->width = ost->enc_ctx->width;
2795  f->height = ost->enc_ctx->height;
2796  if (ost->enc_ctx->pix_fmt != AV_PIX_FMT_NONE) {
2797  f->format = ost->enc_ctx->pix_fmt;
2798  } else {
2799  f->formats = ost->enc->pix_fmts;
2800  }
2801  break;
2802  case AVMEDIA_TYPE_AUDIO:
2803  if (ost->enc_ctx->sample_fmt != AV_SAMPLE_FMT_NONE) {
2804  f->format = ost->enc_ctx->sample_fmt;
2805  } else {
2806  f->formats = ost->enc->sample_fmts;
2807  }
2808  if (ost->enc_ctx->sample_rate) {
2809  f->sample_rate = ost->enc_ctx->sample_rate;
2810  } else {
2811  f->sample_rates = ost->enc->supported_samplerates;
2812  }
2813  if (ost->enc_ctx->ch_layout.nb_channels) {
2815  } else if (ost->enc->ch_layouts) {
2816  f->ch_layouts = ost->enc->ch_layouts;
2817  }
2818  break;
2819  }
2820  }
2821  }
2822 
2823  /* check filename in case of an image number is expected */
2824  if (oc->oformat->flags & AVFMT_NEEDNUMBER) {
2825  if (!av_filename_number_test(oc->url)) {
2826  print_error(oc->url, AVERROR(EINVAL));
2827  exit_program(1);
2828  }
2829  }
2830 
2833  "No input streams but output needs an input stream\n");
2834  exit_program(1);
2835  }
2836 
2837  if (!(oc->oformat->flags & AVFMT_NOFILE)) {
2838  /* test if it already exists to avoid losing precious files */
2839  assert_file_overwrite(filename);
2840 
2841  /* open the file */
2842  if ((err = avio_open2(&oc->pb, filename, AVIO_FLAG_WRITE,
2843  &oc->interrupt_callback,
2844  &of->opts)) < 0) {
2845  print_error(filename, err);
2846  exit_program(1);
2847  }
2848  } else if (strcmp(oc->oformat->name, "image2")==0 && !av_filename_number_test(filename))
2849  assert_file_overwrite(filename);
2850 
2851  if (o->mux_preload) {
2852  av_dict_set_int(&of->opts, "preload", o->mux_preload*AV_TIME_BASE, 0);
2853  }
2854  oc->max_delay = (int)(o->mux_max_delay * AV_TIME_BASE);
2855 
2856  /* copy metadata */
2857  for (i = 0; i < o->nb_metadata_map; i++) {
2858  char *p;
2859  int in_file_index = strtol(o->metadata_map[i].u.str, &p, 0);
2860 
2861  if (in_file_index >= nb_input_files) {
2862  av_log(NULL, AV_LOG_FATAL, "Invalid input file index %d while processing metadata maps\n", in_file_index);
2863  exit_program(1);
2864  }
2865  copy_metadata(o->metadata_map[i].specifier, *p ? p + 1 : p, oc,
2866  in_file_index >= 0 ?
2867  input_files[in_file_index]->ctx : NULL, o);
2868  }
2869 
2870  /* copy chapters */
2871  if (o->chapters_input_file >= nb_input_files) {
2872  if (o->chapters_input_file == INT_MAX) {
2873  /* copy chapters from the first input file that has them*/
2874  o->chapters_input_file = -1;
2875  for (i = 0; i < nb_input_files; i++)
2876  if (input_files[i]->ctx->nb_chapters) {
2877  o->chapters_input_file = i;
2878  break;
2879  }
2880  } else {
2881  av_log(NULL, AV_LOG_FATAL, "Invalid input file index %d in chapter mapping.\n",
2882  o->chapters_input_file);
2883  exit_program(1);
2884  }
2885  }
2886  if (o->chapters_input_file >= 0)
2889 
2890  /* copy global metadata by default */
2894  if(o->recording_time != INT64_MAX)
2895  av_dict_set(&oc->metadata, "duration", NULL, 0);
2896  av_dict_set(&oc->metadata, "creation_time", NULL, 0);
2897  av_dict_set(&oc->metadata, "company_name", NULL, 0);
2898  av_dict_set(&oc->metadata, "product_name", NULL, 0);
2899  av_dict_set(&oc->metadata, "product_version", NULL, 0);
2900  }
2901  if (!o->metadata_streams_manual)
2902  for (i = of->ost_index; i < nb_output_streams; i++) {
2903  InputStream *ist;
2904  if (output_streams[i]->source_index < 0) /* this is true e.g. for attached files */
2905  continue;
2908  if (!output_streams[i]->stream_copy) {
2909  av_dict_set(&output_streams[i]->st->metadata, "encoder", NULL, 0);
2910  }
2911  }
2912 
2913  /* process manually set programs */
2914  for (i = 0; i < o->nb_program; i++) {
2915  const char *p = o->program[i].u.str;
2916  int progid = i+1;
2917  AVProgram *program;
2918 
2919  while(*p) {
2920  const char *p2 = av_get_token(&p, ":");
2921  const char *to_dealloc = p2;
2922  char *key;
2923  if (!p2)
2924  break;
2925 
2926  if(*p) p++;
2927 
2928  key = av_get_token(&p2, "=");
2929  if (!key || !*p2) {
2930  av_freep(&to_dealloc);
2931  av_freep(&key);
2932  break;
2933  }
2934  p2++;
2935 
2936  if (!strcmp(key, "program_num"))
2937  progid = strtol(p2, NULL, 0);
2938  av_freep(&to_dealloc);
2939  av_freep(&key);
2940  }
2941 
2942  program = av_new_program(oc, progid);
2943 
2944  p = o->program[i].u.str;
2945  while(*p) {
2946  const char *p2 = av_get_token(&p, ":");
2947  const char *to_dealloc = p2;
2948  char *key;
2949  if (!p2)
2950  break;
2951  if(*p) p++;
2952 
2953  key = av_get_token(&p2, "=");
2954  if (!key) {
2956  "No '=' character in program string %s.\n",
2957  p2);
2958  exit_program(1);
2959  }
2960  if (!*p2)
2961  exit_program(1);
2962  p2++;
2963 
2964  if (!strcmp(key, "title")) {
2965  av_dict_set(&program->metadata, "title", p2, 0);
2966  } else if (!strcmp(key, "program_num")) {
2967  } else if (!strcmp(key, "st")) {
2968  int st_num = strtol(p2, NULL, 0);
2969  av_program_add_stream_index(oc, progid, st_num);
2970  } else {
2971  av_log(NULL, AV_LOG_FATAL, "Unknown program key %s.\n", key);
2972  exit_program(1);
2973  }
2974  av_freep(&to_dealloc);
2975  av_freep(&key);
2976  }
2977  }
2978 
2979  /* process manually set metadata */
2980  for (i = 0; i < o->nb_metadata; i++) {
2981  AVDictionary **m;
2982  char type, *val;
2983  const char *stream_spec;
2984  int index = 0, j, ret = 0;
2985 
2986  val = strchr(o->metadata[i].u.str, '=');
2987  if (!val) {
2988  av_log(NULL, AV_LOG_FATAL, "No '=' character in metadata string %s.\n",
2989  o->metadata[i].u.str);
2990  exit_program(1);
2991  }
2992  *val++ = 0;
2993 
2994  parse_meta_type(o->metadata[i].specifier, &type, &index, &stream_spec);
2995  if (type == 's') {
2996  for (j = 0; j < oc->nb_streams; j++) {
2998  if ((ret = check_stream_specifier(oc, oc->streams[j], stream_spec)) > 0) {
2999  if (!strcmp(o->metadata[i].u.str, "rotate")) {
3000  char *tail;
3001  double theta = av_strtod(val, &tail);
3002  if (!*tail) {
3003  ost->rotate_overridden = 1;
3004  ost->rotate_override_value = theta;
3005  }
3006  } else {
3007  av_dict_set(&oc->streams[j]->metadata, o->metadata[i].u.str, *val ? val : NULL, 0);
3008  }
3009  } else if (ret < 0)
3010  exit_program(1);
3011  }
3012  }
3013  else {
3014  switch (type) {
3015  case 'g':
3016  m = &oc->metadata;
3017  break;
3018  case 'c':
3019  if (index < 0 || index >= oc->nb_chapters) {
3020  av_log(NULL, AV_LOG_FATAL, "Invalid chapter index %d in metadata specifier.\n", index);
3021  exit_program(1);
3022  }
3023  m = &oc->chapters[index]->metadata;
3024  break;
3025  case 'p':
3026  if (index < 0 || index >= oc->nb_programs) {
3027  av_log(NULL, AV_LOG_FATAL, "Invalid program index %d in metadata specifier.\n", index);
3028  exit_program(1);
3029  }
3030  m = &oc->programs[index]->metadata;
3031  break;
3032  default:
3033  av_log(NULL, AV_LOG_FATAL, "Invalid metadata specifier %s.\n", o->metadata[i].specifier);
3034  exit_program(1);
3035  }
3036  av_dict_set(m, o->metadata[i].u.str, *val ? val : NULL, 0);
3037  }
3038  }
3039 
3040  err = set_dispositions(of, oc);
3041  if (err < 0) {
3042  av_log(NULL, AV_LOG_FATAL, "Error setting output stream dispositions\n");
3043  exit_program(1);
3044  }
3045 
3046  return 0;
3047 }
3048 
3049 static int opt_target(void *optctx, const char *opt, const char *arg)
3050 {
3051  OptionsContext *o = optctx;
3052  enum { PAL, NTSC, FILM, UNKNOWN } norm = UNKNOWN;
3053  static const char *const frame_rates[] = { "25", "30000/1001", "24000/1001" };
3054 
3055  if (!strncmp(arg, "pal-", 4)) {
3056  norm = PAL;
3057  arg += 4;
3058  } else if (!strncmp(arg, "ntsc-", 5)) {
3059  norm = NTSC;
3060  arg += 5;
3061  } else if (!strncmp(arg, "film-", 5)) {
3062  norm = FILM;
3063  arg += 5;
3064  } else {
3065  /* Try to determine PAL/NTSC by peeking in the input files */
3066  if (nb_input_files) {
3067  int i, j;
3068  for (j = 0; j < nb_input_files; j++) {
3069  for (i = 0; i < input_files[j]->nb_streams; i++) {
3070  AVStream *st = input_files[j]->ctx->streams[i];
3071  int64_t fr;
3073  continue;
3074  fr = st->time_base.den * 1000LL / st->time_base.num;
3075  if (fr == 25000) {
3076  norm = PAL;
3077  break;
3078  } else if ((fr == 29970) || (fr == 23976)) {
3079  norm = NTSC;
3080  break;
3081  }
3082  }
3083  if (norm != UNKNOWN)
3084  break;
3085  }
3086  }
3087  if (norm != UNKNOWN)
3088  av_log(NULL, AV_LOG_INFO, "Assuming %s for target.\n", norm == PAL ? "PAL" : "NTSC");
3089  }
3090 
3091  if (norm == UNKNOWN) {
3092  av_log(NULL, AV_LOG_FATAL, "Could not determine norm (PAL/NTSC/NTSC-Film) for target.\n");
3093  av_log(NULL, AV_LOG_FATAL, "Please prefix target with \"pal-\", \"ntsc-\" or \"film-\",\n");
3094  av_log(NULL, AV_LOG_FATAL, "or set a framerate with \"-r xxx\".\n");
3095  exit_program(1);
3096  }
3097 
3098  if (!strcmp(arg, "vcd")) {
3099  opt_video_codec(o, "c:v", "mpeg1video");
3100  opt_audio_codec(o, "c:a", "mp2");
3101  parse_option(o, "f", "vcd", options);
3102 
3103  parse_option(o, "s", norm == PAL ? "352x288" : "352x240", options);
3104  parse_option(o, "r", frame_rates[norm], options);
3105  opt_default(NULL, "g", norm == PAL ? "15" : "18");
3106 
3107  opt_default(NULL, "b:v", "1150000");
3108  opt_default(NULL, "maxrate:v", "1150000");
3109  opt_default(NULL, "minrate:v", "1150000");
3110  opt_default(NULL, "bufsize:v", "327680"); // 40*1024*8;
3111 
3112  opt_default(NULL, "b:a", "224000");
3113  parse_option(o, "ar", "44100", options);
3114  parse_option(o, "ac", "2", options);
3115 
3116  opt_default(NULL, "packetsize", "2324");
3117  opt_default(NULL, "muxrate", "1411200"); // 2352 * 75 * 8;
3118 
3119  /* We have to offset the PTS, so that it is consistent with the SCR.
3120  SCR starts at 36000, but the first two packs contain only padding
3121  and the first pack from the other stream, respectively, may also have
3122  been written before.
3123  So the real data starts at SCR 36000+3*1200. */
3124  o->mux_preload = (36000 + 3 * 1200) / 90000.0; // 0.44
3125  } else if (!strcmp(arg, "svcd")) {
3126 
3127  opt_video_codec(o, "c:v", "mpeg2video");
3128  opt_audio_codec(o, "c:a", "mp2");
3129  parse_option(o, "f", "svcd", options);
3130 
3131  parse_option(o, "s", norm == PAL ? "480x576" : "480x480", options);
3132  parse_option(o, "r", frame_rates[norm], options);
3133  parse_option(o, "pix_fmt", "yuv420p", options);
3134  opt_default(NULL, "g", norm == PAL ? "15" : "18");
3135 
3136  opt_default(NULL, "b:v", "2040000");
3137  opt_default(NULL, "maxrate:v", "2516000");
3138  opt_default(NULL, "minrate:v", "0"); // 1145000;
3139  opt_default(NULL, "bufsize:v", "1835008"); // 224*1024*8;
3140  opt_default(NULL, "scan_offset", "1");
3141 
3142  opt_default(NULL, "b:a", "224000");
3143  parse_option(o, "ar", "44100", options);
3144 
3145  opt_default(NULL, "packetsize", "2324");
3146 
3147  } else if (!strcmp(arg, "dvd")) {
3148 
3149  opt_video_codec(o, "c:v", "mpeg2video");
3150  opt_audio_codec(o, "c:a", "ac3");
3151  parse_option(o, "f", "dvd", options);
3152 
3153  parse_option(o, "s", norm == PAL ? "720x576" : "720x480", options);
3154  parse_option(o, "r", frame_rates[norm], options);
3155  parse_option(o, "pix_fmt", "yuv420p", options);
3156  opt_default(NULL, "g", norm == PAL ? "15" : "18");
3157 
3158  opt_default(NULL, "b:v", "6000000");
3159  opt_default(NULL, "maxrate:v", "9000000");
3160  opt_default(NULL, "minrate:v", "0"); // 1500000;
3161  opt_default(NULL, "bufsize:v", "1835008"); // 224*1024*8;
3162 
3163  opt_default(NULL, "packetsize", "2048"); // from www.mpucoder.com: DVD sectors contain 2048 bytes of data, this is also the size of one pack.
3164  opt_default(NULL, "muxrate", "10080000"); // from mplex project: data_rate = 1260000. mux_rate = data_rate * 8
3165 
3166  opt_default(NULL, "b:a", "448000");
3167  parse_option(o, "ar", "48000", options);
3168 
3169  } else if (!strncmp(arg, "dv", 2)) {
3170 
3171  parse_option(o, "f", "dv", options);
3172 
3173  parse_option(o, "s", norm == PAL ? "720x576" : "720x480", options);
3174  parse_option(o, "pix_fmt", !strncmp(arg, "dv50", 4) ? "yuv422p" :
3175  norm == PAL ? "yuv420p" : "yuv411p", options);
3176  parse_option(o, "r", frame_rates[norm], options);
3177 
3178  parse_option(o, "ar", "48000", options);
3179  parse_option(o, "ac", "2", options);
3180 
3181  } else {
3182  av_log(NULL, AV_LOG_ERROR, "Unknown target: %s\n", arg);
3183  return AVERROR(EINVAL);
3184  }
3185 
3188 
3189  return 0;
3190 }
3191 
3192 static int opt_vstats_file(void *optctx, const char *opt, const char *arg)
3193 {
3196  return 0;
3197 }
3198 
3199 static int opt_vstats(void *optctx, const char *opt, const char *arg)
3200 {
3201  char filename[40];
3202  time_t today2 = time(NULL);
3203  struct tm *today = localtime(&today2);
3204 
3205  if (!today) { // maybe tomorrow
3206  av_log(NULL, AV_LOG_FATAL, "Unable to get current time: %s\n", strerror(errno));
3207  exit_program(1);
3208  }
3209 
3210  snprintf(filename, sizeof(filename), "vstats_%02d%02d%02d.log", today->tm_hour, today->tm_min,
3211  today->tm_sec);
3212  return opt_vstats_file(NULL, opt, filename);
3213 }
3214 
3215 static int opt_video_frames(void *optctx, const char *opt, const char *arg)
3216 {
3217  OptionsContext *o = optctx;
3218  return parse_option(o, "frames:v", arg, options);
3219 }
3220 
3221 static int opt_audio_frames(void *optctx, const char *opt, const char *arg)
3222 {
3223  OptionsContext *o = optctx;
3224  return parse_option(o, "frames:a", arg, options);
3225 }
3226 
3227 static int opt_data_frames(void *optctx, const char *opt, const char *arg)
3228 {
3229  OptionsContext *o = optctx;
3230  return parse_option(o, "frames:d", arg, options);
3231 }
3232 
3233 static int opt_default_new(OptionsContext *o, const char *opt, const char *arg)
3234 {
3235  int ret;
3236  AVDictionary *cbak = codec_opts;
3237  AVDictionary *fbak = format_opts;
3238  codec_opts = NULL;
3239  format_opts = NULL;
3240 
3241  ret = opt_default(NULL, opt, arg);
3242 
3243  av_dict_copy(&o->g->codec_opts , codec_opts, 0);
3247  codec_opts = cbak;
3248  format_opts = fbak;
3249 
3250  return ret;
3251 }
3252 
3253 static int opt_preset(void *optctx, const char *opt, const char *arg)
3254 {
3255  OptionsContext *o = optctx;
3256  FILE *f=NULL;
3257  char filename[1000], line[1000], tmp_line[1000];
3258  const char *codec_name = NULL;
3259 
3260  tmp_line[0] = *opt;
3261  tmp_line[1] = 0;
3262  MATCH_PER_TYPE_OPT(codec_names, str, codec_name, NULL, tmp_line);
3263 
3264  if (!(f = get_preset_file(filename, sizeof(filename), arg, *opt == 'f', codec_name))) {
3265  if(!strncmp(arg, "libx264-lossless", strlen("libx264-lossless"))){
3266  av_log(NULL, AV_LOG_FATAL, "Please use -preset <speed> -qp 0\n");
3267  }else
3268  av_log(NULL, AV_LOG_FATAL, "File for preset '%s' not found\n", arg);
3269  exit_program(1);
3270  }
3271 
3272  while (fgets(line, sizeof(line), f)) {
3273  char *key = tmp_line, *value, *endptr;
3274 
3275  if (strcspn(line, "#\n\r") == 0)
3276  continue;
3277  av_strlcpy(tmp_line, line, sizeof(tmp_line));
3278  if (!av_strtok(key, "=", &value) ||
3279  !av_strtok(value, "\r\n", &endptr)) {
3280  av_log(NULL, AV_LOG_FATAL, "%s: Invalid syntax: '%s'\n", filename, line);
3281  exit_program(1);
3282  }
3283  av_log(NULL, AV_LOG_DEBUG, "ffpreset[%s]: set '%s' = '%s'\n", filename, key, value);
3284 
3285  if (!strcmp(key, "acodec")) opt_audio_codec (o, key, value);
3286  else if (!strcmp(key, "vcodec")) opt_video_codec (o, key, value);
3287  else if (!strcmp(key, "scodec")) opt_subtitle_codec(o, key, value);
3288  else if (!strcmp(key, "dcodec")) opt_data_codec (o, key, value);
3289  else if (opt_default_new(o, key, value) < 0) {
3290  av_log(NULL, AV_LOG_FATAL, "%s: Invalid option or argument: '%s', parsed as '%s' = '%s'\n",
3291  filename, line, key, value);
3292  exit_program(1);
3293  }
3294  }
3295 
3296  fclose(f);
3297 
3298  return 0;
3299 }
3300 
3301 static int opt_old2new(void *optctx, const char *opt, const char *arg)
3302 {
3303  OptionsContext *o = optctx;
3304  int ret;
3305  char *s = av_asprintf("%s:%c", opt + 1, *opt);
3306  if (!s)
3307  return AVERROR(ENOMEM);
3308  ret = parse_option(o, s, arg, options);
3309  av_free(s);
3310  return ret;
3311 }
3312 
3313 static int opt_bitrate(void *optctx, const char *opt, const char *arg)
3314 {
3315  OptionsContext *o = optctx;
3316 
3317  if(!strcmp(opt, "ab")){
3318  av_dict_set(&o->g->codec_opts, "b:a", arg, 0);
3319  return 0;
3320  } else if(!strcmp(opt, "b")){
3321  av_log(NULL, AV_LOG_WARNING, "Please use -b:a or -b:v, -b is ambiguous\n");
3322  av_dict_set(&o->g->codec_opts, "b:v", arg, 0);
3323  return 0;
3324  }
3325  av_dict_set(&o->g->codec_opts, opt, arg, 0);
3326  return 0;
3327 }
3328 
3329 static int opt_qscale(void *optctx, const char *opt, const char *arg)
3330 {
3331  OptionsContext *o = optctx;
3332  char *s;
3333  int ret;
3334  if(!strcmp(opt, "qscale")){
3335  av_log(NULL, AV_LOG_WARNING, "Please use -q:a or -q:v, -qscale is ambiguous\n");
3336  return parse_option(o, "q:v", arg, options);
3337  }
3338  s = av_asprintf("q%s", opt + 6);
3339  if (!s)
3340  return AVERROR(ENOMEM);
3341  ret = parse_option(o, s, arg, options);
3342  av_free(s);
3343  return ret;
3344 }
3345 
3346 static int opt_profile(void *optctx, const char *opt, const char *arg)
3347 {
3348  OptionsContext *o = optctx;
3349  if(!strcmp(opt, "profile")){
3350  av_log(NULL, AV_LOG_WARNING, "Please use -profile:a or -profile:v, -profile is ambiguous\n");
3351  av_dict_set(&o->g->codec_opts, "profile:v", arg, 0);
3352  return 0;
3353  }
3354  av_dict_set(&o->g->codec_opts, opt, arg, 0);
3355  return 0;
3356 }
3357 
3358 static int opt_video_filters(void *optctx, const char *opt, const char *arg)
3359 {
3360  OptionsContext *o = optctx;
3361  return parse_option(o, "filter:v", arg, options);
3362 }
3363 
3364 static int opt_audio_filters(void *optctx, const char *opt, const char *arg)
3365 {
3366  OptionsContext *o = optctx;
3367  return parse_option(o, "filter:a", arg, options);
3368 }
3369 
3370 static int opt_vsync(void *optctx, const char *opt, const char *arg)
3371 {
3372  av_log(NULL, AV_LOG_WARNING, "-vsync is deprecated. Use -fps_mode\n");
3374  return 0;
3375 }
3376 
3377 static int opt_timecode(void *optctx, const char *opt, const char *arg)
3378 {
3379  OptionsContext *o = optctx;
3380  int ret;
3381  char *tcr = av_asprintf("timecode=%s", arg);
3382  if (!tcr)
3383  return AVERROR(ENOMEM);
3384  ret = parse_option(o, "metadata:g", tcr, options);
3385  if (ret >= 0)
3386  ret = av_dict_set(&o->g->codec_opts, "gop_timecode", arg, 0);
3387  av_free(tcr);
3388  return ret;
3389 }
3390 
3391 static int opt_audio_qscale(void *optctx, const char *opt, const char *arg)
3392 {
3393  OptionsContext *o = optctx;
3394  return parse_option(o, "q:a", arg, options);
3395 }
3396 
3397 static int opt_filter_complex(void *optctx, const char *opt, const char *arg)
3398 {
3400 
3401  fg->index = nb_filtergraphs - 1;
3402  fg->graph_desc = av_strdup(arg);
3403  if (!fg->graph_desc)
3404  return AVERROR(ENOMEM);
3405 
3407 
3408  return 0;
3409 }
3410 
3411 static int opt_filter_complex_script(void *optctx, const char *opt, const char *arg)
3412 {
3413  FilterGraph *fg;
3414  char *graph_desc = read_file(arg);
3415  if (!graph_desc)
3416  return AVERROR(EINVAL);
3417 
3419  fg->index = nb_filtergraphs - 1;
3420  fg->graph_desc = graph_desc;
3421 
3423 
3424  return 0;
3425 }
3426 
3427 void show_help_default(const char *opt, const char *arg)
3428 {
3429  /* per-file options have at least one of those set */
3430  const int per_file = OPT_SPEC | OPT_OFFSET | OPT_PERFILE;
3431  int show_advanced = 0, show_avoptions = 0;
3432 
3433  if (opt && *opt) {
3434  if (!strcmp(opt, "long"))
3435  show_advanced = 1;
3436  else if (!strcmp(opt, "full"))
3437  show_advanced = show_avoptions = 1;
3438  else
3439  av_log(NULL, AV_LOG_ERROR, "Unknown help option '%s'.\n", opt);
3440  }
3441 
3442  show_usage();
3443 
3444  printf("Getting help:\n"
3445  " -h -- print basic options\n"
3446  " -h long -- print more options\n"
3447  " -h full -- print all options (including all format and codec specific options, very long)\n"
3448  " -h type=name -- print all options for the named decoder/encoder/demuxer/muxer/filter/bsf/protocol\n"
3449  " See man %s for detailed description of the options.\n"
3450  "\n", program_name);
3451 
3452  show_help_options(options, "Print help / information / capabilities:",
3453  OPT_EXIT, 0, 0);
3454 
3455  show_help_options(options, "Global options (affect whole program "
3456  "instead of just one file):",
3457  0, per_file | OPT_EXIT | OPT_EXPERT, 0);
3458  if (show_advanced)
3459  show_help_options(options, "Advanced global options:", OPT_EXPERT,
3460  per_file | OPT_EXIT, 0);
3461 
3462  show_help_options(options, "Per-file main options:", 0,
3464  OPT_EXIT, per_file);
3465  if (show_advanced)
3466  show_help_options(options, "Advanced per-file options:",
3467  OPT_EXPERT, OPT_AUDIO | OPT_VIDEO | OPT_SUBTITLE, per_file);
3468 
3469  show_help_options(options, "Video options:",
3471  if (show_advanced)
3472  show_help_options(options, "Advanced Video options:",
3474 
3475  show_help_options(options, "Audio options:",
3477  if (show_advanced)
3478  show_help_options(options, "Advanced Audio options:",
3480  show_help_options(options, "Subtitle options:",
3481  OPT_SUBTITLE, 0, 0);
3482  printf("\n");
3483 
3484  if (show_avoptions) {
3488 #if CONFIG_SWSCALE
3490 #endif
3491 #if CONFIG_SWRESAMPLE
3493 #endif
3496  }
3497 }
3498 
3499 void show_usage(void)
3500 {
3501  av_log(NULL, AV_LOG_INFO, "Hyper fast Audio and Video encoder\n");
3502  av_log(NULL, AV_LOG_INFO, "usage: %s [options] [[infile options] -i infile]... {[outfile options] outfile}...\n", program_name);
3503  av_log(NULL, AV_LOG_INFO, "\n");
3504 }
3505 
3506 enum OptGroup {
3507  GROUP_OUTFILE,
3508  GROUP_INFILE,
3509 };
3510 
3511 static const OptionGroupDef groups[] = {
3512  [GROUP_OUTFILE] = { "output url", NULL, OPT_OUTPUT },
3513  [GROUP_INFILE] = { "input url", "i", OPT_INPUT },
3514 };
3515 
3516 static int open_files(OptionGroupList *l, const char *inout,
3517  int (*open_file)(OptionsContext*, const char*))
3518 {
3519  int i, ret;
3520 
3521  for (i = 0; i < l->nb_groups; i++) {
3522  OptionGroup *g = &l->groups[i];
3523  OptionsContext o;
3524 
3525  init_options(&o);
3526  o.g = g;
3527 
3528  ret = parse_optgroup(&o, g);
3529  if (ret < 0) {
3530  av_log(NULL, AV_LOG_ERROR, "Error parsing options for %s file "
3531  "%s.\n", inout, g->arg);
3532  uninit_options(&o);
3533  return ret;
3534  }
3535 
3536  av_log(NULL, AV_LOG_DEBUG, "Opening an %s file: %s.\n", inout, g->arg);
3537  ret = open_file(&o, g->arg);
3538  uninit_options(&o);
3539  if (ret < 0) {
3540  av_log(NULL, AV_LOG_ERROR, "Error opening %s file %s.\n",
3541  inout, g->arg);
3542  return ret;
3543  }
3544  av_log(NULL, AV_LOG_DEBUG, "Successfully opened the file.\n");
3545  }
3546 
3547  return 0;
3548 }
3549 
3550 int ffmpeg_parse_options(int argc, char **argv)
3551 {
3552  OptionParseContext octx;
3553  uint8_t error[128];
3554  int ret;
3555 
3556  memset(&octx, 0, sizeof(octx));
3557 
3558  /* split the commandline into an internal representation */
3559  ret = split_commandline(&octx, argc, argv, options, groups,
3560  FF_ARRAY_ELEMS(groups));
3561  if (ret < 0) {
3562  av_log(NULL, AV_LOG_FATAL, "Error splitting the argument list: ");
3563  goto fail;
3564  }
3565 
3566  /* apply global options */
3567  ret = parse_optgroup(NULL, &octx.global_opts);
3568  if (ret < 0) {
3569  av_log(NULL, AV_LOG_FATAL, "Error parsing global options: ");
3570  goto fail;
3571  }
3572 
3573  /* configure terminal and setup signal handlers */
3574  term_init();
3575 
3576  /* open input files */
3577  ret = open_files(&octx.groups[GROUP_INFILE], "input", open_input_file);
3578  if (ret < 0) {
3579  av_log(NULL, AV_LOG_FATAL, "Error opening input files: ");
3580  goto fail;
3581  }
3582 
3584 
3585  /* create the complex filtergraphs */
3587  if (ret < 0) {
3588  av_log(NULL, AV_LOG_FATAL, "Error initializing complex filters.\n");
3589  goto fail;
3590  }
3591 
3592  /* open output files */
3593  ret = open_files(&octx.groups[GROUP_OUTFILE], "output", open_output_file);
3594  if (ret < 0) {
3595  av_log(NULL, AV_LOG_FATAL, "Error opening output files: ");
3596  goto fail;
3597  }
3598 
3600 
3601 fail:
3602  uninit_parse_context(&octx);
3603  if (ret < 0) {
3604  av_strerror(ret, error, sizeof(error));
3605  av_log(NULL, AV_LOG_FATAL, "%s\n", error);
3606  }
3607  return ret;
3608 }
3609 
3610 static int opt_progress(void *optctx, const char *opt, const char *arg)
3611 {
3612  AVIOContext *avio = NULL;
3613  int ret;
3614 
3615  if (!strcmp(arg, "-"))
3616  arg = "pipe:";
3617  ret = avio_open2(&avio, arg, AVIO_FLAG_WRITE, &int_cb, NULL);
3618  if (ret < 0) {
3619  av_log(NULL, AV_LOG_ERROR, "Failed to open progress URL \"%s\": %s\n",
3620  arg, av_err2str(ret));
3621  return ret;
3622  }
3623  progress_avio = avio;
3624  return 0;
3625 }
3626 
3627 int opt_timelimit(void *optctx, const char *opt, const char *arg)
3628 {
3629 #if HAVE_SETRLIMIT
3630  int lim = parse_number_or_die(opt, arg, OPT_INT64, 0, INT_MAX);
3631  struct rlimit rl = { lim, lim + 1 };
3632  if (setrlimit(RLIMIT_CPU, &rl))
3633  perror("setrlimit");
3634 #else
3635  av_log(NULL, AV_LOG_WARNING, "-%s not implemented on this OS\n", opt);
3636 #endif
3637  return 0;
3638 }
3639 
3640 #define OFFSET(x) offsetof(OptionsContext, x)
3641 const OptionDef options[] = {
3642  /* main options */
3644  { "f", HAS_ARG | OPT_STRING | OPT_OFFSET |
3645  OPT_INPUT | OPT_OUTPUT, { .off = OFFSET(format) },
3646  "force format", "fmt" },
3647  { "y", OPT_BOOL, { &file_overwrite },
3648  "overwrite output files" },
3649  { "n", OPT_BOOL, { &no_file_overwrite },
3650  "never overwrite output files" },
3651  { "ignore_unknown", OPT_BOOL, { &ignore_unknown_streams },
3652  "Ignore unknown stream types" },
3653  { "copy_unknown", OPT_BOOL | OPT_EXPERT, { &copy_unknown_streams },
3654  "Copy unknown stream types" },
3655  { "recast_media", OPT_BOOL | OPT_EXPERT, { &recast_media },
3656  "allow recasting stream type in order to force a decoder of different media type" },
3657  { "c", HAS_ARG | OPT_STRING | OPT_SPEC |
3658  OPT_INPUT | OPT_OUTPUT, { .off = OFFSET(codec_names) },
3659  "codec name", "codec" },
3660  { "codec", HAS_ARG | OPT_STRING | OPT_SPEC |
3661  OPT_INPUT | OPT_OUTPUT, { .off = OFFSET(codec_names) },
3662  "codec name", "codec" },
3663  { "pre", HAS_ARG | OPT_STRING | OPT_SPEC |
3664  OPT_OUTPUT, { .off = OFFSET(presets) },
3665  "preset name", "preset" },
3666  { "map", HAS_ARG | OPT_EXPERT | OPT_PERFILE |
3667  OPT_OUTPUT, { .func_arg = opt_map },
3668  "set input stream mapping",
3669  "[-]input_file_id[:stream_specifier][,sync_file_id[:stream_specifier]]" },
3670  { "map_channel", HAS_ARG | OPT_EXPERT | OPT_PERFILE | OPT_OUTPUT, { .func_arg = opt_map_channel },
3671  "map an audio channel from one stream to another", "file.stream.channel[:syncfile.syncstream]" },
3672  { "map_metadata", HAS_ARG | OPT_STRING | OPT_SPEC |
3673  OPT_OUTPUT, { .off = OFFSET(metadata_map) },
3674  "set metadata information of outfile from infile",
3675  "outfile[,metadata]:infile[,metadata]" },
3676  { "map_chapters", HAS_ARG | OPT_INT | OPT_EXPERT | OPT_OFFSET |
3677  OPT_OUTPUT, { .off = OFFSET(chapters_input_file) },
3678  "set chapters mapping", "input_file_index" },
3679  { "t", HAS_ARG | OPT_TIME | OPT_OFFSET |
3680  OPT_INPUT | OPT_OUTPUT, { .off = OFFSET(recording_time) },
3681  "record or transcode \"duration\" seconds of audio/video",
3682  "duration" },
3683  { "to", HAS_ARG | OPT_TIME | OPT_OFFSET | OPT_INPUT | OPT_OUTPUT, { .off = OFFSET(stop_time) },
3684  "record or transcode stop time", "time_stop" },
3685  { "fs", HAS_ARG | OPT_INT64 | OPT_OFFSET | OPT_OUTPUT, { .off = OFFSET(limit_filesize) },
3686  "set the limit file size in bytes", "limit_size" },
3687  { "ss", HAS_ARG | OPT_TIME | OPT_OFFSET |
3688  OPT_INPUT | OPT_OUTPUT, { .off = OFFSET(start_time) },
3689  "set the start time offset", "time_off" },
3690  { "sseof", HAS_ARG | OPT_TIME | OPT_OFFSET |
3691  OPT_INPUT, { .off = OFFSET(start_time_eof) },
3692  "set the start time offset relative to EOF", "time_off" },
3693  { "seek_timestamp", HAS_ARG | OPT_INT | OPT_OFFSET |
3694  OPT_INPUT, { .off = OFFSET(seek_timestamp) },
3695  "enable/disable seeking by timestamp with -ss" },
3696  { "accurate_seek", OPT_BOOL | OPT_OFFSET | OPT_EXPERT |
3697  OPT_INPUT, { .off = OFFSET(accurate_seek) },
3698  "enable/disable accurate seeking with -ss" },
3699  { "isync", HAS_ARG | OPT_INT | OPT_OFFSET |
3700  OPT_EXPERT | OPT_INPUT, { .off = OFFSET(input_sync_ref) },
3701  "Indicate the input index for sync reference", "sync ref" },
3702  { "itsoffset", HAS_ARG | OPT_TIME | OPT_OFFSET |
3703  OPT_EXPERT | OPT_INPUT, { .off = OFFSET(input_ts_offset) },
3704  "set the input ts offset", "time_off" },
3705  { "itsscale", HAS_ARG | OPT_DOUBLE | OPT_SPEC |
3706  OPT_EXPERT | OPT_INPUT, { .off = OFFSET(ts_scale) },
3707  "set the input ts scale", "scale" },
3708  { "timestamp", HAS_ARG | OPT_PERFILE | OPT_OUTPUT, { .func_arg = opt_recording_timestamp },
3709  "set the recording timestamp ('now' to set the current time)", "time" },
3710  { "metadata", HAS_ARG | OPT_STRING | OPT_SPEC | OPT_OUTPUT, { .off = OFFSET(metadata) },
3711  "add metadata", "string=string" },
3712  { "program", HAS_ARG | OPT_STRING | OPT_SPEC | OPT_OUTPUT, { .off = OFFSET(program) },
3713  "add program with specified streams", "title=string:st=number..." },
3714  { "dframes", HAS_ARG | OPT_PERFILE | OPT_EXPERT |
3715  OPT_OUTPUT, { .func_arg = opt_data_frames },
3716  "set the number of data frames to output", "number" },
3717  { "benchmark", OPT_BOOL | OPT_EXPERT, { &do_benchmark },
3718  "add timings for benchmarking" },
3719  { "benchmark_all", OPT_BOOL | OPT_EXPERT, { &do_benchmark_all },
3720  "add timings for each task" },
3721  { "progress", HAS_ARG | OPT_EXPERT, { .func_arg = opt_progress },
3722  "write program-readable progress information", "url" },
3723  { "stdin", OPT_BOOL | OPT_EXPERT, { &stdin_interaction },
3724  "enable or disable interaction on standard input" },
3725  { "timelimit", HAS_ARG | OPT_EXPERT, { .func_arg = opt_timelimit },
3726  "set max runtime in seconds in CPU user time", "limit" },
3727  { "dump", OPT_BOOL | OPT_EXPERT, { &do_pkt_dump },
3728  "dump each input packet" },
3729  { "hex", OPT_BOOL | OPT_EXPERT, { &do_hex_dump },
3730  "when dumping packets, also dump the payload" },
3731  { "re", OPT_BOOL | OPT_EXPERT | OPT_OFFSET |
3732  OPT_INPUT, { .off = OFFSET(rate_emu) },
3733  "read input at native frame rate; equivalent to -readrate 1", "" },
3734  { "readrate", HAS_ARG | OPT_FLOAT | OPT_OFFSET |
3735  OPT_EXPERT | OPT_INPUT, { .off = OFFSET(readrate) },
3736  "read input at specified rate", "speed" },
3737  { "target", HAS_ARG | OPT_PERFILE | OPT_OUTPUT, { .func_arg = opt_target },
3738  "specify target file type (\"vcd\", \"svcd\", \"dvd\", \"dv\" or \"dv50\" "
3739  "with optional prefixes \"pal-\", \"ntsc-\" or \"film-\")", "type" },
3740  { "vsync", HAS_ARG | OPT_EXPERT, { .func_arg = opt_vsync },
3741  "set video sync method globally; deprecated, use -fps_mode", "" },
3742  { "frame_drop_threshold", HAS_ARG | OPT_FLOAT | OPT_EXPERT, { &frame_drop_threshold },
3743  "frame drop threshold", "" },
3744  { "async", HAS_ARG | OPT_INT | OPT_EXPERT, { &audio_sync_method },
3745  "audio sync method", "" },
3746  { "adrift_threshold", HAS_ARG | OPT_FLOAT | OPT_EXPERT, { &audio_drift_threshold },
3747  "audio drift threshold", "threshold" },
3748  { "copyts", OPT_BOOL | OPT_EXPERT, { &copy_ts },
3749  "copy timestamps" },
3750  { "start_at_zero", OPT_BOOL | OPT_EXPERT, { &start_at_zero },
3751  "shift input timestamps to start at 0 when using copyts" },
3752  { "copytb", HAS_ARG | OPT_INT | OPT_EXPERT, { &copy_tb },
3753  "copy input stream time base when stream copying", "mode" },
3754  { "shortest", OPT_BOOL | OPT_EXPERT | OPT_OFFSET |
3755  OPT_OUTPUT, { .off = OFFSET(shortest) },
3756  "finish encoding within shortest input" },
3757  { "bitexact", OPT_BOOL | OPT_EXPERT | OPT_OFFSET |
3758  OPT_OUTPUT | OPT_INPUT, { .off = OFFSET(bitexact) },
3759  "bitexact mode" },
3760  { "apad", OPT_STRING | HAS_ARG | OPT_SPEC |
3761  OPT_OUTPUT, { .off = OFFSET(apad) },
3762  "audio pad", "" },
3763  { "dts_delta_threshold", HAS_ARG | OPT_FLOAT | OPT_EXPERT, { &dts_delta_threshold },
3764  "timestamp discontinuity delta threshold", "threshold" },
3765  { "dts_error_threshold", HAS_ARG | OPT_FLOAT | OPT_EXPERT, { &dts_error_threshold },
3766  "timestamp error delta threshold", "threshold" },
3767  { "xerror", OPT_BOOL | OPT_EXPERT, { &exit_on_error },
3768  "exit on error", "error" },
3769  { "abort_on", HAS_ARG | OPT_EXPERT, { .func_arg = opt_abort_on },
3770  "abort on the specified condition flags", "flags" },
3771  { "copyinkf", OPT_BOOL | OPT_EXPERT | OPT_SPEC |
3772  OPT_OUTPUT, { .off = OFFSET(copy_initial_nonkeyframes) },
3773  "copy initial non-keyframes" },
3774  { "copypriorss", OPT_INT | HAS_ARG | OPT_EXPERT | OPT_SPEC | OPT_OUTPUT, { .off = OFFSET(copy_prior_start) },
3775  "copy or discard frames before start time" },
3776  { "frames", OPT_INT64 | HAS_ARG | OPT_SPEC | OPT_OUTPUT, { .off = OFFSET(max_frames) },
3777  "set the number of frames to output", "number" },
3778  { "tag", OPT_STRING | HAS_ARG | OPT_SPEC |
3779  OPT_EXPERT | OPT_OUTPUT | OPT_INPUT, { .off = OFFSET(codec_tags) },
3780  "force codec tag/fourcc", "fourcc/tag" },
3781  { "q", HAS_ARG | OPT_EXPERT | OPT_DOUBLE |
3782  OPT_SPEC | OPT_OUTPUT, { .off = OFFSET(qscale) },
3783  "use fixed quality scale (VBR)", "q" },
3784  { "qscale", HAS_ARG | OPT_EXPERT | OPT_PERFILE |
3785  OPT_OUTPUT, { .func_arg = opt_qscale },
3786  "use fixed quality scale (VBR)", "q" },
3787  { "profile", HAS_ARG | OPT_EXPERT | OPT_PERFILE | OPT_OUTPUT, { .func_arg = opt_profile },
3788  "set profile", "profile" },
3789  { "filter", HAS_ARG | OPT_STRING | OPT_SPEC | OPT_OUTPUT, { .off = OFFSET(filters) },
3790  "set stream filtergraph", "filter_graph" },
3791  { "filter_threads", HAS_ARG, { .func_arg = opt_filter_threads },
3792  "number of non-complex filter threads" },
3793  { "filter_script", HAS_ARG | OPT_STRING | OPT_SPEC | OPT_OUTPUT, { .off = OFFSET(filter_scripts) },
3794  "read stream filtergraph description from a file", "filename" },
3795  { "reinit_filter", HAS_ARG | OPT_INT | OPT_SPEC | OPT_INPUT, { .off = OFFSET(reinit_filters) },
3796  "reinit filtergraph on input parameter changes", "" },
3797  { "filter_complex", HAS_ARG | OPT_EXPERT, { .func_arg = opt_filter_complex },
3798  "create a complex filtergraph", "graph_description" },
3799  { "filter_complex_threads", HAS_ARG | OPT_INT, { &filter_complex_nbthreads },
3800  "number of threads for -filter_complex" },
3801  { "lavfi", HAS_ARG | OPT_EXPERT, { .func_arg = opt_filter_complex },
3802  "create a complex filtergraph", "graph_description" },
3803  { "filter_complex_script", HAS_ARG | OPT_EXPERT, { .func_arg = opt_filter_complex_script },
3804  "read complex filtergraph description from a file", "filename" },
3805  { "auto_conversion_filters", OPT_BOOL | OPT_EXPERT, { &auto_conversion_filters },
3806  "enable automatic conversion filters globally" },
3807  { "stats", OPT_BOOL, { &print_stats },
3808  "print progress report during encoding", },
3809  { "stats_period", HAS_ARG | OPT_EXPERT, { .func_arg = opt_stats_period },
3810  "set the period at which ffmpeg updates stats and -progress output", "time" },
3811  { "attach", HAS_ARG | OPT_PERFILE | OPT_EXPERT |
3812  OPT_OUTPUT, { .func_arg = opt_attach },
3813  "add an attachment to the output file", "filename" },
3814  { "dump_attachment", HAS_ARG | OPT_STRING | OPT_SPEC |
3815  OPT_EXPERT | OPT_INPUT, { .off = OFFSET(dump_attachment) },
3816  "extract an attachment into a file", "filename" },
3817  { "stream_loop", OPT_INT | HAS_ARG | OPT_EXPERT | OPT_INPUT |
3818  OPT_OFFSET, { .off = OFFSET(loop) }, "set number of times input stream shall be looped", "loop count" },
3819  { "debug_ts", OPT_BOOL | OPT_EXPERT, { &debug_ts },
3820  "print timestamp debugging info" },
3821  { "max_error_rate", HAS_ARG | OPT_FLOAT, { &max_error_rate },
3822  "ratio of decoding errors (0.0: no errors, 1.0: 100% errors) above which ffmpeg returns an error instead of success.", "maximum error rate" },
3823  { "discard", OPT_STRING | HAS_ARG | OPT_SPEC |
3824  OPT_INPUT, { .off = OFFSET(discard) },
3825  "discard", "" },
3826  { "disposition", OPT_STRING | HAS_ARG | OPT_SPEC |
3827  OPT_OUTPUT, { .off = OFFSET(disposition) },
3828  "disposition", "" },
3829  { "thread_queue_size", HAS_ARG | OPT_INT | OPT_OFFSET | OPT_EXPERT | OPT_INPUT,
3830  { .off = OFFSET(thread_queue_size) },
3831  "set the maximum number of queued packets from the demuxer" },
3832  { "find_stream_info", OPT_BOOL | OPT_PERFILE | OPT_INPUT | OPT_EXPERT, { &find_stream_info },
3833  "read and decode the streams to fill missing information with heuristics" },
3834  { "bits_per_raw_sample", OPT_INT | HAS_ARG | OPT_EXPERT | OPT_SPEC | OPT_OUTPUT,
3835  { .off = OFFSET(bits_per_raw_sample) },
3836  "set the number of bits per raw sample", "number" },
3837 
3838  /* video options */
3839  { "vframes", OPT_VIDEO | HAS_ARG | OPT_PERFILE | OPT_OUTPUT, { .func_arg = opt_video_frames },
3840  "set the number of video frames to output", "number" },
3841  { "r", OPT_VIDEO | HAS_ARG | OPT_STRING | OPT_SPEC |
3842  OPT_INPUT | OPT_OUTPUT, { .off = OFFSET(frame_rates) },
3843  "set frame rate (Hz value, fraction or abbreviation)", "rate" },
3844  { "fpsmax", OPT_VIDEO | HAS_ARG | OPT_STRING | OPT_SPEC |
3845  OPT_OUTPUT, { .off = OFFSET(max_frame_rates) },
3846  "set max frame rate (Hz value, fraction or abbreviation)", "rate" },
3848  OPT_INPUT | OPT_OUTPUT, { .off = OFFSET(frame_sizes) },
3849  "set frame size (WxH or abbreviation)", "size" },
3850  { "aspect", OPT_VIDEO | HAS_ARG | OPT_STRING | OPT_SPEC |
3851  OPT_OUTPUT, { .off = OFFSET(frame_aspect_ratios) },
3852  "set aspect ratio (4:3, 16:9 or 1.3333, 1.7777)", "aspect" },
3853  { "pix_fmt", OPT_VIDEO | HAS_ARG | OPT_EXPERT | OPT_STRING | OPT_SPEC |
3854  OPT_INPUT | OPT_OUTPUT, { .off = OFFSET(frame_pix_fmts) },
3855  "set pixel format", "format" },
3857  "disable video" },
3858  { "rc_override", OPT_VIDEO | HAS_ARG | OPT_EXPERT | OPT_STRING | OPT_SPEC |
3859  OPT_OUTPUT, { .off = OFFSET(rc_overrides) },
3860  "rate control override for specific intervals", "override" },
3861  { "vcodec", OPT_VIDEO | HAS_ARG | OPT_PERFILE | OPT_INPUT |
3862  OPT_OUTPUT, { .func_arg = opt_video_codec },
3863  "force video codec ('copy' to copy stream)", "codec" },
3864  { "timecode", OPT_VIDEO | HAS_ARG | OPT_PERFILE | OPT_OUTPUT, { .func_arg = opt_timecode },
3865  "set initial TimeCode value.", "hh:mm:ss[:;.]ff" },
3866  { "pass", OPT_VIDEO | HAS_ARG | OPT_SPEC | OPT_INT | OPT_OUTPUT, { .off = OFFSET(pass) },
3867  "select the pass number (1 to 3)", "n" },
3868  { "passlogfile", OPT_VIDEO | HAS_ARG | OPT_STRING | OPT_EXPERT | OPT_SPEC |
3869  OPT_OUTPUT, { .off = OFFSET(passlogfiles) },
3870  "select two pass log file name prefix", "prefix" },
3871  { "psnr", OPT_VIDEO | OPT_BOOL | OPT_EXPERT, { &do_psnr },
3872  "calculate PSNR of compressed frames" },
3873  { "vstats", OPT_VIDEO | OPT_EXPERT , { .func_arg = opt_vstats },
3874  "dump video coding statistics to file" },
3875  { "vstats_file", OPT_VIDEO | HAS_ARG | OPT_EXPERT , { .func_arg = opt_vstats_file },
3876  "dump video coding statistics to file", "file" },
3877  { "vstats_version", OPT_VIDEO | OPT_INT | HAS_ARG | OPT_EXPERT , { &vstats_version },
3878  "Version of the vstats format to use."},
3879  { "vf", OPT_VIDEO | HAS_ARG | OPT_PERFILE | OPT_OUTPUT, { .func_arg = opt_video_filters },
3880  "set video filters", "filter_graph" },
3881  { "intra_matrix", OPT_VIDEO | HAS_ARG | OPT_EXPERT | OPT_STRING | OPT_SPEC |
3882  OPT_OUTPUT, { .off = OFFSET(intra_matrices) },
3883  "specify intra matrix coeffs", "matrix" },
3884  { "inter_matrix", OPT_VIDEO | HAS_ARG | OPT_EXPERT | OPT_STRING | OPT_SPEC |
3885  OPT_OUTPUT, { .off = OFFSET(inter_matrices) },
3886  "specify inter matrix coeffs", "matrix" },
3887  { "chroma_intra_matrix", OPT_VIDEO | HAS_ARG | OPT_EXPERT | OPT_STRING | OPT_SPEC |
3888  OPT_OUTPUT, { .off = OFFSET(chroma_intra_matrices) },
3889  "specify intra matrix coeffs", "matrix" },
3890  { "top", OPT_VIDEO | HAS_ARG | OPT_EXPERT | OPT_INT| OPT_SPEC |
3891  OPT_INPUT | OPT_OUTPUT, { .off = OFFSET(top_field_first) },
3892  "top=1/bottom=0/auto=-1 field first", "" },
3893  { "vtag", OPT_VIDEO | HAS_ARG | OPT_EXPERT | OPT_PERFILE |
3894  OPT_INPUT | OPT_OUTPUT, { .func_arg = opt_old2new },
3895  "force video tag/fourcc", "fourcc/tag" },
3896  { "qphist", OPT_VIDEO | OPT_BOOL | OPT_EXPERT , { &qp_hist },
3897  "show QP histogram" },
3898  { "fps_mode", OPT_VIDEO | HAS_ARG | OPT_STRING | OPT_EXPERT |
3899  OPT_SPEC | OPT_OUTPUT, { .off = OFFSET(fps_mode) },
3900  "set framerate mode for matching video streams; overrides vsync" },
3901  { "force_fps", OPT_VIDEO | OPT_BOOL | OPT_EXPERT | OPT_SPEC |
3902  OPT_OUTPUT, { .off = OFFSET(force_fps) },
3903  "force the selected framerate, disable the best supported framerate selection" },
3904  { "streamid", OPT_VIDEO | HAS_ARG | OPT_EXPERT | OPT_PERFILE |
3905  OPT_OUTPUT, { .func_arg = opt_streamid },
3906  "set the value of an outfile streamid", "streamIndex:value" },
3907  { "force_key_frames", OPT_VIDEO | OPT_STRING | HAS_ARG | OPT_EXPERT |
3908  OPT_SPEC | OPT_OUTPUT, { .off = OFFSET(forced_key_frames) },
3909  "force key frames at specified timestamps", "timestamps" },
3910  { "ab", OPT_VIDEO | HAS_ARG | OPT_PERFILE | OPT_OUTPUT, { .func_arg = opt_bitrate },
3911  "audio bitrate (please use -b:a)", "bitrate" },
3912  { "b", OPT_VIDEO | HAS_ARG | OPT_PERFILE | OPT_OUTPUT, { .func_arg = opt_bitrate },
3913  "video bitrate (please use -b:v)", "bitrate" },
3914  { "hwaccel", OPT_VIDEO | OPT_STRING | HAS_ARG | OPT_EXPERT |
3915  OPT_SPEC | OPT_INPUT, { .off = OFFSET(hwaccels) },
3916  "use HW accelerated decoding", "hwaccel name" },
3917  { "hwaccel_device", OPT_VIDEO | OPT_STRING | HAS_ARG | OPT_EXPERT |
3918  OPT_SPEC | OPT_INPUT, { .off = OFFSET(hwaccel_devices) },
3919  "select a device for HW acceleration", "devicename" },
3920  { "hwaccel_output_format", OPT_VIDEO | OPT_STRING | HAS_ARG | OPT_EXPERT |
3921  OPT_SPEC | OPT_INPUT, { .off = OFFSET(hwaccel_output_formats) },
3922  "select output format used with HW accelerated decoding", "format" },
3923  { "hwaccels", OPT_EXIT, { .func_arg = show_hwaccels },
3924  "show available HW acceleration methods" },
3925  { "autorotate", HAS_ARG | OPT_BOOL | OPT_SPEC |
3926  OPT_EXPERT | OPT_INPUT, { .off = OFFSET(autorotate) },
3927  "automatically insert correct rotate filters" },
3928  { "autoscale", HAS_ARG | OPT_BOOL | OPT_SPEC |
3929  OPT_EXPERT | OPT_OUTPUT, { .off = OFFSET(autoscale) },
3930  "automatically insert a scale filter at the end of the filter graph" },
3931 
3932  /* audio options */
3933  { "aframes", OPT_AUDIO | HAS_ARG | OPT_PERFILE | OPT_OUTPUT, { .func_arg = opt_audio_frames },
3934  "set the number of audio frames to output", "number" },
3935  { "aq", OPT_AUDIO | HAS_ARG | OPT_PERFILE | OPT_OUTPUT, { .func_arg = opt_audio_qscale },
3936  "set audio quality (codec-specific)", "quality", },
3937  { "ar", OPT_AUDIO | HAS_ARG | OPT_INT | OPT_SPEC |
3938  OPT_INPUT | OPT_OUTPUT, { .off = OFFSET(audio_sample_rate) },
3939  "set audio sampling rate (in Hz)", "rate" },
3940  { "ac", OPT_AUDIO | HAS_ARG | OPT_INT | OPT_SPEC |
3941  OPT_INPUT | OPT_OUTPUT, { .off = OFFSET(audio_channels) },
3942  "set number of audio channels", "channels" },
3944  "disable audio" },
3945  { "acodec", OPT_AUDIO | HAS_ARG | OPT_PERFILE |
3946  OPT_INPUT | OPT_OUTPUT, { .func_arg = opt_audio_codec },
3947  "force audio codec ('copy' to copy stream)", "codec" },
3948  { "atag", OPT_AUDIO | HAS_ARG | OPT_EXPERT | OPT_PERFILE |
3949  OPT_OUTPUT, { .func_arg = opt_old2new },
3950  "force audio tag/fourcc", "fourcc/tag" },
3951  { "vol", OPT_AUDIO | HAS_ARG | OPT_INT, { &audio_volume },
3952  "change audio volume (256=normal)" , "volume" },
3953  { "sample_fmt", OPT_AUDIO | HAS_ARG | OPT_EXPERT | OPT_SPEC |
3955  "set sample format", "format" },
3956  { "channel_layout", OPT_AUDIO | HAS_ARG | OPT_EXPERT | OPT_SPEC |
3957  OPT_STRING | OPT_INPUT | OPT_OUTPUT, { .off = OFFSET(audio_ch_layouts) },
3958  "set channel layout", "layout" },
3959  { "ch_layout", OPT_AUDIO | HAS_ARG | OPT_EXPERT | OPT_SPEC |
3960  OPT_STRING | OPT_INPUT | OPT_OUTPUT, { .off = OFFSET(audio_ch_layouts) },
3961  "set channel layout", "layout" },
3962  { "af", OPT_AUDIO | HAS_ARG | OPT_PERFILE | OPT_OUTPUT, { .func_arg = opt_audio_filters },
3963  "set audio filters", "filter_graph" },
3964  { "guess_layout_max", OPT_AUDIO | HAS_ARG | OPT_INT | OPT_SPEC | OPT_EXPERT | OPT_INPUT, { .off = OFFSET(guess_layout_max) },
3965  "set the maximum number of channels to try to guess the channel layout" },
3966 
3967  /* subtitle options */
3969  "disable subtitle" },
3970  { "scodec", OPT_SUBTITLE | HAS_ARG | OPT_PERFILE | OPT_INPUT | OPT_OUTPUT, { .func_arg = opt_subtitle_codec },
3971  "force subtitle codec ('copy' to copy stream)", "codec" },
3972  { "stag", OPT_SUBTITLE | HAS_ARG | OPT_EXPERT | OPT_PERFILE | OPT_OUTPUT, { .func_arg = opt_old2new }
3973  , "force subtitle tag/fourcc", "fourcc/tag" },
3974  { "fix_sub_duration", OPT_BOOL | OPT_EXPERT | OPT_SUBTITLE | OPT_SPEC | OPT_INPUT, { .off = OFFSET(fix_sub_duration) },
3975  "fix subtitles duration" },
3976  { "canvas_size", OPT_SUBTITLE | HAS_ARG | OPT_STRING | OPT_SPEC | OPT_INPUT, { .off = OFFSET(canvas_sizes) },
3977  "set canvas size (WxH or abbreviation)", "size" },
3978 
3979  /* muxer options */
3980  { "muxdelay", OPT_FLOAT | HAS_ARG | OPT_EXPERT | OPT_OFFSET | OPT_OUTPUT, { .off = OFFSET(mux_max_delay) },
3981  "set the maximum demux-decode delay", "seconds" },
3982  { "muxpreload", OPT_FLOAT | HAS_ARG | OPT_EXPERT | OPT_OFFSET | OPT_OUTPUT, { .off = OFFSET(mux_preload) },
3983  "set the initial demux-decode delay", "seconds" },
3984  { "sdp_file", HAS_ARG | OPT_EXPERT | OPT_OUTPUT, { .func_arg = opt_sdp_file },
3985  "specify a file in which to print sdp information", "file" },
3986 
3987  { "time_base", HAS_ARG | OPT_STRING | OPT_EXPERT | OPT_SPEC | OPT_OUTPUT, { .off = OFFSET(time_bases) },
3988  "set the desired time base hint for output stream (1:24, 1:48000 or 0.04166, 2.0833e-5)", "ratio" },
3989  { "enc_time_base", HAS_ARG | OPT_STRING | OPT_EXPERT | OPT_SPEC | OPT_OUTPUT, { .off = OFFSET(enc_time_bases) },
3990  "set the desired time base for the encoder (1:24, 1:48000 or 0.04166, 2.0833e-5). "
3991  "two special values are defined - "
3992  "0 = use frame rate (video) or sample rate (audio),"
3993  "-1 = match source time base", "ratio" },
3994 
3995  { "bsf", HAS_ARG | OPT_STRING | OPT_SPEC | OPT_EXPERT | OPT_OUTPUT, { .off = OFFSET(bitstream_filters) },
3996  "A comma-separated list of bitstream filters", "bitstream_filters" },
3997  { "absf", HAS_ARG | OPT_AUDIO | OPT_EXPERT| OPT_PERFILE | OPT_OUTPUT, { .func_arg = opt_old2new },
3998  "deprecated", "audio bitstream_filters" },
3999  { "vbsf", OPT_VIDEO | HAS_ARG | OPT_EXPERT| OPT_PERFILE | OPT_OUTPUT, { .func_arg = opt_old2new },
4000  "deprecated", "video bitstream_filters" },
4001 
4002  { "apre", HAS_ARG | OPT_AUDIO | OPT_EXPERT| OPT_PERFILE | OPT_OUTPUT, { .func_arg = opt_preset },
4003  "set the audio options to the indicated preset", "preset" },
4004  { "vpre", OPT_VIDEO | HAS_ARG | OPT_EXPERT| OPT_PERFILE | OPT_OUTPUT, { .func_arg = opt_preset },
4005  "set the video options to the indicated preset", "preset" },
4006  { "spre", HAS_ARG | OPT_SUBTITLE | OPT_EXPERT| OPT_PERFILE | OPT_OUTPUT, { .func_arg = opt_preset },
4007  "set the subtitle options to the indicated preset", "preset" },
4008  { "fpre", HAS_ARG | OPT_EXPERT| OPT_PERFILE | OPT_OUTPUT, { .func_arg = opt_preset },
4009  "set options from indicated preset file", "filename" },
4010 
4011  { "max_muxing_queue_size", HAS_ARG | OPT_INT | OPT_SPEC | OPT_EXPERT | OPT_OUTPUT, { .off = OFFSET(max_muxing_queue_size) },
4012  "maximum number of packets that can be buffered while waiting for all streams to initialize", "packets" },
4013  { "muxing_queue_data_threshold", HAS_ARG | OPT_INT | OPT_SPEC | OPT_EXPERT | OPT_OUTPUT, { .off = OFFSET(muxing_queue_data_threshold) },
4014  "set the threshold after which max_muxing_queue_size is taken into account", "bytes" },
4015 
4016  /* data codec support */
4017  { "dcodec", HAS_ARG | OPT_DATA | OPT_PERFILE | OPT_EXPERT | OPT_INPUT | OPT_OUTPUT, { .func_arg = opt_data_codec },
4018  "force data codec ('copy' to copy stream)", "codec" },
4019  { "dn", OPT_BOOL | OPT_VIDEO | OPT_OFFSET | OPT_INPUT | OPT_OUTPUT, { .off = OFFSET(data_disable) },
4020  "disable data" },
4021 
4022 #if CONFIG_VAAPI
4023  { "vaapi_device", HAS_ARG | OPT_EXPERT, { .func_arg = opt_vaapi_device },
4024  "set VAAPI hardware device (DRM path or X11 display name)", "device" },
4025 #endif
4026 
4027 #if CONFIG_QSV
4028  { "qsv_device", HAS_ARG | OPT_EXPERT, { .func_arg = opt_qsv_device },
4029  "set QSV hardware device (DirectX adapter index, DRM path or X11 display name)", "device"},
4030 #endif
4031 
4032  { "init_hw_device", HAS_ARG | OPT_EXPERT, { .func_arg = opt_init_hw_device },
4033  "initialise hardware device", "args" },
4034  { "filter_hw_device", HAS_ARG | OPT_EXPERT, { .func_arg = opt_filter_hw_device },
4035  "set hardware device used when filtering", "device" },
4036 
4037  { NULL, },
4038 };
error
static void error(const char *err)
Definition: target_bsf_fuzzer.c:31
OptionsContext::readrate
float readrate
Definition: ffmpeg.h:118
OPT_FLOAT
#define OPT_FLOAT
Definition: cmdutils.h:145
fopen_utf8
static FILE * fopen_utf8(const char *path, const char *mode)
Definition: fopen_utf8.h:65
OPT_EXIT
#define OPT_EXIT
Definition: cmdutils.h:148
AVCodec
AVCodec.
Definition: codec.h:196
OptionsContext::input_ts_offset
int64_t input_ts_offset
Definition: ffmpeg.h:115
AVMEDIA_TYPE_SUBTITLE
@ AVMEDIA_TYPE_SUBTITLE
Definition: avutil.h:204
AV_LOG_WARNING
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:186
AV_BPRINT_SIZE_UNLIMITED
#define AV_BPRINT_SIZE_UNLIMITED
AV_PIX_FMT_CUDA
@ AV_PIX_FMT_CUDA
HW acceleration through CUDA.
Definition: pixfmt.h:225
ignore_unknown_streams
static int ignore_unknown_streams
Definition: ffmpeg_opt.c:188
AVCodecParameters::extradata
uint8_t * extradata
Extra binary data needed for initializing the decoder, codec-dependent.
Definition: codec_par.h:75
name
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf default minimum maximum flags name is the option name
Definition: writing_filters.txt:88
OptionsContext::stop_time
int64_t stop_time
Definition: ffmpeg.h:150
StreamMap::file_index
int file_index
Definition: ffmpeg.h:76
new_output_stream
static OutputStream * new_output_stream(OptionsContext *o, AVFormatContext *oc, enum AVMediaType type, int source_index)
Definition: ffmpeg_opt.c:1521
show_hwaccels
static int show_hwaccels(void *optctx, const char *opt, const char *arg)
Definition: ffmpeg_opt.c:241
program
Undefined Behavior In the C some operations are like signed integer dereferencing freed accessing outside allocated Undefined Behavior must not occur in a C program
Definition: undefined.txt:6
InputStream::hwaccel_device
char * hwaccel_device
Definition: ffmpeg.h:379
opt_abort_on
static int opt_abort_on(void *optctx, const char *opt, const char *arg)
Definition: ffmpeg_opt.c:350
VSYNC_VFR
@ VSYNC_VFR
Definition: ffmpeg.h:54
AVOutputFormat::name
const char * name
Definition: avformat.h:510
AVChapter::metadata
AVDictionary * metadata
Definition: avformat.h:1176
OptionsContext::dump_attachment
SpecifierOpt * dump_attachment
Definition: ffmpeg.h:125
AVERROR
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
nb_input_files
int nb_input_files
Definition: ffmpeg.c:150
opt.h
avformat_new_stream
AVStream * avformat_new_stream(AVFormatContext *s, const AVCodec *c)
Add a new stream to a media file.
Definition: options.c:237
AV_OPT_FLAG_VIDEO_PARAM
#define AV_OPT_FLAG_VIDEO_PARAM
Definition: opt.h:284
OptionsContext::nb_audio_sample_rate
int nb_audio_sample_rate
Definition: ffmpeg.h:104
AVCodecParameters::codec_type
enum AVMediaType codec_type
General type of the encoded data.
Definition: codec_par.h:57
AudioChannelMap::ofile_idx
int ofile_idx
Definition: ffmpeg.h:85
dump_attachment
static void dump_attachment(AVStream *st, const char *filename)
Definition: ffmpeg_opt.c:1116
OptionDef::off
size_t off
Definition: cmdutils.h:160
opt_video_filters
static int opt_video_filters(void *optctx, const char *opt, const char *arg)
Definition: ffmpeg_opt.c:3358
show_help_default
void show_help_default(const char *opt, const char *arg)
Per-fftool specific help handler.
Definition: ffmpeg_opt.c:3427
debug_ts
int debug_ts
Definition: ffmpeg_opt.c:170
stats_period
int64_t stats_period
Definition: ffmpeg_opt.c:181
SET_DICT
#define SET_DICT(type, meta, context, index)
av_bprint_finalize
int av_bprint_finalize(AVBPrint *buf, char **ret_str)
Finalize a print buffer.
Definition: bprint.c:235
AVSTREAM_EVENT_FLAG_NEW_PACKETS
#define AVSTREAM_EVENT_FLAG_NEW_PACKETS
Definition: avformat.h:1087
avio_close
int avio_close(AVIOContext *s)
Close the resource accessed by the AVIOContext s and free it.
Definition: aviobuf.c:1255
out
FILE * out
Definition: movenc.c:54
AVCodecContext::sample_rate
int sample_rate
samples per second
Definition: avcodec.h:998
av_bprint_init
void av_bprint_init(AVBPrint *buf, unsigned size_init, unsigned size_max)
Definition: bprint.c:69
av_get_token
char * av_get_token(const char **buf, const char *term)
Unescape the given string until a non escaped terminating char, and return the token corresponding to...
Definition: avstring.c:154
is
The official guide to swscale for confused that is
Definition: swscale.txt:28
OptionsContext::nb_audio_ch_layouts
int nb_audio_ch_layouts
Definition: ffmpeg.h:100
FilterGraph::graph_desc
const char * graph_desc
Definition: ffmpeg.h:292
AVFormatContext::nb_chapters
unsigned int nb_chapters
Number of chapters in AVChapter array.
Definition: avformat.h:1431
AVCodecParameters
This struct describes the properties of an encoded stream.
Definition: codec_par.h:53
ALLOC_ARRAY_ELEM
#define ALLOC_ARRAY_ELEM(array, nb_elems)
Definition: cmdutils.h:434
u
#define u(width, name, range_min, range_max)
Definition: cbs_h2645.c:262
sample_fmts
static enum AVSampleFormat sample_fmts[]
Definition: adpcmenc.c:947
AVFMT_VARIABLE_FPS
#define AVFMT_VARIABLE_FPS
Format allows variable fps.
Definition: avformat.h:484
AV_DISPOSITION_ATTACHED_PIC
#define AV_DISPOSITION_ATTACHED_PIC
The stream is stored in the file as an attached picture/"cover art" (e.g.
Definition: avformat.h:879
MAX_STREAMS
#define MAX_STREAMS
Definition: ffmpeg.h:59
opt_old2new
static int opt_old2new(void *optctx, const char *opt, const char *arg)
Definition: ffmpeg_opt.c:3301
AVStream::discard
enum AVDiscard discard
Selects which packets can be discarded at will and do not need to be demuxed.
Definition: avformat.h:1010
copy_metadata
static int copy_metadata(char *outspec, char *inspec, AVFormatContext *oc, AVFormatContext *ic, OptionsContext *o)
Definition: ffmpeg_opt.c:713
av_get_channel_layout
uint64_t av_get_channel_layout(const char *name)
Return a channel layout id that matches name, or 0 if no match is found.
Definition: channel_layout.c:237
avcodec_parameters_from_context
int avcodec_parameters_from_context(AVCodecParameters *par, const AVCodecContext *codec)
Fill the parameters struct based on the values from the supplied codec context.
Definition: codec_par.c:99
opt_name_frame_aspect_ratios
static const char *const opt_name_frame_aspect_ratios[]
Definition: ffmpeg_opt.c:87
remove_avoptions
void remove_avoptions(AVDictionary **a, AVDictionary *b)
Definition: ffmpeg.c:658
AV_CODEC_FLAG_QSCALE
#define AV_CODEC_FLAG_QSCALE
Use fixed qscale.
Definition: avcodec.h:216
sdp_filename
char * sdp_filename
Definition: ffmpeg_opt.c:153
InputStream::dec_ctx
AVCodecContext * dec_ctx
Definition: ffmpeg.h:316
AVFMT_NOTIMESTAMPS
#define AVFMT_NOTIMESTAMPS
Format does not need / have any timestamps.
Definition: avformat.h:481
AV_TIME_BASE_Q
#define AV_TIME_BASE_Q
Internal time base represented as fractional value.
Definition: avutil.h:260
OptionsContext::limit_filesize
uint64_t limit_filesize
Definition: ffmpeg.h:151
InputStream::user_set_discard
int user_set_discard
Definition: ffmpeg.h:310
opt_name_frame_pix_fmts
static const char *const opt_name_frame_pix_fmts[]
Definition: ffmpeg_opt.c:72
StreamMap::sync_stream_index
int sync_stream_index
Definition: ffmpeg.h:79
av_asprintf
char * av_asprintf(const char *fmt,...)
Definition: avstring.c:116
OptionsContext::nb_metadata
int nb_metadata
Definition: ffmpeg.h:167
av_strcasecmp
int av_strcasecmp(const char *a, const char *b)
Locale-independent case-insensitive compare.
Definition: avstring.c:218
AVCodecContext::intra_matrix
uint16_t * intra_matrix
custom intra quantization matrix Must be allocated with the av_malloc() family of functions,...
Definition: avcodec.h:874
avformat_get_class
const AVClass * avformat_get_class(void)
Get the AVClass for AVFormatContext.
Definition: options.c:197
program_name
const char program_name[]
program name, defined by the program for show_version().
Definition: ffmpeg.c:110
no_file_overwrite
static int no_file_overwrite
Definition: ffmpeg_opt.c:185
opt_default_new
static int opt_default_new(OptionsContext *o, const char *opt, const char *arg)
Definition: ffmpeg_opt.c:3233
AV_DISPOSITION_DEFAULT
#define AV_DISPOSITION_DEFAULT
The stream should be chosen by default among other streams of the same type, unless the user has expl...
Definition: avformat.h:826
OptionsContext::nb_attachments
int nb_attachments
Definition: ffmpeg.h:145
OutputFile::start_time
int64_t start_time
start time in microseconds == AV_TIME_BASE units
Definition: ffmpeg.h:595
avcodec_find_encoder
const AVCodec * avcodec_find_encoder(enum AVCodecID id)
Find a registered encoder with a matching codec ID.
Definition: allcodecs.c:930
opt_name_top_field_first
static const char *const opt_name_top_field_first[]
Definition: ffmpeg_opt.c:92
auto_conversion_filters
int auto_conversion_filters
Definition: ffmpeg_opt.c:180
audio_channels
int audio_channels
Definition: rtp.c:40
opt_audio_codec
static int opt_audio_codec(void *optctx, const char *opt, const char *arg)
Definition: ffmpeg_opt.c:384
ffmpeg_parse_options
int ffmpeg_parse_options(int argc, char **argv)
tmp
static uint8_t tmp[11]
Definition: aes_ctr.c:28
pixdesc.h
AVFormatContext::streams
AVStream ** streams
A list of all streams in the file.
Definition: avformat.h:1281
OptionsContext::mux_max_delay
float mux_max_delay
Definition: ffmpeg.h:153
OPT_INPUT
#define OPT_INPUT
Definition: cmdutils.h:155
opt_name_max_frames
static const char *const opt_name_max_frames[]
Definition: ffmpeg_opt.c:79
copy_unknown_streams
static int copy_unknown_streams
Definition: ffmpeg_opt.c:189
subtitle_codec_name
static const char * subtitle_codec_name
Definition: ffplay.c:345
AV_HWDEVICE_TYPE_NONE
@ AV_HWDEVICE_TYPE_NONE
Definition: hwcontext.h:28
OptionsContext::subtitle_disable
int subtitle_disable
Definition: ffmpeg.h:159
AVOption
AVOption.
Definition: opt.h:251
HAS_ARG
#define HAS_ARG
Definition: cmdutils.h:138
OptionGroupList::groups
OptionGroup * groups
Definition: cmdutils.h:259
FilterGraph::index
int index
Definition: ffmpeg.h:291
AudioChannelMap::stream_idx
int stream_idx
Definition: ffmpeg.h:84
AVStream::avg_frame_rate
AVRational avg_frame_rate
Average framerate.
Definition: avformat.h:1028
opt_name_bitstream_filters
static const char *const opt_name_bitstream_filters[]
Definition: ffmpeg_opt.c:80
AVChapter::start
int64_t start
Definition: avformat.h:1175
OptionGroupList::nb_groups
int nb_groups
Definition: cmdutils.h:260
opt_timelimit
int opt_timelimit(void *optctx, const char *opt, const char *arg)
Limit the execution time.
format_opts
AVDictionary * format_opts
Definition: cmdutils.c:60
AV_DICT_APPEND
#define AV_DICT_APPEND
If the entry already exists, append to it.
Definition: dict.h:75
RcOverride::qscale
int qscale
Definition: avcodec.h:199
opt_name_presets
static const char *const opt_name_presets[]
Definition: ffmpeg_opt.c:93
AV_DICT_IGNORE_SUFFIX
#define AV_DICT_IGNORE_SUFFIX
Return first entry in a dictionary whose first part corresponds to the search key,...
Definition: dict.h:68
filter_hw_device
HWDevice * filter_hw_device
Definition: ffmpeg_opt.c:150
av_hwdevice_find_type_by_name
enum AVHWDeviceType av_hwdevice_find_type_by_name(const char *name)
Look up an AVHWDeviceType by name.
Definition: hwcontext.c:83
opt_name_autorotate
static const char *const opt_name_autorotate[]
Definition: ffmpeg_opt.c:77
ffmpeg.h
AV_LOG_VERBOSE
#define AV_LOG_VERBOSE
Detailed information.
Definition: log.h:196
opt_name_reinit_filters
static const char *const opt_name_reinit_filters[]
Definition: ffmpeg_opt.c:98
progress_avio
AVIOContext * progress_avio
Definition: ffmpeg.c:143
base
uint8_t base
Definition: vp3data.h:141
opt_filter_hw_device
static int opt_filter_hw_device(void *optctx, const char *opt, const char *arg)
Definition: ffmpeg_opt.c:665
freeenv_utf8
static void freeenv_utf8(char *var)
Definition: getenv_utf8.h:72
AV_NOWARN_DEPRECATED
#define AV_NOWARN_DEPRECATED(code)
Disable warnings about deprecated features This is useful for sections of code kept for backward comp...
Definition: attributes.h:126
OptionGroup::swr_opts
AVDictionary * swr_opts
Definition: cmdutils.h:249
AVFormatContext::programs
AVProgram ** programs
Definition: avformat.h:1382
show_help_children
void show_help_children(const AVClass *class, int flags)
Show help for all options with given flags in class and all its children.
Definition: cmdutils.c:163
av_hwdevice_iterate_types
enum AVHWDeviceType av_hwdevice_iterate_types(enum AVHWDeviceType prev)
Iterate over supported device types.
Definition: hwcontext.c:102
OptionsContext::bitexact
int bitexact
Definition: ffmpeg.h:155
autorotate
static int autorotate
Definition: ffplay.c:355
OptionsContext::audio_channels
SpecifierOpt * audio_channels
Definition: ffmpeg.h:101
UNKNOWN
@ UNKNOWN
Definition: ftp.c:37
OptionsContext::nb_frame_rates
int nb_frame_rates
Definition: ffmpeg.h:106
AVCodecParameters::codec_tag
uint32_t codec_tag
Additional information about the codec (corresponds to the AVI FOURCC).
Definition: codec_par.h:65
video_disable
static int video_disable
Definition: ffplay.c:320
mathematics.h
AVDictionary
Definition: dict.c:30
AVChannelLayout::order
enum AVChannelOrder order
Channel order used in this layout.
Definition: channel_layout.h:295
new_attachment_stream
static OutputStream * new_attachment_stream(OptionsContext *o, AVFormatContext *oc, int source_index)
Definition: ffmpeg_opt.c:2157
FFMAX
#define FFMAX(a, b)
Definition: macros.h:47
AV_CODEC_FLAG_PSNR
#define AV_CODEC_FLAG_PSNR
error[?] variables will be set during encoding.
Definition: avcodec.h:253
HWDevice
Definition: ffmpeg.h:67
hw_device_init_from_string
int hw_device_init_from_string(const char *arg, HWDevice **dev)
Definition: ffmpeg_hw.c:94
do_benchmark
int do_benchmark
Definition: ffmpeg_opt.c:163
AVFormatContext::video_codec_id
enum AVCodecID video_codec_id
Forced video codec_id.
Definition: avformat.h:1388
InputStream::decoding_needed
int decoding_needed
Definition: ffmpeg.h:311
OptionsContext::format
const char * format
Definition: ffmpeg.h:95
AVChannelLayout::nb_channels
int nb_channels
Number of channels in this layout.
Definition: channel_layout.h:300
AV_OPT_FLAG_FILTERING_PARAM
#define AV_OPT_FLAG_FILTERING_PARAM
a generic parameter which can be set by the user for filtering
Definition: opt.h:297
avio_size
int64_t avio_size(AVIOContext *s)
Get the filesize.
Definition: aviobuf.c:352
ost
static AVStream * ost
Definition: vaapi_transcode.c:45
file_iformat
static const AVInputFormat * file_iformat
Definition: ffplay.c:310
AVOutputFormat::subtitle_codec
enum AVCodecID subtitle_codec
default subtitle codec
Definition: avformat.h:522
av_malloc
#define av_malloc(s)
Definition: tableprint_vlc.h:30
AV_CODEC_FLAG_GLOBAL_HEADER
#define AV_CODEC_FLAG_GLOBAL_HEADER
Place global headers in extradata instead of every keyframe.
Definition: avcodec.h:274
av_channel_layout_copy
int av_channel_layout_copy(AVChannelLayout *dst, const AVChannelLayout *src)
Make a copy of a channel layout.
Definition: channel_layout.c:637
OptionDef
Definition: cmdutils.h:135
subtitle_disable
static int subtitle_disable
Definition: ffplay.c:321
init_simple_filtergraph
int init_simple_filtergraph(InputStream *ist, OutputStream *ost)
Definition: ffmpeg_filter.c:176
opt_name_ts_scale
static const char *const opt_name_ts_scale[]
Definition: ffmpeg_opt.c:73
OPT_DATA
#define OPT_DATA
Definition: cmdutils.h:149
av_filename_number_test
int av_filename_number_test(const char *filename)
Check whether filename actually is a numbered sequence generator.
Definition: utils.c:125
exit_program
void exit_program(int ret)
Wraps exit with a program-specific cleanup routine.
Definition: cmdutils.c:93
SpecifierOpt::i
int i
Definition: cmdutils.h:127
InputStream
Definition: ffmpeg.h:306
AVCodecContext::framerate
AVRational framerate
Definition: avcodec.h:1732
OptionsContext::chapters_input_file
int chapters_input_file
Definition: ffmpeg.h:147
opt_name_fix_sub_duration
static const char *const opt_name_fix_sub_duration[]
Definition: ffmpeg_opt.c:99
framerate
int framerate
Definition: h264_levels.c:65
avformat_close_input
void avformat_close_input(AVFormatContext **s)
Close an opened input AVFormatContext.
Definition: demux.c:368
parse_number_or_die
double parse_number_or_die(const char *context, const char *numstr, int type, double min, double max)
Parse a string and return its corresponding value as a double.
Definition: cmdutils.c:101
AVFormatContext::interrupt_callback
AVIOInterruptCB interrupt_callback
Custom interrupt callbacks for the I/O layer.
Definition: avformat.h:1480
OptionsContext::rate_emu
int rate_emu
Definition: ffmpeg.h:117
print_error
void print_error(const char *filename, int err)
Print an error message to stderr, indicating filename and a human readable description of the error c...
Definition: cmdutils.c:793
fifo.h
opt_filter_threads
static int opt_filter_threads(void *optctx, const char *opt, const char *arg)
Definition: ffmpeg_opt.c:343
avio_open2
int avio_open2(AVIOContext **s, const char *url, int flags, const AVIOInterruptCB *int_cb, AVDictionary **options)
Create and initialize a AVIOContext for accessing the resource indicated by url.
Definition: aviobuf.c:1249
do_hex_dump
int do_hex_dump
Definition: ffmpeg_opt.c:165
opt_name_max_muxing_queue_size
static const char *const opt_name_max_muxing_queue_size[]
Definition: ffmpeg_opt.c:103
fopen_utf8.h
OptionGroupList
A list of option groups that all have the same group type (e.g.
Definition: cmdutils.h:256
bsf.h
do_pkt_dump
int do_pkt_dump
Definition: ffmpeg_opt.c:166
uninit_options
static void uninit_options(OptionsContext *o)
Definition: ffmpeg_opt.c:193
AVFMT_SEEK_TO_PTS
#define AVFMT_SEEK_TO_PTS
Seeking is based on PTS.
Definition: avformat.h:503
presets
static const Preset presets[]
Definition: vf_pseudocolor.c:179
OptionsContext::nb_dump_attachment
int nb_dump_attachment
Definition: ffmpeg.h:126
opt_timecode
static int opt_timecode(void *optctx, const char *opt, const char *arg)
Definition: ffmpeg_opt.c:3377
OptionsContext::g
OptionGroup * g
Definition: ffmpeg.h:89
AVCodecContext::ch_layout
AVChannelLayout ch_layout
Audio channel layout.
Definition: avcodec.h:2056
fail
#define fail()
Definition: checkasm.h:131
StreamMap::disabled
int disabled
Definition: ffmpeg.h:75
AudioChannelMap::ostream_idx
int ostream_idx
Definition: ffmpeg.h:85
av_strerror
int av_strerror(int errnum, char *errbuf, size_t errbuf_size)
Put a description of the AVERROR code errnum in errbuf.
Definition: error.c:108
check_streamcopy_filters
static void check_streamcopy_filters(OptionsContext *o, AVFormatContext *oc, const OutputStream *ost, enum AVMediaType type)
Definition: ffmpeg_opt.c:1779
opt_data_frames
static int opt_data_frames(void *optctx, const char *opt, const char *arg)
Definition: ffmpeg_opt.c:3227
OptionParseContext
Definition: cmdutils.h:263
InputStream::decoder_opts
AVDictionary * decoder_opts
Definition: ffmpeg.h:346
get_line
static char * get_line(AVIOContext *s, AVBPrint *bprint)
Definition: ffmpeg_opt.c:1442
InputStream::filter_in_rescale_delta_last
int64_t filter_in_rescale_delta_last
Definition: ffmpeg.h:333
AVDISCARD_NONE
@ AVDISCARD_NONE
discard nothing
Definition: defs.h:48
AVCodecContext::flags
int flags
AV_CODEC_FLAG_*.
Definition: avcodec.h:469
AVChapter
Definition: avformat.h:1172
val
static double val(void *priv, double ch)
Definition: aeval.c:77
type
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf type
Definition: writing_filters.txt:86
AudioChannelMap::file_idx
int file_idx
Definition: ffmpeg.h:84
sws_get_class
const AVClass * sws_get_class(void)
Get the AVClass for swsContext.
Definition: options.c:97
OptionsContext
Definition: ffmpeg.h:88
av_opt_set
int av_opt_set(void *obj, const char *name, const char *val, int search_flags)
Definition: opt.c:487
av_new_program
AVProgram * av_new_program(AVFormatContext *ac, int id)
Definition: avformat.c:238
OPT_STRING
#define OPT_STRING
Definition: cmdutils.h:141
OutputFile::opts
AVDictionary * opts
Definition: ffmpeg.h:592
loop
static int loop
Definition: ffplay.c:340
set_dispositions
static int set_dispositions(OutputFile *of, AVFormatContext *ctx)
Definition: ffmpeg_opt.c:2256
AVRational::num
int num
Numerator.
Definition: rational.h:59
opt_audio_filters
static int opt_audio_filters(void *optctx, const char *opt, const char *arg)
Definition: ffmpeg_opt.c:3364
opt_name_hwaccels
static const char *const opt_name_hwaccels[]
Definition: ffmpeg_opt.c:74
OptionsContext::nb_audio_channel_maps
int nb_audio_channel_maps
Definition: ffmpeg.h:140
InputFile
Definition: ffmpeg.h:404
opt_filter_complex_script
static int opt_filter_complex_script(void *optctx, const char *opt, const char *arg)
Definition: ffmpeg_opt.c:3411
OptionGroupDef
Definition: cmdutils.h:224
input_stream_potentially_available
static int input_stream_potentially_available
Definition: ffmpeg_opt.c:187
av_frame_alloc
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
Definition: frame.c:99
OptionsContext::recording_time
int64_t recording_time
Definition: ffmpeg.h:149
OptionsContext::metadata_chapters_manual
int metadata_chapters_manual
Definition: ffmpeg.h:143
OptionsContext::nb_stream_maps
int nb_stream_maps
Definition: ffmpeg.h:138
OptionsContext::audio_disable
int audio_disable
Definition: ffmpeg.h:158
InputStream::first_dts
int64_t first_dts
dts of the first packet read for this stream (in AV_TIME_BASE units)
Definition: ffmpeg.h:326
check_stream_specifier
int check_stream_specifier(AVFormatContext *s, AVStream *st, const char *spec)
Check if the given stream matches a stream specifier.
Definition: cmdutils.c:886
preset
preset
Definition: vf_curves.c:46
InputStream::hwaccel_pix_fmt
enum AVPixelFormat hwaccel_pix_fmt
Definition: ffmpeg.h:386
OutputFile::shortest
int shortest
Definition: ffmpeg.h:598
avfilter_inout_free
void avfilter_inout_free(AVFilterInOut **inout)
Free the supplied list of AVFilterInOut and set *inout to NULL.
Definition: graphparser.c:212
avassert.h
RcOverride::quality_factor
float quality_factor
Definition: avcodec.h:200
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:180
AudioChannelMap
Definition: ffmpeg.h:83
AVFormatContext::metadata
AVDictionary * metadata
Metadata that applies to the whole file.
Definition: avformat.h:1442
init_complex_filters
static int init_complex_filters(void)
Definition: ffmpeg_opt.c:2363
FF_ARRAY_ELEMS
#define FF_ARRAY_ELEMS(a)
Definition: sinewin_tablegen.c:29
AVInputFormat
Definition: avformat.h:656
ABORT_ON_FLAG_EMPTY_OUTPUT_STREAM
#define ABORT_ON_FLAG_EMPTY_OUTPUT_STREAM
Definition: ffmpeg.h:448
new_audio_stream
static OutputStream * new_audio_stream(OptionsContext *o, AVFormatContext *oc, int source_index)
Definition: ffmpeg_opt.c:2031
AVFormatContext::subtitle_codec
const AVCodec * subtitle_codec
Forced subtitle codec.
Definition: avformat.h:1698
OptionGroup::codec_opts
AVDictionary * codec_opts
Definition: cmdutils.h:246
av_dump_format
void av_dump_format(AVFormatContext *ic, int index, const char *url, int is_output)
Print detailed information about the input or output format, such as duration, bitrate,...
Definition: dump.c:630
MATCH_PER_STREAM_OPT
#define MATCH_PER_STREAM_OPT(name, type, outvar, fmtctx, st)
Definition: ffmpeg_opt.c:123
parse_matrix_coeffs
static void parse_matrix_coeffs(uint16_t *dest, const char *str)
Definition: ffmpeg_opt.c:1716
avformat_open_input
int avformat_open_input(AVFormatContext **ps, const char *url, const AVInputFormat *fmt, AVDictionary **options)
Open an input stream and read the header.
Definition: demux.c:220
opt_attach
static int opt_attach(void *optctx, const char *opt, const char *arg)
Definition: ffmpeg_opt.c:526
mask
static const uint16_t mask[17]
Definition: lzw.c:38
OptionsContext::nb_program
int nb_program
Definition: ffmpeg.h:231
opt_recording_timestamp
static int opt_recording_timestamp(void *optctx, const char *opt, const char *arg)
Definition: ffmpeg_opt.c:803
av_dict_get
AVDictionaryEntry * av_dict_get(const AVDictionary *m, const char *key, const AVDictionaryEntry *prev, int flags)
Get a dictionary entry with matching key.
Definition: dict.c:40
StreamMap::linklabel
char * linklabel
Definition: ffmpeg.h:80
avformat_query_codec
int avformat_query_codec(const AVOutputFormat *ofmt, enum AVCodecID codec_id, int std_compliance)
Test if the given container can store a codec.
Definition: mux_utils.c:40
HWACCEL_GENERIC
@ HWACCEL_GENERIC
Definition: ffmpeg.h:64
OPT_INT
#define OPT_INT
Definition: cmdutils.h:144
VSYNC_VSCFR
@ VSYNC_VSCFR
Definition: ffmpeg.h:55
avcodec_alloc_context3
AVCodecContext * avcodec_alloc_context3(const AVCodec *codec)
Allocate an AVCodecContext and set its fields to default values.
Definition: options.c:149
AVChapter::end
int64_t end
chapter start/end time in time_base units
Definition: avformat.h:1175
input_streams
InputStream ** input_streams
Definition: ffmpeg.c:147
SpecifierOpt::specifier
char * specifier
stream/chapter/program/...
Definition: cmdutils.h:124
AVCodecDescriptor
This struct describes the properties of a single codec described by an AVCodecID.
Definition: codec_desc.h:38
intreadwrite.h
opt_name_frame_rates
static const char *const opt_name_frame_rates[]
Definition: ffmpeg_opt.c:69
s
#define s(width, name)
Definition: cbs_vp9.c:256
AVCodecContext::stats_in
char * stats_in
pass2 encoding statistics input buffer Concatenated stuff from stats_out of pass1 should be placed he...
Definition: avcodec.h:1264
add_input_streams
static void add_input_streams(OptionsContext *o, AVFormatContext *ic)
Definition: ffmpeg_opt.c:864
split_commandline
int split_commandline(OptionParseContext *octx, int argc, char *argv[], const OptionDef *options, const OptionGroupDef *groups, int nb_groups)
Split the commandline into an intermediate form convenient for further processing.
Definition: cmdutils.c:687
AV_OPT_FLAG_ENCODING_PARAM
#define AV_OPT_FLAG_ENCODING_PARAM
a generic parameter which can be set by the user for muxing or encoding
Definition: opt.h:281
FilterGraph::outputs
OutputFilter ** outputs
Definition: ffmpeg.h:302
avio_read_to_bprint
int avio_read_to_bprint(AVIOContext *h, struct AVBPrint *pb, size_t max_size)
Read contents of h into print buffer, up to max_size bytes, or up to EOF.
Definition: aviobuf.c:1355
InputStream::framerate
AVRational framerate
Definition: ffmpeg.h:347
opt_name_rc_overrides
static const char *const opt_name_rc_overrides[]
Definition: ffmpeg_opt.c:88
av_realloc_array
void * av_realloc_array(void *ptr, size_t nmemb, size_t size)
Definition: mem.c:225
AVFormatContext::flags
int flags
Flags modifying the (de)muxer behaviour.
Definition: avformat.h:1331
format
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample format(the sample packing is implied by the sample format) and sample rate. The lists are not just lists
AVFormatContext::nb_programs
unsigned int nb_programs
Definition: avformat.h:1381
RcOverride
Definition: avcodec.h:196
parse_meta_type
static void parse_meta_type(char *arg, char *type, int *index, const char **stream_spec)
Parse a metadata specifier passed as 'arg' parameter.
Definition: ffmpeg_opt.c:686
AVFormatContext::iformat
const struct AVInputFormat * iformat
The input container format.
Definition: avformat.h:1225
g
const char * g
Definition: vf_curves.c:117
AVFormatContext::chapters
AVChapter ** chapters
Definition: avformat.h:1432
AV_CHANNEL_ORDER_UNSPEC
@ AV_CHANNEL_ORDER_UNSPEC
Only the channel count is specified, without any further information about the channel order.
Definition: channel_layout.h:106
AVDictionaryEntry::key
char * key
Definition: dict.h:80
frame_size
int frame_size
Definition: mxfenc.c:2201
AVMEDIA_TYPE_AUDIO
@ AVMEDIA_TYPE_AUDIO
Definition: avutil.h:202
AVCodecParameters::width
int width
Video only.
Definition: codec_par.h:127
new_video_stream
static OutputStream * new_video_stream(OptionsContext *o, AVFormatContext *oc, int source_index)
Definition: ffmpeg_opt.c:1793
av_strtok
char * av_strtok(char *s, const char *delim, char **saveptr)
Split the string into several tokens which can be accessed by successive calls to av_strtok().
Definition: avstring.c:189
opt_audio_qscale
static int opt_audio_qscale(void *optctx, const char *opt, const char *arg)
Definition: ffmpeg_opt.c:3391
filters
#define filters(fmt, type, inverse, clp, inverset, clip, one, clip_fn, packed)
Definition: af_crystalizer.c:55
OptionsContext::audio_ch_layouts
SpecifierOpt * audio_ch_layouts
Definition: ffmpeg.h:99
av_assert0
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:37
AVHWDeviceType
AVHWDeviceType
Definition: hwcontext.h:27
AVMEDIA_TYPE_NB
@ AVMEDIA_TYPE_NB
Definition: avutil.h:206
term_init
void term_init(void)
Definition: ffmpeg.c:407
AVIO_FLAG_WRITE
#define AVIO_FLAG_WRITE
write-only
Definition: avio.h:629
OutputFilter::ost
struct OutputStream * ost
Definition: ffmpeg.h:268
OptionsContext::metadata_streams_manual
int metadata_streams_manual
Definition: ffmpeg.h:142
AV_LOG_DEBUG
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: log.h:201
exit_on_error
int exit_on_error
Definition: ffmpeg_opt.c:171
ctx
AVFormatContext * ctx
Definition: movenc.c:48
RcOverride::start_frame
int start_frame
Definition: avcodec.h:197
channels
channels
Definition: aptx.h:32
nb_streams
static int nb_streams
Definition: ffprobe.c:307
av_rescale_q
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)
Rescale a 64-bit integer by 2 rational numbers.
Definition: mathematics.c:142
term_exit
void term_exit(void)
Definition: ffmpeg.c:336
OptionsContext::shortest
int shortest
Definition: ffmpeg.h:154
new_data_stream
static OutputStream * new_data_stream(OptionsContext *o, AVFormatContext *oc, int source_index)
Definition: ffmpeg_opt.c:2131
av_hwdevice_get_type_name
const char * av_hwdevice_get_type_name(enum AVHWDeviceType type)
Get the string name of an AVHWDeviceType.
Definition: hwcontext.c:93
opt_name_codec_names
static const char *const opt_name_codec_names[]
Definition: ffmpeg_opt.c:65
opt_name_pass
static const char *const opt_name_pass[]
Definition: ffmpeg_opt.c:101
codec_id
enum AVCodecID codec_id
Definition: vaapi_decode.c:371
do_benchmark_all
int do_benchmark_all
Definition: ffmpeg_opt.c:164
AV_OPT_FLAG_BSF_PARAM
#define AV_OPT_FLAG_BSF_PARAM
a generic parameter which can be set by the user for bit stream filtering
Definition: opt.h:295
OptionsContext::accurate_seek
int accurate_seek
Definition: ffmpeg.h:119
key
const char * key
Definition: hwcontext_opencl.c:174
AVMEDIA_TYPE_DATA
@ AVMEDIA_TYPE_DATA
Opaque data information usually continuous.
Definition: avutil.h:203
pass
#define pass
Definition: fft_template.c:608
assert_avoptions
void assert_avoptions(AVDictionary *m)
Definition: ffmpeg.c:667
opt_video_frames
static int opt_video_frames(void *optctx, const char *opt, const char *arg)
Definition: ffmpeg_opt.c:3215
AV_OPT_FLAG_AUDIO_PARAM
#define AV_OPT_FLAG_AUDIO_PARAM
Definition: opt.h:283
opt_name_canvas_sizes
static const char *const opt_name_canvas_sizes[]
Definition: ffmpeg_opt.c:100
AVFMT_NEEDNUMBER
#define AVFMT_NEEDNUMBER
Needs 'd' in filename.
Definition: avformat.h:471
av_opt_find
const AVOption * av_opt_find(void *obj, const char *name, const char *unit, int opt_flags, int search_flags)
Look for an option in an object.
Definition: opt.c:1771
arg
const char * arg
Definition: jacosubdec.c:67
AVCodecDescriptor::props
int props
Codec properties, a combination of AV_CODEC_PROP_* flags.
Definition: codec_desc.h:54
if
if(ret)
Definition: filter_design.txt:179
OPT_SPEC
#define OPT_SPEC
Definition: cmdutils.h:152
option
option
Definition: libkvazaar.c:312
avio_flush
void avio_flush(AVIOContext *s)
Force flushing of buffered data.
Definition: aviobuf.c:252
init_output_filter
static void init_output_filter(OutputFilter *ofilter, OptionsContext *o, AVFormatContext *oc)
Definition: ffmpeg_opt.c:2322
output_streams
OutputStream ** output_streams
Definition: ffmpeg.c:152
OptionsContext::start_time
int64_t start_time
Definition: ffmpeg.h:92
AVDISCARD_ALL
@ AVDISCARD_ALL
discard all
Definition: defs.h:54
AVFormatContext
Format I/O context.
Definition: avformat.h:1213
av_realloc_f
#define av_realloc_f(p, o, n)
Definition: tableprint_vlc.h:32
do_psnr
static int do_psnr
Definition: ffmpeg_opt.c:186
AVFormatContext::audio_codec_id
enum AVCodecID audio_codec_id
Forced audio codec_id.
Definition: avformat.h:1394
OptionGroup::format_opts
AVDictionary * format_opts
Definition: cmdutils.h:247
opts
AVDictionary * opts
Definition: movenc.c:50
opt_target
static int opt_target(void *optctx, const char *opt, const char *arg)
Definition: ffmpeg_opt.c:3049
AVStream::codecpar
AVCodecParameters * codecpar
Codec parameters associated with this stream.
Definition: avformat.h:1108
open_file
static int open_file(AVFormatContext *avf, unsigned fileno)
Definition: concatdec.c:333
opt_profile
static int opt_profile(void *optctx, const char *opt, const char *arg)
Definition: ffmpeg_opt.c:3346
LIBAVUTIL_VERSION_INT
#define LIBAVUTIL_VERSION_INT
Definition: version.h:85
assert_file_overwrite
static void assert_file_overwrite(const char *filename)
Definition: ffmpeg_opt.c:1073
AVClass
Describe the class of an AVClass context structure.
Definition: log.h:66
avcodec_get_class
const AVClass * avcodec_get_class(void)
Get the AVClass for AVCodecContext.
Definition: options.c:183
AVStream::time_base
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented.
Definition: avformat.h:978
NULL
#define NULL
Definition: coverity.c:32
OptionParseContext::global_opts
OptionGroup global_opts
Definition: cmdutils.h:264
avcodec_find_decoder_by_name
const AVCodec * avcodec_find_decoder_by_name(const char *name)
Find a registered decoder with the specified name.
Definition: allcodecs.c:963
opt_name_copy_initial_nonkeyframes
static const char *const opt_name_copy_initial_nonkeyframes[]
Definition: ffmpeg_opt.c:94
av_program_add_stream_index
void av_program_add_stream_index(AVFormatContext *ac, int progid, unsigned idx)
Definition: avformat.c:269
av_bsf_get_class
const AVClass * av_bsf_get_class(void)
Get the AVClass for AVBSFContext.
Definition: bsf.c:100
InputStream::top_field_first
int top_field_first
Definition: ffmpeg.h:348
InputStream::st
AVStream * st
Definition: ffmpeg.h:308
OptionsContext::frame_sizes
SpecifierOpt * frame_sizes
Definition: ffmpeg.h:109
OPT_EXPERT
#define OPT_EXPERT
Definition: cmdutils.h:140
swr_get_class
const AVClass * swr_get_class(void)
Get the AVClass for SwrContext.
Definition: options.c:162
AVCodec::type
enum AVMediaType type
Definition: codec.h:209
AVRational
Rational number (pair of numerator and denominator).
Definition: rational.h:58
open_input_file
static int open_input_file(OptionsContext *o, const char *filename)
Definition: ffmpeg_opt.c:1148
av_default_item_name
const char * av_default_item_name(void *ptr)
Return the context name.
Definition: log.c:237
OptionsContext::metadata_global_manual
int metadata_global_manual
Definition: ffmpeg.h:141
AVFormatContext::pb
AVIOContext * pb
I/O context.
Definition: avformat.h:1255
AV_CODEC_PROP_BITMAP_SUB
#define AV_CODEC_PROP_BITMAP_SUB
Subtitle codec is bitmap based Decoded AVSubtitle data can be read from the AVSubtitleRect->pict fiel...
Definition: codec_desc.h:97
parseutils.h
InputStream::hwaccel_id
enum HWAccelID hwaccel_id
Definition: ffmpeg.h:377
getenv_utf8
static char * getenv_utf8(const char *varname)
Definition: getenv_utf8.h:67
OPT_INT64
#define OPT_INT64
Definition: cmdutils.h:147
av_channel_layout_default
void av_channel_layout_default(AVChannelLayout *ch_layout, int nb_channels)
Get the default channel layout for a given number of channels.
Definition: channel_layout.c:960
AVStream::metadata
AVDictionary * metadata
Definition: avformat.h:1019
InputStream::fix_sub_duration
int fix_sub_duration
Definition: ffmpeg.h:353
InputStream::hwaccel_output_format
enum AVPixelFormat hwaccel_output_format
Definition: ffmpeg.h:380
AV_DICT_DONT_OVERWRITE
#define AV_DICT_DONT_OVERWRITE
Don't overwrite existing entries.
Definition: dict.h:74
av_parse_ratio
int av_parse_ratio(AVRational *q, const char *str, int max, int log_offset, void *log_ctx)
Parse str and store the parsed ratio in q.
Definition: parseutils.c:45
OptionsContext::max_frames
SpecifierOpt * max_frames
Definition: ffmpeg.h:168
nb_input_streams
int nb_input_streams
Definition: ffmpeg.c:148
AV_PIX_FMT_QSV
@ AV_PIX_FMT_QSV
HW acceleration through QSV, data[3] contains a pointer to the mfxFrameSurface1 structure.
Definition: pixfmt.h:212
AVFormatContext::audio_codec
const AVCodec * audio_codec
Forced audio codec.
Definition: avformat.h:1690
AVCodecParameters::ch_layout
AVChannelLayout ch_layout
Audio only.
Definition: codec_par.h:212
OptionsContext::input_sync_ref
int input_sync_ref
Definition: ffmpeg.h:121
InputStream::min_pts
int64_t min_pts
Definition: ffmpeg.h:335
OutputFile::index
int index
Definition: ffmpeg.h:587
OptionGroup
Definition: cmdutils.h:239
OptionsContext::program
SpecifierOpt * program
Definition: ffmpeg.h:230
find_stream_info
static int find_stream_info
Definition: ffmpeg_opt.c:191
FilterGraph::nb_outputs
int nb_outputs
Definition: ffmpeg.h:303
index
int index
Definition: gxfenc.c:89
c
Undefined Behavior In the C some operations are like signed integer dereferencing freed accessing outside allocated Undefined Behavior must not occur in a C it is not safe even if the output of undefined operations is unused The unsafety may seem nit picking but Optimizing compilers have in fact optimized code on the assumption that no undefined Behavior occurs Optimizing code based on wrong assumptions can and has in some cases lead to effects beyond the output of computations The signed integer overflow problem in speed critical code Code which is highly optimized and works with signed integers sometimes has the problem that often the output of the computation does not c
Definition: undefined.txt:32
choose_encoder
static int choose_encoder(OptionsContext *o, AVFormatContext *s, OutputStream *ost)
Definition: ffmpeg_opt.c:1486
OptionsContext::nb_metadata_map
int nb_metadata_map
Definition: ffmpeg.h:197
opt_name_guess_layout_max
static const char *const opt_name_guess_layout_max[]
Definition: ffmpeg_opt.c:105
input_files
InputFile ** input_files
Definition: ffmpeg.c:149
opt_name_max_frame_rates
static const char *const opt_name_max_frame_rates[]
Definition: ffmpeg_opt.c:70
AV_OPT_SEARCH_FAKE_OBJ
#define AV_OPT_SEARCH_FAKE_OBJ
The obj passed to av_opt_find() is fake – only a double pointer to AVClass instead of a required poin...
Definition: opt.h:571
av_bprint_is_complete
static int av_bprint_is_complete(const AVBPrint *buf)
Test if the print buffer is complete (not truncated).
Definition: bprint.h:185
AVCodecID
AVCodecID
Identify the syntax and semantics of the bitstream.
Definition: codec_id.h:47
avcodec_find_decoder
const AVCodec * avcodec_find_decoder(enum AVCodecID id)
Find a registered decoder with a matching codec ID.
Definition: allcodecs.c:935
FilterGraph
Definition: ffmpeg.h:290
AVCodecParameters::extradata_size
int extradata_size
Size of the extradata content in bytes.
Definition: codec_par.h:79
opt_streamid
static int opt_streamid(void *optctx, const char *opt, const char *arg)
Definition: ffmpeg_opt.c:2191
AVFormatContext::nb_streams
unsigned int nb_streams
Number of elements in AVFormatContext.streams.
Definition: avformat.h:1269
AVOutputFormat::flags
int flags
can use flags: AVFMT_NOFILE, AVFMT_NEEDNUMBER, AVFMT_GLOBALHEADER, AVFMT_NOTIMESTAMPS,...
Definition: avformat.h:529
opt_preset
static int opt_preset(void *optctx, const char *opt, const char *arg)
Definition: ffmpeg_opt.c:3253
opt_vstats_file
static int opt_vstats_file(void *optctx, const char *opt, const char *arg)
Definition: ffmpeg_opt.c:3192
codec_opts
AVDictionary * codec_opts
Definition: cmdutils.c:60
AVFormatContext::data_codec
const AVCodec * data_codec
Forced data codec.
Definition: avformat.h:1706
options
const OptionDef options[]
VideoSyncMethod
VideoSyncMethod
Definition: ffmpeg.h:50
opt_bitrate
static int opt_bitrate(void *optctx, const char *opt, const char *arg)
Definition: ffmpeg_opt.c:3313
av_get_exact_bits_per_sample
int av_get_exact_bits_per_sample(enum AVCodecID codec_id)
Return codec bits per sample.
Definition: utils.c:495
avformat_find_stream_info
int avformat_find_stream_info(AVFormatContext *ic, AVDictionary **options)
Read packets of a media file to get stream information.
Definition: demux.c:2415
max_error_rate
float max_error_rate
Definition: ffmpeg_opt.c:176
frame_sizes
static const uint8_t frame_sizes[]
Definition: rtpdec_qcelp.c:24
opt_name_audio_sample_rate
static const char *const opt_name_audio_sample_rate[]
Definition: ffmpeg_opt.c:68
f
f
Definition: af_crystalizer.c:122
AVIOContext
Bytestream IO Context.
Definition: avio.h:162
AVCodecContext::rc_override
RcOverride * rc_override
Definition: avcodec.h:1207
InputStream::hwaccel_device_type
enum AVHWDeviceType hwaccel_device_type
Definition: ffmpeg.h:378
OptionsContext::thread_queue_size
int thread_queue_size
Definition: ffmpeg.h:120
AVMediaType
AVMediaType
Definition: avutil.h:199
InputStream::decoded_frame
AVFrame * decoded_frame
Definition: ffmpeg.h:318
opt_init_hw_device
static int opt_init_hw_device(void *optctx, const char *opt, const char *arg)
Definition: ffmpeg_opt.c:650
find_codec_or_die
static const AVCodec * find_codec_or_die(const char *name, enum AVMediaType type, int encoder)
Definition: ffmpeg_opt.c:818
avformat_alloc_context
AVFormatContext * avformat_alloc_context(void)
Allocate an AVFormatContext.
Definition: options.c:164
MATCH_PER_TYPE_OPT
#define MATCH_PER_TYPE_OPT(name, type, outvar, fmtctx, mediatype)
Definition: ffmpeg_opt.c:140
OPT_AUDIO
#define OPT_AUDIO
Definition: cmdutils.h:143
InputStream::file_index
int file_index
Definition: ffmpeg.h:307
output_files
OutputFile ** output_files
Definition: ffmpeg.c:154
opt_map
static int opt_map(void *optctx, const char *opt, const char *arg)
Definition: ffmpeg_opt.c:408
choose_decoder
static const AVCodec * choose_decoder(OptionsContext *o, AVFormatContext *s, AVStream *st)
Definition: ffmpeg_opt.c:847
av_err2str
#define av_err2str(errnum)
Convenience macro, the return value should be used only directly in function arguments but never stan...
Definition: error.h:121
start_time
static int64_t start_time
Definition: ffplay.c:331
AVFormatContext::url
char * url
input or output URL.
Definition: avformat.h:1296
get_preset_file
FILE * get_preset_file(char *filename, size_t filename_size, const char *preset_name, int is_path, const char *codec_name)
Get a file corresponding to a preset file.
Definition: cmdutils.c:814
InputStream::pkt
AVPacket * pkt
Definition: ffmpeg.h:319
AVCodecContext::sample_fmt
enum AVSampleFormat sample_fmt
audio sample format
Definition: avcodec.h:1014
AV_SAMPLE_FMT_NONE
@ AV_SAMPLE_FMT_NONE
Definition: samplefmt.h:56
open_output_file
static int open_output_file(OptionsContext *o, const char *filename)
Definition: ffmpeg_opt.c:2412
StreamMap
Definition: ffmpeg.h:74
file_overwrite
static int file_overwrite
Definition: ffmpeg_opt.c:184
opt_name_filters
static const char *const opt_name_filters[]
Definition: ffmpeg_opt.c:96
avformat_seek_file
int avformat_seek_file(AVFormatContext *s, int stream_index, int64_t min_ts, int64_t ts, int64_t max_ts, int flags)
Seek to timestamp ts.
Definition: seek.c:657
AV_NOPTS_VALUE
#define AV_NOPTS_VALUE
Undefined timestamp value.
Definition: avutil.h:248
OptionsContext::seek_timestamp
int seek_timestamp
Definition: ffmpeg.h:94
opt_subtitle_codec
static int opt_subtitle_codec(void *optctx, const char *opt, const char *arg)
Definition: ffmpeg_opt.c:396
AVStream::event_flags
int event_flags
Flags indicating events happening on the stream, a combination of AVSTREAM_EVENT_FLAG_*.
Definition: avformat.h:1074
OutputStream::source_index
int source_index
Definition: ffmpeg.h:460
DECODING_FOR_OST
#define DECODING_FOR_OST
Definition: ffmpeg.h:312
PAL
#define PAL
Definition: bktr.c:65
avio_check
int avio_check(const char *url, int flags)
Return AVIO_FLAG_* access flags corresponding to the access permissions of the resource in url,...
Definition: avio.c:474
AVFMT_NOFILE
#define AVFMT_NOFILE
Demuxer will use avio_open, no opened file should be provided by the caller.
Definition: avformat.h:470
vstats_filename
char * vstats_filename
Definition: ffmpeg_opt.c:152
setup_find_stream_info_opts
AVDictionary ** setup_find_stream_info_opts(AVFormatContext *s, AVDictionary *codec_opts)
Setup AVCodecContext options for avformat_find_stream_info().
Definition: cmdutils.c:952
AVCodecContext::chroma_intra_matrix
uint16_t * chroma_intra_matrix
custom intra quantization matrix
Definition: avcodec.h:1821
printf
printf("static const uint8_t my_array[100] = {\n")
opt_name_filter_scripts
static const char *const opt_name_filter_scripts[]
Definition: ffmpeg_opt.c:97
AVMEDIA_TYPE_UNKNOWN
@ AVMEDIA_TYPE_UNKNOWN
Usually treated as AVMEDIA_TYPE_DATA.
Definition: avutil.h:200
show_usage
void show_usage(void)
Definition: ffmpeg_opt.c:3499
AVStream::sample_aspect_ratio
AVRational sample_aspect_ratio
sample aspect ratio (0 if unknown)
Definition: avformat.h:1017
opt_sdp_file
static int opt_sdp_file(void *optctx, const char *opt, const char *arg)
Definition: ffmpeg_opt.c:611
opt_name_chroma_intra_matrices
static const char *const opt_name_chroma_intra_matrices[]
Definition: ffmpeg_opt.c:91
AVFMT_NOSTREAMS
#define AVFMT_NOSTREAMS
Format does not require any streams.
Definition: avformat.h:486
audio_sync_method
int audio_sync_method
Definition: ffmpeg_opt.c:160
AV_OPT_SEARCH_CHILDREN
#define AV_OPT_SEARCH_CHILDREN
Search in possible children of the given object first.
Definition: opt.h:563
avio_write
void avio_write(AVIOContext *s, const unsigned char *buf, int size)
Definition: aviobuf.c:232
AV_CODEC_FLAG_PASS2
#define AV_CODEC_FLAG_PASS2
Use internal 2pass ratecontrol in second pass mode.
Definition: avcodec.h:241
avio_r8
int avio_r8(AVIOContext *s)
Definition: aviobuf.c:632
getenv_utf8.h
av_reallocp_array
int av_reallocp_array(void *ptr, size_t nmemb, size_t size)
Allocate, reallocate an array through a pointer to a pointer.
Definition: mem.c:233
OutputFile::limit_filesize
uint64_t limit_filesize
Definition: ffmpeg.h:596
opt_name_passlogfiles
static const char *const opt_name_passlogfiles[]
Definition: ffmpeg_opt.c:102
check_filter_outputs
void check_filter_outputs(void)
Definition: ffmpeg_filter.c:645
line
Definition: graph2dot.c:48
get_ost_filters
static char * get_ost_filters(OptionsContext *o, AVFormatContext *oc, OutputStream *ost)
Definition: ffmpeg_opt.c:1759
OptionsContext::metadata
SpecifierOpt * metadata
Definition: ffmpeg.h:166
opt_data_codec
static int opt_data_codec(void *optctx, const char *opt, const char *arg)
Definition: ffmpeg_opt.c:402
InputStream::max_pts
int64_t max_pts
Definition: ffmpeg.h:336
av_packet_alloc
AVPacket * av_packet_alloc(void)
Allocate an AVPacket and set its fields to default values.
Definition: avpacket.c:62
av_dict_free
void av_dict_free(AVDictionary **pm)
Free all the memory allocated for an AVDictionary struct and all keys and values.
Definition: dict.c:203
init_options
static void init_options(OptionsContext *o)
Definition: ffmpeg_opt.c:225
NTSC
#define NTSC
Definition: bktr.c:67
opt_name_frame_sizes
static const char *const opt_name_frame_sizes[]
Definition: ffmpeg_opt.c:71
av_parse_video_size
int av_parse_video_size(int *width_ptr, int *height_ptr, const char *str)
Parse str and put in width_ptr and height_ptr the detected values.
Definition: parseutils.c:150
OptionsContext::frame_rates
SpecifierOpt * frame_rates
Definition: ffmpeg.h:105
OutputFilter::type
enum AVMediaType type
Definition: ffmpeg.h:274
video_sync_method
enum VideoSyncMethod video_sync_method
Definition: ffmpeg_opt.c:161
AV_LOG_INFO
#define AV_LOG_INFO
Standard information.
Definition: log.h:191
video_codec_name
static const char * video_codec_name
Definition: ffplay.c:346
AVCodec::id
enum AVCodecID id
Definition: codec.h:210
StreamMap::sync_file_index
int sync_file_index
Definition: ffmpeg.h:78
opt_name_enc_time_bases
static const char *const opt_name_enc_time_bases[]
Definition: ffmpeg_opt.c:110
start_at_zero
int start_at_zero
Definition: ffmpeg_opt.c:168
guess_input_channel_layout
int guess_input_channel_layout(InputStream *ist)
Definition: ffmpeg.c:1888
layout
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel layout
Definition: filter_design.txt:18
avcodec_get_name
const char * avcodec_get_name(enum AVCodecID id)
Get the name of a codec.
Definition: utils.c:447
HWACCEL_AUTO
@ HWACCEL_AUTO
Definition: ffmpeg.h:63
InputStream::guess_layout_max
int guess_layout_max
Definition: ffmpeg.h:349
av_parse_video_rate
int av_parse_video_rate(AVRational *rate, const char *arg)
Parse str and store the detected values in *rate.
Definition: parseutils.c:181
avio_closep
int avio_closep(AVIOContext **s)
Close the resource accessed by the AVIOContext *s, free it and set the pointer pointing to it to NULL...
Definition: aviobuf.c:1288
opt_name_audio_ch_layouts
static const char *const opt_name_audio_ch_layouts[]
Definition: ffmpeg_opt.c:67
bprint.h
init_complex_filtergraph
int init_complex_filtergraph(FilterGraph *fg)
Definition: ffmpeg_filter.c:315
apply_sync_offsets
static int apply_sync_offsets(void)
Definition: ffmpeg_opt.c:291
audio_volume
int audio_volume
Definition: ffmpeg_opt.c:159
AVFMT_GLOBALHEADER
#define AVFMT_GLOBALHEADER
Format wants global header.
Definition: avformat.h:480
AV_CODEC_ID_NONE
@ AV_CODEC_ID_NONE
Definition: codec_id.h:48
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:269
RcOverride::end_frame
int end_frame
Definition: avcodec.h:198
opt_name_autoscale
static const char *const opt_name_autoscale[]
Definition: ffmpeg_opt.c:78
OptionsContext::metadata_map
SpecifierOpt * metadata_map
Definition: ffmpeg.h:196
StreamMap::stream_index
int stream_index
Definition: ffmpeg.h:77
OPT_TIME
#define OPT_TIME
Definition: cmdutils.h:153
AVChapter::id
int64_t id
unique ID to identify the chapter
Definition: avformat.h:1173
OptionsContext::stream_maps
StreamMap * stream_maps
Definition: ffmpeg.h:137
opt_name_audio_channels
static const char *const opt_name_audio_channels[]
Definition: ffmpeg_opt.c:66
AVCodecParameters::height
int height
Definition: codec_par.h:128
av_fifo_alloc2
AVFifo * av_fifo_alloc2(size_t nb_elems, size_t elem_size, unsigned int flags)
Allocate and initialize an AVFifo with a given element size.
Definition: fifo.c:47
avcodec_parameters_to_context
int avcodec_parameters_to_context(AVCodecContext *codec, const AVCodecParameters *par)
Fill the codec context based on the values from the supplied codec parameters.
Definition: codec_par.c:182
av_get_sample_fmt
enum AVSampleFormat av_get_sample_fmt(const char *name)
Return a sample format corresponding to name, or AV_SAMPLE_FMT_NONE on error.
Definition: samplefmt.c:58
AV_TIME_BASE
#define AV_TIME_BASE
Internal time base represented as integer.
Definition: avutil.h:254
opt_name_muxing_queue_data_threshold
static const char *const opt_name_muxing_queue_data_threshold[]
Definition: ffmpeg_opt.c:104
OptionsContext::audio_sample_rate
SpecifierOpt * audio_sample_rate
Definition: ffmpeg.h:103
OptionsContext::start_time_eof
int64_t start_time_eof
Definition: ffmpeg.h:93
VSYNC_CFR
@ VSYNC_CFR
Definition: ffmpeg.h:53
opt_video_codec
static int opt_video_codec(void *optctx, const char *opt, const char *arg)
Definition: ffmpeg_opt.c:390
opt_name_sample_fmts
static const char *const opt_name_sample_fmts[]
Definition: ffmpeg_opt.c:82
AVProgram::metadata
AVDictionary * metadata
Definition: avformat.h:1143
opt_qscale
static int opt_qscale(void *optctx, const char *opt, const char *arg)
Definition: ffmpeg_opt.c:3329
OutputFile::ost_index
int ost_index
Definition: ffmpeg.h:593
OptionsContext::nb_frame_pix_fmts
int nb_frame_pix_fmts
Definition: ffmpeg.h:112
stdin_interaction
int stdin_interaction
Definition: ffmpeg_opt.c:175
filter_codec_opts
AVDictionary * filter_codec_opts(AVDictionary *opts, enum AVCodecID codec_id, AVFormatContext *s, AVStream *st, const AVCodec *codec)
Filter out options for given codec.
Definition: cmdutils.c:894
InputStream::processing_needed
int processing_needed
Definition: ffmpeg.h:314
value
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf default value
Definition: writing_filters.txt:86
AVMEDIA_TYPE_ATTACHMENT
@ AVMEDIA_TYPE_ATTACHMENT
Opaque data information usually sparse.
Definition: avutil.h:205
AV_OPT_FLAG_DECODING_PARAM
#define AV_OPT_FLAG_DECODING_PARAM
a generic parameter which can be set by the user for demuxing or decoding
Definition: opt.h:282
InputFile::ctx
AVFormatContext * ctx
Definition: ffmpeg.h:405
FFMIN
#define FFMIN(a, b)
Definition: macros.h:49
new_unknown_stream
static OutputStream * new_unknown_stream(OptionsContext *o, AVFormatContext *oc, int source_index)
Definition: ffmpeg_opt.c:2144
AVFormatContext::max_delay
int max_delay
Definition: avformat.h:1325
opt_vstats
static int opt_vstats(void *optctx, const char *opt, const char *arg)
Definition: ffmpeg_opt.c:3199
av_mallocz
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
Definition: mem.c:264
AVProgram
New fields can be added to the end with minor version bumps.
Definition: avformat.h:1137
avcodec_parameters_alloc
AVCodecParameters * avcodec_parameters_alloc(void)
Allocate a new AVCodecParameters and set its fields to default values (unknown/invalid/0).
Definition: codec_par.c:53
OPT_OUTPUT
#define OPT_OUTPUT
Definition: cmdutils.h:156
AVCodec::name
const char * name
Name of the codec implementation.
Definition: codec.h:203
len
int len
Definition: vorbis_enc_data.h:426
dts_error_threshold
float dts_error_threshold
Definition: ffmpeg_opt.c:157
opt_name_bits_per_raw_sample
static const char *const opt_name_bits_per_raw_sample[]
Definition: ffmpeg_opt.c:111
filtergraphs
FilterGraph ** filtergraphs
Definition: ffmpeg.c:157
int_cb
const AVIOInterruptCB int_cb
Definition: ffmpeg.c:512
AVCodecContext::height
int height
Definition: avcodec.h:562
AVCodecContext::pix_fmt
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
Definition: avcodec.h:599
OPT_OFFSET
#define OPT_OFFSET
Definition: cmdutils.h:151
nb_output_files
int nb_output_files
Definition: ffmpeg.c:155
OptionParseContext::groups
OptionGroupList * groups
Definition: cmdutils.h:266
AVFMT_FLAG_NONBLOCK
#define AVFMT_FLAG_NONBLOCK
Do not block when reading packets from input.
Definition: avformat.h:1334
opt_audio_frames
static int opt_audio_frames(void *optctx, const char *opt, const char *arg)
Definition: ffmpeg_opt.c:3221
OptionsContext::streamid_map
int * streamid_map
Definition: ffmpeg.h:163
parse_optgroup
int parse_optgroup(void *optctx, OptionGroup *g)
Parse an options group and write results into optctx.
Definition: cmdutils.c:376
AudioChannelMap::channel_idx
int channel_idx
Definition: ffmpeg.h:84
OptionDef::u
union OptionDef::@1 u
avcodec.h
opt_map_channel
static int opt_map_channel(void *optctx, const char *opt, const char *arg)
Definition: ffmpeg_opt.c:534
OptionGroup::sws_dict
AVDictionary * sws_dict
Definition: cmdutils.h:248
av_opt_eval_flags
int av_opt_eval_flags(void *obj, const AVOption *o, const char *val, int *flags_out)
av_channel_layout_from_mask
FF_ENABLE_DEPRECATION_WARNINGS int av_channel_layout_from_mask(AVChannelLayout *channel_layout, uint64_t mask)
Initialize a native channel layout from a bitmask indicating which channels are present.
Definition: channel_layout.c:389
SpecifierOpt
Definition: cmdutils.h:123
AVStream::disposition
int disposition
Stream disposition - a combination of AV_DISPOSITION_* flags.
Definition: avformat.h:1008
opt_name_force_fps
static const char *const opt_name_force_fps[]
Definition: ffmpeg_opt.c:86
tag
uint32_t tag
Definition: movenc.c:1646
AVStream::id
int id
Format-specific stream ID.
Definition: avformat.h:962
AVFMT_FLAG_BITEXACT
#define AVFMT_FLAG_BITEXACT
When muxing, try to avoid writing any random/volatile data to the output.
Definition: avformat.h:1348
ret
ret
Definition: filter_design.txt:187
AVStream
Stream structure.
Definition: avformat.h:948
AV_LOG_FATAL
#define AV_LOG_FATAL
Something went wrong and recovery is not possible.
Definition: log.h:174
pixfmt.h
read_yesno
int read_yesno(void)
Return a positive value if a line read from standard input starts with [yY], otherwise return 0.
Definition: cmdutils.c:803
AVClass::class_name
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
Definition: log.h:71
av_strtod
double av_strtod(const char *numstr, char **tail)
Parse the string in numstr and return its value as a double.
Definition: eval.c:106
AVFormatContext::oformat
const struct AVOutputFormat * oformat
The output container format.
Definition: avformat.h:1232
OptionsContext::nb_streamid_map
int nb_streamid_map
Definition: ffmpeg.h:164
VSYNC_DROP
@ VSYNC_DROP
Definition: ffmpeg.h:56
normalize.ifile
ifile
Definition: normalize.py:6
av_opt_eval_int
int av_opt_eval_int(void *obj, const AVOption *o, const char *val, int *int_out)
uninit_parse_context
void uninit_parse_context(OptionParseContext *octx)
Free all allocated memory in an OptionParseContext.
Definition: cmdutils.c:662
AV_CODEC_PROP_TEXT_SUB
#define AV_CODEC_PROP_TEXT_SUB
Subtitle codec is text based.
Definition: codec_desc.h:102
OptionsContext::audio_channel_maps
AudioChannelMap * audio_channel_maps
Definition: ffmpeg.h:139
OPT_PERFILE
#define OPT_PERFILE
Definition: cmdutils.h:150
InputStream::reinit_filters
int reinit_filters
Definition: ffmpeg.h:374
avformat.h
InputFile::ist_index
int ist_index
Definition: ffmpeg.h:408
AV_INPUT_BUFFER_PADDING_SIZE
#define AV_INPUT_BUFFER_PADDING_SIZE
Definition: defs.h:40
av_guess_codec
enum AVCodecID av_guess_codec(const AVOutputFormat *fmt, const char *short_name, const char *filename, const char *mime_type, enum AVMediaType type)
Guess the codec ID based upon muxer and filename.
Definition: format.c:89
CMDUTILS_COMMON_OPTIONS
#define CMDUTILS_COMMON_OPTIONS
Definition: opt_common.h:199
AV_DICT_MATCH_CASE
#define AV_DICT_MATCH_CASE
Only get an entry with exact-case key match.
Definition: dict.h:67
AV_RL32
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_RL32
Definition: bytestream.h:92
filter_nbthreads
char * filter_nbthreads
Definition: ffmpeg_opt.c:177
av_get_pix_fmt
enum AVPixelFormat av_get_pix_fmt(const char *name)
Return the pixel format corresponding to name.
Definition: pixdesc.c:2594
OptionsContext::nb_max_frames
int nb_max_frames
Definition: ffmpeg.h:169
OutputFilter::format
int format
Definition: ffmpeg.h:279
AVFormatContext::data_codec_id
enum AVCodecID data_codec_id
Forced Data codec_id.
Definition: avformat.h:1744
av_get_media_type_string
const char * av_get_media_type_string(enum AVMediaType media_type)
Return a string describing the media_type enum, NULL if media_type is unknown.
Definition: utils.c:28
AVCodecContext
main external API structure.
Definition: avcodec.h:389
AVStream::index
int index
stream index in AVFormatContext
Definition: avformat.h:956
av_bprint_clear
void av_bprint_clear(AVBPrint *buf)
Reset the string to "" but keep internal allocated data.
Definition: bprint.c:227
parse_option
int parse_option(void *optctx, const char *opt, const char *arg, const OptionDef *options)
Parse one given option.
Definition: cmdutils.c:306
opt_name_time_bases
static const char *const opt_name_time_bases[]
Definition: ffmpeg_opt.c:109
audio_codec_name
static const char * audio_codec_name
Definition: ffplay.c:344
OptionsContext::mux_preload
float mux_preload
Definition: ffmpeg.h:152
channel_layout.h
audio_drift_threshold
float audio_drift_threshold
Definition: ffmpeg_opt.c:155
OptionsContext::nb_audio_channels
int nb_audio_channels
Definition: ffmpeg.h:102
InputStream::prev_pkt_pts
int64_t prev_pkt_pts
Definition: ffmpeg.h:321
av_channel_layout_from_string
int av_channel_layout_from_string(AVChannelLayout *channel_layout, const char *str)
Initialize a channel layout from a given string description.
Definition: channel_layout.c:402
opt_common.h
AVInputFormat::flags
int flags
Can use flags: AVFMT_NOFILE, AVFMT_NEEDNUMBER, AVFMT_SHOW_IDS, AVFMT_NOTIMESTAMPS,...
Definition: avformat.h:675
AVRational::den
int den
Denominator.
Definition: rational.h:60
SpecifierOpt::str
uint8_t * str
Definition: cmdutils.h:126
AV_PIX_FMT_NONE
@ AV_PIX_FMT_NONE
Definition: pixfmt.h:65
OPT_SUBTITLE
#define OPT_SUBTITLE
Definition: cmdutils.h:146
read_file
static char * read_file(const char *filename)
Definition: ffmpeg_opt.c:1734
avfilter.h
opt_name_forced_key_frames
static const char *const opt_name_forced_key_frames[]
Definition: ffmpeg_opt.c:84
avio_read
int avio_read(AVIOContext *s, unsigned char *buf, int size)
Read size bytes from AVIOContext into buf.
Definition: aviobuf.c:641
OptionsContext::video_disable
int video_disable
Definition: ffmpeg.h:157
opt_name_hwaccel_output_formats
static const char *const opt_name_hwaccel_output_formats[]
Definition: ffmpeg_opt.c:76
ref
static int ref[MAX_W *MAX_W]
Definition: jpeg2000dwt.c:112
AVOutputFormat::video_codec
enum AVCodecID video_codec
default video codec
Definition: avformat.h:521
InputStream::nb_samples
int64_t nb_samples
Definition: ffmpeg.h:342
strip_specifiers
static AVDictionary * strip_specifiers(AVDictionary *dict)
Definition: ffmpeg_opt.c:254
OptionsContext::frame_pix_fmts
SpecifierOpt * frame_pix_fmts
Definition: ffmpeg.h:111
av_find_input_format
const AVInputFormat * av_find_input_format(const char *short_name)
Find AVInputFormat based on the short name of the input format.
Definition: format.c:120
avio_open
int avio_open(AVIOContext **s, const char *url, int flags)
Create and initialize a AVIOContext for accessing the resource indicated by url.
Definition: aviobuf.c:1223
AVFormatContext::duration
int64_t duration
Duration of the stream, in AV_TIME_BASE fractional seconds.
Definition: avformat.h:1315
GROW_ARRAY
#define GROW_ARRAY(array, nb_elems)
Definition: cmdutils.h:431
opt_name_fps_mode
static const char *const opt_name_fps_mode[]
Definition: ffmpeg_opt.c:85
HWACCEL_NONE
@ HWACCEL_NONE
Definition: ffmpeg.h:62
OptionsContext::nb_frame_sizes
int nb_frame_sizes
Definition: ffmpeg.h:110
InputStream::discard
int discard
Definition: ffmpeg.h:309
VSYNC_AUTO
@ VSYNC_AUTO
Definition: ffmpeg.h:51
OutputFilter
Definition: ffmpeg.h:266
opt_vsync
static int opt_vsync(void *optctx, const char *opt, const char *arg)
Definition: ffmpeg_opt.c:3370
av_dict_set_int
int av_dict_set_int(AVDictionary **pm, const char *key, int64_t value, int flags)
Convenience wrapper for av_dict_set that converts the value to a string and stores it.
Definition: dict.c:147
AVIO_FLAG_READ
#define AVIO_FLAG_READ
read-only
Definition: avio.h:628
get_preset_file_2
static int get_preset_file_2(const char *preset_name, const char *codec_name, AVIOContext **s)
Definition: ffmpeg_opt.c:1456
AVCodecContext::codec_type
enum AVMediaType codec_type
Definition: avcodec.h:397
opt_default
int opt_default(void *optctx, const char *opt, const char *arg)
Fallback for options that are not explicitly handled, these will be parsed through AVOptions.
Definition: cmdutils.c:510
av_strdup
char * av_strdup(const char *s)
Duplicate a string.
Definition: mem.c:280
desc
const char * desc
Definition: libsvtav1.c:83
AVMEDIA_TYPE_VIDEO
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:201
AVERROR_ENCODER_NOT_FOUND
#define AVERROR_ENCODER_NOT_FOUND
Encoder not found.
Definition: error.h:56
av_bsf_list_parse_str
int av_bsf_list_parse_str(const char *str, AVBSFContext **bsf_lst)
Parse string describing list of bitstream filters and create single AVBSFContext describing the whole...
Definition: bsf.c:527
avutil.h
copy_tb
int copy_tb
Definition: ffmpeg_opt.c:169
SpecifierOpt::u
union SpecifierOpt::@0 u
opt_stats_period
static int opt_stats_period(void *optctx, const char *opt, const char *arg)
Definition: ffmpeg_opt.c:369
vstats_version
int vstats_version
Definition: ffmpeg_opt.c:179
AV_CODEC_FLAG_BITEXACT
#define AV_CODEC_FLAG_BITEXACT
Use only bitexact stuff (except (I)DCT).
Definition: avcodec.h:278
OutputFile::ctx
AVFormatContext * ctx
Definition: ffmpeg.h:591
OutputFilter::out_tmp
AVFilterInOut * out_tmp
Definition: ffmpeg.h:273
AVCodecParameters::video_delay
int video_delay
Video only.
Definition: codec_par.h:156
OptionDef::name
const char * name
Definition: cmdutils.h:136
opt_name_intra_matrices
static const char *const opt_name_intra_matrices[]
Definition: ffmpeg_opt.c:89
map
const VDPAUPixFmtMap * map
Definition: hwcontext_vdpau.c:71
OPT_VIDEO
#define OPT_VIDEO
Definition: cmdutils.h:142
av_free
#define av_free(p)
Definition: tableprint_vlc.h:33
AVDictionaryEntry
Definition: dict.h:79
OptionsContext::attachments
const char ** attachments
Definition: ffmpeg.h:144
AVCodecParameters::codec_id
enum AVCodecID codec_id
Specific type of the encoded data (the codec used).
Definition: codec_par.h:61
InputStream::ts_scale
double ts_scale
Definition: ffmpeg.h:344
AVPacket
This structure stores compressed data.
Definition: packet.h:351
audio_disable
static int audio_disable
Definition: ffplay.c:319
copy_chapters
static int copy_chapters(InputFile *ifile, OutputFile *ofile, AVFormatContext *os, int copy_metadata)
Definition: ffmpeg_opt.c:2213
opt_name_copy_prior_start
static const char *const opt_name_copy_prior_start[]
Definition: ffmpeg_opt.c:95
av_freep
#define av_freep(p)
Definition: tableprint_vlc.h:34
av_dict_set
int av_dict_set(AVDictionary **pm, const char *key, const char *value, int flags)
Set the given entry in *pm, overwriting an existing entry.
Definition: dict.c:70
av_dict_copy
int av_dict_copy(AVDictionary **dst, const AVDictionary *src, int flags)
Copy entries from one AVDictionary struct into another.
Definition: dict.c:217
AVCodecContext::inter_matrix
uint16_t * inter_matrix
custom inter quantization matrix Must be allocated with the av_malloc() family of functions,...
Definition: avcodec.h:883
copy_ts
int copy_ts
Definition: ffmpeg_opt.c:167
cmdutils.h
AVCodecContext::rc_override_count
int rc_override_count
ratecontrol override, see RcOverride
Definition: avcodec.h:1206
OFFSET
#define OFFSET(x)
OptionsContext::data_disable
int data_disable
Definition: ffmpeg.h:160
opt_name_apad
static const char *const opt_name_apad[]
Definition: ffmpeg_opt.c:106
OPT_BOOL
#define OPT_BOOL
Definition: cmdutils.h:139
nb_filtergraphs
int nb_filtergraphs
Definition: ffmpeg.c:158
AVFilterInOut::name
char * name
unique name for this input/output in the list
Definition: avfilter.h:1033
avio_find_protocol_name
const char * avio_find_protocol_name(const char *url)
Return the name of the protocol that will handle the passed URL.
Definition: avio.c:467
codec_string
Definition: dashenc.c:204
AVCodecContext::width
int width
picture width / height.
Definition: avcodec.h:562
qp_hist
int qp_hist
Definition: ffmpeg_opt.c:174
AV_OPT_TYPE_FLAGS
@ AV_OPT_TYPE_FLAGS
Definition: opt.h:224
convert_header.str
string str
Definition: convert_header.py:20
parse_time_or_die
int64_t parse_time_or_die(const char *context, const char *timestr, int is_duration)
Parse a string specifying a time and return its corresponding value as a number of microseconds.
Definition: cmdutils.c:122
frame_drop_threshold
float frame_drop_threshold
Definition: ffmpeg_opt.c:162
grow_array
void * grow_array(void *array, int elem_size, int *size, int new_size)
Realloc array to hold new_size elements of elem_size.
Definition: cmdutils.c:972
recast_media
static int recast_media
Definition: ffmpeg_opt.c:190
OutputStream
Definition: muxing.c:54
flags
#define flags(name, subs,...)
Definition: cbs_av1.c:561
opt_name_disposition
static const char *const opt_name_disposition[]
Definition: ffmpeg_opt.c:108
av_strlcpy
size_t av_strlcpy(char *dst, const char *src, size_t size)
Copy the string src to dst, but no more than size - 1 bytes, and null-terminate dst.
Definition: avstring.c:86
print_stats
int print_stats
Definition: ffmpeg_opt.c:173
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:27
AVFormatContext::start_time
int64_t start_time
Position of the first frame of the component, in AV_TIME_BASE fractional seconds.
Definition: avformat.h:1305
MKTAG
#define MKTAG(a, b, c, d)
Definition: macros.h:55
avcodec_descriptor_get
const AVCodecDescriptor * avcodec_descriptor_get(enum AVCodecID id)
Definition: codec_desc.c:3559
OutputFile::format
const AVOutputFormat * format
Definition: ffmpeg.h:589
AVDictionaryEntry::value
char * value
Definition: dict.h:81
avstring.h
opt_name_qscale
static const char *const opt_name_qscale[]
Definition: ffmpeg_opt.c:83
show_help_options
void show_help_options(const OptionDef *options, const char *msg, int req_flags, int rej_flags, int alt_flags)
Print help for all options matching specified flags.
Definition: cmdutils.c:134
av_stream_get_class
const AVClass * av_stream_get_class(void)
Get the AVClass for AVStream.
Definition: options.c:232
FF_QP2LAMBDA
#define FF_QP2LAMBDA
factor to convert from H.263 QP to lambda
Definition: avutil.h:227
set_channel_layout
static void set_channel_layout(OutputFilter *f, OutputStream *ost)
Definition: ffmpeg_opt.c:2375
avcodec_descriptor_get_by_name
const AVCodecDescriptor * avcodec_descriptor_get_by_name(const char *name)
Definition: codec_desc.c:3574
InputFile::nb_streams
int nb_streams
Definition: ffmpeg.h:420
avformat_alloc_output_context2
int avformat_alloc_output_context2(AVFormatContext **ctx, const AVOutputFormat *oformat, const char *format_name, const char *filename)
Allocate an AVFormatContext for an output format.
Definition: mux.c:91
AVChapter::time_base
AVRational time_base
time base in which the start/end timestamps are specified
Definition: avformat.h:1174
opt_name_hwaccel_devices
static const char *const opt_name_hwaccel_devices[]
Definition: ffmpeg_opt.c:75
OutputStream::metadata
uint8_t * metadata
Definition: hdsenc.c:59
OutputFile::recording_time
int64_t recording_time
desired length of the resulting file in microseconds == AV_TIME_BASE units
Definition: ffmpeg.h:594
int
int
Definition: ffmpeg_filter.c:153
opt_name_discard
static const char *const opt_name_discard[]
Definition: ffmpeg_opt.c:107
hw_device_get_by_name
HWDevice * hw_device_get_by_name(const char *name)
Definition: ffmpeg_hw.c:44
avfilter_get_class
const AVClass * avfilter_get_class(void)
Definition: avfilter.c:1547
AVFilterInOut
A linked-list of the inputs/outputs of the filter chain.
Definition: avfilter.h:1031
VSYNC_PASSTHROUGH
@ VSYNC_PASSTHROUGH
Definition: ffmpeg.h:52
AVERROR_PROTOCOL_NOT_FOUND
#define AVERROR_PROTOCOL_NOT_FOUND
Protocol not found.
Definition: error.h:65
InputStream::dec
const AVCodec * dec
Definition: ffmpeg.h:317
AV_OPT_TYPE_CONST
@ AV_OPT_TYPE_CONST
Definition: opt.h:234
snprintf
#define snprintf
Definition: snprintf.h:34
ABORT_ON_FLAG_EMPTY_OUTPUT
#define ABORT_ON_FLAG_EMPTY_OUTPUT
Definition: ffmpeg.h:447
normalize.ofile
ofile
Definition: normalize.py:8
opt_filter_complex
static int opt_filter_complex(void *optctx, const char *opt, const char *arg)
Definition: ffmpeg_opt.c:3397
AVCodecContext::sample_aspect_ratio
AVRational sample_aspect_ratio
sample aspect ratio (0 if unknown) That is the width of a pixel divided by the height of the pixel.
Definition: avcodec.h:759
opt_name_inter_matrices
static const char *const opt_name_inter_matrices[]
Definition: ffmpeg_opt.c:90
av_bprint_chars
void av_bprint_chars(AVBPrint *buf, char c, unsigned n)
Append char c n times to a print buffer.
Definition: bprint.c:140
parse_and_set_vsync
static int parse_and_set_vsync(const char *arg, int *vsync_var, int file_idx, int st_idx, int is_global)
Definition: ffmpeg_opt.c:271
AVInputFormat::priv_class
const AVClass * priv_class
AVClass for the private context.
Definition: avformat.h:686
nb_output_streams
int nb_output_streams
Definition: ffmpeg.c:153
opt_name_codec_tags
static const char *const opt_name_codec_tags[]
Definition: ffmpeg_opt.c:81
avcodec_find_encoder_by_name
const AVCodec * avcodec_find_encoder_by_name(const char *name)
Find a registered encoder with the specified name.
Definition: allcodecs.c:958
OutputFile
Definition: ffmpeg.h:586
AV_CODEC_FLAG_PASS1
#define AV_CODEC_FLAG_PASS1
Use internal 2pass ratecontrol in first pass mode.
Definition: avcodec.h:237
dts_delta_threshold
float dts_delta_threshold
Definition: ffmpeg_opt.c:156
new_subtitle_stream
static OutputStream * new_subtitle_stream(OptionsContext *o, AVFormatContext *oc, int source_index)
Definition: ffmpeg_opt.c:2165
abort_on_flags
int abort_on_flags
Definition: ffmpeg_opt.c:172
OptionsContext::loop
int loop
Definition: ffmpeg.h:116
InputStream::autorotate
int autorotate
Definition: ffmpeg.h:351
AVFormatContext::video_codec
const AVCodec * video_codec
Forced video codec.
Definition: avformat.h:1682
DEFAULT_PASS_LOGFILENAME_PREFIX
#define DEFAULT_PASS_LOGFILENAME_PREFIX
Definition: ffmpeg_opt.c:56
filter_complex_nbthreads
int filter_complex_nbthreads
Definition: ffmpeg_opt.c:178
OptionDef::flags
int flags
Definition: cmdutils.h:137
AVFormatContext::subtitle_codec_id
enum AVCodecID subtitle_codec_id
Forced subtitle codec_id.
Definition: avformat.h:1400
OPT_DOUBLE
#define OPT_DOUBLE
Definition: cmdutils.h:154