MobileFFmpeg iOS / tvOS API  4.4
fftools_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 /*
22  * CHANGES 01.2020
23  * - ffprobe support changes
24  *
25  * CHANGES 12.2019
26  * - Concurrent execution support
27  *
28  * CHANGES 08.2018
29  * --------------------------------------------------------
30  * - fftools_ prefix added to file name and parent headers
31  *
32  * CHANGES 07.2018
33  * --------------------------------------------------------
34  * - Parentheses placed around assignments in condition to prevent -Wparentheses warning
35  */
36 
37 #include <stdint.h>
38 
39 #include "fftools_ffmpeg.h"
40 #include "fftools_cmdutils.h"
41 
42 #include "libavformat/avformat.h"
43 
44 #include "libavcodec/avcodec.h"
45 
46 #include "libavfilter/avfilter.h"
47 
48 #include "libavutil/avassert.h"
49 #include "libavutil/avstring.h"
50 #include "libavutil/avutil.h"
51 #include "libavutil/channel_layout.h"
52 #include "libavutil/intreadwrite.h"
53 #include "libavutil/fifo.h"
54 #include "libavutil/mathematics.h"
55 #include "libavutil/opt.h"
56 #include "libavutil/parseutils.h"
57 #include "libavutil/pixdesc.h"
58 #include "libavutil/pixfmt.h"
59 
60 #define DEFAULT_PASS_LOGFILENAME_PREFIX "ffmpeg2pass"
61 
62 #define MATCH_PER_STREAM_OPT(name, type, outvar, fmtctx, st)\
63 {\
64  int i, ret;\
65  for (i = 0; i < o->nb_ ## name; i++) {\
66  char *spec = o->name[i].specifier;\
67  if ((ret = check_stream_specifier(fmtctx, st, spec)) > 0)\
68  outvar = o->name[i].u.type;\
69  else if (ret < 0)\
70  exit_program(1);\
71  }\
72 }
73 
74 #define MATCH_PER_TYPE_OPT(name, type, outvar, fmtctx, mediatype)\
75 {\
76  int i;\
77  for (i = 0; i < o->nb_ ## name; i++) {\
78  char *spec = o->name[i].specifier;\
79  if (!strcmp(spec, mediatype))\
80  outvar = o->name[i].u.type;\
81  }\
82 }
83 
84 const HWAccel hwaccels[] = {
85 #if CONFIG_VIDEOTOOLBOX
86  { "videotoolbox", videotoolbox_init, HWACCEL_VIDEOTOOLBOX, AV_PIX_FMT_VIDEOTOOLBOX },
87 #endif
88 #if CONFIG_LIBMFX
89  { "qsv", qsv_init, HWACCEL_QSV, AV_PIX_FMT_QSV },
90 #endif
91 #if CONFIG_CUVID
92  { "cuvid", cuvid_init, HWACCEL_CUVID, AV_PIX_FMT_CUDA },
93 #endif
94  { 0 },
95 };
96 __thread AVBufferRef *hw_device_ctx;
98 
99 __thread char *vstats_filename;
100 __thread char *sdp_filename;
101 
102 __thread float audio_drift_threshold = 0.1;
103 __thread float dts_delta_threshold = 10;
104 __thread float dts_error_threshold = 3600*30;
105 
106 __thread int audio_volume = 256;
107 __thread int audio_sync_method = 0;
109 __thread float frame_drop_threshold = 0;
110 __thread int do_deinterlace = 0;
111 __thread int do_benchmark = 0;
112 __thread int do_benchmark_all = 0;
113 __thread int do_hex_dump = 0;
114 __thread int do_pkt_dump = 0;
115 __thread int copy_ts = 0;
116 __thread int start_at_zero = 0;
117 __thread int copy_tb = -1;
118 __thread int debug_ts = 0;
119 __thread int exit_on_error = 0;
120 __thread int abort_on_flags = 0;
121 __thread int print_stats = -1;
122 __thread int qp_hist = 0;
123 __thread int stdin_interaction = 1;
124 __thread int frame_bits_per_raw_sample = 0;
125 __thread float max_error_rate = 2.0/3;
126 __thread int filter_nbthreads = 0;
127 __thread int filter_complex_nbthreads = 0;
128 __thread int vstats_version = 2;
129 
130 
131 __thread int intra_only = 0;
132 __thread int file_overwrite = 0;
133 __thread int no_file_overwrite = 0;
134 __thread int do_psnr = 0;
135 __thread int input_sync;
137 __thread int ignore_unknown_streams = 0;
138 __thread int copy_unknown_streams = 0;
139 __thread int find_stream_info = 1;
140 
141 extern __thread OptionDef *ffmpeg_options;
142 
144 {
145  const OptionDef *po = ffmpeg_options;
146  int i;
147 
148  /* all OPT_SPEC and OPT_STRING can be freed in generic way */
149  while (po->name) {
150  void *dst = (uint8_t*)o + po->u.off;
151 
152  if (po->flags & OPT_SPEC) {
153  SpecifierOpt **so = dst;
154  int i, *count = (int*)(so + 1);
155  for (i = 0; i < *count; i++) {
156  av_freep(&(*so)[i].specifier);
157  if (po->flags & OPT_STRING)
158  av_freep(&(*so)[i].u.str);
159  }
160  av_freep(so);
161  *count = 0;
162  } else if (po->flags & OPT_OFFSET && po->flags & OPT_STRING)
163  av_freep(dst);
164  po++;
165  }
166 
167  for (i = 0; i < o->nb_stream_maps; i++)
168  av_freep(&o->stream_maps[i].linklabel);
169  av_freep(&o->stream_maps);
170  av_freep(&o->audio_channel_maps);
171  av_freep(&o->streamid_map);
172  av_freep(&o->attachments);
173 }
174 
176 {
177  memset(o, 0, sizeof(*o));
178 
179  o->stop_time = INT64_MAX;
180  o->mux_max_delay = 0.7;
181  o->start_time = AV_NOPTS_VALUE;
182  o->start_time_eof = AV_NOPTS_VALUE;
183  o->recording_time = INT64_MAX;
184  o->limit_filesize = UINT64_MAX;
185  o->chapters_input_file = INT_MAX;
186  o->accurate_seek = 1;
187 }
188 
189 int show_hwaccels(void *optctx, const char *opt, const char *arg)
190 {
191  enum AVHWDeviceType type = AV_HWDEVICE_TYPE_NONE;
192  int i;
193 
194  av_log(NULL, AV_LOG_STDERR, "Hardware acceleration methods:\n");
195  while ((type = av_hwdevice_iterate_types(type)) !=
196  AV_HWDEVICE_TYPE_NONE)
197  av_log(NULL, AV_LOG_STDERR, "%s\n", av_hwdevice_get_type_name(type));
198  for (i = 0; hwaccels[i].name; i++)
199  av_log(NULL, AV_LOG_STDERR, "%s\n", hwaccels[i].name);
200  av_log(NULL, AV_LOG_STDERR, "\n");
201  return 0;
202 }
203 
204 /* return a copy of the input with the stream specifiers removed from the keys */
205 AVDictionary *strip_specifiers(AVDictionary *dict)
206 {
207  AVDictionaryEntry *e = NULL;
208  AVDictionary *ret = NULL;
209 
210  while ((e = av_dict_get(dict, "", e, AV_DICT_IGNORE_SUFFIX))) {
211  char *p = strchr(e->key, ':');
212 
213  if (p)
214  *p = 0;
215  av_dict_set(&ret, e->key, e->value, 0);
216  if (p)
217  *p = ':';
218  }
219  return ret;
220 }
221 
222 int opt_abort_on(void *optctx, const char *opt, const char *arg)
223 {
224  const AVOption opts[] = {
225  { "abort_on" , NULL, 0, AV_OPT_TYPE_FLAGS, { .i64 = 0 }, INT64_MIN, INT64_MAX, .unit = "flags" },
226  { "empty_output" , NULL, 0, AV_OPT_TYPE_CONST, { .i64 = ABORT_ON_FLAG_EMPTY_OUTPUT }, .unit = "flags" },
227  { NULL },
228  };
229  const AVClass class = {
230  .class_name = "",
231  .item_name = av_default_item_name,
232  .option = opts,
233  .version = LIBAVUTIL_VERSION_INT,
234  };
235  const AVClass *pclass = &class;
236 
237  return av_opt_eval_flags(&pclass, &opts[0], arg, &abort_on_flags);
238 }
239 
240 int opt_sameq(void *optctx, const char *opt, const char *arg)
241 {
242  av_log(NULL, AV_LOG_ERROR, "Option '%s' was removed. "
243  "If you are looking for an option to preserve the quality (which is not "
244  "what -%s was for), use -qscale 0 or an equivalent quality factor option.\n",
245  opt, opt);
246  return AVERROR(EINVAL);
247 }
248 
249 int opt_video_channel(void *optctx, const char *opt, const char *arg)
250 {
251  av_log(NULL, AV_LOG_WARNING, "This option is deprecated, use -channel.\n");
252  return opt_default(optctx, "channel", arg);
253 }
254 
255 int opt_video_standard(void *optctx, const char *opt, const char *arg)
256 {
257  av_log(NULL, AV_LOG_WARNING, "This option is deprecated, use -standard.\n");
258  return opt_default(optctx, "standard", arg);
259 }
260 
261 int opt_audio_codec(void *optctx, const char *opt, const char *arg)
262 {
263  OptionsContext *o = optctx;
264  return parse_option(o, "codec:a", arg, ffmpeg_options);
265 }
266 
267 int opt_video_codec(void *optctx, const char *opt, const char *arg)
268 {
269  OptionsContext *o = optctx;
270  return parse_option(o, "codec:v", arg, ffmpeg_options);
271 }
272 
273 int opt_subtitle_codec(void *optctx, const char *opt, const char *arg)
274 {
275  OptionsContext *o = optctx;
276  return parse_option(o, "codec:s", arg, ffmpeg_options);
277 }
278 
279 int opt_data_codec(void *optctx, const char *opt, const char *arg)
280 {
281  OptionsContext *o = optctx;
282  return parse_option(o, "codec:d", arg, ffmpeg_options);
283 }
284 
285 int opt_map(void *optctx, const char *opt, const char *arg)
286 {
287  OptionsContext *o = optctx;
288  StreamMap *m = NULL;
289  int i, negative = 0, file_idx, disabled = 0;
290  int sync_file_idx = -1, sync_stream_idx = 0;
291  char *p, *sync;
292  char *map;
293  char *allow_unused;
294 
295  if (*arg == '-') {
296  negative = 1;
297  arg++;
298  }
299  map = av_strdup(arg);
300  if (!map)
301  return AVERROR(ENOMEM);
302 
303  /* parse sync stream first, just pick first matching stream */
304  if ((sync = strchr(map, ','))) {
305  *sync = 0;
306  sync_file_idx = strtol(sync + 1, &sync, 0);
307  if (sync_file_idx >= nb_input_files || sync_file_idx < 0) {
308  av_log(NULL, AV_LOG_FATAL, "Invalid sync file index: %d.\n", sync_file_idx);
309  exit_program(1);
310  }
311  if (*sync)
312  sync++;
313  for (i = 0; i < input_files[sync_file_idx]->nb_streams; i++)
314  if (check_stream_specifier(input_files[sync_file_idx]->ctx,
315  input_files[sync_file_idx]->ctx->streams[i], sync) == 1) {
316  sync_stream_idx = i;
317  break;
318  }
319  if (i == input_files[sync_file_idx]->nb_streams) {
320  av_log(NULL, AV_LOG_FATAL, "Sync stream specification in map %s does not "
321  "match any streams.\n", arg);
322  exit_program(1);
323  }
324  if (input_streams[input_files[sync_file_idx]->ist_index + sync_stream_idx]->user_set_discard == AVDISCARD_ALL) {
325  av_log(NULL, AV_LOG_FATAL, "Sync stream specification in map %s matches a disabled input "
326  "stream.\n", arg);
327  exit_program(1);
328  }
329  }
330 
331 
332  if (map[0] == '[') {
333  /* this mapping refers to lavfi output */
334  const char *c = map + 1;
336  m = &o->stream_maps[o->nb_stream_maps - 1];
337  m->linklabel = av_get_token(&c, "]");
338  if (!m->linklabel) {
339  av_log(NULL, AV_LOG_ERROR, "Invalid output link label: %s.\n", map);
340  exit_program(1);
341  }
342  } else {
343  if ((allow_unused = strchr(map, '?')))
344  *allow_unused = 0;
345  file_idx = strtol(map, &p, 0);
346  if (file_idx >= nb_input_files || file_idx < 0) {
347  av_log(NULL, AV_LOG_FATAL, "Invalid input file index: %d.\n", file_idx);
348  exit_program(1);
349  }
350  if (negative)
351  /* disable some already defined maps */
352  for (i = 0; i < o->nb_stream_maps; i++) {
353  m = &o->stream_maps[i];
354  if (file_idx == m->file_index &&
356  input_files[m->file_index]->ctx->streams[m->stream_index],
357  *p == ':' ? p + 1 : p) > 0)
358  m->disabled = 1;
359  }
360  else
361  for (i = 0; i < input_files[file_idx]->nb_streams; i++) {
362  if (check_stream_specifier(input_files[file_idx]->ctx, input_files[file_idx]->ctx->streams[i],
363  *p == ':' ? p + 1 : p) <= 0)
364  continue;
365  if (input_streams[input_files[file_idx]->ist_index + i]->user_set_discard == AVDISCARD_ALL) {
366  disabled = 1;
367  continue;
368  }
370  m = &o->stream_maps[o->nb_stream_maps - 1];
371 
372  m->file_index = file_idx;
373  m->stream_index = i;
374 
375  if (sync_file_idx >= 0) {
376  m->sync_file_index = sync_file_idx;
377  m->sync_stream_index = sync_stream_idx;
378  } else {
379  m->sync_file_index = file_idx;
380  m->sync_stream_index = i;
381  }
382  }
383  }
384 
385  if (!m) {
386  if (allow_unused) {
387  av_log(NULL, AV_LOG_VERBOSE, "Stream map '%s' matches no streams; ignoring.\n", arg);
388  } else if (disabled) {
389  av_log(NULL, AV_LOG_FATAL, "Stream map '%s' matches disabled streams.\n"
390  "To ignore this, add a trailing '?' to the map.\n", arg);
391  exit_program(1);
392  } else {
393  av_log(NULL, AV_LOG_FATAL, "Stream map '%s' matches no streams.\n"
394  "To ignore this, add a trailing '?' to the map.\n", arg);
395  exit_program(1);
396  }
397  }
398 
399  av_freep(&map);
400  return 0;
401 }
402 
403 int opt_attach(void *optctx, const char *opt, const char *arg)
404 {
405  OptionsContext *o = optctx;
407  o->attachments[o->nb_attachments - 1] = arg;
408  return 0;
409 }
410 
411 int opt_map_channel(void *optctx, const char *opt, const char *arg)
412 {
413  OptionsContext *o = optctx;
414  int n;
415  AVStream *st;
416  AudioChannelMap *m;
417  char *allow_unused;
418  char *mapchan;
419  mapchan = av_strdup(arg);
420  if (!mapchan)
421  return AVERROR(ENOMEM);
422 
425 
426  /* muted channel syntax */
427  n = sscanf(arg, "%d:%d.%d", &m->channel_idx, &m->ofile_idx, &m->ostream_idx);
428  if ((n == 1 || n == 3) && m->channel_idx == -1) {
429  m->file_idx = m->stream_idx = -1;
430  if (n == 1)
431  m->ofile_idx = m->ostream_idx = -1;
432  av_free(mapchan);
433  return 0;
434  }
435 
436  /* normal syntax */
437  n = sscanf(arg, "%d.%d.%d:%d.%d",
438  &m->file_idx, &m->stream_idx, &m->channel_idx,
439  &m->ofile_idx, &m->ostream_idx);
440 
441  if (n != 3 && n != 5) {
442  av_log(NULL, AV_LOG_FATAL, "Syntax error, mapchan usage: "
443  "[file.stream.channel|-1][:syncfile:syncstream]\n");
444  exit_program(1);
445  }
446 
447  if (n != 5) // only file.stream.channel specified
448  m->ofile_idx = m->ostream_idx = -1;
449 
450  /* check input */
451  if (m->file_idx < 0 || m->file_idx >= nb_input_files) {
452  av_log(NULL, AV_LOG_FATAL, "mapchan: invalid input file index: %d\n",
453  m->file_idx);
454  exit_program(1);
455  }
456  if (m->stream_idx < 0 ||
458  av_log(NULL, AV_LOG_FATAL, "mapchan: invalid input file stream index #%d.%d\n",
459  m->file_idx, m->stream_idx);
460  exit_program(1);
461  }
462  st = input_files[m->file_idx]->ctx->streams[m->stream_idx];
463  if (st->codecpar->codec_type != AVMEDIA_TYPE_AUDIO) {
464  av_log(NULL, AV_LOG_FATAL, "mapchan: stream #%d.%d is not an audio stream.\n",
465  m->file_idx, m->stream_idx);
466  exit_program(1);
467  }
468  /* allow trailing ? to map_channel */
469  if ((allow_unused = strchr(mapchan, '?')))
470  *allow_unused = 0;
471  if (m->channel_idx < 0 || m->channel_idx >= st->codecpar->channels ||
473  if (allow_unused) {
474  av_log(NULL, AV_LOG_VERBOSE, "mapchan: invalid audio channel #%d.%d.%d\n",
475  m->file_idx, m->stream_idx, m->channel_idx);
476  } else {
477  av_log(NULL, AV_LOG_FATAL, "mapchan: invalid audio channel #%d.%d.%d\n"
478  "To ignore this, add a trailing '?' to the map_channel.\n",
479  m->file_idx, m->stream_idx, m->channel_idx);
480  exit_program(1);
481  }
482 
483  }
484  av_free(mapchan);
485  return 0;
486 }
487 
488 int opt_sdp_file(void *optctx, const char *opt, const char *arg)
489 {
490  av_free(sdp_filename);
491  sdp_filename = av_strdup(arg);
492  return 0;
493 }
494 
495 #if CONFIG_VAAPI
496 int opt_vaapi_device(void *optctx, const char *opt, const char *arg)
497 {
498  HWDevice *dev;
499  const char *prefix = "vaapi:";
500  char *tmp;
501  int err;
502  tmp = av_asprintf("%s%s", prefix, arg);
503  if (!tmp)
504  return AVERROR(ENOMEM);
505  err = hw_device_init_from_string(tmp, &dev);
506  av_free(tmp);
507  if (err < 0)
508  return err;
509  hw_device_ctx = av_buffer_ref(dev->device_ref);
510  if (!hw_device_ctx)
511  return AVERROR(ENOMEM);
512  return 0;
513 }
514 #endif
515 
516 int opt_init_hw_device(void *optctx, const char *opt, const char *arg)
517 {
518  if (!strcmp(arg, "list")) {
519  enum AVHWDeviceType type = AV_HWDEVICE_TYPE_NONE;
520  av_log(NULL, AV_LOG_STDERR, "Supported hardware device types:\n");
521  while ((type = av_hwdevice_iterate_types(type)) !=
522  AV_HWDEVICE_TYPE_NONE)
523  av_log(NULL, AV_LOG_STDERR, "%s\n", av_hwdevice_get_type_name(type));
524  av_log(NULL, AV_LOG_STDERR, "\n");
525  exit_program(0);
526  } else {
527  return hw_device_init_from_string(arg, NULL);
528  }
529 }
530 
531 int opt_filter_hw_device(void *optctx, const char *opt, const char *arg)
532 {
533  if (filter_hw_device) {
534  av_log(NULL, AV_LOG_ERROR, "Only one filter device can be used.\n");
535  return AVERROR(EINVAL);
536  }
538  if (!filter_hw_device) {
539  av_log(NULL, AV_LOG_ERROR, "Invalid filter device %s.\n", arg);
540  return AVERROR(EINVAL);
541  }
542  return 0;
543 }
544 
552 void parse_meta_type(char *arg, char *type, int *index, const char **stream_spec)
553 {
554  if (*arg) {
555  *type = *arg;
556  switch (*arg) {
557  case 'g':
558  break;
559  case 's':
560  if (*(++arg) && *arg != ':') {
561  av_log(NULL, AV_LOG_FATAL, "Invalid metadata specifier %s.\n", arg);
562  exit_program(1);
563  }
564  *stream_spec = *arg == ':' ? arg + 1 : "";
565  break;
566  case 'c':
567  case 'p':
568  if (*(++arg) == ':')
569  *index = strtol(++arg, NULL, 0);
570  break;
571  default:
572  av_log(NULL, AV_LOG_FATAL, "Invalid metadata type %c.\n", *arg);
573  exit_program(1);
574  }
575  } else
576  *type = 'g';
577 }
578 
579 int fftools_copy_metadata(char *outspec, char *inspec, AVFormatContext *oc, AVFormatContext *ic, OptionsContext *o)
580 {
581  AVDictionary **meta_in = NULL;
582  AVDictionary **meta_out = NULL;
583  int i, ret = 0;
584  char type_in, type_out;
585  const char *istream_spec = NULL, *ostream_spec = NULL;
586  int idx_in = 0, idx_out = 0;
587 
588  parse_meta_type(inspec, &type_in, &idx_in, &istream_spec);
589  parse_meta_type(outspec, &type_out, &idx_out, &ostream_spec);
590 
591  if (!ic) {
592  if (type_out == 'g' || !*outspec)
593  o->metadata_global_manual = 1;
594  if (type_out == 's' || !*outspec)
596  if (type_out == 'c' || !*outspec)
598  return 0;
599  }
600 
601  if (type_in == 'g' || type_out == 'g')
602  o->metadata_global_manual = 1;
603  if (type_in == 's' || type_out == 's')
605  if (type_in == 'c' || type_out == 'c')
607 
608  /* ic is NULL when just disabling automatic mappings */
609  if (!ic)
610  return 0;
611 
612 #define METADATA_CHECK_INDEX(index, nb_elems, desc)\
613  if ((index) < 0 || (index) >= (nb_elems)) {\
614  av_log(NULL, AV_LOG_FATAL, "Invalid %s index %d while processing metadata maps.\n",\
615  (desc), (index));\
616  exit_program(1);\
617  }
618 
619 #define SET_DICT(type, meta, context, index)\
620  switch (type) {\
621  case 'g':\
622  meta = &context->metadata;\
623  break;\
624  case 'c':\
625  METADATA_CHECK_INDEX(index, context->nb_chapters, "chapter")\
626  meta = &context->chapters[index]->metadata;\
627  break;\
628  case 'p':\
629  METADATA_CHECK_INDEX(index, context->nb_programs, "program")\
630  meta = &context->programs[index]->metadata;\
631  break;\
632  case 's':\
633  break; /* handled separately below */ \
634  default: av_assert0(0);\
635  }\
636 
637  SET_DICT(type_in, meta_in, ic, idx_in);
638  SET_DICT(type_out, meta_out, oc, idx_out);
639 
640  /* for input streams choose first matching stream */
641  if (type_in == 's') {
642  for (i = 0; i < ic->nb_streams; i++) {
643  if ((ret = check_stream_specifier(ic, ic->streams[i], istream_spec)) > 0) {
644  meta_in = &ic->streams[i]->metadata;
645  break;
646  } else if (ret < 0)
647  exit_program(1);
648  }
649  if (!meta_in) {
650  av_log(NULL, AV_LOG_FATAL, "Stream specifier %s does not match any streams.\n", istream_spec);
651  exit_program(1);
652  }
653  }
654 
655  if (type_out == 's') {
656  for (i = 0; i < oc->nb_streams; i++) {
657  if ((ret = check_stream_specifier(oc, oc->streams[i], ostream_spec)) > 0) {
658  meta_out = &oc->streams[i]->metadata;
659  av_dict_copy(meta_out, *meta_in, AV_DICT_DONT_OVERWRITE);
660  } else if (ret < 0)
661  exit_program(1);
662  }
663  } else
664  av_dict_copy(meta_out, *meta_in, AV_DICT_DONT_OVERWRITE);
665 
666  return 0;
667 }
668 
669 int opt_recording_timestamp(void *optctx, const char *opt, const char *arg)
670 {
671  OptionsContext *o = optctx;
672  char buf[128];
673  int64_t recording_timestamp = parse_time_or_die(opt, arg, 0) / 1E6;
674  struct tm time = *gmtime((time_t*)&recording_timestamp);
675  if (!strftime(buf, sizeof(buf), "creation_time=%Y-%m-%dT%H:%M:%S%z", &time))
676  return -1;
677  parse_option(o, "metadata", buf, ffmpeg_options);
678 
679  av_log(NULL, AV_LOG_WARNING, "%s is deprecated, set the 'creation_time' metadata "
680  "tag instead.\n", opt);
681  return 0;
682 }
683 
684 AVCodec *find_codec_or_die(const char *name, enum AVMediaType type, int encoder)
685 {
686  const AVCodecDescriptor *desc;
687  const char *codec_string = encoder ? "encoder" : "decoder";
688  AVCodec *codec;
689 
690  codec = encoder ?
691  avcodec_find_encoder_by_name(name) :
692  avcodec_find_decoder_by_name(name);
693 
694  if (!codec && (desc = avcodec_descriptor_get_by_name(name))) {
695  codec = encoder ? avcodec_find_encoder(desc->id) :
696  avcodec_find_decoder(desc->id);
697  if (codec)
698  av_log(NULL, AV_LOG_VERBOSE, "Matched %s '%s' for codec '%s'.\n",
699  codec_string, codec->name, desc->name);
700  }
701 
702  if (!codec) {
703  av_log(NULL, AV_LOG_FATAL, "Unknown %s '%s'\n", codec_string, name);
704  exit_program(1);
705  }
706  if (codec->type != type) {
707  av_log(NULL, AV_LOG_FATAL, "Invalid %s type '%s'\n", codec_string, name);
708  exit_program(1);
709  }
710  return codec;
711 }
712 
713 AVCodec *choose_decoder(OptionsContext *o, AVFormatContext *s, AVStream *st)
714 {
715  char *codec_name = NULL;
716 
717  MATCH_PER_STREAM_OPT(codec_names, str, codec_name, s, st);
718  if (codec_name) {
719  AVCodec *codec = find_codec_or_die(codec_name, st->codecpar->codec_type, 0);
720  st->codecpar->codec_id = codec->id;
721  return codec;
722  } else
723  return avcodec_find_decoder(st->codecpar->codec_id);
724 }
725 
726 /* Add all the streams from the given input file to the global
727  * list of input streams. */
728 void add_input_streams(OptionsContext *o, AVFormatContext *ic)
729 {
730  int i, ret;
731 
732  for (i = 0; i < ic->nb_streams; i++) {
733  AVStream *st = ic->streams[i];
734  AVCodecParameters *par = st->codecpar;
735  InputStream *ist = av_mallocz(sizeof(*ist));
736  char *framerate = NULL, *hwaccel_device = NULL;
737  const char *hwaccel = NULL;
738  char *hwaccel_output_format = NULL;
739  char *codec_tag = NULL;
740  char *next;
741  char *discard_str = NULL;
742  const AVClass *cc = avcodec_get_class();
743  const AVOption *discard_opt = av_opt_find(&cc, "skip_frame", NULL, 0, 0);
744 
745  if (!ist)
746  exit_program(1);
747 
749  input_streams[nb_input_streams - 1] = ist;
750 
751  ist->st = st;
752  ist->file_index = nb_input_files;
753  ist->discard = 1;
754  st->discard = AVDISCARD_ALL;
755  ist->nb_samples = 0;
756  ist->min_pts = INT64_MAX;
757  ist->max_pts = INT64_MIN;
758 
759  ist->ts_scale = 1.0;
760  MATCH_PER_STREAM_OPT(ts_scale, dbl, ist->ts_scale, ic, st);
761 
762  ist->autorotate = 1;
763  MATCH_PER_STREAM_OPT(autorotate, i, ist->autorotate, ic, st);
764 
765  MATCH_PER_STREAM_OPT(codec_tags, str, codec_tag, ic, st);
766  if (codec_tag) {
767  uint32_t tag = strtol(codec_tag, &next, 0);
768  if (*next)
769  tag = AV_RL32(codec_tag);
770  st->codecpar->codec_tag = tag;
771  }
772 
773  ist->dec = choose_decoder(o, ic, st);
774  ist->decoder_opts = filter_codec_opts(o->g->codec_opts, ist->st->codecpar->codec_id, ic, st, ist->dec);
775 
776  ist->reinit_filters = -1;
777  MATCH_PER_STREAM_OPT(reinit_filters, i, ist->reinit_filters, ic, st);
778 
779  MATCH_PER_STREAM_OPT(discard, str, discard_str, ic, st);
780  ist->user_set_discard = AVDISCARD_NONE;
781 
782  if ((o->video_disable && ist->st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) ||
783  (o->audio_disable && ist->st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) ||
784  (o->subtitle_disable && ist->st->codecpar->codec_type == AVMEDIA_TYPE_SUBTITLE) ||
785  (o->data_disable && ist->st->codecpar->codec_type == AVMEDIA_TYPE_DATA))
786  ist->user_set_discard = AVDISCARD_ALL;
787 
788  if (discard_str && av_opt_eval_int(&cc, discard_opt, discard_str, &ist->user_set_discard) < 0) {
789  av_log(NULL, AV_LOG_ERROR, "Error parsing discard %s.\n",
790  discard_str);
791  exit_program(1);
792  }
793 
794  ist->filter_in_rescale_delta_last = AV_NOPTS_VALUE;
795 
796  ist->dec_ctx = avcodec_alloc_context3(ist->dec);
797  if (!ist->dec_ctx) {
798  av_log(NULL, AV_LOG_ERROR, "Error allocating the decoder context.\n");
799  exit_program(1);
800  }
801 
802  ret = avcodec_parameters_to_context(ist->dec_ctx, par);
803  if (ret < 0) {
804  av_log(NULL, AV_LOG_ERROR, "Error initializing the decoder context.\n");
805  exit_program(1);
806  }
807 
808  if (o->bitexact)
809  ist->dec_ctx->flags |= AV_CODEC_FLAG_BITEXACT;
810 
811  switch (par->codec_type) {
812  case AVMEDIA_TYPE_VIDEO:
813  if(!ist->dec)
814  ist->dec = avcodec_find_decoder(par->codec_id);
815 #if FF_API_LOWRES
816  if (st->codec->lowres) {
817  ist->dec_ctx->lowres = st->codec->lowres;
818  ist->dec_ctx->width = st->codec->width;
819  ist->dec_ctx->height = st->codec->height;
820  ist->dec_ctx->coded_width = st->codec->coded_width;
821  ist->dec_ctx->coded_height = st->codec->coded_height;
822  }
823 #endif
824 
825  // avformat_find_stream_info() doesn't set this for us anymore.
826  ist->dec_ctx->framerate = st->avg_frame_rate;
827 
828  MATCH_PER_STREAM_OPT(frame_rates, str, framerate, ic, st);
829  if (framerate && av_parse_video_rate(&ist->framerate,
830  framerate) < 0) {
831  av_log(NULL, AV_LOG_ERROR, "Error parsing framerate %s.\n",
832  framerate);
833  exit_program(1);
834  }
835 
836  ist->top_field_first = -1;
837  MATCH_PER_STREAM_OPT(top_field_first, i, ist->top_field_first, ic, st);
838 
839  MATCH_PER_STREAM_OPT(hwaccels, str, hwaccel, ic, st);
840  if (hwaccel) {
841  // The NVDEC hwaccels use a CUDA device, so remap the name here.
842  if (!strcmp(hwaccel, "nvdec"))
843  hwaccel = "cuda";
844 
845  if (!strcmp(hwaccel, "none"))
846  ist->hwaccel_id = HWACCEL_NONE;
847  else if (!strcmp(hwaccel, "auto"))
848  ist->hwaccel_id = HWACCEL_AUTO;
849  else {
850  enum AVHWDeviceType type;
851  int i;
852  for (i = 0; hwaccels[i].name; i++) {
853  if (!strcmp(hwaccels[i].name, hwaccel)) {
854  ist->hwaccel_id = hwaccels[i].id;
855  break;
856  }
857  }
858 
859  if (!ist->hwaccel_id) {
860  type = av_hwdevice_find_type_by_name(hwaccel);
861  if (type != AV_HWDEVICE_TYPE_NONE) {
863  ist->hwaccel_device_type = type;
864  }
865  }
866 
867  if (!ist->hwaccel_id) {
868  av_log(NULL, AV_LOG_FATAL, "Unrecognized hwaccel: %s.\n",
869  hwaccel);
870  av_log(NULL, AV_LOG_FATAL, "Supported hwaccels: ");
871  type = AV_HWDEVICE_TYPE_NONE;
872  while ((type = av_hwdevice_iterate_types(type)) !=
873  AV_HWDEVICE_TYPE_NONE)
874  av_log(NULL, AV_LOG_FATAL, "%s ",
875  av_hwdevice_get_type_name(type));
876  for (i = 0; hwaccels[i].name; i++)
877  av_log(NULL, AV_LOG_FATAL, "%s ", hwaccels[i].name);
878  av_log(NULL, AV_LOG_FATAL, "\n");
879  exit_program(1);
880  }
881  }
882  }
883 
884  MATCH_PER_STREAM_OPT(hwaccel_devices, str, hwaccel_device, ic, st);
885  if (hwaccel_device) {
886  ist->hwaccel_device = av_strdup(hwaccel_device);
887  if (!ist->hwaccel_device)
888  exit_program(1);
889  }
890 
891  MATCH_PER_STREAM_OPT(hwaccel_output_formats, str,
892  hwaccel_output_format, ic, st);
893  if (hwaccel_output_format) {
894  ist->hwaccel_output_format = av_get_pix_fmt(hwaccel_output_format);
895  if (ist->hwaccel_output_format == AV_PIX_FMT_NONE) {
896  av_log(NULL, AV_LOG_FATAL, "Unrecognised hwaccel output "
897  "format: %s", hwaccel_output_format);
898  }
899  } else {
900  ist->hwaccel_output_format = AV_PIX_FMT_NONE;
901  }
902 
903  ist->hwaccel_pix_fmt = AV_PIX_FMT_NONE;
904 
905  break;
906  case AVMEDIA_TYPE_AUDIO:
907  ist->guess_layout_max = INT_MAX;
908  MATCH_PER_STREAM_OPT(guess_layout_max, i, ist->guess_layout_max, ic, st);
910  break;
911  case AVMEDIA_TYPE_DATA:
912  case AVMEDIA_TYPE_SUBTITLE: {
913  char *canvas_size = NULL;
914  if(!ist->dec)
915  ist->dec = avcodec_find_decoder(par->codec_id);
916  MATCH_PER_STREAM_OPT(fix_sub_duration, i, ist->fix_sub_duration, ic, st);
917  MATCH_PER_STREAM_OPT(canvas_sizes, str, canvas_size, ic, st);
918  if (canvas_size &&
919  av_parse_video_size(&ist->dec_ctx->width, &ist->dec_ctx->height, canvas_size) < 0) {
920  av_log(NULL, AV_LOG_FATAL, "Invalid canvas size: %s.\n", canvas_size);
921  exit_program(1);
922  }
923  break;
924  }
925  case AVMEDIA_TYPE_ATTACHMENT:
926  case AVMEDIA_TYPE_UNKNOWN:
927  break;
928  default:
929  abort();
930  }
931 
932  ret = avcodec_parameters_from_context(par, ist->dec_ctx);
933  if (ret < 0) {
934  av_log(NULL, AV_LOG_ERROR, "Error initializing the decoder context.\n");
935  exit_program(1);
936  }
937  }
938 }
939 
940 void assert_file_overwrite(const char *filename)
941 {
942  const char *proto_name = avio_find_protocol_name(filename);
943 
945  fprintf(stderr, "Error, both -y and -n supplied. Exiting.\n");
946  exit_program(1);
947  }
948 
949  if (!file_overwrite) {
950  if (proto_name && !strcmp(proto_name, "file") && avio_check(filename, 0) == 0) {
952  fprintf(stderr,"File '%s' already exists. Overwrite ? [y/N] ", filename);
953  fflush(stderr);
954  term_exit();
955  signal(SIGINT, SIG_DFL);
956  if (!read_yesno()) {
957  av_log(NULL, AV_LOG_FATAL, "Not overwriting - exiting\n");
958  exit_program(1);
959  }
960  term_init();
961  }
962  else {
963  av_log(NULL, AV_LOG_FATAL, "File '%s' already exists. Exiting.\n", filename);
964  exit_program(1);
965  }
966  }
967  }
968 
969  if (proto_name && !strcmp(proto_name, "file")) {
970  for (int i = 0; i < nb_input_files; i++) {
971  InputFile *file = input_files[i];
972  if (file->ctx->iformat->flags & AVFMT_NOFILE)
973  continue;
974  if (!strcmp(filename, file->ctx->url)) {
975  av_log(NULL, AV_LOG_FATAL, "Output %s same as Input #%d - exiting\n", filename, i);
976  av_log(NULL, AV_LOG_WARNING, "FFmpeg cannot edit existing files in-place.\n");
977  exit_program(1);
978  }
979  }
980  }
981 }
982 
983 void dump_attachment(AVStream *st, const char *filename)
984 {
985  int ret;
986  AVIOContext *out = NULL;
987  AVDictionaryEntry *e;
988 
989  if (!st->codecpar->extradata_size) {
990  av_log(NULL, AV_LOG_WARNING, "No extradata to dump in stream #%d:%d.\n",
991  nb_input_files - 1, st->index);
992  return;
993  }
994  if (!*filename && (e = av_dict_get(st->metadata, "filename", NULL, 0)))
995  filename = e->value;
996  if (!*filename) {
997  av_log(NULL, AV_LOG_FATAL, "No filename specified and no 'filename' tag"
998  "in stream #%d:%d.\n", nb_input_files - 1, st->index);
999  exit_program(1);
1000  }
1001 
1002  assert_file_overwrite(filename);
1003 
1004  if ((ret = avio_open2(&out, filename, AVIO_FLAG_WRITE, &int_cb, NULL)) < 0) {
1005  av_log(NULL, AV_LOG_FATAL, "Could not open file %s for writing.\n",
1006  filename);
1007  exit_program(1);
1008  }
1009 
1010  avio_write(out, st->codecpar->extradata, st->codecpar->extradata_size);
1011  avio_flush(out);
1012  avio_close(out);
1013 }
1014 
1015 int open_input_file(OptionsContext *o, const char *filename)
1016 {
1017  InputFile *f;
1018  AVFormatContext *ic;
1019  AVInputFormat *file_iformat = NULL;
1020  int err, i, ret;
1021  int64_t timestamp;
1022  AVDictionary *unused_opts = NULL;
1023  AVDictionaryEntry *e = NULL;
1024  char * video_codec_name = NULL;
1025  char * audio_codec_name = NULL;
1026  char *subtitle_codec_name = NULL;
1027  char * data_codec_name = NULL;
1028  int scan_all_pmts_set = 0;
1029 
1030  if (o->stop_time != INT64_MAX && o->recording_time != INT64_MAX) {
1031  o->stop_time = INT64_MAX;
1032  av_log(NULL, AV_LOG_WARNING, "-t and -to cannot be used together; using -t.\n");
1033  }
1034 
1035  if (o->stop_time != INT64_MAX && o->recording_time == INT64_MAX) {
1036  int64_t start_time = o->start_time == AV_NOPTS_VALUE ? 0 : o->start_time;
1037  if (o->stop_time <= start_time) {
1038  av_log(NULL, AV_LOG_ERROR, "-to value smaller than -ss; aborting.\n");
1039  exit_program(1);
1040  } else {
1041  o->recording_time = o->stop_time - start_time;
1042  }
1043  }
1044 
1045  if (o->format) {
1046  if (!(file_iformat = av_find_input_format(o->format))) {
1047  av_log(NULL, AV_LOG_FATAL, "Unknown input format: '%s'\n", o->format);
1048  exit_program(1);
1049  }
1050  }
1051 
1052  if (!strcmp(filename, "-"))
1053  filename = "pipe:";
1054 
1055  stdin_interaction &= strncmp(filename, "pipe:", 5) &&
1056  strcmp(filename, "/dev/stdin");
1057 
1058  /* get default parameters from command line */
1059  ic = avformat_alloc_context();
1060  if (!ic) {
1061  print_error(filename, AVERROR(ENOMEM));
1062  exit_program(1);
1063  }
1064  if (o->nb_audio_sample_rate) {
1065  av_dict_set_int(&o->g->format_opts, "sample_rate", o->audio_sample_rate[o->nb_audio_sample_rate - 1].u.i, 0);
1066  }
1067  if (o->nb_audio_channels) {
1068  /* because we set audio_channels based on both the "ac" and
1069  * "channel_layout" options, we need to check that the specified
1070  * demuxer actually has the "channels" option before setting it */
1071  if (file_iformat && file_iformat->priv_class &&
1072  av_opt_find(&file_iformat->priv_class, "channels", NULL, 0,
1073  AV_OPT_SEARCH_FAKE_OBJ)) {
1074  av_dict_set_int(&o->g->format_opts, "channels", o->audio_channels[o->nb_audio_channels - 1].u.i, 0);
1075  }
1076  }
1077  if (o->nb_frame_rates) {
1078  /* set the format-level framerate option;
1079  * this is important for video grabbers, e.g. x11 */
1080  if (file_iformat && file_iformat->priv_class &&
1081  av_opt_find(&file_iformat->priv_class, "framerate", NULL, 0,
1082  AV_OPT_SEARCH_FAKE_OBJ)) {
1083  av_dict_set(&o->g->format_opts, "framerate",
1084  o->frame_rates[o->nb_frame_rates - 1].u.str, 0);
1085  }
1086  }
1087  if (o->nb_frame_sizes) {
1088  av_dict_set(&o->g->format_opts, "video_size", o->frame_sizes[o->nb_frame_sizes - 1].u.str, 0);
1089  }
1090  if (o->nb_frame_pix_fmts)
1091  av_dict_set(&o->g->format_opts, "pixel_format", o->frame_pix_fmts[o->nb_frame_pix_fmts - 1].u.str, 0);
1092 
1093  MATCH_PER_TYPE_OPT(codec_names, str, video_codec_name, ic, "v");
1094  MATCH_PER_TYPE_OPT(codec_names, str, audio_codec_name, ic, "a");
1095  MATCH_PER_TYPE_OPT(codec_names, str, subtitle_codec_name, ic, "s");
1096  MATCH_PER_TYPE_OPT(codec_names, str, data_codec_name, ic, "d");
1097 
1098  if (video_codec_name)
1099  ic->video_codec = find_codec_or_die(video_codec_name , AVMEDIA_TYPE_VIDEO , 0);
1100  if (audio_codec_name)
1101  ic->audio_codec = find_codec_or_die(audio_codec_name , AVMEDIA_TYPE_AUDIO , 0);
1102  if (subtitle_codec_name)
1103  ic->subtitle_codec = find_codec_or_die(subtitle_codec_name, AVMEDIA_TYPE_SUBTITLE, 0);
1104  if (data_codec_name)
1105  ic->data_codec = find_codec_or_die(data_codec_name , AVMEDIA_TYPE_DATA , 0);
1106 
1107  ic->video_codec_id = video_codec_name ? ic->video_codec->id : AV_CODEC_ID_NONE;
1108  ic->audio_codec_id = audio_codec_name ? ic->audio_codec->id : AV_CODEC_ID_NONE;
1109  ic->subtitle_codec_id = subtitle_codec_name ? ic->subtitle_codec->id : AV_CODEC_ID_NONE;
1110  ic->data_codec_id = data_codec_name ? ic->data_codec->id : AV_CODEC_ID_NONE;
1111 
1112  ic->flags |= AVFMT_FLAG_NONBLOCK;
1113  if (o->bitexact)
1114  ic->flags |= AVFMT_FLAG_BITEXACT;
1115  ic->interrupt_callback = int_cb;
1116 
1117  if (!av_dict_get(o->g->format_opts, "scan_all_pmts", NULL, AV_DICT_MATCH_CASE)) {
1118  av_dict_set(&o->g->format_opts, "scan_all_pmts", "1", AV_DICT_DONT_OVERWRITE);
1119  scan_all_pmts_set = 1;
1120  }
1121  /* open the input file with generic avformat function */
1122  err = avformat_open_input(&ic, filename, file_iformat, &o->g->format_opts);
1123  if (err < 0) {
1124  print_error(filename, err);
1125  if (err == AVERROR_PROTOCOL_NOT_FOUND)
1126  av_log(NULL, AV_LOG_ERROR, "Did you mean file:%s?\n", filename);
1127  exit_program(1);
1128  }
1129  if (scan_all_pmts_set)
1130  av_dict_set(&o->g->format_opts, "scan_all_pmts", NULL, AV_DICT_MATCH_CASE);
1133 
1134  /* apply forced codec ids */
1135  for (i = 0; i < ic->nb_streams; i++)
1136  choose_decoder(o, ic, ic->streams[i]);
1137 
1138  if (find_stream_info) {
1139  AVDictionary **opts = setup_find_stream_info_opts(ic, o->g->codec_opts);
1140  int orig_nb_streams = ic->nb_streams;
1141 
1142  /* If not enough info to get the stream parameters, we decode the
1143  first frames to get it. (used in mpeg case for example) */
1144  ret = avformat_find_stream_info(ic, opts);
1145 
1146  for (i = 0; i < orig_nb_streams; i++)
1147  av_dict_free(&opts[i]);
1148  av_freep(&opts);
1149 
1150  if (ret < 0) {
1151  av_log(NULL, AV_LOG_FATAL, "%s: could not find codec parameters\n", filename);
1152  if (ic->nb_streams == 0) {
1153  avformat_close_input(&ic);
1154  exit_program(1);
1155  }
1156  }
1157  }
1158 
1159  if (o->start_time != AV_NOPTS_VALUE && o->start_time_eof != AV_NOPTS_VALUE) {
1160  av_log(NULL, AV_LOG_WARNING, "Cannot use -ss and -sseof both, using -ss for %s\n", filename);
1161  o->start_time_eof = AV_NOPTS_VALUE;
1162  }
1163 
1164  if (o->start_time_eof != AV_NOPTS_VALUE) {
1165  if (o->start_time_eof >= 0) {
1166  av_log(NULL, AV_LOG_ERROR, "-sseof value must be negative; aborting\n");
1167  exit_program(1);
1168  }
1169  if (ic->duration > 0) {
1170  o->start_time = o->start_time_eof + ic->duration;
1171  if (o->start_time < 0) {
1172  av_log(NULL, AV_LOG_WARNING, "-sseof value seeks to before start of file %s; ignored\n", filename);
1173  o->start_time = AV_NOPTS_VALUE;
1174  }
1175  } else
1176  av_log(NULL, AV_LOG_WARNING, "Cannot use -sseof, duration of %s not known\n", filename);
1177  }
1178  timestamp = (o->start_time == AV_NOPTS_VALUE) ? 0 : o->start_time;
1179  /* add the stream start time */
1180  if (!o->seek_timestamp && ic->start_time != AV_NOPTS_VALUE)
1181  timestamp += ic->start_time;
1182 
1183  /* if seeking requested, we execute it */
1184  if (o->start_time != AV_NOPTS_VALUE) {
1185  int64_t seek_timestamp = timestamp;
1186 
1187  if (!(ic->iformat->flags & AVFMT_SEEK_TO_PTS)) {
1188  int dts_heuristic = 0;
1189  for (i=0; i<ic->nb_streams; i++) {
1190  const AVCodecParameters *par = ic->streams[i]->codecpar;
1191  if (par->video_delay) {
1192  dts_heuristic = 1;
1193  break;
1194  }
1195  }
1196  if (dts_heuristic) {
1197  seek_timestamp -= 3*AV_TIME_BASE / 23;
1198  }
1199  }
1200  ret = avformat_seek_file(ic, -1, INT64_MIN, seek_timestamp, seek_timestamp, 0);
1201  if (ret < 0) {
1202  av_log(NULL, AV_LOG_WARNING, "%s: could not seek to position %0.3f\n",
1203  filename, (double)timestamp / AV_TIME_BASE);
1204  }
1205  }
1206 
1207  /* update the current parameters so that they match the one of the input stream */
1208  add_input_streams(o, ic);
1209 
1210  /* dump the file content */
1211  av_dump_format(ic, nb_input_files, filename, 0);
1212 
1214  f = av_mallocz(sizeof(*f));
1215  if (!f)
1216  exit_program(1);
1217  input_files[nb_input_files - 1] = f;
1218 
1219  f->ctx = ic;
1220  f->ist_index = nb_input_streams - ic->nb_streams;
1221  f->start_time = o->start_time;
1224  f->ts_offset = o->input_ts_offset - (copy_ts ? (start_at_zero && ic->start_time != AV_NOPTS_VALUE ? ic->start_time : 0) : timestamp);
1225  f->nb_streams = ic->nb_streams;
1226  f->rate_emu = o->rate_emu;
1227  f->accurate_seek = o->accurate_seek;
1228  f->loop = o->loop;
1229  f->duration = 0;
1230  f->time_base = (AVRational){ 1, 1 };
1231 #if HAVE_THREADS
1232  f->thread_queue_size = o->thread_queue_size > 0 ? o->thread_queue_size : 8;
1233 #endif
1234 
1235  /* check if all codec options have been used */
1236  unused_opts = strip_specifiers(o->g->codec_opts);
1237  for (i = f->ist_index; i < nb_input_streams; i++) {
1238  e = NULL;
1239  while ((e = av_dict_get(input_streams[i]->decoder_opts, "", e,
1240  AV_DICT_IGNORE_SUFFIX)))
1241  av_dict_set(&unused_opts, e->key, NULL, 0);
1242  }
1243 
1244  e = NULL;
1245  while ((e = av_dict_get(unused_opts, "", e, AV_DICT_IGNORE_SUFFIX))) {
1246  const AVClass *class = avcodec_get_class();
1247  const AVOption *option = av_opt_find(&class, e->key, NULL, 0,
1248  AV_OPT_SEARCH_CHILDREN | AV_OPT_SEARCH_FAKE_OBJ);
1249  const AVClass *fclass = avformat_get_class();
1250  const AVOption *foption = av_opt_find(&fclass, e->key, NULL, 0,
1251  AV_OPT_SEARCH_CHILDREN | AV_OPT_SEARCH_FAKE_OBJ);
1252  if (!option || foption)
1253  continue;
1254 
1255 
1256  if (!(option->flags & AV_OPT_FLAG_DECODING_PARAM)) {
1257  av_log(NULL, AV_LOG_ERROR, "Codec AVOption %s (%s) specified for "
1258  "input file #%d (%s) is not a decoding option.\n", e->key,
1259  option->help ? option->help : "", nb_input_files - 1,
1260  filename);
1261  exit_program(1);
1262  }
1263 
1264  av_log(NULL, AV_LOG_WARNING, "Codec AVOption %s (%s) specified for "
1265  "input file #%d (%s) has not been used for any stream. The most "
1266  "likely reason is either wrong type (e.g. a video option with "
1267  "no video streams) or that it is a private option of some decoder "
1268  "which was not actually used for any stream.\n", e->key,
1269  option->help ? option->help : "", nb_input_files - 1, filename);
1270  }
1271  av_dict_free(&unused_opts);
1272 
1273  for (i = 0; i < o->nb_dump_attachment; i++) {
1274  int j;
1275 
1276  for (j = 0; j < ic->nb_streams; j++) {
1277  AVStream *st = ic->streams[j];
1278 
1279  if (check_stream_specifier(ic, st, o->dump_attachment[i].specifier) == 1)
1280  dump_attachment(st, o->dump_attachment[i].u.str);
1281  }
1282  }
1283 
1285 
1286  return 0;
1287 }
1288 
1289 uint8_t *get_line(AVIOContext *s)
1290 {
1291  AVIOContext *line;
1292  uint8_t *buf;
1293  char c;
1294 
1295  if (avio_open_dyn_buf(&line) < 0) {
1296  av_log(NULL, AV_LOG_FATAL, "Could not alloc buffer for reading preset.\n");
1297  exit_program(1);
1298  }
1299 
1300  while ((c = avio_r8(s)) && c != '\n')
1301  avio_w8(line, c);
1302  avio_w8(line, 0);
1303  avio_close_dyn_buf(line, &buf);
1304 
1305  return buf;
1306 }
1307 
1308 int get_preset_file_2(const char *preset_name, const char *codec_name, AVIOContext **s)
1309 {
1310  int i, ret = -1;
1311  char filename[1000];
1312  const char *base[3] = { getenv("AVCONV_DATADIR"),
1313  getenv("HOME"),
1314  AVCONV_DATADIR,
1315  };
1316 
1317  for (i = 0; i < FF_ARRAY_ELEMS(base) && ret < 0; i++) {
1318  if (!base[i])
1319  continue;
1320  if (codec_name) {
1321  snprintf(filename, sizeof(filename), "%s%s/%s-%s.avpreset", base[i],
1322  i != 1 ? "" : "/.avconv", codec_name, preset_name);
1323  ret = avio_open2(s, filename, AVIO_FLAG_READ, &int_cb, NULL);
1324  }
1325  if (ret < 0) {
1326  snprintf(filename, sizeof(filename), "%s%s/%s.avpreset", base[i],
1327  i != 1 ? "" : "/.avconv", preset_name);
1328  ret = avio_open2(s, filename, AVIO_FLAG_READ, &int_cb, NULL);
1329  }
1330  }
1331  return ret;
1332 }
1333 
1334 int choose_encoder(OptionsContext *o, AVFormatContext *s, OutputStream *ost)
1335 {
1336  enum AVMediaType type = ost->st->codecpar->codec_type;
1337  char *codec_name = NULL;
1338 
1339  if (type == AVMEDIA_TYPE_VIDEO || type == AVMEDIA_TYPE_AUDIO || type == AVMEDIA_TYPE_SUBTITLE) {
1340  MATCH_PER_STREAM_OPT(codec_names, str, codec_name, s, ost->st);
1341  if (!codec_name) {
1342  ost->st->codecpar->codec_id = av_guess_codec(s->oformat, NULL, s->url,
1343  NULL, ost->st->codecpar->codec_type);
1344  ost->enc = avcodec_find_encoder(ost->st->codecpar->codec_id);
1345  if (!ost->enc) {
1346  av_log(NULL, AV_LOG_FATAL, "Automatic encoder selection failed for "
1347  "output stream #%d:%d. Default encoder for format %s (codec %s) is "
1348  "probably disabled. Please choose an encoder manually.\n",
1349  ost->file_index, ost->index, s->oformat->name,
1350  avcodec_get_name(ost->st->codecpar->codec_id));
1351  return AVERROR_ENCODER_NOT_FOUND;
1352  }
1353  } else if (!strcmp(codec_name, "copy"))
1354  ost->stream_copy = 1;
1355  else {
1356  ost->enc = find_codec_or_die(codec_name, ost->st->codecpar->codec_type, 1);
1357  ost->st->codecpar->codec_id = ost->enc->id;
1358  }
1359  ost->encoding_needed = !ost->stream_copy;
1360  } else {
1361  /* no encoding supported for other media types */
1362  ost->stream_copy = 1;
1363  ost->encoding_needed = 0;
1364  }
1365 
1366  return 0;
1367 }
1368 
1369 OutputStream *new_output_stream(OptionsContext *o, AVFormatContext *oc, enum AVMediaType type, int source_index)
1370 {
1371  OutputStream *ost;
1372  AVStream *st = avformat_new_stream(oc, NULL);
1373  int idx = oc->nb_streams - 1, ret = 0;
1374  const char *bsfs = NULL, *time_base = NULL;
1375  char *next, *codec_tag = NULL;
1376  double qscale = -1;
1377  int i;
1378 
1379  if (!st) {
1380  av_log(NULL, AV_LOG_FATAL, "Could not alloc stream.\n");
1381  exit_program(1);
1382  }
1383 
1384  if (oc->nb_streams - 1 < o->nb_streamid_map)
1385  st->id = o->streamid_map[oc->nb_streams - 1];
1386 
1388  if (!(ost = av_mallocz(sizeof(*ost))))
1389  exit_program(1);
1390  output_streams[nb_output_streams - 1] = ost;
1391 
1392  ost->file_index = nb_output_files - 1;
1393  ost->index = idx;
1394  ost->st = st;
1395  ost->forced_kf_ref_pts = AV_NOPTS_VALUE;
1396  st->codecpar->codec_type = type;
1397 
1398  ret = choose_encoder(o, oc, ost);
1399  if (ret < 0) {
1400  av_log(NULL, AV_LOG_FATAL, "Error selecting an encoder for stream "
1401  "%d:%d\n", ost->file_index, ost->index);
1402  exit_program(1);
1403  }
1404 
1405  ost->enc_ctx = avcodec_alloc_context3(ost->enc);
1406  if (!ost->enc_ctx) {
1407  av_log(NULL, AV_LOG_ERROR, "Error allocating the encoding context.\n");
1408  exit_program(1);
1409  }
1410  ost->enc_ctx->codec_type = type;
1411 
1412  ost->ref_par = avcodec_parameters_alloc();
1413  if (!ost->ref_par) {
1414  av_log(NULL, AV_LOG_ERROR, "Error allocating the encoding parameters.\n");
1415  exit_program(1);
1416  }
1417 
1418  if (ost->enc) {
1419  AVIOContext *s = NULL;
1420  char *buf = NULL, *arg = NULL, *preset = NULL;
1421 
1422  ost->encoder_opts = filter_codec_opts(o->g->codec_opts, ost->enc->id, oc, st, ost->enc);
1423 
1424  MATCH_PER_STREAM_OPT(presets, str, preset, oc, st);
1425  if (preset && (!(ret = get_preset_file_2(preset, ost->enc->name, &s)))) {
1426  do {
1427  buf = get_line(s);
1428  if (!buf[0] || buf[0] == '#') {
1429  av_free(buf);
1430  continue;
1431  }
1432  if (!(arg = strchr(buf, '='))) {
1433  av_log(NULL, AV_LOG_FATAL, "Invalid line found in the preset file.\n");
1434  exit_program(1);
1435  }
1436  *arg++ = 0;
1437  av_dict_set(&ost->encoder_opts, buf, arg, AV_DICT_DONT_OVERWRITE);
1438  av_free(buf);
1439  } while (!s->eof_reached);
1440  avio_closep(&s);
1441  }
1442  if (ret) {
1443  av_log(NULL, AV_LOG_FATAL,
1444  "Preset %s specified for stream %d:%d, but could not be opened.\n",
1445  preset, ost->file_index, ost->index);
1446  exit_program(1);
1447  }
1448  } else {
1449  ost->encoder_opts = filter_codec_opts(o->g->codec_opts, AV_CODEC_ID_NONE, oc, st, NULL);
1450  }
1451 
1452 
1453  if (o->bitexact)
1454  ost->enc_ctx->flags |= AV_CODEC_FLAG_BITEXACT;
1455 
1456  MATCH_PER_STREAM_OPT(time_bases, str, time_base, oc, st);
1457  if (time_base) {
1458  AVRational q;
1459  if (av_parse_ratio(&q, time_base, INT_MAX, 0, NULL) < 0 ||
1460  q.num <= 0 || q.den <= 0) {
1461  av_log(NULL, AV_LOG_FATAL, "Invalid time base: %s\n", time_base);
1462  exit_program(1);
1463  }
1464  st->time_base = q;
1465  }
1466 
1467  MATCH_PER_STREAM_OPT(enc_time_bases, str, time_base, oc, st);
1468  if (time_base) {
1469  AVRational q;
1470  if (av_parse_ratio(&q, time_base, INT_MAX, 0, NULL) < 0 ||
1471  q.den <= 0) {
1472  av_log(NULL, AV_LOG_FATAL, "Invalid time base: %s\n", time_base);
1473  exit_program(1);
1474  }
1475  ost->enc_timebase = q;
1476  }
1477 
1478  ost->max_frames = INT64_MAX;
1479  MATCH_PER_STREAM_OPT(max_frames, i64, ost->max_frames, oc, st);
1480  for (i = 0; i<o->nb_max_frames; i++) {
1481  char *p = o->max_frames[i].specifier;
1482  if (!*p && type != AVMEDIA_TYPE_VIDEO) {
1483  av_log(NULL, AV_LOG_WARNING, "Applying unspecific -frames to non video streams, maybe you meant -vframes ?\n");
1484  break;
1485  }
1486  }
1487 
1488  ost->copy_prior_start = -1;
1489  MATCH_PER_STREAM_OPT(copy_prior_start, i, ost->copy_prior_start, oc ,st);
1490 
1491  MATCH_PER_STREAM_OPT(bitstream_filters, str, bsfs, oc, st);
1492  while (bsfs && *bsfs) {
1493  const AVBitStreamFilter *filter;
1494  char *bsf, *bsf_options_str, *bsf_name;
1495 
1496  bsf = av_get_token(&bsfs, ",");
1497  if (!bsf)
1498  exit_program(1);
1499  bsf_name = av_strtok(bsf, "=", &bsf_options_str);
1500  if (!bsf_name)
1501  exit_program(1);
1502 
1503  filter = av_bsf_get_by_name(bsf_name);
1504  if (!filter) {
1505  av_log(NULL, AV_LOG_FATAL, "Unknown bitstream filter %s\n", bsf_name);
1506  exit_program(1);
1507  }
1508 
1509  ost->bsf_ctx = av_realloc_array(ost->bsf_ctx,
1510  ost->nb_bitstream_filters + 1,
1511  sizeof(*ost->bsf_ctx));
1512  if (!ost->bsf_ctx)
1513  exit_program(1);
1514 
1515  ret = av_bsf_alloc(filter, &ost->bsf_ctx[ost->nb_bitstream_filters]);
1516  if (ret < 0) {
1517  av_log(NULL, AV_LOG_ERROR, "Error allocating a bitstream filter context\n");
1518  exit_program(1);
1519  }
1520 
1521  ost->nb_bitstream_filters++;
1522 
1523  if (bsf_options_str && filter->priv_class) {
1524  const AVOption *opt = av_opt_next(ost->bsf_ctx[ost->nb_bitstream_filters-1]->priv_data, NULL);
1525  const char * shorthand[2] = {NULL};
1526 
1527  if (opt)
1528  shorthand[0] = opt->name;
1529 
1530  ret = av_opt_set_from_string(ost->bsf_ctx[ost->nb_bitstream_filters-1]->priv_data, bsf_options_str, shorthand, "=", ":");
1531  if (ret < 0) {
1532  av_log(NULL, AV_LOG_ERROR, "Error parsing options for bitstream filter %s\n", bsf_name);
1533  exit_program(1);
1534  }
1535  }
1536  av_freep(&bsf);
1537 
1538  if (*bsfs)
1539  bsfs++;
1540  }
1541 
1542  MATCH_PER_STREAM_OPT(codec_tags, str, codec_tag, oc, st);
1543  if (codec_tag) {
1544  uint32_t tag = strtol(codec_tag, &next, 0);
1545  if (*next)
1546  tag = AV_RL32(codec_tag);
1547  ost->st->codecpar->codec_tag =
1548  ost->enc_ctx->codec_tag = tag;
1549  }
1550 
1551  MATCH_PER_STREAM_OPT(qscale, dbl, qscale, oc, st);
1552  if (qscale >= 0) {
1553  ost->enc_ctx->flags |= AV_CODEC_FLAG_QSCALE;
1554  ost->enc_ctx->global_quality = FF_QP2LAMBDA * qscale;
1555  }
1556 
1557  MATCH_PER_STREAM_OPT(disposition, str, ost->disposition, oc, st);
1558  ost->disposition = av_strdup(ost->disposition);
1559 
1560  ost->max_muxing_queue_size = 128;
1561  MATCH_PER_STREAM_OPT(max_muxing_queue_size, i, ost->max_muxing_queue_size, oc, st);
1562  ost->max_muxing_queue_size *= sizeof(AVPacket);
1563 
1564  if (oc->oformat->flags & AVFMT_GLOBALHEADER)
1565  ost->enc_ctx->flags |= AV_CODEC_FLAG_GLOBAL_HEADER;
1566 
1567  av_dict_copy(&ost->sws_dict, o->g->sws_dict, 0);
1568 
1569  av_dict_copy(&ost->swr_opts, o->g->swr_opts, 0);
1570  if (ost->enc && av_get_exact_bits_per_sample(ost->enc->id) == 24)
1571  av_dict_set(&ost->swr_opts, "output_sample_bits", "24", 0);
1572 
1573  av_dict_copy(&ost->resample_opts, o->g->resample_opts, 0);
1574 
1575  ost->source_index = source_index;
1576  if (source_index >= 0) {
1577  ost->sync_ist = input_streams[source_index];
1578  input_streams[source_index]->discard = 0;
1579  input_streams[source_index]->st->discard = input_streams[source_index]->user_set_discard;
1580  }
1581  ost->last_mux_dts = AV_NOPTS_VALUE;
1582 
1583  ost->muxing_queue = av_fifo_alloc(8 * sizeof(AVPacket));
1584  if (!ost->muxing_queue)
1585  exit_program(1);
1586 
1587  return ost;
1588 }
1589 
1590 void parse_matrix_coeffs(uint16_t *dest, const char *str)
1591 {
1592  int i;
1593  const char *p = str;
1594  for (i = 0;; i++) {
1595  dest[i] = atoi(p);
1596  if (i == 63)
1597  break;
1598  p = strchr(p, ',');
1599  if (!p) {
1600  av_log(NULL, AV_LOG_FATAL, "Syntax error in matrix \"%s\" at coeff %d\n", str, i);
1601  exit_program(1);
1602  }
1603  p++;
1604  }
1605 }
1606 
1607 /* read file contents into a string */
1608 uint8_t *fftools_read_file(const char *filename)
1609 {
1610  AVIOContext *pb = NULL;
1611  AVIOContext *dyn_buf = NULL;
1612  int ret = avio_open(&pb, filename, AVIO_FLAG_READ);
1613  uint8_t buf[1024], *str;
1614 
1615  if (ret < 0) {
1616  av_log(NULL, AV_LOG_ERROR, "Error opening file %s.\n", filename);
1617  return NULL;
1618  }
1619 
1620  ret = avio_open_dyn_buf(&dyn_buf);
1621  if (ret < 0) {
1622  avio_closep(&pb);
1623  return NULL;
1624  }
1625  while ((ret = avio_read(pb, buf, sizeof(buf))) > 0)
1626  avio_write(dyn_buf, buf, ret);
1627  avio_w8(dyn_buf, 0);
1628  avio_closep(&pb);
1629 
1630  ret = avio_close_dyn_buf(dyn_buf, &str);
1631  if (ret < 0)
1632  return NULL;
1633  return str;
1634 }
1635 
1636 char *get_ost_filters(OptionsContext *o, AVFormatContext *oc,
1637  OutputStream *ost)
1638 {
1639  AVStream *st = ost->st;
1640 
1641  if (ost->filters_script && ost->filters) {
1642  av_log(NULL, AV_LOG_ERROR, "Both -filter and -filter_script set for "
1643  "output stream #%d:%d.\n", nb_output_files, st->index);
1644  exit_program(1);
1645  }
1646 
1647  if (ost->filters_script)
1648  return fftools_read_file(ost->filters_script);
1649  else if (ost->filters)
1650  return av_strdup(ost->filters);
1651 
1652  return av_strdup(st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO ?
1653  "null" : "anull");
1654 }
1655 
1656 void check_streamcopy_filters(OptionsContext *o, AVFormatContext *oc,
1657  const OutputStream *ost, enum AVMediaType type)
1658 {
1659  if (ost->filters_script || ost->filters) {
1660  av_log(NULL, AV_LOG_ERROR,
1661  "%s '%s' was defined for %s output stream %d:%d but codec copy was selected.\n"
1662  "Filtering and streamcopy cannot be used together.\n",
1663  ost->filters ? "Filtergraph" : "Filtergraph script",
1664  ost->filters ? ost->filters : ost->filters_script,
1665  av_get_media_type_string(type), ost->file_index, ost->index);
1666  exit_program(1);
1667  }
1668 }
1669 
1670 OutputStream *new_video_stream(OptionsContext *o, AVFormatContext *oc, int source_index)
1671 {
1672  AVStream *st;
1673  OutputStream *ost;
1674  AVCodecContext *video_enc;
1675  char *frame_rate = NULL, *frame_aspect_ratio = NULL;
1676 
1677  ost = new_output_stream(o, oc, AVMEDIA_TYPE_VIDEO, source_index);
1678  st = ost->st;
1679  video_enc = ost->enc_ctx;
1680 
1681  MATCH_PER_STREAM_OPT(frame_rates, str, frame_rate, oc, st);
1682  if (frame_rate && av_parse_video_rate(&ost->frame_rate, frame_rate) < 0) {
1683  av_log(NULL, AV_LOG_FATAL, "Invalid framerate value: %s\n", frame_rate);
1684  exit_program(1);
1685  }
1686  if (frame_rate && video_sync_method == VSYNC_PASSTHROUGH)
1687  av_log(NULL, AV_LOG_ERROR, "Using -vsync 0 and -r can produce invalid output files\n");
1688 
1689  MATCH_PER_STREAM_OPT(frame_aspect_ratios, str, frame_aspect_ratio, oc, st);
1690  if (frame_aspect_ratio) {
1691  AVRational q;
1692  if (av_parse_ratio(&q, frame_aspect_ratio, 255, 0, NULL) < 0 ||
1693  q.num <= 0 || q.den <= 0) {
1694  av_log(NULL, AV_LOG_FATAL, "Invalid aspect ratio: %s\n", frame_aspect_ratio);
1695  exit_program(1);
1696  }
1697  ost->frame_aspect_ratio = q;
1698  }
1699 
1700  MATCH_PER_STREAM_OPT(filter_scripts, str, ost->filters_script, oc, st);
1701  MATCH_PER_STREAM_OPT(filters, str, ost->filters, oc, st);
1702  if (o->nb_filters > 1)
1703  av_log(NULL, AV_LOG_ERROR, "Only '-vf %s' read, ignoring remaining -vf options: Use ',' to separate filters\n", ost->filters);
1704 
1705  if (!ost->stream_copy) {
1706  const char *p = NULL;
1707  char *frame_size = NULL;
1708  char *frame_pix_fmt = NULL;
1709  char *intra_matrix = NULL, *inter_matrix = NULL;
1710  char *chroma_intra_matrix = NULL;
1711  int do_pass = 0;
1712  int i;
1713 
1714  MATCH_PER_STREAM_OPT(frame_sizes, str, frame_size, oc, st);
1715  if (frame_size && av_parse_video_size(&video_enc->width, &video_enc->height, frame_size) < 0) {
1716  av_log(NULL, AV_LOG_FATAL, "Invalid frame size: %s.\n", frame_size);
1717  exit_program(1);
1718  }
1719 
1720  video_enc->bits_per_raw_sample = frame_bits_per_raw_sample;
1721  MATCH_PER_STREAM_OPT(frame_pix_fmts, str, frame_pix_fmt, oc, st);
1722  if (frame_pix_fmt && *frame_pix_fmt == '+') {
1723  ost->keep_pix_fmt = 1;
1724  if (!*++frame_pix_fmt)
1725  frame_pix_fmt = NULL;
1726  }
1727  if (frame_pix_fmt && (video_enc->pix_fmt = av_get_pix_fmt(frame_pix_fmt)) == AV_PIX_FMT_NONE) {
1728  av_log(NULL, AV_LOG_FATAL, "Unknown pixel format requested: %s.\n", frame_pix_fmt);
1729  exit_program(1);
1730  }
1731  st->sample_aspect_ratio = video_enc->sample_aspect_ratio;
1732 
1733  if (intra_only)
1734  video_enc->gop_size = 0;
1735  MATCH_PER_STREAM_OPT(intra_matrices, str, intra_matrix, oc, st);
1736  if (intra_matrix) {
1737  if (!(video_enc->intra_matrix = av_mallocz(sizeof(*video_enc->intra_matrix) * 64))) {
1738  av_log(NULL, AV_LOG_FATAL, "Could not allocate memory for intra matrix.\n");
1739  exit_program(1);
1740  }
1741  parse_matrix_coeffs(video_enc->intra_matrix, intra_matrix);
1742  }
1743  MATCH_PER_STREAM_OPT(chroma_intra_matrices, str, chroma_intra_matrix, oc, st);
1744  if (chroma_intra_matrix) {
1745  uint16_t *p = av_mallocz(sizeof(*video_enc->chroma_intra_matrix) * 64);
1746  if (!p) {
1747  av_log(NULL, AV_LOG_FATAL, "Could not allocate memory for intra matrix.\n");
1748  exit_program(1);
1749  }
1750  video_enc->chroma_intra_matrix = p;
1751  parse_matrix_coeffs(p, chroma_intra_matrix);
1752  }
1753  MATCH_PER_STREAM_OPT(inter_matrices, str, inter_matrix, oc, st);
1754  if (inter_matrix) {
1755  if (!(video_enc->inter_matrix = av_mallocz(sizeof(*video_enc->inter_matrix) * 64))) {
1756  av_log(NULL, AV_LOG_FATAL, "Could not allocate memory for inter matrix.\n");
1757  exit_program(1);
1758  }
1759  parse_matrix_coeffs(video_enc->inter_matrix, inter_matrix);
1760  }
1761 
1762  MATCH_PER_STREAM_OPT(rc_overrides, str, p, oc, st);
1763  for (i = 0; p; i++) {
1764  int start, end, q;
1765  int e = sscanf(p, "%d,%d,%d", &start, &end, &q);
1766  if (e != 3) {
1767  av_log(NULL, AV_LOG_FATAL, "error parsing rc_override\n");
1768  exit_program(1);
1769  }
1770  video_enc->rc_override =
1771  av_realloc_array(video_enc->rc_override,
1772  i + 1, sizeof(RcOverride));
1773  if (!video_enc->rc_override) {
1774  av_log(NULL, AV_LOG_FATAL, "Could not (re)allocate memory for rc_override.\n");
1775  exit_program(1);
1776  }
1777  video_enc->rc_override[i].start_frame = start;
1778  video_enc->rc_override[i].end_frame = end;
1779  if (q > 0) {
1780  video_enc->rc_override[i].qscale = q;
1781  video_enc->rc_override[i].quality_factor = 1.0;
1782  }
1783  else {
1784  video_enc->rc_override[i].qscale = 0;
1785  video_enc->rc_override[i].quality_factor = -q/100.0;
1786  }
1787  p = strchr(p, '/');
1788  if (p) p++;
1789  }
1790  video_enc->rc_override_count = i;
1791 
1792  if (do_psnr)
1793  video_enc->flags|= AV_CODEC_FLAG_PSNR;
1794 
1795  /* two pass mode */
1796  MATCH_PER_STREAM_OPT(pass, i, do_pass, oc, st);
1797  if (do_pass) {
1798  if (do_pass & 1) {
1799  video_enc->flags |= AV_CODEC_FLAG_PASS1;
1800  av_dict_set(&ost->encoder_opts, "flags", "+pass1", AV_DICT_APPEND);
1801  }
1802  if (do_pass & 2) {
1803  video_enc->flags |= AV_CODEC_FLAG_PASS2;
1804  av_dict_set(&ost->encoder_opts, "flags", "+pass2", AV_DICT_APPEND);
1805  }
1806  }
1807 
1808  MATCH_PER_STREAM_OPT(passlogfiles, str, ost->logfile_prefix, oc, st);
1809  if (ost->logfile_prefix &&
1810  !(ost->logfile_prefix = av_strdup(ost->logfile_prefix)))
1811  exit_program(1);
1812 
1813  if (do_pass) {
1814  char logfilename[1024];
1815  FILE *f;
1816 
1817  snprintf(logfilename, sizeof(logfilename), "%s-%d.log",
1818  ost->logfile_prefix ? ost->logfile_prefix :
1820  i);
1821  if (!strcmp(ost->enc->name, "libx264")) {
1822  av_dict_set(&ost->encoder_opts, "stats", logfilename, AV_DICT_DONT_OVERWRITE);
1823  } else {
1824  if (video_enc->flags & AV_CODEC_FLAG_PASS2) {
1825  char *logbuffer = fftools_read_file(logfilename);
1826 
1827  if (!logbuffer) {
1828  av_log(NULL, AV_LOG_FATAL, "Error reading log file '%s' for pass-2 encoding\n",
1829  logfilename);
1830  exit_program(1);
1831  }
1832  video_enc->stats_in = logbuffer;
1833  }
1834  if (video_enc->flags & AV_CODEC_FLAG_PASS1) {
1835  f = av_fopen_utf8(logfilename, "wb");
1836  if (!f) {
1837  av_log(NULL, AV_LOG_FATAL,
1838  "Cannot write log file '%s' for pass-1 encoding: %s\n",
1839  logfilename, strerror(errno));
1840  exit_program(1);
1841  }
1842  ost->logfile = f;
1843  }
1844  }
1845  }
1846 
1847  MATCH_PER_STREAM_OPT(forced_key_frames, str, ost->forced_keyframes, oc, st);
1848  if (ost->forced_keyframes)
1849  ost->forced_keyframes = av_strdup(ost->forced_keyframes);
1850 
1851  MATCH_PER_STREAM_OPT(force_fps, i, ost->force_fps, oc, st);
1852 
1853  ost->top_field_first = -1;
1854  MATCH_PER_STREAM_OPT(top_field_first, i, ost->top_field_first, oc, st);
1855 
1856 
1857  ost->avfilter = get_ost_filters(o, oc, ost);
1858  if (!ost->avfilter)
1859  exit_program(1);
1860  } else {
1861  MATCH_PER_STREAM_OPT(copy_initial_nonkeyframes, i, ost->copy_initial_nonkeyframes, oc ,st);
1862  }
1863 
1864  if (ost->stream_copy)
1865  check_streamcopy_filters(o, oc, ost, AVMEDIA_TYPE_VIDEO);
1866 
1867  return ost;
1868 }
1869 
1870 OutputStream *new_audio_stream(OptionsContext *o, AVFormatContext *oc, int source_index)
1871 {
1872  int n;
1873  AVStream *st;
1874  OutputStream *ost;
1875  AVCodecContext *audio_enc;
1876 
1877  ost = new_output_stream(o, oc, AVMEDIA_TYPE_AUDIO, source_index);
1878  st = ost->st;
1879 
1880  audio_enc = ost->enc_ctx;
1881  audio_enc->codec_type = AVMEDIA_TYPE_AUDIO;
1882 
1883  MATCH_PER_STREAM_OPT(filter_scripts, str, ost->filters_script, oc, st);
1884  MATCH_PER_STREAM_OPT(filters, str, ost->filters, oc, st);
1885  if (o->nb_filters > 1)
1886  av_log(NULL, AV_LOG_ERROR, "Only '-af %s' read, ignoring remaining -af options: Use ',' to separate filters\n", ost->filters);
1887 
1888  if (!ost->stream_copy) {
1889  char *sample_fmt = NULL;
1890 
1891  MATCH_PER_STREAM_OPT(audio_channels, i, audio_enc->channels, oc, st);
1892 
1893  MATCH_PER_STREAM_OPT(sample_fmts, str, sample_fmt, oc, st);
1894  if (sample_fmt &&
1895  (audio_enc->sample_fmt = av_get_sample_fmt(sample_fmt)) == AV_SAMPLE_FMT_NONE) {
1896  av_log(NULL, AV_LOG_FATAL, "Invalid sample format '%s'\n", sample_fmt);
1897  exit_program(1);
1898  }
1899 
1900  MATCH_PER_STREAM_OPT(audio_sample_rate, i, audio_enc->sample_rate, oc, st);
1901 
1902  MATCH_PER_STREAM_OPT(apad, str, ost->apad, oc, st);
1903  ost->apad = av_strdup(ost->apad);
1904 
1905  ost->avfilter = get_ost_filters(o, oc, ost);
1906  if (!ost->avfilter)
1907  exit_program(1);
1908 
1909  /* check for channel mapping for this audio stream */
1910  for (n = 0; n < o->nb_audio_channel_maps; n++) {
1911  AudioChannelMap *map = &o->audio_channel_maps[n];
1912  if ((map->ofile_idx == -1 || ost->file_index == map->ofile_idx) &&
1913  (map->ostream_idx == -1 || ost->st->index == map->ostream_idx)) {
1914  InputStream *ist;
1915 
1916  if (map->channel_idx == -1) {
1917  ist = NULL;
1918  } else if (ost->source_index < 0) {
1919  av_log(NULL, AV_LOG_FATAL, "Cannot determine input stream for channel mapping %d.%d\n",
1920  ost->file_index, ost->st->index);
1921  continue;
1922  } else {
1923  ist = input_streams[ost->source_index];
1924  }
1925 
1926  if (!ist || (ist->file_index == map->file_idx && ist->st->index == map->stream_idx)) {
1927  if (av_reallocp_array(&ost->audio_channels_map,
1928  ost->audio_channels_mapped + 1,
1929  sizeof(*ost->audio_channels_map)
1930  ) < 0 )
1931  exit_program(1);
1932 
1934  }
1935  }
1936  }
1937  }
1938 
1939  if (ost->stream_copy)
1940  check_streamcopy_filters(o, oc, ost, AVMEDIA_TYPE_AUDIO);
1941 
1942  return ost;
1943 }
1944 
1945 OutputStream *new_data_stream(OptionsContext *o, AVFormatContext *oc, int source_index)
1946 {
1947  OutputStream *ost;
1948 
1949  ost = new_output_stream(o, oc, AVMEDIA_TYPE_DATA, source_index);
1950  if (!ost->stream_copy) {
1951  av_log(NULL, AV_LOG_FATAL, "Data stream encoding not supported yet (only streamcopy)\n");
1952  exit_program(1);
1953  }
1954 
1955  return ost;
1956 }
1957 
1958 OutputStream *new_unknown_stream(OptionsContext *o, AVFormatContext *oc, int source_index)
1959 {
1960  OutputStream *ost;
1961 
1962  ost = new_output_stream(o, oc, AVMEDIA_TYPE_UNKNOWN, source_index);
1963  if (!ost->stream_copy) {
1964  av_log(NULL, AV_LOG_FATAL, "Unknown stream encoding not supported yet (only streamcopy)\n");
1965  exit_program(1);
1966  }
1967 
1968  return ost;
1969 }
1970 
1971 OutputStream *new_attachment_stream(OptionsContext *o, AVFormatContext *oc, int source_index)
1972 {
1973  OutputStream *ost = new_output_stream(o, oc, AVMEDIA_TYPE_ATTACHMENT, source_index);
1974  ost->stream_copy = 1;
1975  ost->finished = 1;
1976  return ost;
1977 }
1978 
1979 OutputStream *new_subtitle_stream(OptionsContext *o, AVFormatContext *oc, int source_index)
1980 {
1981  AVStream *st;
1982  OutputStream *ost;
1983  AVCodecContext *subtitle_enc;
1984 
1985  ost = new_output_stream(o, oc, AVMEDIA_TYPE_SUBTITLE, source_index);
1986  st = ost->st;
1987  subtitle_enc = ost->enc_ctx;
1988 
1989  subtitle_enc->codec_type = AVMEDIA_TYPE_SUBTITLE;
1990 
1991  MATCH_PER_STREAM_OPT(copy_initial_nonkeyframes, i, ost->copy_initial_nonkeyframes, oc, st);
1992 
1993  if (!ost->stream_copy) {
1994  char *frame_size = NULL;
1995 
1996  MATCH_PER_STREAM_OPT(frame_sizes, str, frame_size, oc, st);
1997  if (frame_size && av_parse_video_size(&subtitle_enc->width, &subtitle_enc->height, frame_size) < 0) {
1998  av_log(NULL, AV_LOG_FATAL, "Invalid frame size: %s.\n", frame_size);
1999  exit_program(1);
2000  }
2001  }
2002 
2003  return ost;
2004 }
2005 
2006 /* arg format is "output-stream-index:streamid-value". */
2007 int opt_streamid(void *optctx, const char *opt, const char *arg)
2008 {
2009  OptionsContext *o = optctx;
2010  int idx;
2011  char *p;
2012  char idx_str[16];
2013 
2014  av_strlcpy(idx_str, arg, sizeof(idx_str));
2015  p = strchr(idx_str, ':');
2016  if (!p) {
2017  av_log(NULL, AV_LOG_FATAL,
2018  "Invalid value '%s' for option '%s', required syntax is 'index:value'\n",
2019  arg, opt);
2020  exit_program(1);
2021  }
2022  *p++ = '\0';
2023  idx = parse_number_or_die(opt, idx_str, OPT_INT, 0, MAX_STREAMS-1);
2024  o->streamid_map = grow_array(o->streamid_map, sizeof(*o->streamid_map), &o->nb_streamid_map, idx+1);
2025  o->streamid_map[idx] = parse_number_or_die(opt, p, OPT_INT, 0, INT_MAX);
2026  return 0;
2027 }
2028 
2029 int copy_chapters(InputFile *ifile, OutputFile *ofile, int copy_metadata)
2030 {
2031  AVFormatContext *is = ifile->ctx;
2032  AVFormatContext *os = ofile->ctx;
2033  AVChapter **tmp;
2034  int i;
2035 
2036  tmp = av_realloc_f(os->chapters, is->nb_chapters + os->nb_chapters, sizeof(*os->chapters));
2037  if (!tmp)
2038  return AVERROR(ENOMEM);
2039  os->chapters = tmp;
2040 
2041  for (i = 0; i < is->nb_chapters; i++) {
2042  AVChapter *in_ch = is->chapters[i], *out_ch;
2043  int64_t start_time = (ofile->start_time == AV_NOPTS_VALUE) ? 0 : ofile->start_time;
2044  int64_t ts_off = av_rescale_q(start_time - ifile->ts_offset,
2045  AV_TIME_BASE_Q, in_ch->time_base);
2046  int64_t rt = (ofile->recording_time == INT64_MAX) ? INT64_MAX :
2047  av_rescale_q(ofile->recording_time, AV_TIME_BASE_Q, in_ch->time_base);
2048 
2049 
2050  if (in_ch->end < ts_off)
2051  continue;
2052  if (rt != INT64_MAX && in_ch->start > rt + ts_off)
2053  break;
2054 
2055  out_ch = av_mallocz(sizeof(AVChapter));
2056  if (!out_ch)
2057  return AVERROR(ENOMEM);
2058 
2059  out_ch->id = in_ch->id;
2060  out_ch->time_base = in_ch->time_base;
2061  out_ch->start = FFMAX(0, in_ch->start - ts_off);
2062  out_ch->end = FFMIN(rt, in_ch->end - ts_off);
2063 
2064  if (copy_metadata)
2065  av_dict_copy(&out_ch->metadata, in_ch->metadata, 0);
2066 
2067  os->chapters[os->nb_chapters++] = out_ch;
2068  }
2069  return 0;
2070 }
2071 
2073  AVFormatContext *oc)
2074 {
2075  OutputStream *ost;
2076 
2077  switch (ofilter->type) {
2078  case AVMEDIA_TYPE_VIDEO: ost = new_video_stream(o, oc, -1); break;
2079  case AVMEDIA_TYPE_AUDIO: ost = new_audio_stream(o, oc, -1); break;
2080  default:
2081  av_log(NULL, AV_LOG_FATAL, "Only video and audio filters are supported "
2082  "currently.\n");
2083  exit_program(1);
2084  }
2085 
2086  ost->source_index = -1;
2087  ost->filter = ofilter;
2088 
2089  ofilter->ost = ost;
2090  ofilter->format = -1;
2091 
2092  if (ost->stream_copy) {
2093  av_log(NULL, AV_LOG_ERROR, "Streamcopy requested for output stream %d:%d, "
2094  "which is fed from a complex filtergraph. Filtering and streamcopy "
2095  "cannot be used together.\n", ost->file_index, ost->index);
2096  exit_program(1);
2097  }
2098 
2099  if (ost->avfilter && (ost->filters || ost->filters_script)) {
2100  const char *opt = ost->filters ? "-vf/-af/-filter" : "-filter_script";
2101  av_log(NULL, AV_LOG_ERROR,
2102  "%s '%s' was specified through the %s option "
2103  "for output stream %d:%d, which is fed from a complex filtergraph.\n"
2104  "%s and -filter_complex cannot be used together for the same stream.\n",
2105  ost->filters ? "Filtergraph" : "Filtergraph script",
2106  ost->filters ? ost->filters : ost->filters_script,
2107  opt, ost->file_index, ost->index, opt);
2108  exit_program(1);
2109  }
2110 
2111  avfilter_inout_free(&ofilter->out_tmp);
2112 }
2113 
2115 {
2116  int i, ret = 0;
2117 
2118  for (i = 0; i < nb_filtergraphs; i++) {
2120  if (ret < 0)
2121  return ret;
2122  }
2123  return 0;
2124 }
2125 
2126 int open_output_file(OptionsContext *o, const char *filename)
2127 {
2128  AVFormatContext *oc;
2129  int i, j, err;
2130  OutputFile *of;
2131  OutputStream *ost;
2132  InputStream *ist;
2133  AVDictionary *unused_opts = NULL;
2134  AVDictionaryEntry *e = NULL;
2135  int format_flags = 0;
2136 
2137  if (o->stop_time != INT64_MAX && o->recording_time != INT64_MAX) {
2138  o->stop_time = INT64_MAX;
2139  av_log(NULL, AV_LOG_WARNING, "-t and -to cannot be used together; using -t.\n");
2140  }
2141 
2142  if (o->stop_time != INT64_MAX && o->recording_time == INT64_MAX) {
2143  int64_t start_time = o->start_time == AV_NOPTS_VALUE ? 0 : o->start_time;
2144  if (o->stop_time <= start_time) {
2145  av_log(NULL, AV_LOG_ERROR, "-to value smaller than -ss; aborting.\n");
2146  exit_program(1);
2147  } else {
2148  o->recording_time = o->stop_time - start_time;
2149  }
2150  }
2151 
2153  of = av_mallocz(sizeof(*of));
2154  if (!of)
2155  exit_program(1);
2156  output_files[nb_output_files - 1] = of;
2157 
2159  of->recording_time = o->recording_time;
2160  of->start_time = o->start_time;
2161  of->limit_filesize = o->limit_filesize;
2162  of->shortest = o->shortest;
2163  av_dict_copy(&of->opts, o->g->format_opts, 0);
2164 
2165  if (!strcmp(filename, "-"))
2166  filename = "pipe:";
2167 
2168  err = avformat_alloc_output_context2(&oc, NULL, o->format, filename);
2169  if (!oc) {
2170  print_error(filename, err);
2171  exit_program(1);
2172  }
2173 
2174  of->ctx = oc;
2175  if (o->recording_time != INT64_MAX)
2176  oc->duration = o->recording_time;
2177 
2178  oc->interrupt_callback = int_cb;
2179 
2180  e = av_dict_get(o->g->format_opts, "fflags", NULL, 0);
2181  if (e) {
2182  const AVOption *o = av_opt_find(oc, "fflags", NULL, 0, 0);
2183  av_opt_eval_flags(oc, o, e->value, &format_flags);
2184  }
2185  if (o->bitexact) {
2186  format_flags |= AVFMT_FLAG_BITEXACT;
2187  oc->flags |= AVFMT_FLAG_BITEXACT;
2188  }
2189 
2190  /* create streams for all unlabeled output pads */
2191  for (i = 0; i < nb_filtergraphs; i++) {
2192  FilterGraph *fg = filtergraphs[i];
2193  for (j = 0; j < fg->nb_outputs; j++) {
2194  OutputFilter *ofilter = fg->outputs[j];
2195 
2196  if (!ofilter->out_tmp || ofilter->out_tmp->name)
2197  continue;
2198 
2199  switch (ofilter->type) {
2200  case AVMEDIA_TYPE_VIDEO: o->video_disable = 1; break;
2201  case AVMEDIA_TYPE_AUDIO: o->audio_disable = 1; break;
2202  case AVMEDIA_TYPE_SUBTITLE: o->subtitle_disable = 1; break;
2203  }
2204  init_output_filter(ofilter, o, oc);
2205  }
2206  }
2207 
2208  if (!o->nb_stream_maps) {
2209  char *subtitle_codec_name = NULL;
2210  /* pick the "best" stream of each type */
2211 
2212  /* video: highest resolution */
2213  if (!o->video_disable && av_guess_codec(oc->oformat, NULL, filename, NULL, AVMEDIA_TYPE_VIDEO) != AV_CODEC_ID_NONE) {
2214  int area = 0, idx = -1;
2215  int qcr = avformat_query_codec(oc->oformat, oc->oformat->video_codec, 0);
2216  for (i = 0; i < nb_input_streams; i++) {
2217  int new_area;
2218  ist = input_streams[i];
2219  new_area = ist->st->codecpar->width * ist->st->codecpar->height + 100000000*!!ist->st->codec_info_nb_frames
2220  + 5000000*!!(ist->st->disposition & AV_DISPOSITION_DEFAULT);
2221  if (ist->user_set_discard == AVDISCARD_ALL)
2222  continue;
2223  if((qcr!=MKTAG('A', 'P', 'I', 'C')) && (ist->st->disposition & AV_DISPOSITION_ATTACHED_PIC))
2224  new_area = 1;
2225  if (ist->st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO &&
2226  new_area > area) {
2227  if((qcr==MKTAG('A', 'P', 'I', 'C')) && !(ist->st->disposition & AV_DISPOSITION_ATTACHED_PIC))
2228  continue;
2229  area = new_area;
2230  idx = i;
2231  }
2232  }
2233  if (idx >= 0)
2234  new_video_stream(o, oc, idx);
2235  }
2236 
2237  /* audio: most channels */
2238  if (!o->audio_disable && av_guess_codec(oc->oformat, NULL, filename, NULL, AVMEDIA_TYPE_AUDIO) != AV_CODEC_ID_NONE) {
2239  int best_score = 0, idx = -1;
2240  for (i = 0; i < nb_input_streams; i++) {
2241  int score;
2242  ist = input_streams[i];
2243  score = ist->st->codecpar->channels + 100000000*!!ist->st->codec_info_nb_frames
2244  + 5000000*!!(ist->st->disposition & AV_DISPOSITION_DEFAULT);
2245  if (ist->user_set_discard == AVDISCARD_ALL)
2246  continue;
2247  if (ist->st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO &&
2248  score > best_score) {
2249  best_score = score;
2250  idx = i;
2251  }
2252  }
2253  if (idx >= 0)
2254  new_audio_stream(o, oc, idx);
2255  }
2256 
2257  /* subtitles: pick first */
2258  MATCH_PER_TYPE_OPT(codec_names, str, subtitle_codec_name, oc, "s");
2259  if (!o->subtitle_disable && (avcodec_find_encoder(oc->oformat->subtitle_codec) || subtitle_codec_name)) {
2260  for (i = 0; i < nb_input_streams; i++)
2261  if (input_streams[i]->st->codecpar->codec_type == AVMEDIA_TYPE_SUBTITLE) {
2262  AVCodecDescriptor const *input_descriptor =
2263  avcodec_descriptor_get(input_streams[i]->st->codecpar->codec_id);
2264  AVCodecDescriptor const *output_descriptor = NULL;
2265  AVCodec const *output_codec =
2266  avcodec_find_encoder(oc->oformat->subtitle_codec);
2267  int input_props = 0, output_props = 0;
2268  if (input_streams[i]->user_set_discard == AVDISCARD_ALL)
2269  continue;
2270  if (output_codec)
2271  output_descriptor = avcodec_descriptor_get(output_codec->id);
2272  if (input_descriptor)
2273  input_props = input_descriptor->props & (AV_CODEC_PROP_TEXT_SUB | AV_CODEC_PROP_BITMAP_SUB);
2274  if (output_descriptor)
2275  output_props = output_descriptor->props & (AV_CODEC_PROP_TEXT_SUB | AV_CODEC_PROP_BITMAP_SUB);
2276  if (subtitle_codec_name ||
2277  input_props & output_props ||
2278  // Map dvb teletext which has neither property to any output subtitle encoder
2279  (input_descriptor && output_descriptor &&
2280  (!input_descriptor->props ||
2281  !output_descriptor->props))) {
2282  new_subtitle_stream(o, oc, i);
2283  break;
2284  }
2285  }
2286  }
2287  /* Data only if codec id match */
2288  if (!o->data_disable ) {
2289  enum AVCodecID codec_id = av_guess_codec(oc->oformat, NULL, filename, NULL, AVMEDIA_TYPE_DATA);
2290  for (i = 0; codec_id != AV_CODEC_ID_NONE && i < nb_input_streams; i++) {
2291  if (input_streams[i]->user_set_discard == AVDISCARD_ALL)
2292  continue;
2293  if (input_streams[i]->st->codecpar->codec_type == AVMEDIA_TYPE_DATA
2294  && input_streams[i]->st->codecpar->codec_id == codec_id )
2295  new_data_stream(o, oc, i);
2296  }
2297  }
2298  } else {
2299  for (i = 0; i < o->nb_stream_maps; i++) {
2300  StreamMap *map = &o->stream_maps[i];
2301 
2302  if (map->disabled)
2303  continue;
2304 
2305  if (map->linklabel) {
2306  FilterGraph *fg;
2307  OutputFilter *ofilter = NULL;
2308  int j, k;
2309 
2310  for (j = 0; j < nb_filtergraphs; j++) {
2311  fg = filtergraphs[j];
2312  for (k = 0; k < fg->nb_outputs; k++) {
2313  AVFilterInOut *out = fg->outputs[k]->out_tmp;
2314  if (out && !strcmp(out->name, map->linklabel)) {
2315  ofilter = fg->outputs[k];
2316  goto loop_end;
2317  }
2318  }
2319  }
2320 loop_end:
2321  if (!ofilter) {
2322  av_log(NULL, AV_LOG_FATAL, "Output with label '%s' does not exist "
2323  "in any defined filter graph, or was already used elsewhere.\n", map->linklabel);
2324  exit_program(1);
2325  }
2326  init_output_filter(ofilter, o, oc);
2327  } else {
2328  int src_idx = input_files[map->file_index]->ist_index + map->stream_index;
2329 
2331  if (ist->user_set_discard == AVDISCARD_ALL) {
2332  av_log(NULL, AV_LOG_FATAL, "Stream #%d:%d is disabled and cannot be mapped.\n",
2333  map->file_index, map->stream_index);
2334  exit_program(1);
2335  }
2336  if(o->subtitle_disable && ist->st->codecpar->codec_type == AVMEDIA_TYPE_SUBTITLE)
2337  continue;
2338  if(o-> audio_disable && ist->st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO)
2339  continue;
2340  if(o-> video_disable && ist->st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO)
2341  continue;
2342  if(o-> data_disable && ist->st->codecpar->codec_type == AVMEDIA_TYPE_DATA)
2343  continue;
2344 
2345  ost = NULL;
2346  switch (ist->st->codecpar->codec_type) {
2347  case AVMEDIA_TYPE_VIDEO: ost = new_video_stream (o, oc, src_idx); break;
2348  case AVMEDIA_TYPE_AUDIO: ost = new_audio_stream (o, oc, src_idx); break;
2349  case AVMEDIA_TYPE_SUBTITLE: ost = new_subtitle_stream (o, oc, src_idx); break;
2350  case AVMEDIA_TYPE_DATA: ost = new_data_stream (o, oc, src_idx); break;
2351  case AVMEDIA_TYPE_ATTACHMENT: ost = new_attachment_stream(o, oc, src_idx); break;
2352  case AVMEDIA_TYPE_UNKNOWN:
2353  if (copy_unknown_streams) {
2354  ost = new_unknown_stream (o, oc, src_idx);
2355  break;
2356  }
2357  default:
2359  "Cannot map stream #%d:%d - unsupported type.\n",
2360  map->file_index, map->stream_index);
2361  if (!ignore_unknown_streams) {
2362  av_log(NULL, AV_LOG_FATAL,
2363  "If you want unsupported types ignored instead "
2364  "of failing, please use the -ignore_unknown option\n"
2365  "If you want them copied, please use -copy_unknown\n");
2366  exit_program(1);
2367  }
2368  }
2369  if (ost)
2371  + map->sync_stream_index];
2372  }
2373  }
2374  }
2375 
2376  /* handle attached files */
2377  for (i = 0; i < o->nb_attachments; i++) {
2378  AVIOContext *pb;
2379  uint8_t *attachment;
2380  const char *p;
2381  int64_t len;
2382 
2383  if ((err = avio_open2(&pb, o->attachments[i], AVIO_FLAG_READ, &int_cb, NULL)) < 0) {
2384  av_log(NULL, AV_LOG_FATAL, "Could not open attachment file %s.\n",
2385  o->attachments[i]);
2386  exit_program(1);
2387  }
2388  if ((len = avio_size(pb)) <= 0) {
2389  av_log(NULL, AV_LOG_FATAL, "Could not get size of the attachment %s.\n",
2390  o->attachments[i]);
2391  exit_program(1);
2392  }
2393  if (!(attachment = av_malloc(len))) {
2394  av_log(NULL, AV_LOG_FATAL, "Attachment %s too large to fit into memory.\n",
2395  o->attachments[i]);
2396  exit_program(1);
2397  }
2398  avio_read(pb, attachment, len);
2399 
2400  ost = new_attachment_stream(o, oc, -1);
2401  ost->stream_copy = 0;
2402  ost->attachment_filename = o->attachments[i];
2403  ost->st->codecpar->extradata = attachment;
2404  ost->st->codecpar->extradata_size = len;
2405 
2406  p = strrchr(o->attachments[i], '/');
2407  av_dict_set(&ost->st->metadata, "filename", (p && *p) ? p + 1 : o->attachments[i], AV_DICT_DONT_OVERWRITE);
2408  avio_closep(&pb);
2409  }
2410 
2411 #if FF_API_LAVF_AVCTX
2412  for (i = nb_output_streams - oc->nb_streams; i < nb_output_streams; i++) { //for all streams of this output file
2413  AVDictionaryEntry *e;
2414  ost = output_streams[i];
2415 
2416  if ((ost->stream_copy || ost->attachment_filename)
2417  && (e = av_dict_get(o->g->codec_opts, "flags", NULL, AV_DICT_IGNORE_SUFFIX))
2418  && (!e->key[5] || check_stream_specifier(oc, ost->st, e->key+6)))
2419  if (av_opt_set(ost->st->codec, "flags", e->value, 0) < 0)
2420  exit_program(1);
2421  }
2422 #endif
2423 
2424  if (!oc->nb_streams && !(oc->oformat->flags & AVFMT_NOSTREAMS)) {
2425  av_dump_format(oc, nb_output_files - 1, oc->url, 1);
2426  av_log(NULL, AV_LOG_ERROR, "Output file #%d does not contain any stream\n", nb_output_files - 1);
2427  exit_program(1);
2428  }
2429 
2430  /* check if all codec options have been used */
2431  unused_opts = strip_specifiers(o->g->codec_opts);
2432  for (i = of->ost_index; i < nb_output_streams; i++) {
2433  e = NULL;
2434  while ((e = av_dict_get(output_streams[i]->encoder_opts, "", e,
2435  AV_DICT_IGNORE_SUFFIX)))
2436  av_dict_set(&unused_opts, e->key, NULL, 0);
2437  }
2438 
2439  e = NULL;
2440  while ((e = av_dict_get(unused_opts, "", e, AV_DICT_IGNORE_SUFFIX))) {
2441  const AVClass *class = avcodec_get_class();
2442  const AVOption *option = av_opt_find(&class, e->key, NULL, 0,
2443  AV_OPT_SEARCH_CHILDREN | AV_OPT_SEARCH_FAKE_OBJ);
2444  const AVClass *fclass = avformat_get_class();
2445  const AVOption *foption = av_opt_find(&fclass, e->key, NULL, 0,
2446  AV_OPT_SEARCH_CHILDREN | AV_OPT_SEARCH_FAKE_OBJ);
2447  if (!option || foption)
2448  continue;
2449 
2450 
2451  if (!(option->flags & AV_OPT_FLAG_ENCODING_PARAM)) {
2452  av_log(NULL, AV_LOG_ERROR, "Codec AVOption %s (%s) specified for "
2453  "output file #%d (%s) is not an encoding option.\n", e->key,
2454  option->help ? option->help : "", nb_output_files - 1,
2455  filename);
2456  exit_program(1);
2457  }
2458 
2459  // gop_timecode is injected by generic code but not always used
2460  if (!strcmp(e->key, "gop_timecode"))
2461  continue;
2462 
2463  av_log(NULL, AV_LOG_WARNING, "Codec AVOption %s (%s) specified for "
2464  "output file #%d (%s) has not been used for any stream. The most "
2465  "likely reason is either wrong type (e.g. a video option with "
2466  "no video streams) or that it is a private option of some encoder "
2467  "which was not actually used for any stream.\n", e->key,
2468  option->help ? option->help : "", nb_output_files - 1, filename);
2469  }
2470  av_dict_free(&unused_opts);
2471 
2472  /* set the decoding_needed flags and create simple filtergraphs */
2473  for (i = of->ost_index; i < nb_output_streams; i++) {
2474  OutputStream *ost = output_streams[i];
2475 
2476  if (ost->encoding_needed && ost->source_index >= 0) {
2477  InputStream *ist = input_streams[ost->source_index];
2479 
2480  if (ost->st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO ||
2481  ost->st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) {
2482  err = init_simple_filtergraph(ist, ost);
2483  if (err < 0) {
2484  av_log(NULL, AV_LOG_ERROR,
2485  "Error initializing a simple filtergraph between streams "
2486  "%d:%d->%d:%d\n", ist->file_index, ost->source_index,
2487  nb_output_files - 1, ost->st->index);
2488  exit_program(1);
2489  }
2490  }
2491  }
2492 
2493  /* set the filter output constraints */
2494  if (ost->filter) {
2495  OutputFilter *f = ost->filter;
2496  int count;
2497  switch (ost->enc_ctx->codec_type) {
2498  case AVMEDIA_TYPE_VIDEO:
2499  f->frame_rate = ost->frame_rate;
2500  f->width = ost->enc_ctx->width;
2501  f->height = ost->enc_ctx->height;
2502  if (ost->enc_ctx->pix_fmt != AV_PIX_FMT_NONE) {
2503  f->format = ost->enc_ctx->pix_fmt;
2504  } else if (ost->enc->pix_fmts) {
2505  count = 0;
2506  while (ost->enc->pix_fmts[count] != AV_PIX_FMT_NONE)
2507  count++;
2508  f->formats = av_mallocz_array(count + 1, sizeof(*f->formats));
2509  if (!f->formats)
2510  exit_program(1);
2511  memcpy(f->formats, ost->enc->pix_fmts, (count + 1) * sizeof(*f->formats));
2512  }
2513  break;
2514  case AVMEDIA_TYPE_AUDIO:
2515  if (ost->enc_ctx->sample_fmt != AV_SAMPLE_FMT_NONE) {
2516  f->format = ost->enc_ctx->sample_fmt;
2517  } else if (ost->enc->sample_fmts) {
2518  count = 0;
2519  while (ost->enc->sample_fmts[count] != AV_SAMPLE_FMT_NONE)
2520  count++;
2521  f->formats = av_mallocz_array(count + 1, sizeof(*f->formats));
2522  if (!f->formats)
2523  exit_program(1);
2524  memcpy(f->formats, ost->enc->sample_fmts, (count + 1) * sizeof(*f->formats));
2525  }
2526  if (ost->enc_ctx->sample_rate) {
2527  f->sample_rate = ost->enc_ctx->sample_rate;
2528  } else if (ost->enc->supported_samplerates) {
2529  count = 0;
2530  while (ost->enc->supported_samplerates[count])
2531  count++;
2532  f->sample_rates = av_mallocz_array(count + 1, sizeof(*f->sample_rates));
2533  if (!f->sample_rates)
2534  exit_program(1);
2535  memcpy(f->sample_rates, ost->enc->supported_samplerates,
2536  (count + 1) * sizeof(*f->sample_rates));
2537  }
2538  if (ost->enc_ctx->channels) {
2539  f->channel_layout = av_get_default_channel_layout(ost->enc_ctx->channels);
2540  } else if (ost->enc->channel_layouts) {
2541  count = 0;
2542  while (ost->enc->channel_layouts[count])
2543  count++;
2544  f->channel_layouts = av_mallocz_array(count + 1, sizeof(*f->channel_layouts));
2545  if (!f->channel_layouts)
2546  exit_program(1);
2547  memcpy(f->channel_layouts, ost->enc->channel_layouts,
2548  (count + 1) * sizeof(*f->channel_layouts));
2549  }
2550  break;
2551  }
2552  }
2553  }
2554 
2555  /* check filename in case of an image number is expected */
2556  if (oc->oformat->flags & AVFMT_NEEDNUMBER) {
2557  if (!av_filename_number_test(oc->url)) {
2558  print_error(oc->url, AVERROR(EINVAL));
2559  exit_program(1);
2560  }
2561  }
2562 
2563  if (!(oc->oformat->flags & AVFMT_NOSTREAMS) && !input_stream_potentially_available) {
2564  av_log(NULL, AV_LOG_ERROR,
2565  "No input streams but output needs an input stream\n");
2566  exit_program(1);
2567  }
2568 
2569  if (!(oc->oformat->flags & AVFMT_NOFILE)) {
2570  /* test if it already exists to avoid losing precious files */
2571  assert_file_overwrite(filename);
2572 
2573  /* open the file */
2574  if ((err = avio_open2(&oc->pb, filename, AVIO_FLAG_WRITE,
2575  &oc->interrupt_callback,
2576  &of->opts)) < 0) {
2577  print_error(filename, err);
2578  exit_program(1);
2579  }
2580  } else if (strcmp(oc->oformat->name, "image2")==0 && !av_filename_number_test(filename))
2581  assert_file_overwrite(filename);
2582 
2583  if (o->mux_preload) {
2584  av_dict_set_int(&of->opts, "preload", o->mux_preload*AV_TIME_BASE, 0);
2585  }
2586  oc->max_delay = (int)(o->mux_max_delay * AV_TIME_BASE);
2587 
2588  /* copy metadata */
2589  for (i = 0; i < o->nb_metadata_map; i++) {
2590  char *p;
2591  int in_file_index = strtol(o->metadata_map[i].u.str, &p, 0);
2592 
2593  if (in_file_index >= nb_input_files) {
2594  av_log(NULL, AV_LOG_FATAL, "Invalid input file index %d while processing metadata maps\n", in_file_index);
2595  exit_program(1);
2596  }
2597  fftools_copy_metadata(o->metadata_map[i].specifier, *p ? p + 1 : p, oc,
2598  in_file_index >= 0 ?
2599  input_files[in_file_index]->ctx : NULL, o);
2600  }
2601 
2602  /* copy chapters */
2603  if (o->chapters_input_file >= nb_input_files) {
2604  if (o->chapters_input_file == INT_MAX) {
2605  /* copy chapters from the first input file that has them*/
2606  o->chapters_input_file = -1;
2607  for (i = 0; i < nb_input_files; i++)
2608  if (input_files[i]->ctx->nb_chapters) {
2609  o->chapters_input_file = i;
2610  break;
2611  }
2612  } else {
2613  av_log(NULL, AV_LOG_FATAL, "Invalid input file index %d in chapter mapping.\n",
2614  o->chapters_input_file);
2615  exit_program(1);
2616  }
2617  }
2618  if (o->chapters_input_file >= 0)
2621 
2622  /* copy global metadata by default */
2624  av_dict_copy(&oc->metadata, input_files[0]->ctx->metadata,
2625  AV_DICT_DONT_OVERWRITE);
2626  if(o->recording_time != INT64_MAX)
2627  av_dict_set(&oc->metadata, "duration", NULL, 0);
2628  av_dict_set(&oc->metadata, "creation_time", NULL, 0);
2629  }
2630  if (!o->metadata_streams_manual)
2631  for (i = of->ost_index; i < nb_output_streams; i++) {
2632  InputStream *ist;
2633  if (output_streams[i]->source_index < 0) /* this is true e.g. for attached files */
2634  continue;
2636  av_dict_copy(&output_streams[i]->st->metadata, ist->st->metadata, AV_DICT_DONT_OVERWRITE);
2637  if (!output_streams[i]->stream_copy) {
2638  av_dict_set(&output_streams[i]->st->metadata, "encoder", NULL, 0);
2639  }
2640  }
2641 
2642  /* process manually set programs */
2643  for (i = 0; i < o->nb_program; i++) {
2644  const char *p = o->program[i].u.str;
2645  int progid = i+1;
2646  AVProgram *program;
2647 
2648  while(*p) {
2649  const char *p2 = av_get_token(&p, ":");
2650  const char *to_dealloc = p2;
2651  char *key;
2652  if (!p2)
2653  break;
2654 
2655  if(*p) p++;
2656 
2657  key = av_get_token(&p2, "=");
2658  if (!key || !*p2) {
2659  av_freep(&to_dealloc);
2660  av_freep(&key);
2661  break;
2662  }
2663  p2++;
2664 
2665  if (!strcmp(key, "program_num"))
2666  progid = strtol(p2, NULL, 0);
2667  av_freep(&to_dealloc);
2668  av_freep(&key);
2669  }
2670 
2671  program = av_new_program(oc, progid);
2672 
2673  p = o->program[i].u.str;
2674  while(*p) {
2675  const char *p2 = av_get_token(&p, ":");
2676  const char *to_dealloc = p2;
2677  char *key;
2678  if (!p2)
2679  break;
2680  if(*p) p++;
2681 
2682  key = av_get_token(&p2, "=");
2683  if (!key) {
2684  av_log(NULL, AV_LOG_FATAL,
2685  "No '=' character in program string %s.\n",
2686  p2);
2687  exit_program(1);
2688  }
2689  if (!*p2)
2690  exit_program(1);
2691  p2++;
2692 
2693  if (!strcmp(key, "title")) {
2694  av_dict_set(&program->metadata, "title", p2, 0);
2695  } else if (!strcmp(key, "program_num")) {
2696  } else if (!strcmp(key, "st")) {
2697  int st_num = strtol(p2, NULL, 0);
2698  av_program_add_stream_index(oc, progid, st_num);
2699  } else {
2700  av_log(NULL, AV_LOG_FATAL, "Unknown program key %s.\n", key);
2701  exit_program(1);
2702  }
2703  av_freep(&to_dealloc);
2704  av_freep(&key);
2705  }
2706  }
2707 
2708  /* process manually set metadata */
2709  for (i = 0; i < o->nb_metadata; i++) {
2710  AVDictionary **m;
2711  char type, *val;
2712  const char *stream_spec;
2713  int index = 0, j, ret = 0;
2714 
2715  val = strchr(o->metadata[i].u.str, '=');
2716  if (!val) {
2717  av_log(NULL, AV_LOG_FATAL, "No '=' character in metadata string %s.\n",
2718  o->metadata[i].u.str);
2719  exit_program(1);
2720  }
2721  *val++ = 0;
2722 
2723  parse_meta_type(o->metadata[i].specifier, &type, &index, &stream_spec);
2724  if (type == 's') {
2725  for (j = 0; j < oc->nb_streams; j++) {
2726  ost = output_streams[nb_output_streams - oc->nb_streams + j];
2727  if ((ret = check_stream_specifier(oc, oc->streams[j], stream_spec)) > 0) {
2728  if (!strcmp(o->metadata[i].u.str, "rotate")) {
2729  char *tail;
2730  double theta = av_strtod(val, &tail);
2731  if (!*tail) {
2732  ost->rotate_overridden = 1;
2733  ost->rotate_override_value = theta;
2734  }
2735  } else {
2736  av_dict_set(&oc->streams[j]->metadata, o->metadata[i].u.str, *val ? val : NULL, 0);
2737  }
2738  } else if (ret < 0)
2739  exit_program(1);
2740  }
2741  }
2742  else {
2743  switch (type) {
2744  case 'g':
2745  m = &oc->metadata;
2746  break;
2747  case 'c':
2748  if (index < 0 || index >= oc->nb_chapters) {
2749  av_log(NULL, AV_LOG_FATAL, "Invalid chapter index %d in metadata specifier.\n", index);
2750  exit_program(1);
2751  }
2752  m = &oc->chapters[index]->metadata;
2753  break;
2754  case 'p':
2755  if (index < 0 || index >= oc->nb_programs) {
2756  av_log(NULL, AV_LOG_FATAL, "Invalid program index %d in metadata specifier.\n", index);
2757  exit_program(1);
2758  }
2759  m = &oc->programs[index]->metadata;
2760  break;
2761  default:
2762  av_log(NULL, AV_LOG_FATAL, "Invalid metadata specifier %s.\n", o->metadata[i].specifier);
2763  exit_program(1);
2764  }
2765  av_dict_set(m, o->metadata[i].u.str, *val ? val : NULL, 0);
2766  }
2767  }
2768 
2769  return 0;
2770 }
2771 
2772 int opt_target(void *optctx, const char *opt, const char *arg)
2773 {
2774  const OptionDef *options = ffmpeg_options;
2775  OptionsContext *o = optctx;
2776  enum { PAL, NTSC, FILM, UNKNOWN } norm = UNKNOWN;
2777  const char *const frame_rates[] = { "25", "30000/1001", "24000/1001" };
2778 
2779  if (!strncmp(arg, "pal-", 4)) {
2780  norm = PAL;
2781  arg += 4;
2782  } else if (!strncmp(arg, "ntsc-", 5)) {
2783  norm = NTSC;
2784  arg += 5;
2785  } else if (!strncmp(arg, "film-", 5)) {
2786  norm = FILM;
2787  arg += 5;
2788  } else {
2789  /* Try to determine PAL/NTSC by peeking in the input files */
2790  if (nb_input_files) {
2791  int i, j;
2792  for (j = 0; j < nb_input_files; j++) {
2793  for (i = 0; i < input_files[j]->nb_streams; i++) {
2794  AVStream *st = input_files[j]->ctx->streams[i];
2795  int64_t fr;
2796  if (st->codecpar->codec_type != AVMEDIA_TYPE_VIDEO)
2797  continue;
2798  fr = st->time_base.den * 1000LL / st->time_base.num;
2799  if (fr == 25000) {
2800  norm = PAL;
2801  break;
2802  } else if ((fr == 29970) || (fr == 23976)) {
2803  norm = NTSC;
2804  break;
2805  }
2806  }
2807  if (norm != UNKNOWN)
2808  break;
2809  }
2810  }
2811  if (norm != UNKNOWN)
2812  av_log(NULL, AV_LOG_INFO, "Assuming %s for target.\n", norm == PAL ? "PAL" : "NTSC");
2813  }
2814 
2815  if (norm == UNKNOWN) {
2816  av_log(NULL, AV_LOG_FATAL, "Could not determine norm (PAL/NTSC/NTSC-Film) for target.\n");
2817  av_log(NULL, AV_LOG_FATAL, "Please prefix target with \"pal-\", \"ntsc-\" or \"film-\",\n");
2818  av_log(NULL, AV_LOG_FATAL, "or set a framerate with \"-r xxx\".\n");
2819  exit_program(1);
2820  }
2821 
2822  if (!strcmp(arg, "vcd")) {
2823  opt_video_codec(o, "c:v", "mpeg1video");
2824  opt_audio_codec(o, "c:a", "mp2");
2825  parse_option(o, "f", "vcd", options);
2826 
2827  parse_option(o, "s", norm == PAL ? "352x288" : "352x240", options);
2828  parse_option(o, "r", frame_rates[norm], options);
2829  opt_default(NULL, "g", norm == PAL ? "15" : "18");
2830 
2831  opt_default(NULL, "b:v", "1150000");
2832  opt_default(NULL, "maxrate:v", "1150000");
2833  opt_default(NULL, "minrate:v", "1150000");
2834  opt_default(NULL, "bufsize:v", "327680"); // 40*1024*8;
2835 
2836  opt_default(NULL, "b:a", "224000");
2837  parse_option(o, "ar", "44100", options);
2838  parse_option(o, "ac", "2", options);
2839 
2840  opt_default(NULL, "packetsize", "2324");
2841  opt_default(NULL, "muxrate", "1411200"); // 2352 * 75 * 8;
2842 
2843  /* We have to offset the PTS, so that it is consistent with the SCR.
2844  SCR starts at 36000, but the first two packs contain only padding
2845  and the first pack from the other stream, respectively, may also have
2846  been written before.
2847  So the real data starts at SCR 36000+3*1200. */
2848  o->mux_preload = (36000 + 3 * 1200) / 90000.0; // 0.44
2849  } else if (!strcmp(arg, "svcd")) {
2850 
2851  opt_video_codec(o, "c:v", "mpeg2video");
2852  opt_audio_codec(o, "c:a", "mp2");
2853  parse_option(o, "f", "svcd", options);
2854 
2855  parse_option(o, "s", norm == PAL ? "480x576" : "480x480", options);
2856  parse_option(o, "r", frame_rates[norm], options);
2857  parse_option(o, "pix_fmt", "yuv420p", options);
2858  opt_default(NULL, "g", norm == PAL ? "15" : "18");
2859 
2860  opt_default(NULL, "b:v", "2040000");
2861  opt_default(NULL, "maxrate:v", "2516000");
2862  opt_default(NULL, "minrate:v", "0"); // 1145000;
2863  opt_default(NULL, "bufsize:v", "1835008"); // 224*1024*8;
2864  opt_default(NULL, "scan_offset", "1");
2865 
2866  opt_default(NULL, "b:a", "224000");
2867  parse_option(o, "ar", "44100", options);
2868 
2869  opt_default(NULL, "packetsize", "2324");
2870 
2871  } else if (!strcmp(arg, "dvd")) {
2872 
2873  opt_video_codec(o, "c:v", "mpeg2video");
2874  opt_audio_codec(o, "c:a", "ac3");
2875  parse_option(o, "f", "dvd", options);
2876 
2877  parse_option(o, "s", norm == PAL ? "720x576" : "720x480", options);
2878  parse_option(o, "r", frame_rates[norm], options);
2879  parse_option(o, "pix_fmt", "yuv420p", options);
2880  opt_default(NULL, "g", norm == PAL ? "15" : "18");
2881 
2882  opt_default(NULL, "b:v", "6000000");
2883  opt_default(NULL, "maxrate:v", "9000000");
2884  opt_default(NULL, "minrate:v", "0"); // 1500000;
2885  opt_default(NULL, "bufsize:v", "1835008"); // 224*1024*8;
2886 
2887  opt_default(NULL, "packetsize", "2048"); // from www.mpucoder.com: DVD sectors contain 2048 bytes of data, this is also the size of one pack.
2888  opt_default(NULL, "muxrate", "10080000"); // from mplex project: data_rate = 1260000. mux_rate = data_rate * 8
2889 
2890  opt_default(NULL, "b:a", "448000");
2891  parse_option(o, "ar", "48000", options);
2892 
2893  } else if (!strncmp(arg, "dv", 2)) {
2894 
2895  parse_option(o, "f", "dv", options);
2896 
2897  parse_option(o, "s", norm == PAL ? "720x576" : "720x480", options);
2898  parse_option(o, "pix_fmt", !strncmp(arg, "dv50", 4) ? "yuv422p" :
2899  norm == PAL ? "yuv420p" : "yuv411p", options);
2900  parse_option(o, "r", frame_rates[norm], options);
2901 
2902  parse_option(o, "ar", "48000", options);
2903  parse_option(o, "ac", "2", options);
2904 
2905  } else {
2906  av_log(NULL, AV_LOG_ERROR, "Unknown target: %s\n", arg);
2907  return AVERROR(EINVAL);
2908  }
2909 
2910  av_dict_copy(&o->g->codec_opts, codec_opts, AV_DICT_DONT_OVERWRITE);
2911  av_dict_copy(&o->g->format_opts, format_opts, AV_DICT_DONT_OVERWRITE);
2912 
2913  return 0;
2914 }
2915 
2916 int opt_vstats_file(void *optctx, const char *opt, const char *arg)
2917 {
2918  av_free (vstats_filename);
2919  vstats_filename = av_strdup (arg);
2920  return 0;
2921 }
2922 
2923 int opt_vstats(void *optctx, const char *opt, const char *arg)
2924 {
2925  char filename[40];
2926  time_t today2 = time(NULL);
2927  struct tm *today = localtime(&today2);
2928 
2929  if (!today) { // maybe tomorrow
2930  av_log(NULL, AV_LOG_FATAL, "Unable to get current time: %s\n", strerror(errno));
2931  exit_program(1);
2932  }
2933 
2934  snprintf(filename, sizeof(filename), "vstats_%02d%02d%02d.log", today->tm_hour, today->tm_min,
2935  today->tm_sec);
2936  return opt_vstats_file(NULL, opt, filename);
2937 }
2938 
2939 int opt_video_frames(void *optctx, const char *opt, const char *arg)
2940 {
2941  OptionsContext *o = optctx;
2942  return parse_option(o, "frames:v", arg, ffmpeg_options);
2943 }
2944 
2945 int opt_audio_frames(void *optctx, const char *opt, const char *arg)
2946 {
2947  OptionsContext *o = optctx;
2948  return parse_option(o, "frames:a", arg, ffmpeg_options);
2949 }
2950 
2951 int opt_data_frames(void *optctx, const char *opt, const char *arg)
2952 {
2953  OptionsContext *o = optctx;
2954  return parse_option(o, "frames:d", arg, ffmpeg_options);
2955 }
2956 
2957 int opt_default_new(OptionsContext *o, const char *opt, const char *arg)
2958 {
2959  int ret;
2960  AVDictionary *cbak = codec_opts;
2961  AVDictionary *fbak = format_opts;
2962  codec_opts = NULL;
2963  format_opts = NULL;
2964 
2965  ret = opt_default(NULL, opt, arg);
2966 
2967  av_dict_copy(&o->g->codec_opts , codec_opts, 0);
2968  av_dict_copy(&o->g->format_opts, format_opts, 0);
2969  av_dict_free(&codec_opts);
2970  av_dict_free(&format_opts);
2971  codec_opts = cbak;
2972  format_opts = fbak;
2973 
2974  return ret;
2975 }
2976 
2977 int opt_preset(void *optctx, const char *opt, const char *arg)
2978 {
2979  OptionsContext *o = optctx;
2980  FILE *f=NULL;
2981  char filename[1000], line[1000], tmp_line[1000];
2982  const char *codec_name = NULL;
2983 
2984  tmp_line[0] = *opt;
2985  tmp_line[1] = 0;
2986  MATCH_PER_TYPE_OPT(codec_names, str, codec_name, NULL, tmp_line);
2987 
2988  if (!(f = get_preset_file(filename, sizeof(filename), arg, *opt == 'f', codec_name))) {
2989  if(!strncmp(arg, "libx264-lossless", strlen("libx264-lossless"))){
2990  av_log(NULL, AV_LOG_FATAL, "Please use -preset <speed> -qp 0\n");
2991  }else
2992  av_log(NULL, AV_LOG_FATAL, "File for preset '%s' not found\n", arg);
2993  exit_program(1);
2994  }
2995 
2996  while (fgets(line, sizeof(line), f)) {
2997  char *key = tmp_line, *value, *endptr;
2998 
2999  if (strcspn(line, "#\n\r") == 0)
3000  continue;
3001  av_strlcpy(tmp_line, line, sizeof(tmp_line));
3002  if (!av_strtok(key, "=", &value) ||
3003  !av_strtok(value, "\r\n", &endptr)) {
3004  av_log(NULL, AV_LOG_FATAL, "%s: Invalid syntax: '%s'\n", filename, line);
3005  exit_program(1);
3006  }
3007  av_log(NULL, AV_LOG_DEBUG, "ffpreset[%s]: set '%s' = '%s'\n", filename, key, value);
3008 
3009  if (!strcmp(key, "acodec")) opt_audio_codec (o, key, value);
3010  else if (!strcmp(key, "vcodec")) opt_video_codec (o, key, value);
3011  else if (!strcmp(key, "scodec")) opt_subtitle_codec(o, key, value);
3012  else if (!strcmp(key, "dcodec")) opt_data_codec (o, key, value);
3013  else if (opt_default_new(o, key, value) < 0) {
3014  av_log(NULL, AV_LOG_FATAL, "%s: Invalid option or argument: '%s', parsed as '%s' = '%s'\n",
3015  filename, line, key, value);
3016  exit_program(1);
3017  }
3018  }
3019 
3020  fclose(f);
3021 
3022  return 0;
3023 }
3024 
3025 int opt_old2new(void *optctx, const char *opt, const char *arg)
3026 {
3027  OptionsContext *o = optctx;
3028  int ret;
3029  char *s = av_asprintf("%s:%c", opt + 1, *opt);
3030  if (!s)
3031  return AVERROR(ENOMEM);
3032  ret = parse_option(o, s, arg, ffmpeg_options);
3033  av_free(s);
3034  return ret;
3035 }
3036 
3037 int opt_bitrate(void *optctx, const char *opt, const char *arg)
3038 {
3039  OptionsContext *o = optctx;
3040 
3041  if(!strcmp(opt, "ab")){
3042  av_dict_set(&o->g->codec_opts, "b:a", arg, 0);
3043  return 0;
3044  } else if(!strcmp(opt, "b")){
3045  av_log(NULL, AV_LOG_WARNING, "Please use -b:a or -b:v, -b is ambiguous\n");
3046  av_dict_set(&o->g->codec_opts, "b:v", arg, 0);
3047  return 0;
3048  }
3049  av_dict_set(&o->g->codec_opts, opt, arg, 0);
3050  return 0;
3051 }
3052 
3053 int opt_qscale(void *optctx, const char *opt, const char *arg)
3054 {
3055  OptionDef *options = ffmpeg_options;
3056  OptionsContext *o = optctx;
3057  char *s;
3058  int ret;
3059  if(!strcmp(opt, "qscale")){
3060  av_log(NULL, AV_LOG_WARNING, "Please use -q:a or -q:v, -qscale is ambiguous\n");
3061  return parse_option(o, "q:v", arg, options);
3062  }
3063  s = av_asprintf("q%s", opt + 6);
3064  if (!s)
3065  return AVERROR(ENOMEM);
3066  ret = parse_option(o, s, arg, options);
3067  av_free(s);
3068  return ret;
3069 }
3070 
3071 int opt_profile(void *optctx, const char *opt, const char *arg)
3072 {
3073  OptionsContext *o = optctx;
3074  if(!strcmp(opt, "profile")){
3075  av_log(NULL, AV_LOG_WARNING, "Please use -profile:a or -profile:v, -profile is ambiguous\n");
3076  av_dict_set(&o->g->codec_opts, "profile:v", arg, 0);
3077  return 0;
3078  }
3079  av_dict_set(&o->g->codec_opts, opt, arg, 0);
3080  return 0;
3081 }
3082 
3083 int opt_video_filters(void *optctx, const char *opt, const char *arg)
3084 {
3085  OptionsContext *o = optctx;
3086  return parse_option(o, "filter:v", arg, ffmpeg_options);
3087 }
3088 
3089 int opt_audio_filters(void *optctx, const char *opt, const char *arg)
3090 {
3091  OptionsContext *o = optctx;
3092  return parse_option(o, "filter:a", arg, ffmpeg_options);
3093 }
3094 
3095 int opt_vsync(void *optctx, const char *opt, const char *arg)
3096 {
3097  if (!av_strcasecmp(arg, "cfr")) video_sync_method = VSYNC_CFR;
3098  else if (!av_strcasecmp(arg, "vfr")) video_sync_method = VSYNC_VFR;
3099  else if (!av_strcasecmp(arg, "passthrough")) video_sync_method = VSYNC_PASSTHROUGH;
3100  else if (!av_strcasecmp(arg, "drop")) video_sync_method = VSYNC_DROP;
3101 
3104  return 0;
3105 }
3106 
3107 int opt_timecode(void *optctx, const char *opt, const char *arg)
3108 {
3109  OptionsContext *o = optctx;
3110  int ret;
3111  char *tcr = av_asprintf("timecode=%s", arg);
3112  if (!tcr)
3113  return AVERROR(ENOMEM);
3114  ret = parse_option(o, "metadata:g", tcr, ffmpeg_options);
3115  if (ret >= 0)
3116  ret = av_dict_set(&o->g->codec_opts, "gop_timecode", arg, 0);
3117  av_free(tcr);
3118  return ret;
3119 }
3120 
3121 int opt_channel_layout(void *optctx, const char *opt, const char *arg)
3122 {
3123  OptionsContext *o = optctx;
3124  char layout_str[32];
3125  char *stream_str;
3126  char *ac_str;
3127  int ret, channels, ac_str_size;
3128  uint64_t layout;
3129 
3130  layout = av_get_channel_layout(arg);
3131  if (!layout) {
3132  av_log(NULL, AV_LOG_ERROR, "Unknown channel layout: %s\n", arg);
3133  return AVERROR(EINVAL);
3134  }
3135  snprintf(layout_str, sizeof(layout_str), "%"PRIu64, layout);
3136  ret = opt_default_new(o, opt, layout_str);
3137  if (ret < 0)
3138  return ret;
3139 
3140  /* set 'ac' option based on channel layout */
3141  channels = av_get_channel_layout_nb_channels(layout);
3142  snprintf(layout_str, sizeof(layout_str), "%d", channels);
3143  stream_str = strchr(opt, ':');
3144  ac_str_size = 3 + (stream_str ? strlen(stream_str) : 0);
3145  ac_str = av_mallocz(ac_str_size);
3146  if (!ac_str)
3147  return AVERROR(ENOMEM);
3148  av_strlcpy(ac_str, "ac", 3);
3149  if (stream_str)
3150  av_strlcat(ac_str, stream_str, ac_str_size);
3151  ret = parse_option(o, ac_str, layout_str, ffmpeg_options);
3152  av_free(ac_str);
3153 
3154  return ret;
3155 }
3156 
3157 int opt_audio_qscale(void *optctx, const char *opt, const char *arg)
3158 {
3159  OptionsContext *o = optctx;
3160  return parse_option(o, "q:a", arg, ffmpeg_options);
3161 }
3162 
3163 int opt_filter_complex(void *optctx, const char *opt, const char *arg)
3164 {
3166  if (!(filtergraphs[nb_filtergraphs - 1] = av_mallocz(sizeof(*filtergraphs[0]))))
3167  return AVERROR(ENOMEM);
3169  filtergraphs[nb_filtergraphs - 1]->graph_desc = av_strdup(arg);
3170  if (!filtergraphs[nb_filtergraphs - 1]->graph_desc)
3171  return AVERROR(ENOMEM);
3172 
3174 
3175  return 0;
3176 }
3177 
3178 int opt_filter_complex_script(void *optctx, const char *opt, const char *arg)
3179 {
3180  uint8_t *graph_desc = fftools_read_file(arg);
3181  if (!graph_desc)
3182  return AVERROR(EINVAL);
3183 
3185  if (!(filtergraphs[nb_filtergraphs - 1] = av_mallocz(sizeof(*filtergraphs[0]))))
3186  return AVERROR(ENOMEM);
3188  filtergraphs[nb_filtergraphs - 1]->graph_desc = graph_desc;
3189 
3191 
3192  return 0;
3193 }
3194 
3195 void show_help_default_ffmpeg(const char *opt, const char *arg)
3196 {
3197  OptionDef *options = ffmpeg_options;
3198  /* per-file options have at least one of those set */
3199  const int per_file = OPT_SPEC | OPT_OFFSET | OPT_PERFILE;
3200  int show_advanced = 0, show_avoptions = 0;
3201 
3202  if (opt && *opt) {
3203  if (!strcmp(opt, "long"))
3204  show_advanced = 1;
3205  else if (!strcmp(opt, "full"))
3206  show_advanced = show_avoptions = 1;
3207  else
3208  av_log(NULL, AV_LOG_ERROR, "Unknown help option '%s'.\n", opt);
3209  }
3210 
3211  show_usage();
3212 
3213  av_log(NULL, AV_LOG_STDERR, "Getting help:\n"
3214  " -h -- print basic options\n"
3215  " -h long -- print more options\n"
3216  " -h full -- print all options (including all format and codec specific options, very long)\n"
3217  " -h type=name -- print all options for the named decoder/encoder/demuxer/muxer/filter/bsf\n"
3218  " See man %s for detailed description of the options.\n"
3219  "\n", program_name);
3220 
3221  show_help_options(options, "Print help / information / capabilities:",
3222  OPT_EXIT, 0, 0);
3223 
3224  show_help_options(options, "Global options (affect whole program "
3225  "instead of just one file:",
3226  0, per_file | OPT_EXIT | OPT_EXPERT, 0);
3227  if (show_advanced)
3228  show_help_options(options, "Advanced global options:", OPT_EXPERT,
3229  per_file | OPT_EXIT, 0);
3230 
3231  show_help_options(options, "Per-file main options:", 0,
3233  OPT_EXIT, per_file);
3234  if (show_advanced)
3235  show_help_options(options, "Advanced per-file options:",
3236  OPT_EXPERT, OPT_AUDIO | OPT_VIDEO | OPT_SUBTITLE, per_file);
3237 
3238  show_help_options(options, "Video options:",
3240  if (show_advanced)
3241  show_help_options(options, "Advanced Video options:",
3243 
3244  show_help_options(options, "Audio options:",
3246  if (show_advanced)
3247  show_help_options(options, "Advanced Audio options:",
3249  show_help_options(options, "Subtitle options:",
3250  OPT_SUBTITLE, 0, 0);
3251  av_log(NULL, AV_LOG_STDERR, "\n");
3252 
3253  if (show_avoptions) {
3254  int flags = AV_OPT_FLAG_DECODING_PARAM | AV_OPT_FLAG_ENCODING_PARAM;
3255  show_help_children(avcodec_get_class(), flags);
3256  show_help_children(avformat_get_class(), flags);
3257 #if CONFIG_SWSCALE
3258  show_help_children(sws_get_class(), flags);
3259 #endif
3260 #if CONFIG_SWRESAMPLE
3261  show_help_children(swr_get_class(), AV_OPT_FLAG_AUDIO_PARAM);
3262 #endif
3263  show_help_children(avfilter_get_class(), AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_AUDIO_PARAM | AV_OPT_FLAG_FILTERING_PARAM);
3264  show_help_children(av_bsf_get_class(), AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_AUDIO_PARAM | AV_OPT_FLAG_BSF_PARAM);
3265  }
3266 }
3267 
3268 void show_usage(void)
3269 {
3270  av_log(NULL, AV_LOG_INFO, "Hyper fast Audio and Video encoder\n");
3271  av_log(NULL, AV_LOG_INFO, "usage: %s [options] [[infile options] -i infile]... {[outfile options] outfile}...\n", program_name);
3272  av_log(NULL, AV_LOG_INFO, "\n");
3273 }
3274 
3275 enum OptGroup {
3276  GROUP_OUTFILE,
3277  GROUP_INFILE,
3278 };
3279 
3280 const OptionGroupDef groups[] = {
3281  [GROUP_OUTFILE] = { "output url", NULL, OPT_OUTPUT },
3282  [GROUP_INFILE] = { "input url", "i", OPT_INPUT },
3283 };
3284 
3285 int open_files(OptionGroupList *l, const char *inout,
3286  int (*open_file)(OptionsContext*, const char*))
3287 {
3288  int i, ret;
3289 
3290  for (i = 0; i < l->nb_groups; i++) {
3291  OptionGroup *g = &l->groups[i];
3292  OptionsContext o;
3293 
3294  init_options(&o);
3295  o.g = g;
3296 
3297  ret = parse_optgroup(&o, g);
3298  if (ret < 0) {
3299  av_log(NULL, AV_LOG_ERROR, "Error parsing options for %s file "
3300  "%s.\n", inout, g->arg);
3301  return ret;
3302  }
3303 
3304  av_log(NULL, AV_LOG_DEBUG, "Opening an %s file: %s.\n", inout, g->arg);
3305  ret = open_file(&o, g->arg);
3306  uninit_options(&o);
3307  if (ret < 0) {
3308  av_log(NULL, AV_LOG_ERROR, "Error opening %s file %s.\n",
3309  inout, g->arg);
3310  return ret;
3311  }
3312  av_log(NULL, AV_LOG_DEBUG, "Successfully opened the file.\n");
3313  }
3314 
3315  return 0;
3316 }
3317 
3318 int ffmpeg_parse_options(int argc, char **argv)
3319 {
3320  OptionParseContext octx;
3321  uint8_t error[128];
3322  int ret;
3323 
3324  memset(&octx, 0, sizeof(octx));
3325 
3326  /* split the commandline into an internal representation */
3327  ret = split_commandline(&octx, argc, argv, ffmpeg_options, groups,
3328  FF_ARRAY_ELEMS(groups));
3329  if (ret < 0) {
3330  av_log(NULL, AV_LOG_FATAL, "Error splitting the argument list: ");
3331  goto fail;
3332  }
3333 
3334  /* apply global options */
3335  ret = parse_optgroup(NULL, &octx.global_opts);
3336  if (ret < 0) {
3337  av_log(NULL, AV_LOG_FATAL, "Error parsing global options: ");
3338  goto fail;
3339  }
3340 
3341  /* configure terminal and setup signal handlers */
3342  term_init();
3343 
3344  /* open input files */
3345  ret = open_files(&octx.groups[GROUP_INFILE], "input", open_input_file);
3346  if (ret < 0) {
3347  av_log(NULL, AV_LOG_FATAL, "Error opening input files: ");
3348  goto fail;
3349  }
3350 
3351  /* create the complex filtergraphs */
3352  ret = init_complex_filters();
3353  if (ret < 0) {
3354  av_log(NULL, AV_LOG_FATAL, "Error initializing complex filters.\n");
3355  goto fail;
3356  }
3357 
3358  /* open output files */
3359  ret = open_files(&octx.groups[GROUP_OUTFILE], "output", open_output_file);
3360  if (ret < 0) {
3361  av_log(NULL, AV_LOG_FATAL, "Error opening output files: ");
3362  goto fail;
3363  }
3364 
3366 
3367 fail:
3368  uninit_parse_context(&octx);
3369  if (ret < 0) {
3370  av_strerror(ret, error, sizeof(error));
3371  av_log(NULL, AV_LOG_FATAL, "%s\n", error);
3372  }
3373  return ret;
3374 }
3375 
3376 int opt_progress(void *optctx, const char *opt, const char *arg)
3377 {
3378  AVIOContext *avio = NULL;
3379  int ret;
3380 
3381  if (!strcmp(arg, "-"))
3382  arg = "pipe:";
3383  ret = avio_open2(&avio, arg, AVIO_FLAG_WRITE, &int_cb, NULL);
3384  if (ret < 0) {
3385  av_log(NULL, AV_LOG_ERROR, "Failed to open progress URL \"%s\": %s\n",
3386  arg, av_err2str(ret));
3387  return ret;
3388  }
3389  progress_avio = avio;
3390  return 0;
3391 }
check_stream_specifier
int check_stream_specifier(AVFormatContext *s, AVStream *st, const char *spec)
Definition: fftools_cmdutils.c:2123
grow_array
void * grow_array(void *array, int elem_size, int *size, int new_size)
Definition: fftools_cmdutils.c:2208
OutputStream::last_mux_dts
int64_t last_mux_dts
Definition: fftools_ffmpeg.h:480
OptionsContext::seek_timestamp
int seek_timestamp
Definition: fftools_ffmpeg.h:124
OutputStream::avfilter
char * avfilter
Definition: fftools_ffmpeg.h:526
show_hwaccels
int show_hwaccels(void *optctx, const char *opt, const char *arg)
Definition: fftools_ffmpeg_opt.c:189
uninit_parse_context
void uninit_parse_context(OptionParseContext *octx)
Definition: fftools_cmdutils.c:764
OptionGroupList::nb_groups
int nb_groups
Definition: fftools_cmdutils.h:317
OutputStream::stream_copy
int stream_copy
Definition: fftools_ffmpeg.h:537
ffmpeg_parse_options
int ffmpeg_parse_options(int argc, char **argv)
hw_device_ctx
__thread AVBufferRef * hw_device_ctx
Definition: fftools_ffmpeg_opt.c:96
HWACCEL_QSV
@ HWACCEL_QSV
Definition: fftools_ffmpeg.h:86
qsv_init
int qsv_init(AVCodecContext *s)
OptionDef::flags
int flags
Definition: fftools_cmdutils.h:187
AV_LOG_INFO
#define AV_LOG_INFO
Definition: MobileFFmpegConfig.h:66
HWACCEL_CUVID
@ HWACCEL_CUVID
Definition: fftools_ffmpeg.h:87
filter_hw_device
__thread HWDevice * filter_hw_device
Definition: fftools_ffmpeg_opt.c:97
parse_matrix_coeffs
void parse_matrix_coeffs(uint16_t *dest, const char *str)
Definition: fftools_ffmpeg_opt.c:1590
AudioChannelMap::stream_idx
int stream_idx
Definition: fftools_ffmpeg.h:114
OutputStream::finished
OSTFinished finished
Definition: fftools_ffmpeg.h:535
do_pkt_dump
__thread int do_pkt_dump
Definition: fftools_ffmpeg_opt.c:114
AudioChannelMap::file_idx
int file_idx
Definition: fftools_ffmpeg.h:114
do_benchmark_all
__thread int do_benchmark_all
Definition: fftools_ffmpeg_opt.c:112
opt_vstats
int opt_vstats(void *optctx, const char *opt, const char *arg)
Definition: fftools_ffmpeg_opt.c:2923
OutputStream::rotate_override_value
double rotate_override_value
Definition: fftools_ffmpeg.h:505
OPT_EXIT
#define OPT_EXIT
Definition: fftools_cmdutils.h:198
opt_audio_filters
int opt_audio_filters(void *optctx, const char *opt, const char *arg)
Definition: fftools_ffmpeg_opt.c:3089
OutputStream::ref_par
AVCodecParameters * ref_par
Definition: fftools_ffmpeg.h:489
hw_device_init_from_string
int hw_device_init_from_string(const char *arg, HWDevice **dev)
Definition: fftools_ffmpeg_hw.c:101
filter_nbthreads
__thread int filter_nbthreads
Definition: fftools_ffmpeg_opt.c:126
OptionsContext::accurate_seek
int accurate_seek
Definition: fftools_ffmpeg.h:144
program_name
__thread char * program_name
Definition: fftools_cmdutils.c:98
codec_opts
__thread AVDictionary * codec_opts
Definition: fftools_cmdutils.c:103
opt_preset
int opt_preset(void *optctx, const char *opt, const char *arg)
Definition: fftools_ffmpeg_opt.c:2977
InputStream::ts_scale
double ts_scale
Definition: fftools_ffmpeg.h:353
OptionsContext::limit_filesize
uint64_t limit_filesize
Definition: fftools_ffmpeg.h:175
fftools_copy_metadata
int fftools_copy_metadata(char *outspec, char *inspec, AVFormatContext *oc, AVFormatContext *ic, OptionsContext *o)
Definition: fftools_ffmpeg_opt.c:579
OptionsContext::attachments
const char ** attachments
Definition: fftools_ffmpeg.h:168
OutputStream::filters
char * filters
filtergraph associated to the -filter option
Definition: fftools_ffmpeg.h:527
OPT_OFFSET
#define OPT_OFFSET
Definition: fftools_cmdutils.h:201
OptionsContext::mux_preload
float mux_preload
Definition: fftools_ffmpeg.h:176
InputStream::discard
int discard
Definition: fftools_ffmpeg.h:321
OutputStream::logfile_prefix
char * logfile_prefix
Definition: fftools_ffmpeg.h:522
OPT_INPUT
#define OPT_INPUT
Definition: fftools_cmdutils.h:205
OutputStream::muxing_queue
AVFifoBuffer * muxing_queue
Definition: fftools_ffmpeg.h:568
OutputStream::rotate_overridden
int rotate_overridden
Definition: fftools_ffmpeg.h:504
opt_default_new
int opt_default_new(OptionsContext *o, const char *opt, const char *arg)
Definition: fftools_ffmpeg_opt.c:2957
OutputFile::ctx
AVFormatContext * ctx
Definition: fftools_ffmpeg.h:578
OptionDef::name
const char * name
Definition: fftools_cmdutils.h:186
fftools_ffmpeg.h
AV_LOG_WARNING
#define AV_LOG_WARNING
Definition: MobileFFmpegConfig.h:61
OutputStream::force_fps
int force_fps
Definition: fftools_ffmpeg.h:502
FilterGraph::index
int index
Definition: fftools_ffmpeg.h:306
opt_old2new
int opt_old2new(void *optctx, const char *opt, const char *arg)
Definition: fftools_ffmpeg_opt.c:3025
exit_program
void exit_program(int ret)
Definition: fftools_cmdutils.c:166
output_files
__thread OutputFile ** output_files
Definition: fftools_ffmpeg.c:182
nb_input_streams
__thread int nb_input_streams
Definition: fftools_ffmpeg.c:176
opt_abort_on
int opt_abort_on(void *optctx, const char *opt, const char *arg)
Definition: fftools_ffmpeg_opt.c:222
OptionsContext::streamid_map
int * streamid_map
Definition: fftools_ffmpeg.h:187
OptionsContext::nb_filters
int nb_filters
Definition: fftools_ffmpeg.h:227
InputStream
Definition: fftools_ffmpeg.h:318
OptionsContext::start_time
int64_t start_time
Definition: fftools_ffmpeg.h:122
progress_avio
__thread AVIOContext * progress_avio
Definition: fftools_ffmpeg.c:171
VSYNC_CFR
#define VSYNC_CFR
Definition: fftools_ffmpeg.h:74
OptionsContext::nb_audio_channel_maps
int nb_audio_channel_maps
Definition: fftools_ffmpeg.h:164
assert_file_overwrite
void assert_file_overwrite(const char *filename)
Definition: fftools_ffmpeg_opt.c:940
OptionsContext::stream_maps
StreamMap * stream_maps
Definition: fftools_ffmpeg.h:161
OutputStream::bsf_ctx
AVBSFContext ** bsf_ctx
Definition: fftools_ffmpeg.h:486
new_subtitle_stream
OutputStream * new_subtitle_stream(OptionsContext *o, AVFormatContext *oc, int source_index)
Definition: fftools_ffmpeg_opt.c:1979
OptionsContext::dump_attachment
SpecifierOpt * dump_attachment
Definition: fftools_ffmpeg.h:149
do_psnr
__thread int do_psnr
Definition: fftools_ffmpeg_opt.c:134
print_stats
__thread int print_stats
Definition: fftools_ffmpeg_opt.c:121
AV_LOG_FATAL
#define AV_LOG_FATAL
Definition: MobileFFmpegConfig.h:49
open_input_file
int open_input_file(OptionsContext *o, const char *filename)
Definition: fftools_ffmpeg_opt.c:1015
HWACCEL_NONE
@ HWACCEL_NONE
Definition: fftools_ffmpeg.h:82
add_input_streams
void add_input_streams(OptionsContext *o, AVFormatContext *ic)
Definition: fftools_ffmpeg_opt.c:728
opt_data_codec
int opt_data_codec(void *optctx, const char *opt, const char *arg)
Definition: fftools_ffmpeg_opt.c:279
InputStream::hwaccel_device_type
enum AVHWDeviceType hwaccel_device_type
Definition: fftools_ffmpeg.h:388
OutputFilter::channel_layout
uint64_t channel_layout
Definition: fftools_ffmpeg.h:297
opt_sdp_file
int opt_sdp_file(void *optctx, const char *opt, const char *arg)
Definition: fftools_ffmpeg_opt.c:488
OptionsContext::stop_time
int64_t stop_time
Definition: fftools_ffmpeg.h:174
AV_LOG_ERROR
#define AV_LOG_ERROR
Definition: MobileFFmpegConfig.h:55
AudioChannelMap::ofile_idx
int ofile_idx
Definition: fftools_ffmpeg.h:115
show_help_options
void show_help_options(const OptionDef *options, const char *msg, int req_flags, int rej_flags, int alt_flags)
Definition: fftools_cmdutils.c:210
video_sync_method
__thread int video_sync_method
Definition: fftools_ffmpeg_opt.c:108
get_line
uint8_t * get_line(AVIOContext *s)
Definition: fftools_ffmpeg_opt.c:1289
opt_progress
int opt_progress(void *optctx, const char *opt, const char *arg)
OutputStream::audio_channels_mapped
int audio_channels_mapped
Definition: fftools_ffmpeg.h:520
OutputStream::attachment_filename
const char * attachment_filename
Definition: fftools_ffmpeg.h:546
OutputStream::file_index
int file_index
Definition: fftools_ffmpeg.h:466
OptionGroup::codec_opts
AVDictionary * codec_opts
Definition: fftools_cmdutils.h:302
OPT_OUTPUT
#define OPT_OUTPUT
Definition: fftools_cmdutils.h:206
OptionsContext::input_ts_offset
int64_t input_ts_offset
Definition: fftools_ffmpeg.h:141
OptionsContext::data_disable
int data_disable
Definition: fftools_ffmpeg.h:184
OptionsContext::metadata
SpecifierOpt * metadata
Definition: fftools_ffmpeg.h:190
HWACCEL_AUTO
@ HWACCEL_AUTO
Definition: fftools_ffmpeg.h:83
new_audio_stream
OutputStream * new_audio_stream(OptionsContext *o, AVFormatContext *oc, int source_index)
Definition: fftools_ffmpeg_opt.c:1870
InputStream::top_field_first
int top_field_first
Definition: fftools_ffmpeg.h:357
abort_on_flags
__thread int abort_on_flags
Definition: fftools_ffmpeg_opt.c:120
input_sync
__thread int input_sync
Definition: fftools_ffmpeg_opt.c:135
max_error_rate
__thread float max_error_rate
Definition: fftools_ffmpeg_opt.c:125
OptionsContext::metadata_chapters_manual
int metadata_chapters_manual
Definition: fftools_ffmpeg.h:167
OptionGroupList
Definition: fftools_cmdutils.h:313
qp_hist
__thread int qp_hist
Definition: fftools_ffmpeg_opt.c:122
debug_ts
__thread int debug_ts
Definition: fftools_ffmpeg_opt.c:118
new_output_stream
OutputStream * new_output_stream(OptionsContext *o, AVFormatContext *oc, enum AVMediaType type, int source_index)
Definition: fftools_ffmpeg_opt.c:1369
StreamMap::disabled
int disabled
Definition: fftools_ffmpeg.h:105
OutputStream::top_field_first
int top_field_first
Definition: fftools_ffmpeg.h:503
InputFile::loop
int loop
Definition: fftools_ffmpeg.h:421
opt_timecode
int opt_timecode(void *optctx, const char *opt, const char *arg)
Definition: fftools_ffmpeg_opt.c:3107
ffmpeg_options
__thread OptionDef * ffmpeg_options
Definition: fftools_ffmpeg.c:5068
OutputStream::copy_prior_start
int copy_prior_start
Definition: fftools_ffmpeg.h:548
OptionsContext::frame_rates
SpecifierOpt * frame_rates
Definition: fftools_ffmpeg.h:133
exit_on_error
__thread int exit_on_error
Definition: fftools_ffmpeg_opt.c:119
OutputStream::disposition
char * disposition
Definition: fftools_ffmpeg.h:549
parse_number_or_die
double parse_number_or_die(const char *context, const char *numstr, int type, double min, double max)
Definition: fftools_cmdutils.c:177
OutputStream::source_index
int source_index
Definition: fftools_ffmpeg.h:468
OPT_VIDEO
#define OPT_VIDEO
Definition: fftools_cmdutils.h:192
OptionsContext::shortest
int shortest
Definition: fftools_ffmpeg.h:178
audio_sync_method
__thread int audio_sync_method
Definition: fftools_ffmpeg_opt.c:107
OutputFilter
Definition: fftools_ffmpeg.h:282
OptionGroup::swr_opts
AVDictionary * swr_opts
Definition: fftools_cmdutils.h:306
input_stream_potentially_available
__thread int input_stream_potentially_available
Definition: fftools_ffmpeg_opt.c:136
OutputStream::sws_dict
AVDictionary * sws_dict
Definition: fftools_ffmpeg.h:531
opt_vsync
int opt_vsync(void *optctx, const char *opt, const char *arg)
Definition: fftools_ffmpeg_opt.c:3095
OptionsContext
Definition: fftools_ffmpeg.h:118
OutputStream::max_muxing_queue_size
int max_muxing_queue_size
Definition: fftools_ffmpeg.h:565
OPT_INT
#define OPT_INT
Definition: fftools_cmdutils.h:194
OptionsContext::nb_frame_rates
int nb_frame_rates
Definition: fftools_ffmpeg.h:134
init_simple_filtergraph
int init_simple_filtergraph(InputStream *ist, OutputStream *ost)
OptionGroup::sws_dict
AVDictionary * sws_dict
Definition: fftools_cmdutils.h:305
opt_default
int opt_default(void *optctx, const char *opt, const char *arg)
Definition: fftools_cmdutils.c:582
OptionsContext::nb_stream_maps
int nb_stream_maps
Definition: fftools_ffmpeg.h:162
DECODING_FOR_OST
#define DECODING_FOR_OST
Definition: fftools_ffmpeg.h:324
int_cb
__thread const AVIOInterruptCB int_cb
Definition: fftools_ffmpeg.c:580
HWAccel::id
enum HWAccelID id
Definition: fftools_ffmpeg.h:93
InputStream::autorotate
int autorotate
Definition: fftools_ffmpeg.h:360
start_at_zero
__thread int start_at_zero
Definition: fftools_ffmpeg_opt.c:116
stdin_interaction
__thread int stdin_interaction
Definition: fftools_ffmpeg_opt.c:123
OptionDef::off
size_t off
Definition: fftools_cmdutils.h:210
OutputFile::opts
AVDictionary * opts
Definition: fftools_ffmpeg.h:579
get_preset_file
FILE * get_preset_file(char *filename, size_t filename_size, const char *preset_name, int is_path, const char *codec_name)
Definition: fftools_cmdutils.c:2073
sdp_filename
__thread char * sdp_filename
Definition: fftools_ffmpeg_opt.c:100
MATCH_PER_TYPE_OPT
#define MATCH_PER_TYPE_OPT(name, type, outvar, fmtctx, mediatype)
Definition: fftools_ffmpeg_opt.c:74
OptionsContext::max_frames
SpecifierOpt * max_frames
Definition: fftools_ffmpeg.h:192
do_hex_dump
__thread int do_hex_dump
Definition: fftools_ffmpeg_opt.c:113
find_stream_info
__thread int find_stream_info
Definition: fftools_ffmpeg_opt.c:139
dts_error_threshold
__thread float dts_error_threshold
Definition: fftools_ffmpeg_opt.c:104
InputStream::fix_sub_duration
int fix_sub_duration
Definition: fftools_ffmpeg.h:362
VSYNC_AUTO
#define VSYNC_AUTO
Definition: fftools_ffmpeg.h:72
SpecifierOpt::i
int i
Definition: fftools_cmdutils.h:177
OptionsContext::mux_max_delay
float mux_max_delay
Definition: fftools_ffmpeg.h:177
InputFile
Definition: fftools_ffmpeg.h:416
opt_sameq
int opt_sameq(void *optctx, const char *opt, const char *arg)
Definition: fftools_ffmpeg_opt.c:240
InputFile::accurate_seek
int accurate_seek
Definition: fftools_ffmpeg.h:436
FilterGraph::graph_desc
const char * graph_desc
Definition: fftools_ffmpeg.h:307
OutputStream::encoding_needed
int encoding_needed
Definition: fftools_ffmpeg.h:470
file_overwrite
__thread int file_overwrite
Definition: fftools_ffmpeg_opt.c:132
OPT_STRING
#define OPT_STRING
Definition: fftools_cmdutils.h:191
OutputFile::shortest
int shortest
Definition: fftools_ffmpeg.h:585
parse_time_or_die
int64_t parse_time_or_die(const char *context, const char *timestr, int is_duration)
Definition: fftools_cmdutils.c:198
OptionsContext::audio_sample_rate
SpecifierOpt * audio_sample_rate
Definition: fftools_ffmpeg.h:131
nb_input_files
__thread int nb_input_files
Definition: fftools_ffmpeg.c:178
InputFile::streams
InputStream * streams
Definition: fftools_ffprobe.c:85
OutputFile::recording_time
int64_t recording_time
desired length of the resulting file in microseconds == AV_TIME_BASE units
Definition: fftools_ffmpeg.h:581
OptionsContext::metadata_global_manual
int metadata_global_manual
Definition: fftools_ffmpeg.h:165
StreamMap
Definition: fftools_ffmpeg.h:104
assert_avoptions
void assert_avoptions(AVDictionary *m)
Definition: fftools_ffmpeg.c:747
nb_output_streams
__thread int nb_output_streams
Definition: fftools_ffmpeg.c:181
opt_filter_hw_device
int opt_filter_hw_device(void *optctx, const char *opt, const char *arg)
Definition: fftools_ffmpeg_opt.c:531
frame_drop_threshold
__thread float frame_drop_threshold
Definition: fftools_ffmpeg_opt.c:109
OptionsContext::audio_channel_maps
AudioChannelMap * audio_channel_maps
Definition: fftools_ffmpeg.h:163
ABORT_ON_FLAG_EMPTY_OUTPUT
#define ABORT_ON_FLAG_EMPTY_OUTPUT
Definition: fftools_ffmpeg.h:456
new_video_stream
OutputStream * new_video_stream(OptionsContext *o, AVFormatContext *oc, int source_index)
Definition: fftools_ffmpeg_opt.c:1670
OptionsContext::nb_audio_sample_rate
int nb_audio_sample_rate
Definition: fftools_ffmpeg.h:132
OptionsContext::nb_frame_pix_fmts
int nb_frame_pix_fmts
Definition: fftools_ffmpeg.h:138
open_output_file
int open_output_file(OptionsContext *o, const char *filename)
Definition: fftools_ffmpeg_opt.c:2126
OptionsContext::loop
int loop
Definition: fftools_ffmpeg.h:142
init_complex_filters
int init_complex_filters(void)
Definition: fftools_ffmpeg_opt.c:2114
vstats_filename
__thread char * vstats_filename
Definition: fftools_ffmpeg_opt.c:99
term_exit
void term_exit(void)
Definition: fftools_ffmpeg.c:414
OutputStream::forced_kf_ref_pts
int64_t forced_kf_ref_pts
Definition: fftools_ffmpeg.h:510
OptionGroupList::groups
OptionGroup * groups
Definition: fftools_cmdutils.h:316
InputFile::ctx
AVFormatContext * ctx
Definition: fftools_ffmpeg.h:417
split_commandline
int split_commandline(OptionParseContext *octx, int argc, char *argv[], const OptionDef *options, const OptionGroupDef *groups, int nb_groups)
Definition: fftools_cmdutils.c:790
OutputStream::logfile
FILE * logfile
Definition: fftools_ffmpeg.h:523
filter_codec_opts
AVDictionary * filter_codec_opts(AVDictionary *opts, enum AVCodecID codec_id, AVFormatContext *s, AVStream *st, AVCodec *codec)
Definition: fftools_cmdutils.c:2131
parse_meta_type
void parse_meta_type(char *arg, char *type, int *index, const char **stream_spec)
Definition: fftools_ffmpeg_opt.c:552
vstats_version
__thread int vstats_version
Definition: fftools_ffmpeg_opt.c:128
InputStream::max_pts
int64_t max_pts
Definition: fftools_ffmpeg.h:345
AudioChannelMap::ostream_idx
int ostream_idx
Definition: fftools_ffmpeg.h:115
check_streamcopy_filters
void check_streamcopy_filters(OptionsContext *o, AVFormatContext *oc, const OutputStream *ost, enum AVMediaType type)
Definition: fftools_ffmpeg_opt.c:1656
get_preset_file_2
int get_preset_file_2(const char *preset_name, const char *codec_name, AVIOContext **s)
Definition: fftools_ffmpeg_opt.c:1308
OptionsContext::frame_pix_fmts
SpecifierOpt * frame_pix_fmts
Definition: fftools_ffmpeg.h:137
FilterGraph::nb_outputs
int nb_outputs
Definition: fftools_ffmpeg.h:315
fftools_read_file
uint8_t * fftools_read_file(const char *filename)
Definition: fftools_ffmpeg_opt.c:1608
OutputStream::resample_opts
AVDictionary * resample_opts
Definition: fftools_ffmpeg.h:533
MATCH_PER_STREAM_OPT
#define MATCH_PER_STREAM_OPT(name, type, outvar, fmtctx, st)
Definition: fftools_ffmpeg_opt.c:62
OutputStream::filter
OutputFilter * filter
Definition: fftools_ffmpeg.h:525
nb_output_files
__thread int nb_output_files
Definition: fftools_ffmpeg.c:183
choose_encoder
int choose_encoder(OptionsContext *o, AVFormatContext *s, OutputStream *ost)
Definition: fftools_ffmpeg_opt.c:1334
HWACCEL_VIDEOTOOLBOX
@ HWACCEL_VIDEOTOOLBOX
Definition: fftools_ffmpeg.h:85
time
int time
Definition: Statistics.m:28
OutputFilter::sample_rates
int * sample_rates
Definition: fftools_ffmpeg.h:302
AudioChannelMap
Definition: fftools_ffmpeg.h:113
new_attachment_stream
OutputStream * new_attachment_stream(OptionsContext *o, AVFormatContext *oc, int source_index)
Definition: fftools_ffmpeg_opt.c:1971
GROW_ARRAY
#define GROW_ARRAY(array, nb_elems)
Definition: fftools_cmdutils.h:607
opt_recording_timestamp
int opt_recording_timestamp(void *optctx, const char *opt, const char *arg)
Definition: fftools_ffmpeg_opt.c:669
OutputStream::enc_timebase
AVRational enc_timebase
Definition: fftools_ffmpeg.h:483
OptionsContext::nb_attachments
int nb_attachments
Definition: fftools_ffmpeg.h:169
OptionGroup::arg
const char * arg
Definition: fftools_cmdutils.h:297
InputFile::nb_streams
int nb_streams
Definition: fftools_ffmpeg.h:432
OPT_SUBTITLE
#define OPT_SUBTITLE
Definition: fftools_cmdutils.h:196
copy_tb
__thread int copy_tb
Definition: fftools_ffmpeg_opt.c:117
uninit_options
void uninit_options(OptionsContext *o)
Definition: fftools_ffmpeg_opt.c:143
format_opts
__thread AVDictionary * format_opts
Definition: fftools_cmdutils.c:103
InputStream::user_set_discard
int user_set_discard
Definition: fftools_ffmpeg.h:322
OutputFilter::formats
int * formats
Definition: fftools_ffmpeg.h:300
OptionsContext::thread_queue_size
int thread_queue_size
Definition: fftools_ffmpeg.h:145
OptionDef::u
union OptionDef::@1 u
OptionsContext::nb_audio_channels
int nb_audio_channels
Definition: fftools_ffmpeg.h:130
InputStream::framerate
AVRational framerate
Definition: fftools_ffmpeg.h:356
OptionsContext::frame_sizes
SpecifierOpt * frame_sizes
Definition: fftools_ffmpeg.h:135
opt_map_channel
int opt_map_channel(void *optctx, const char *opt, const char *arg)
Definition: fftools_ffmpeg_opt.c:411
find_codec_or_die
AVCodec * find_codec_or_die(const char *name, enum AVMediaType type, int encoder)
Definition: fftools_ffmpeg_opt.c:684
SET_DICT
#define SET_DICT(type, meta, context, index)
read_yesno
int read_yesno(void)
Definition: fftools_cmdutils.c:2062
no_file_overwrite
__thread int no_file_overwrite
Definition: fftools_ffmpeg_opt.c:133
StreamMap::sync_file_index
int sync_file_index
Definition: fftools_ffmpeg.h:108
FilterGraph::outputs
OutputFilter ** outputs
Definition: fftools_ffmpeg.h:314
OutputStream::sync_ist
struct InputStream * sync_ist
Definition: fftools_ffmpeg.h:474
opt_video_filters
int opt_video_filters(void *optctx, const char *opt, const char *arg)
Definition: fftools_ffmpeg_opt.c:3083
OptionsContext::metadata_map
SpecifierOpt * metadata_map
Definition: fftools_ffmpeg.h:218
print_error
void print_error(const char *filename, int err)
Definition: fftools_cmdutils.c:1130
SpecifierOpt
Definition: fftools_cmdutils.h:173
InputFile::ts_offset
int64_t ts_offset
Definition: fftools_ffmpeg.h:427
OutputFilter::format
int format
Definition: fftools_ffmpeg.h:295
value
long value
Definition: AtomicLong.m:22
OptionParseContext
Definition: fftools_cmdutils.h:320
OutputStream::index
int index
Definition: fftools_ffmpeg.h:467
term_init
void term_init(void)
Definition: fftools_ffmpeg.c:474
InputStream::st
AVStream * st
Definition: fftools_ffmpeg.h:320
InputStream::hwaccel_pix_fmt
enum AVPixelFormat hwaccel_pix_fmt
Definition: fftools_ffmpeg.h:397
OptionsContext::nb_program
int nb_program
Definition: fftools_ffmpeg.h:251
OptionGroupDef
Definition: fftools_cmdutils.h:280
HWAccel
Definition: fftools_ffmpeg.h:90
OutputStream::forced_keyframes
char * forced_keyframes
Definition: fftools_ffmpeg.h:514
OptionsContext::format
const char * format
Definition: fftools_ffmpeg.h:125
OutputStream::keep_pix_fmt
int keep_pix_fmt
Definition: fftools_ffmpeg.h:551
opt_map
int opt_map(void *optctx, const char *opt, const char *arg)
Definition: fftools_ffmpeg_opt.c:285
InputStream::dec_ctx
AVCodecContext * dec_ctx
Definition: fftools_ffmpeg.h:327
OptionParseContext::groups
OptionGroupList * groups
Definition: fftools_cmdutils.h:323
OptionsContext::bitexact
int bitexact
Definition: fftools_ffmpeg.h:179
cuvid_init
int cuvid_init(AVCodecContext *s)
AV_LOG_VERBOSE
#define AV_LOG_VERBOSE
Definition: MobileFFmpegConfig.h:71
OptionsContext::audio_disable
int audio_disable
Definition: fftools_ffmpeg.h:182
OptionsContext::nb_metadata_map
int nb_metadata_map
Definition: fftools_ffmpeg.h:219
AV_LOG_STDERR
#define AV_LOG_STDERR
Definition: fftools_cmdutils.h:61
OptionsContext::rate_emu
int rate_emu
Definition: fftools_ffmpeg.h:143
guess_input_channel_layout
int guess_input_channel_layout(InputStream *ist)
Definition: fftools_ffmpeg.c:2256
StreamMap::sync_stream_index
int sync_stream_index
Definition: fftools_ffmpeg.h:109
OptionsContext::nb_max_frames
int nb_max_frames
Definition: fftools_ffmpeg.h:193
opt_target
int opt_target(void *optctx, const char *opt, const char *arg)
Definition: fftools_ffmpeg_opt.c:2772
StreamMap::file_index
int file_index
Definition: fftools_ffmpeg.h:106
opt_video_frames
int opt_video_frames(void *optctx, const char *opt, const char *arg)
Definition: fftools_ffmpeg_opt.c:2939
InputFile::ist_index
int ist_index
Definition: fftools_ffmpeg.h:420
OptionsContext::g
OptionGroup * g
Definition: fftools_ffmpeg.h:119
InputStream::decoding_needed
int decoding_needed
Definition: fftools_ffmpeg.h:323
OutputStream::frame_rate
AVRational frame_rate
Definition: fftools_ffmpeg.h:500
OptionsContext::nb_metadata
int nb_metadata
Definition: fftools_ffmpeg.h:191
int
int
Definition: fftools_ffmpeg_filter.c:199
OutputFilter::sample_rate
int sample_rate
Definition: fftools_ffmpeg.h:296
OutputFilter::width
int width
Definition: fftools_ffmpeg.h:293
input_files
__thread InputFile ** input_files
Definition: fftools_ffmpeg.c:177
init_output_filter
void init_output_filter(OutputFilter *ofilter, OptionsContext *o, AVFormatContext *oc)
Definition: fftools_ffmpeg_opt.c:2072
dts_delta_threshold
__thread float dts_delta_threshold
Definition: fftools_ffmpeg_opt.c:103
do_benchmark
__thread int do_benchmark
Definition: fftools_ffmpeg_opt.c:111
filtergraphs
__thread FilterGraph ** filtergraphs
Definition: fftools_ffmpeg.c:185
InputStream::guess_layout_max
int guess_layout_max
Definition: fftools_ffmpeg.h:358
videotoolbox_init
int videotoolbox_init(AVCodecContext *s)
Definition: fftools_ffmpeg_videotoolbox.c:121
OutputStream::nb_bitstream_filters
int nb_bitstream_filters
Definition: fftools_ffmpeg.h:485
OPT_SPEC
#define OPT_SPEC
Definition: fftools_cmdutils.h:202
OPT_PERFILE
#define OPT_PERFILE
Definition: fftools_cmdutils.h:200
OutputFile::ost_index
int ost_index
Definition: fftools_ffmpeg.h:580
OptionDef
Definition: fftools_cmdutils.h:185
OutputStream::filters_script
char * filters_script
filtergraph script associated to the -filter_script option
Definition: fftools_ffmpeg.h:528
remove_avoptions
void remove_avoptions(AVDictionary **a, AVDictionary *b)
Definition: fftools_ffmpeg.c:738
DEFAULT_PASS_LOGFILENAME_PREFIX
#define DEFAULT_PASS_LOGFILENAME_PREFIX
Definition: fftools_ffmpeg_opt.c:60
InputFile::start_time
int64_t start_time
Definition: fftools_ffmpeg.h:429
get_ost_filters
char * get_ost_filters(OptionsContext *o, AVFormatContext *oc, OutputStream *ost)
Definition: fftools_ffmpeg_opt.c:1636
choose_decoder
AVCodec * choose_decoder(OptionsContext *o, AVFormatContext *s, AVStream *st)
Definition: fftools_ffmpeg_opt.c:713
OutputFile::limit_filesize
uint64_t limit_filesize
Definition: fftools_ffmpeg.h:583
StreamMap::stream_index
int stream_index
Definition: fftools_ffmpeg.h:107
SpecifierOpt::specifier
char * specifier
Definition: fftools_cmdutils.h:174
ignore_unknown_streams
__thread int ignore_unknown_streams
Definition: fftools_ffmpeg_opt.c:137
OutputStream::enc
AVCodec * enc
Definition: fftools_ffmpeg.h:490
InputStream::min_pts
int64_t min_pts
Definition: fftools_ffmpeg.h:344
InputStream::filter_in_rescale_delta_last
int64_t filter_in_rescale_delta_last
Definition: fftools_ffmpeg.h:342
opt_filter_complex_script
int opt_filter_complex_script(void *optctx, const char *opt, const char *arg)
Definition: fftools_ffmpeg_opt.c:3178
OutputStream::st
AVStream * st
Definition: fftools_ffmpeg.h:469
HWAccel::name
const char * name
Definition: fftools_ffmpeg.h:91
copy_chapters
int copy_chapters(InputFile *ifile, OutputFile *ofile, int copy_metadata)
Definition: fftools_ffmpeg_opt.c:2029
AV_LOG_DEBUG
#define AV_LOG_DEBUG
Definition: MobileFFmpegConfig.h:76
OptionGroup::resample_opts
AVDictionary * resample_opts
Definition: fftools_cmdutils.h:304
OutputFile
Definition: fftools_ffmpeg.h:577
VSYNC_PASSTHROUGH
#define VSYNC_PASSTHROUGH
Definition: fftools_ffmpeg.h:73
OptionsContext::nb_frame_sizes
int nb_frame_sizes
Definition: fftools_ffmpeg.h:136
nb_streams
__thread int nb_streams
Definition: fftools_ffprobe.c:286
OptionsContext::chapters_input_file
int chapters_input_file
Definition: fftools_ffmpeg.h:171
nb_filtergraphs
__thread int nb_filtergraphs
Definition: fftools_ffmpeg.c:186
OutputFilter::frame_rate
AVRational frame_rate
Definition: fftools_ffmpeg.h:294
opt_video_channel
int opt_video_channel(void *optctx, const char *opt, const char *arg)
Definition: fftools_ffmpeg_opt.c:249
OptionGroup::format_opts
AVDictionary * format_opts
Definition: fftools_cmdutils.h:303
SpecifierOpt::u
union SpecifierOpt::@0 u
OPT_AUDIO
#define OPT_AUDIO
Definition: fftools_cmdutils.h:193
dump_attachment
void dump_attachment(AVStream *st, const char *filename)
Definition: fftools_ffmpeg_opt.c:983
HWDevice
Definition: fftools_ffmpeg.h:97
OutputStream::max_frames
int64_t max_frames
Definition: fftools_ffmpeg.h:491
OutputStream::apad
char * apad
Definition: fftools_ffmpeg.h:534
OptionsContext::nb_streamid_map
int nb_streamid_map
Definition: fftools_ffmpeg.h:188
SpecifierOpt::str
uint8_t * str
Definition: fftools_cmdutils.h:176
OutputStream::frame_aspect_ratio
AVRational frame_aspect_ratio
Definition: fftools_ffmpeg.h:507
OptionsContext::nb_dump_attachment
int nb_dump_attachment
Definition: fftools_ffmpeg.h:150
opt_video_codec
int opt_video_codec(void *optctx, const char *opt, const char *arg)
Definition: fftools_ffmpeg_opt.c:267
hwaccels
const HWAccel hwaccels[]
Definition: fftools_ffmpeg_opt.c:84
opt_profile
int opt_profile(void *optctx, const char *opt, const char *arg)
Definition: fftools_ffmpeg_opt.c:3071
opt_vstats_file
int opt_vstats_file(void *optctx, const char *opt, const char *arg)
Definition: fftools_ffmpeg_opt.c:2916
audio_volume
__thread int audio_volume
Definition: fftools_ffmpeg_opt.c:106
fftools_cmdutils.h
show_help_children
void show_help_children(const AVClass *class, int flags)
Definition: fftools_cmdutils.c:239
OptionsContext::subtitle_disable
int subtitle_disable
Definition: fftools_ffmpeg.h:183
do_deinterlace
__thread int do_deinterlace
Definition: fftools_ffmpeg_opt.c:110
InputStream::hwaccel_device
char * hwaccel_device
Definition: fftools_ffmpeg.h:389
MAX_STREAMS
#define MAX_STREAMS
Definition: fftools_ffmpeg.h:79
frame_bits_per_raw_sample
__thread int frame_bits_per_raw_sample
Definition: fftools_ffmpeg_opt.c:124
OutputFilter::type
enum AVMediaType type
Definition: fftools_ffmpeg.h:290
InputStream::hwaccel_id
enum HWAccelID hwaccel_id
Definition: fftools_ffmpeg.h:387
init_options
void init_options(OptionsContext *o)
Definition: fftools_ffmpeg_opt.c:175
OptionsContext::recording_time
int64_t recording_time
Definition: fftools_ffmpeg.h:173
input_streams
__thread InputStream ** input_streams
Definition: fftools_ffmpeg.c:175
new_data_stream
OutputStream * new_data_stream(OptionsContext *o, AVFormatContext *oc, int source_index)
Definition: fftools_ffmpeg_opt.c:1945
output_streams
__thread OutputStream ** output_streams
Definition: fftools_ffmpeg.c:180
OptionsContext::metadata_streams_manual
int metadata_streams_manual
Definition: fftools_ffmpeg.h:166
InputStream::dec
AVCodec * dec
Definition: fftools_ffmpeg.h:328
init_complex_filtergraph
int init_complex_filtergraph(FilterGraph *fg)
Definition: fftools_ffmpeg_filter.c:348
OutputFilter::out_tmp
AVFilterInOut * out_tmp
Definition: fftools_ffmpeg.h:289
VSYNC_VFR
#define VSYNC_VFR
Definition: fftools_ffmpeg.h:75
setup_find_stream_info_opts
AVDictionary ** setup_find_stream_info_opts(AVFormatContext *s, AVDictionary *codec_opts)
Definition: fftools_cmdutils.c:2188
AudioChannelMap::channel_idx
int channel_idx
Definition: fftools_ffmpeg.h:114
opt_channel_layout
int opt_channel_layout(void *optctx, const char *opt, const char *arg)
Definition: fftools_ffmpeg_opt.c:3121
check_filter_outputs
void check_filter_outputs(void)
Definition: fftools_ffmpeg_filter.c:698
OptionParseContext::global_opts
OptionGroup global_opts
Definition: fftools_cmdutils.h:321
OptionsContext::audio_channels
SpecifierOpt * audio_channels
Definition: fftools_ffmpeg.h:129
InputStream::nb_samples
int64_t nb_samples
Definition: fftools_ffmpeg.h:351
VSYNC_DROP
#define VSYNC_DROP
Definition: fftools_ffmpeg.h:77
OutputStream::enc_ctx
AVCodecContext * enc_ctx
Definition: fftools_ffmpeg.h:488
HWDevice::device_ref
AVBufferRef * device_ref
Definition: fftools_ffmpeg.h:100
OptionsContext::video_disable
int video_disable
Definition: fftools_ffmpeg.h:181
opt_attach
int opt_attach(void *optctx, const char *opt, const char *arg)
Definition: fftools_ffmpeg_opt.c:403
parse_option
int parse_option(void *optctx, const char *opt, const char *arg, const OptionDef *options)
Definition: fftools_cmdutils.c:383
InputFile::time_base
AVRational time_base
Definition: fftools_ffmpeg.h:424
OptionsContext::program
SpecifierOpt * program
Definition: fftools_ffmpeg.h:250
InputStream::file_index
int file_index
Definition: fftools_ffmpeg.h:319
OutputFile::start_time
int64_t start_time
start time in microseconds == AV_TIME_BASE units
Definition: fftools_ffmpeg.h:582
OutputStream::audio_channels_map
int * audio_channels_map
Definition: fftools_ffmpeg.h:519
OptionGroup
Definition: fftools_cmdutils.h:295
hw_device_get_by_name
HWDevice * hw_device_get_by_name(const char *name)
Definition: fftools_ffmpeg_hw.c:51
FilterGraph
Definition: fftools_ffmpeg.h:305
OutputStream
Definition: fftools_ffmpeg.h:465
InputStream::hwaccel_output_format
enum AVPixelFormat hwaccel_output_format
Definition: fftools_ffmpeg.h:390
copy_ts
__thread int copy_ts
Definition: fftools_ffmpeg_opt.c:115
open_files
int open_files(OptionGroupList *l, const char *inout, int(*open_file)(OptionsContext *, const char *))
HWACCEL_GENERIC
@ HWACCEL_GENERIC
Definition: fftools_ffmpeg.h:84
OptionsContext::start_time_eof
int64_t start_time_eof
Definition: fftools_ffmpeg.h:123
new_unknown_stream
OutputStream * new_unknown_stream(OptionsContext *o, AVFormatContext *oc, int source_index)
Definition: fftools_ffmpeg_opt.c:1958
opt_qscale
int opt_qscale(void *optctx, const char *opt, const char *arg)
Definition: fftools_ffmpeg_opt.c:3053
audio_drift_threshold
__thread float audio_drift_threshold
Definition: fftools_ffmpeg_opt.c:102
opt_audio_qscale
int opt_audio_qscale(void *optctx, const char *opt, const char *arg)
Definition: fftools_ffmpeg_opt.c:3157
copy_unknown_streams
__thread int copy_unknown_streams
Definition: fftools_ffmpeg_opt.c:138
opt_bitrate
int opt_bitrate(void *optctx, const char *opt, const char *arg)
Definition: fftools_ffmpeg_opt.c:3037
OutputStream::copy_initial_nonkeyframes
int copy_initial_nonkeyframes
Definition: fftools_ffmpeg.h:547
opt_video_standard
int opt_video_standard(void *optctx, const char *opt, const char *arg)
Definition: fftools_ffmpeg_opt.c:255
opt_audio_codec
int opt_audio_codec(void *optctx, const char *opt, const char *arg)
Definition: fftools_ffmpeg_opt.c:261
opt_filter_complex
int opt_filter_complex(void *optctx, const char *opt, const char *arg)
Definition: fftools_ffmpeg_opt.c:3163
intra_only
__thread int intra_only
Definition: fftools_ffmpeg_opt.c:131
OutputFilter::height
int height
Definition: fftools_ffmpeg.h:293
InputFile::rate_emu
int rate_emu
Definition: fftools_ffmpeg.h:435
InputStream::decoder_opts
AVDictionary * decoder_opts
Definition: fftools_ffmpeg.h:355
InputFile::duration
int64_t duration
Definition: fftools_ffmpeg.h:422
opt_streamid
int opt_streamid(void *optctx, const char *opt, const char *arg)
Definition: fftools_ffmpeg_opt.c:2007
OutputStream::encoder_opts
AVDictionary * encoder_opts
Definition: fftools_ffmpeg.h:530
opt_audio_frames
int opt_audio_frames(void *optctx, const char *opt, const char *arg)
Definition: fftools_ffmpeg_opt.c:2945
OutputStream::swr_opts
AVDictionary * swr_opts
Definition: fftools_ffmpeg.h:532
OutputFilter::ost
struct OutputStream * ost
Definition: fftools_ffmpeg.h:284
OutputFilter::channel_layouts
uint64_t * channel_layouts
Definition: fftools_ffmpeg.h:301
show_help_default_ffmpeg
void show_help_default_ffmpeg(const char *opt, const char *arg)
Definition: fftools_ffmpeg_opt.c:3195
InputFile::recording_time
int64_t recording_time
Definition: fftools_ffmpeg.h:431
StreamMap::linklabel
char * linklabel
Definition: fftools_ffmpeg.h:110
show_usage
void show_usage(void)
Definition: fftools_ffmpeg_opt.c:3268
opt_data_frames
int opt_data_frames(void *optctx, const char *opt, const char *arg)
Definition: fftools_ffmpeg_opt.c:2951
OPT_EXPERT
#define OPT_EXPERT
Definition: fftools_cmdutils.h:190
InputFile::input_ts_offset
int64_t input_ts_offset
Definition: fftools_ffmpeg.h:425
opt_init_hw_device
int opt_init_hw_device(void *optctx, const char *opt, const char *arg)
Definition: fftools_ffmpeg_opt.c:516
InputStream::reinit_filters
int reinit_filters
Definition: fftools_ffmpeg.h:384
parse_optgroup
int parse_optgroup(void *optctx, OptionGroup *g)
Definition: fftools_cmdutils.c:451
filter_complex_nbthreads
__thread int filter_complex_nbthreads
Definition: fftools_ffmpeg_opt.c:127
opt_subtitle_codec
int opt_subtitle_codec(void *optctx, const char *opt, const char *arg)
Definition: fftools_ffmpeg_opt.c:273
strip_specifiers
AVDictionary * strip_specifiers(AVDictionary *dict)
Definition: fftools_ffmpeg_opt.c:205