3 * ffmpeg option parsing
5 * This file is part of FFmpeg.
7 * FFmpeg is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * FFmpeg is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with FFmpeg; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
27 #include "libavformat/avformat.h"
29 #include "libavcodec/avcodec.h"
31 #include "libavfilter/avfilter.h"
33 #include "libavutil/avassert.h"
34 #include "libavutil/avstring.h"
35 #include "libavutil/avutil.h"
36 #include "libavutil/channel_layout.h"
37 #include "libavutil/intreadwrite.h"
38 #include "libavutil/fifo.h"
39 #include "libavutil/mathematics.h"
40 #include "libavutil/opt.h"
41 #include "libavutil/parseutils.h"
42 #include "libavutil/pixdesc.h"
43 #include "libavutil/pixfmt.h"
45 #define DEFAULT_PASS_LOGFILENAME_PREFIX "ffmpeg2pass"
47 #define MATCH_PER_STREAM_OPT(name, type, outvar, fmtctx, st)\
50 for (i = 0; i < o->nb_ ## name; i++) {\
51 char *spec = o->name[i].specifier;\
52 if ((ret = check_stream_specifier(fmtctx, st, spec)) > 0)\
53 outvar = o->name[i].u.type;\
59 #define MATCH_PER_TYPE_OPT(name, type, outvar, fmtctx, mediatype)\
62 for (i = 0; i < o->nb_ ## name; i++) {\
63 char *spec = o->name[i].specifier;\
64 if (!strcmp(spec, mediatype))\
65 outvar = o->name[i].u.type;\
69 const HWAccel hwaccels[] = {
70 #if CONFIG_VIDEOTOOLBOX
71 { "videotoolbox", videotoolbox_init, HWACCEL_VIDEOTOOLBOX, AV_PIX_FMT_VIDEOTOOLBOX },
74 { "qsv", qsv_init, HWACCEL_QSV, AV_PIX_FMT_QSV },
78 AVBufferRef *hw_device_ctx;
79 HWDevice *filter_hw_device;
81 char *vstats_filename;
84 float audio_drift_threshold = 0.1;
85 float dts_delta_threshold = 10;
86 float dts_error_threshold = 3600*30;
88 int audio_volume = 256;
89 int audio_sync_method = 0;
90 int video_sync_method = VSYNC_AUTO;
91 float frame_drop_threshold = 0;
92 int do_deinterlace = 0;
94 int do_benchmark_all = 0;
98 int start_at_zero = 0;
101 int exit_on_error = 0;
102 int abort_on_flags = 0;
103 int print_stats = -1;
105 int stdin_interaction = 1;
106 int frame_bits_per_raw_sample = 0;
107 float max_error_rate = 2.0/3;
108 int filter_nbthreads = 0;
109 int filter_complex_nbthreads = 0;
110 int vstats_version = 2;
113 static int intra_only = 0;
114 static int file_overwrite = 0;
115 static int no_file_overwrite = 0;
116 static int do_psnr = 0;
117 static int input_sync;
118 static int input_stream_potentially_available = 0;
119 static int ignore_unknown_streams = 0;
120 static int copy_unknown_streams = 0;
121 static int find_stream_info = 1;
123 static void uninit_options(OptionsContext *o)
125 const OptionDef *po = options;
128 /* all OPT_SPEC and OPT_STRING can be freed in generic way */
130 void *dst = (uint8_t*)o + po->u.off;
132 if (po->flags & OPT_SPEC) {
133 SpecifierOpt **so = dst;
134 int i, *count = (int*)(so + 1);
135 for (i = 0; i < *count; i++) {
136 av_freep(&(*so)[i].specifier);
137 if (po->flags & OPT_STRING)
138 av_freep(&(*so)[i].u.str);
142 } else if (po->flags & OPT_OFFSET && po->flags & OPT_STRING)
147 for (i = 0; i < o->nb_stream_maps; i++)
148 av_freep(&o->stream_maps[i].linklabel);
149 av_freep(&o->stream_maps);
150 av_freep(&o->audio_channel_maps);
151 av_freep(&o->streamid_map);
152 av_freep(&o->attachments);
155 static void init_options(OptionsContext *o)
157 memset(o, 0, sizeof(*o));
159 o->stop_time = INT64_MAX;
160 o->mux_max_delay = 0.7;
161 o->start_time = AV_NOPTS_VALUE;
162 o->start_time_eof = AV_NOPTS_VALUE;
163 o->recording_time = INT64_MAX;
164 o->limit_filesize = UINT64_MAX;
165 o->chapters_input_file = INT_MAX;
166 o->accurate_seek = 1;
169 static int show_hwaccels(void *optctx, const char *opt, const char *arg)
171 enum AVHWDeviceType type = AV_HWDEVICE_TYPE_NONE;
174 printf("Hardware acceleration methods:\n");
175 while ((type = av_hwdevice_iterate_types(type)) !=
176 AV_HWDEVICE_TYPE_NONE)
177 printf("%s\n", av_hwdevice_get_type_name(type));
178 for (i = 0; hwaccels[i].name; i++)
179 printf("%s\n", hwaccels[i].name);
184 /* return a copy of the input with the stream specifiers removed from the keys */
185 static AVDictionary *strip_specifiers(AVDictionary *dict)
187 AVDictionaryEntry *e = NULL;
188 AVDictionary *ret = NULL;
190 while ((e = av_dict_get(dict, "", e, AV_DICT_IGNORE_SUFFIX))) {
191 char *p = strchr(e->key, ':');
195 av_dict_set(&ret, e->key, e->value, 0);
202 static int opt_abort_on(void *optctx, const char *opt, const char *arg)
204 static const AVOption opts[] = {
205 { "abort_on" , NULL, 0, AV_OPT_TYPE_FLAGS, { .i64 = 0 }, INT64_MIN, INT64_MAX, .unit = "flags" },
206 { "empty_output" , NULL, 0, AV_OPT_TYPE_CONST, { .i64 = ABORT_ON_FLAG_EMPTY_OUTPUT }, .unit = "flags" },
209 static const AVClass class = {
211 .item_name = av_default_item_name,
213 .version = LIBAVUTIL_VERSION_INT,
215 const AVClass *pclass = &class;
217 return av_opt_eval_flags(&pclass, &opts[0], arg, &abort_on_flags);
220 static int opt_sameq(void *optctx, const char *opt, const char *arg)
222 av_log(NULL, AV_LOG_ERROR, "Option '%s' was removed. "
223 "If you are looking for an option to preserve the quality (which is not "
224 "what -%s was for), use -qscale 0 or an equivalent quality factor option.\n",
226 return AVERROR(EINVAL);
229 static int opt_video_channel(void *optctx, const char *opt, const char *arg)
231 av_log(NULL, AV_LOG_WARNING, "This option is deprecated, use -channel.\n");
232 return opt_default(optctx, "channel", arg);
235 static int opt_video_standard(void *optctx, const char *opt, const char *arg)
237 av_log(NULL, AV_LOG_WARNING, "This option is deprecated, use -standard.\n");
238 return opt_default(optctx, "standard", arg);
241 static int opt_audio_codec(void *optctx, const char *opt, const char *arg)
243 OptionsContext *o = optctx;
244 return parse_option(o, "codec:a", arg, options);
247 static int opt_video_codec(void *optctx, const char *opt, const char *arg)
249 OptionsContext *o = optctx;
250 return parse_option(o, "codec:v", arg, options);
253 static int opt_subtitle_codec(void *optctx, const char *opt, const char *arg)
255 OptionsContext *o = optctx;
256 return parse_option(o, "codec:s", arg, options);
259 static int opt_data_codec(void *optctx, const char *opt, const char *arg)
261 OptionsContext *o = optctx;
262 return parse_option(o, "codec:d", arg, options);
265 static int opt_map(void *optctx, const char *opt, const char *arg)
267 OptionsContext *o = optctx;
269 int i, negative = 0, file_idx, disabled = 0;
270 int sync_file_idx = -1, sync_stream_idx = 0;
279 map = av_strdup(arg);
281 return AVERROR(ENOMEM);
283 /* parse sync stream first, just pick first matching stream */
284 if (sync = strchr(map, ',')) {
286 sync_file_idx = strtol(sync + 1, &sync, 0);
287 if (sync_file_idx >= nb_input_files || sync_file_idx < 0) {
288 av_log(NULL, AV_LOG_FATAL, "Invalid sync file index: %d.\n", sync_file_idx);
293 for (i = 0; i < input_files[sync_file_idx]->nb_streams; i++)
294 if (check_stream_specifier(input_files[sync_file_idx]->ctx,
295 input_files[sync_file_idx]->ctx->streams[i], sync) == 1) {
299 if (i == input_files[sync_file_idx]->nb_streams) {
300 av_log(NULL, AV_LOG_FATAL, "Sync stream specification in map %s does not "
301 "match any streams.\n", arg);
304 if (input_streams[input_files[sync_file_idx]->ist_index + sync_stream_idx]->user_set_discard == AVDISCARD_ALL) {
305 av_log(NULL, AV_LOG_FATAL, "Sync stream specification in map %s matches a disabled input "
313 /* this mapping refers to lavfi output */
314 const char *c = map + 1;
315 GROW_ARRAY(o->stream_maps, o->nb_stream_maps);
316 m = &o->stream_maps[o->nb_stream_maps - 1];
317 m->linklabel = av_get_token(&c, "]");
319 av_log(NULL, AV_LOG_ERROR, "Invalid output link label: %s.\n", map);
323 if (allow_unused = strchr(map, '?'))
325 file_idx = strtol(map, &p, 0);
326 if (file_idx >= nb_input_files || file_idx < 0) {
327 av_log(NULL, AV_LOG_FATAL, "Invalid input file index: %d.\n", file_idx);
331 /* disable some already defined maps */
332 for (i = 0; i < o->nb_stream_maps; i++) {
333 m = &o->stream_maps[i];
334 if (file_idx == m->file_index &&
335 check_stream_specifier(input_files[m->file_index]->ctx,
336 input_files[m->file_index]->ctx->streams[m->stream_index],
337 *p == ':' ? p + 1 : p) > 0)
341 for (i = 0; i < input_files[file_idx]->nb_streams; i++) {
342 if (check_stream_specifier(input_files[file_idx]->ctx, input_files[file_idx]->ctx->streams[i],
343 *p == ':' ? p + 1 : p) <= 0)
345 if (input_streams[input_files[file_idx]->ist_index + i]->user_set_discard == AVDISCARD_ALL) {
349 GROW_ARRAY(o->stream_maps, o->nb_stream_maps);
350 m = &o->stream_maps[o->nb_stream_maps - 1];
352 m->file_index = file_idx;
355 if (sync_file_idx >= 0) {
356 m->sync_file_index = sync_file_idx;
357 m->sync_stream_index = sync_stream_idx;
359 m->sync_file_index = file_idx;
360 m->sync_stream_index = i;
367 av_log(NULL, AV_LOG_VERBOSE, "Stream map '%s' matches no streams; ignoring.\n", arg);
368 } else if (disabled) {
369 av_log(NULL, AV_LOG_FATAL, "Stream map '%s' matches disabled streams.\n"
370 "To ignore this, add a trailing '?' to the map.\n", arg);
373 av_log(NULL, AV_LOG_FATAL, "Stream map '%s' matches no streams.\n"
374 "To ignore this, add a trailing '?' to the map.\n", arg);
383 static int opt_attach(void *optctx, const char *opt, const char *arg)
385 OptionsContext *o = optctx;
386 GROW_ARRAY(o->attachments, o->nb_attachments);
387 o->attachments[o->nb_attachments - 1] = arg;
391 static int opt_map_channel(void *optctx, const char *opt, const char *arg)
393 OptionsContext *o = optctx;
399 mapchan = av_strdup(arg);
401 return AVERROR(ENOMEM);
403 GROW_ARRAY(o->audio_channel_maps, o->nb_audio_channel_maps);
404 m = &o->audio_channel_maps[o->nb_audio_channel_maps - 1];
406 /* muted channel syntax */
407 n = sscanf(arg, "%d:%d.%d", &m->channel_idx, &m->ofile_idx, &m->ostream_idx);
408 if ((n == 1 || n == 3) && m->channel_idx == -1) {
409 m->file_idx = m->stream_idx = -1;
411 m->ofile_idx = m->ostream_idx = -1;
417 n = sscanf(arg, "%d.%d.%d:%d.%d",
418 &m->file_idx, &m->stream_idx, &m->channel_idx,
419 &m->ofile_idx, &m->ostream_idx);
421 if (n != 3 && n != 5) {
422 av_log(NULL, AV_LOG_FATAL, "Syntax error, mapchan usage: "
423 "[file.stream.channel|-1][:syncfile:syncstream]\n");
427 if (n != 5) // only file.stream.channel specified
428 m->ofile_idx = m->ostream_idx = -1;
431 if (m->file_idx < 0 || m->file_idx >= nb_input_files) {
432 av_log(NULL, AV_LOG_FATAL, "mapchan: invalid input file index: %d\n",
436 if (m->stream_idx < 0 ||
437 m->stream_idx >= input_files[m->file_idx]->nb_streams) {
438 av_log(NULL, AV_LOG_FATAL, "mapchan: invalid input file stream index #%d.%d\n",
439 m->file_idx, m->stream_idx);
442 st = input_files[m->file_idx]->ctx->streams[m->stream_idx];
443 if (st->codecpar->codec_type != AVMEDIA_TYPE_AUDIO) {
444 av_log(NULL, AV_LOG_FATAL, "mapchan: stream #%d.%d is not an audio stream.\n",
445 m->file_idx, m->stream_idx);
448 /* allow trailing ? to map_channel */
449 if (allow_unused = strchr(mapchan, '?'))
451 if (m->channel_idx < 0 || m->channel_idx >= st->codecpar->channels ||
452 input_streams[input_files[m->file_idx]->ist_index + m->stream_idx]->user_set_discard == AVDISCARD_ALL) {
454 av_log(NULL, AV_LOG_VERBOSE, "mapchan: invalid audio channel #%d.%d.%d\n",
455 m->file_idx, m->stream_idx, m->channel_idx);
457 av_log(NULL, AV_LOG_FATAL, "mapchan: invalid audio channel #%d.%d.%d\n"
458 "To ignore this, add a trailing '?' to the map_channel.\n",
459 m->file_idx, m->stream_idx, m->channel_idx);
468 static int opt_sdp_file(void *optctx, const char *opt, const char *arg)
470 av_free(sdp_filename);
471 sdp_filename = av_strdup(arg);
476 static int opt_vaapi_device(void *optctx, const char *opt, const char *arg)
479 const char *prefix = "vaapi:";
482 tmp = av_asprintf("%s%s", prefix, arg);
484 return AVERROR(ENOMEM);
485 err = hw_device_init_from_string(tmp, &dev);
489 hw_device_ctx = av_buffer_ref(dev->device_ref);
491 return AVERROR(ENOMEM);
496 static int opt_init_hw_device(void *optctx, const char *opt, const char *arg)
498 if (!strcmp(arg, "list")) {
499 enum AVHWDeviceType type = AV_HWDEVICE_TYPE_NONE;
500 printf("Supported hardware device types:\n");
501 while ((type = av_hwdevice_iterate_types(type)) !=
502 AV_HWDEVICE_TYPE_NONE)
503 printf("%s\n", av_hwdevice_get_type_name(type));
507 return hw_device_init_from_string(arg, NULL);
511 static int opt_filter_hw_device(void *optctx, const char *opt, const char *arg)
513 if (filter_hw_device) {
514 av_log(NULL, AV_LOG_ERROR, "Only one filter device can be used.\n");
515 return AVERROR(EINVAL);
517 filter_hw_device = hw_device_get_by_name(arg);
518 if (!filter_hw_device) {
519 av_log(NULL, AV_LOG_ERROR, "Invalid filter device %s.\n", arg);
520 return AVERROR(EINVAL);
526 * Parse a metadata specifier passed as 'arg' parameter.
527 * @param arg metadata string to parse
528 * @param type metadata type is written here -- g(lobal)/s(tream)/c(hapter)/p(rogram)
529 * @param index for type c/p, chapter/program index is written here
530 * @param stream_spec for type s, the stream specifier is written here
532 static void parse_meta_type(char *arg, char *type, int *index, const char **stream_spec)
540 if (*(++arg) && *arg != ':') {
541 av_log(NULL, AV_LOG_FATAL, "Invalid metadata specifier %s.\n", arg);
544 *stream_spec = *arg == ':' ? arg + 1 : "";
549 *index = strtol(++arg, NULL, 0);
552 av_log(NULL, AV_LOG_FATAL, "Invalid metadata type %c.\n", *arg);
559 static int copy_metadata(char *outspec, char *inspec, AVFormatContext *oc, AVFormatContext *ic, OptionsContext *o)
561 AVDictionary **meta_in = NULL;
562 AVDictionary **meta_out = NULL;
564 char type_in, type_out;
565 const char *istream_spec = NULL, *ostream_spec = NULL;
566 int idx_in = 0, idx_out = 0;
568 parse_meta_type(inspec, &type_in, &idx_in, &istream_spec);
569 parse_meta_type(outspec, &type_out, &idx_out, &ostream_spec);
572 if (type_out == 'g' || !*outspec)
573 o->metadata_global_manual = 1;
574 if (type_out == 's' || !*outspec)
575 o->metadata_streams_manual = 1;
576 if (type_out == 'c' || !*outspec)
577 o->metadata_chapters_manual = 1;
581 if (type_in == 'g' || type_out == 'g')
582 o->metadata_global_manual = 1;
583 if (type_in == 's' || type_out == 's')
584 o->metadata_streams_manual = 1;
585 if (type_in == 'c' || type_out == 'c')
586 o->metadata_chapters_manual = 1;
588 /* ic is NULL when just disabling automatic mappings */
592 #define METADATA_CHECK_INDEX(index, nb_elems, desc)\
593 if ((index) < 0 || (index) >= (nb_elems)) {\
594 av_log(NULL, AV_LOG_FATAL, "Invalid %s index %d while processing metadata maps.\n",\
599 #define SET_DICT(type, meta, context, index)\
602 meta = &context->metadata;\
605 METADATA_CHECK_INDEX(index, context->nb_chapters, "chapter")\
606 meta = &context->chapters[index]->metadata;\
609 METADATA_CHECK_INDEX(index, context->nb_programs, "program")\
610 meta = &context->programs[index]->metadata;\
613 break; /* handled separately below */ \
614 default: av_assert0(0);\
617 SET_DICT(type_in, meta_in, ic, idx_in);
618 SET_DICT(type_out, meta_out, oc, idx_out);
620 /* for input streams choose first matching stream */
621 if (type_in == 's') {
622 for (i = 0; i < ic->nb_streams; i++) {
623 if ((ret = check_stream_specifier(ic, ic->streams[i], istream_spec)) > 0) {
624 meta_in = &ic->streams[i]->metadata;
630 av_log(NULL, AV_LOG_FATAL, "Stream specifier %s does not match any streams.\n", istream_spec);
635 if (type_out == 's') {
636 for (i = 0; i < oc->nb_streams; i++) {
637 if ((ret = check_stream_specifier(oc, oc->streams[i], ostream_spec)) > 0) {
638 meta_out = &oc->streams[i]->metadata;
639 av_dict_copy(meta_out, *meta_in, AV_DICT_DONT_OVERWRITE);
644 av_dict_copy(meta_out, *meta_in, AV_DICT_DONT_OVERWRITE);
649 static int opt_recording_timestamp(void *optctx, const char *opt, const char *arg)
651 OptionsContext *o = optctx;
653 int64_t recording_timestamp = parse_time_or_die(opt, arg, 0) / 1E6;
654 struct tm time = *gmtime((time_t*)&recording_timestamp);
655 if (!strftime(buf, sizeof(buf), "creation_time=%Y-%m-%dT%H:%M:%S%z", &time))
657 parse_option(o, "metadata", buf, options);
659 av_log(NULL, AV_LOG_WARNING, "%s is deprecated, set the 'creation_time' metadata "
660 "tag instead.\n", opt);
664 static AVCodec *find_codec_or_die(const char *name, enum AVMediaType type, int encoder)
666 const AVCodecDescriptor *desc;
667 const char *codec_string = encoder ? "encoder" : "decoder";
671 avcodec_find_encoder_by_name(name) :
672 avcodec_find_decoder_by_name(name);
674 if (!codec && (desc = avcodec_descriptor_get_by_name(name))) {
675 codec = encoder ? avcodec_find_encoder(desc->id) :
676 avcodec_find_decoder(desc->id);
678 av_log(NULL, AV_LOG_VERBOSE, "Matched %s '%s' for codec '%s'.\n",
679 codec_string, codec->name, desc->name);
683 av_log(NULL, AV_LOG_FATAL, "Unknown %s '%s'\n", codec_string, name);
686 if (codec->type != type) {
687 av_log(NULL, AV_LOG_FATAL, "Invalid %s type '%s'\n", codec_string, name);
693 static AVCodec *choose_decoder(OptionsContext *o, AVFormatContext *s, AVStream *st)
695 char *codec_name = NULL;
697 MATCH_PER_STREAM_OPT(codec_names, str, codec_name, s, st);
699 AVCodec *codec = find_codec_or_die(codec_name, st->codecpar->codec_type, 0);
700 st->codecpar->codec_id = codec->id;
703 return avcodec_find_decoder(st->codecpar->codec_id);
706 /* Add all the streams from the given input file to the global
707 * list of input streams. */
708 static void add_input_streams(OptionsContext *o, AVFormatContext *ic)
712 for (i = 0; i < ic->nb_streams; i++) {
713 AVStream *st = ic->streams[i];
714 AVCodecParameters *par = st->codecpar;
715 InputStream *ist = av_mallocz(sizeof(*ist));
716 char *framerate = NULL, *hwaccel_device = NULL;
717 const char *hwaccel = NULL;
718 char *hwaccel_output_format = NULL;
719 char *codec_tag = NULL;
721 char *discard_str = NULL;
722 const AVClass *cc = avcodec_get_class();
723 const AVOption *discard_opt = av_opt_find(&cc, "skip_frame", NULL, 0, 0);
728 GROW_ARRAY(input_streams, nb_input_streams);
729 input_streams[nb_input_streams - 1] = ist;
732 ist->file_index = nb_input_files;
734 st->discard = AVDISCARD_ALL;
736 ist->min_pts = INT64_MAX;
737 ist->max_pts = INT64_MIN;
740 MATCH_PER_STREAM_OPT(ts_scale, dbl, ist->ts_scale, ic, st);
743 MATCH_PER_STREAM_OPT(autorotate, i, ist->autorotate, ic, st);
745 MATCH_PER_STREAM_OPT(codec_tags, str, codec_tag, ic, st);
747 uint32_t tag = strtol(codec_tag, &next, 0);
749 tag = AV_RL32(codec_tag);
750 st->codecpar->codec_tag = tag;
753 ist->dec = choose_decoder(o, ic, st);
754 ist->decoder_opts = filter_codec_opts(o->g->codec_opts, ist->st->codecpar->codec_id, ic, st, ist->dec);
756 ist->reinit_filters = -1;
757 MATCH_PER_STREAM_OPT(reinit_filters, i, ist->reinit_filters, ic, st);
759 MATCH_PER_STREAM_OPT(discard, str, discard_str, ic, st);
760 ist->user_set_discard = AVDISCARD_NONE;
762 if ((o->video_disable && ist->st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) ||
763 (o->audio_disable && ist->st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) ||
764 (o->subtitle_disable && ist->st->codecpar->codec_type == AVMEDIA_TYPE_SUBTITLE) ||
765 (o->data_disable && ist->st->codecpar->codec_type == AVMEDIA_TYPE_DATA))
766 ist->user_set_discard = AVDISCARD_ALL;
768 if (discard_str && av_opt_eval_int(&cc, discard_opt, discard_str, &ist->user_set_discard) < 0) {
769 av_log(NULL, AV_LOG_ERROR, "Error parsing discard %s.\n",
774 ist->filter_in_rescale_delta_last = AV_NOPTS_VALUE;
776 ist->dec_ctx = avcodec_alloc_context3(ist->dec);
778 av_log(NULL, AV_LOG_ERROR, "Error allocating the decoder context.\n");
782 ret = avcodec_parameters_to_context(ist->dec_ctx, par);
784 av_log(NULL, AV_LOG_ERROR, "Error initializing the decoder context.\n");
789 ist->dec_ctx->flags |= AV_CODEC_FLAG_BITEXACT;
791 switch (par->codec_type) {
792 case AVMEDIA_TYPE_VIDEO:
794 ist->dec = avcodec_find_decoder(par->codec_id);
796 if (st->codec->lowres) {
797 ist->dec_ctx->lowres = st->codec->lowres;
798 ist->dec_ctx->width = st->codec->width;
799 ist->dec_ctx->height = st->codec->height;
800 ist->dec_ctx->coded_width = st->codec->coded_width;
801 ist->dec_ctx->coded_height = st->codec->coded_height;
805 // avformat_find_stream_info() doesn't set this for us anymore.
806 ist->dec_ctx->framerate = st->avg_frame_rate;
808 MATCH_PER_STREAM_OPT(frame_rates, str, framerate, ic, st);
809 if (framerate && av_parse_video_rate(&ist->framerate,
811 av_log(NULL, AV_LOG_ERROR, "Error parsing framerate %s.\n",
816 ist->top_field_first = -1;
817 MATCH_PER_STREAM_OPT(top_field_first, i, ist->top_field_first, ic, st);
819 MATCH_PER_STREAM_OPT(hwaccels, str, hwaccel, ic, st);
821 // The NVDEC hwaccels use a CUDA device, so remap the name here.
822 if (!strcmp(hwaccel, "nvdec") || !strcmp(hwaccel, "cuvid"))
825 if (!strcmp(hwaccel, "none"))
826 ist->hwaccel_id = HWACCEL_NONE;
827 else if (!strcmp(hwaccel, "auto"))
828 ist->hwaccel_id = HWACCEL_AUTO;
830 enum AVHWDeviceType type;
832 for (i = 0; hwaccels[i].name; i++) {
833 if (!strcmp(hwaccels[i].name, hwaccel)) {
834 ist->hwaccel_id = hwaccels[i].id;
839 if (!ist->hwaccel_id) {
840 type = av_hwdevice_find_type_by_name(hwaccel);
841 if (type != AV_HWDEVICE_TYPE_NONE) {
842 ist->hwaccel_id = HWACCEL_GENERIC;
843 ist->hwaccel_device_type = type;
847 if (!ist->hwaccel_id) {
848 av_log(NULL, AV_LOG_FATAL, "Unrecognized hwaccel: %s.\n",
850 av_log(NULL, AV_LOG_FATAL, "Supported hwaccels: ");
851 type = AV_HWDEVICE_TYPE_NONE;
852 while ((type = av_hwdevice_iterate_types(type)) !=
853 AV_HWDEVICE_TYPE_NONE)
854 av_log(NULL, AV_LOG_FATAL, "%s ",
855 av_hwdevice_get_type_name(type));
856 for (i = 0; hwaccels[i].name; i++)
857 av_log(NULL, AV_LOG_FATAL, "%s ", hwaccels[i].name);
858 av_log(NULL, AV_LOG_FATAL, "\n");
864 MATCH_PER_STREAM_OPT(hwaccel_devices, str, hwaccel_device, ic, st);
865 if (hwaccel_device) {
866 ist->hwaccel_device = av_strdup(hwaccel_device);
867 if (!ist->hwaccel_device)
871 MATCH_PER_STREAM_OPT(hwaccel_output_formats, str,
872 hwaccel_output_format, ic, st);
873 if (hwaccel_output_format) {
874 ist->hwaccel_output_format = av_get_pix_fmt(hwaccel_output_format);
875 if (ist->hwaccel_output_format == AV_PIX_FMT_NONE) {
876 av_log(NULL, AV_LOG_FATAL, "Unrecognised hwaccel output "
877 "format: %s", hwaccel_output_format);
880 ist->hwaccel_output_format = AV_PIX_FMT_NONE;
883 ist->hwaccel_pix_fmt = AV_PIX_FMT_NONE;
886 case AVMEDIA_TYPE_AUDIO:
887 ist->guess_layout_max = INT_MAX;
888 MATCH_PER_STREAM_OPT(guess_layout_max, i, ist->guess_layout_max, ic, st);
889 guess_input_channel_layout(ist);
891 case AVMEDIA_TYPE_DATA:
892 case AVMEDIA_TYPE_SUBTITLE: {
893 char *canvas_size = NULL;
895 ist->dec = avcodec_find_decoder(par->codec_id);
896 MATCH_PER_STREAM_OPT(fix_sub_duration, i, ist->fix_sub_duration, ic, st);
897 MATCH_PER_STREAM_OPT(canvas_sizes, str, canvas_size, ic, st);
899 av_parse_video_size(&ist->dec_ctx->width, &ist->dec_ctx->height, canvas_size) < 0) {
900 av_log(NULL, AV_LOG_FATAL, "Invalid canvas size: %s.\n", canvas_size);
905 case AVMEDIA_TYPE_ATTACHMENT:
906 case AVMEDIA_TYPE_UNKNOWN:
912 ret = avcodec_parameters_from_context(par, ist->dec_ctx);
914 av_log(NULL, AV_LOG_ERROR, "Error initializing the decoder context.\n");
920 static void assert_file_overwrite(const char *filename)
922 const char *proto_name = avio_find_protocol_name(filename);
924 if (file_overwrite && no_file_overwrite) {
925 fprintf(stderr, "Error, both -y and -n supplied. Exiting.\n");
929 if (!file_overwrite) {
930 if (proto_name && !strcmp(proto_name, "file") && avio_check(filename, 0) == 0) {
931 if (stdin_interaction && !no_file_overwrite) {
932 fprintf(stderr,"File '%s' already exists. Overwrite? [y/N] ", filename);
935 signal(SIGINT, SIG_DFL);
937 av_log(NULL, AV_LOG_FATAL, "Not overwriting - exiting\n");
943 av_log(NULL, AV_LOG_FATAL, "File '%s' already exists. Exiting.\n", filename);
949 if (proto_name && !strcmp(proto_name, "file")) {
950 for (int i = 0; i < nb_input_files; i++) {
951 InputFile *file = input_files[i];
952 if (file->ctx->iformat->flags & AVFMT_NOFILE)
954 if (!strcmp(filename, file->ctx->url)) {
955 av_log(NULL, AV_LOG_FATAL, "Output %s same as Input #%d - exiting\n", filename, i);
956 av_log(NULL, AV_LOG_WARNING, "FFmpeg cannot edit existing files in-place.\n");
963 static void dump_attachment(AVStream *st, const char *filename)
966 AVIOContext *out = NULL;
967 AVDictionaryEntry *e;
969 if (!st->codecpar->extradata_size) {
970 av_log(NULL, AV_LOG_WARNING, "No extradata to dump in stream #%d:%d.\n",
971 nb_input_files - 1, st->index);
974 if (!*filename && (e = av_dict_get(st->metadata, "filename", NULL, 0)))
977 av_log(NULL, AV_LOG_FATAL, "No filename specified and no 'filename' tag"
978 "in stream #%d:%d.\n", nb_input_files - 1, st->index);
982 assert_file_overwrite(filename);
984 if ((ret = avio_open2(&out, filename, AVIO_FLAG_WRITE, &int_cb, NULL)) < 0) {
985 av_log(NULL, AV_LOG_FATAL, "Could not open file %s for writing.\n",
990 avio_write(out, st->codecpar->extradata, st->codecpar->extradata_size);
995 static int open_input_file(OptionsContext *o, const char *filename)
999 AVInputFormat *file_iformat = NULL;
1002 AVDictionary *unused_opts = NULL;
1003 AVDictionaryEntry *e = NULL;
1004 char * video_codec_name = NULL;
1005 char * audio_codec_name = NULL;
1006 char *subtitle_codec_name = NULL;
1007 char * data_codec_name = NULL;
1008 int scan_all_pmts_set = 0;
1010 if (o->stop_time != INT64_MAX && o->recording_time != INT64_MAX) {
1011 o->stop_time = INT64_MAX;
1012 av_log(NULL, AV_LOG_WARNING, "-t and -to cannot be used together; using -t.\n");
1015 if (o->stop_time != INT64_MAX && o->recording_time == INT64_MAX) {
1016 int64_t start_time = o->start_time == AV_NOPTS_VALUE ? 0 : o->start_time;
1017 if (o->stop_time <= start_time) {
1018 av_log(NULL, AV_LOG_ERROR, "-to value smaller than -ss; aborting.\n");
1021 o->recording_time = o->stop_time - start_time;
1026 if (!(file_iformat = av_find_input_format(o->format))) {
1027 av_log(NULL, AV_LOG_FATAL, "Unknown input format: '%s'\n", o->format);
1032 if (!strcmp(filename, "-"))
1035 stdin_interaction &= strncmp(filename, "pipe:", 5) &&
1036 strcmp(filename, "/dev/stdin");
1038 /* get default parameters from command line */
1039 ic = avformat_alloc_context();
1041 print_error(filename, AVERROR(ENOMEM));
1044 if (o->nb_audio_sample_rate) {
1045 av_dict_set_int(&o->g->format_opts, "sample_rate", o->audio_sample_rate[o->nb_audio_sample_rate - 1].u.i, 0);
1047 if (o->nb_audio_channels) {
1048 /* because we set audio_channels based on both the "ac" and
1049 * "channel_layout" options, we need to check that the specified
1050 * demuxer actually has the "channels" option before setting it */
1051 if (file_iformat && file_iformat->priv_class &&
1052 av_opt_find(&file_iformat->priv_class, "channels", NULL, 0,
1053 AV_OPT_SEARCH_FAKE_OBJ)) {
1054 av_dict_set_int(&o->g->format_opts, "channels", o->audio_channels[o->nb_audio_channels - 1].u.i, 0);
1057 if (o->nb_frame_rates) {
1058 /* set the format-level framerate option;
1059 * this is important for video grabbers, e.g. x11 */
1060 if (file_iformat && file_iformat->priv_class &&
1061 av_opt_find(&file_iformat->priv_class, "framerate", NULL, 0,
1062 AV_OPT_SEARCH_FAKE_OBJ)) {
1063 av_dict_set(&o->g->format_opts, "framerate",
1064 o->frame_rates[o->nb_frame_rates - 1].u.str, 0);
1067 if (o->nb_frame_sizes) {
1068 av_dict_set(&o->g->format_opts, "video_size", o->frame_sizes[o->nb_frame_sizes - 1].u.str, 0);
1070 if (o->nb_frame_pix_fmts)
1071 av_dict_set(&o->g->format_opts, "pixel_format", o->frame_pix_fmts[o->nb_frame_pix_fmts - 1].u.str, 0);
1073 MATCH_PER_TYPE_OPT(codec_names, str, video_codec_name, ic, "v");
1074 MATCH_PER_TYPE_OPT(codec_names, str, audio_codec_name, ic, "a");
1075 MATCH_PER_TYPE_OPT(codec_names, str, subtitle_codec_name, ic, "s");
1076 MATCH_PER_TYPE_OPT(codec_names, str, data_codec_name, ic, "d");
1078 if (video_codec_name)
1079 ic->video_codec = find_codec_or_die(video_codec_name , AVMEDIA_TYPE_VIDEO , 0);
1080 if (audio_codec_name)
1081 ic->audio_codec = find_codec_or_die(audio_codec_name , AVMEDIA_TYPE_AUDIO , 0);
1082 if (subtitle_codec_name)
1083 ic->subtitle_codec = find_codec_or_die(subtitle_codec_name, AVMEDIA_TYPE_SUBTITLE, 0);
1084 if (data_codec_name)
1085 ic->data_codec = find_codec_or_die(data_codec_name , AVMEDIA_TYPE_DATA , 0);
1087 ic->video_codec_id = video_codec_name ? ic->video_codec->id : AV_CODEC_ID_NONE;
1088 ic->audio_codec_id = audio_codec_name ? ic->audio_codec->id : AV_CODEC_ID_NONE;
1089 ic->subtitle_codec_id = subtitle_codec_name ? ic->subtitle_codec->id : AV_CODEC_ID_NONE;
1090 ic->data_codec_id = data_codec_name ? ic->data_codec->id : AV_CODEC_ID_NONE;
1092 ic->flags |= AVFMT_FLAG_NONBLOCK;
1094 ic->flags |= AVFMT_FLAG_BITEXACT;
1095 ic->interrupt_callback = int_cb;
1097 if (!av_dict_get(o->g->format_opts, "scan_all_pmts", NULL, AV_DICT_MATCH_CASE)) {
1098 av_dict_set(&o->g->format_opts, "scan_all_pmts", "1", AV_DICT_DONT_OVERWRITE);
1099 scan_all_pmts_set = 1;
1101 /* open the input file with generic avformat function */
1102 err = avformat_open_input(&ic, filename, file_iformat, &o->g->format_opts);
1104 print_error(filename, err);
1105 if (err == AVERROR_PROTOCOL_NOT_FOUND)
1106 av_log(NULL, AV_LOG_ERROR, "Did you mean file:%s?\n", filename);
1109 if (scan_all_pmts_set)
1110 av_dict_set(&o->g->format_opts, "scan_all_pmts", NULL, AV_DICT_MATCH_CASE);
1111 remove_avoptions(&o->g->format_opts, o->g->codec_opts);
1112 assert_avoptions(o->g->format_opts);
1114 /* apply forced codec ids */
1115 for (i = 0; i < ic->nb_streams; i++)
1116 choose_decoder(o, ic, ic->streams[i]);
1118 if (find_stream_info) {
1119 AVDictionary **opts = setup_find_stream_info_opts(ic, o->g->codec_opts);
1120 int orig_nb_streams = ic->nb_streams;
1122 /* If not enough info to get the stream parameters, we decode the
1123 first frames to get it. (used in mpeg case for example) */
1124 ret = avformat_find_stream_info(ic, opts);
1126 for (i = 0; i < orig_nb_streams; i++)
1127 av_dict_free(&opts[i]);
1131 av_log(NULL, AV_LOG_FATAL, "%s: could not find codec parameters\n", filename);
1132 if (ic->nb_streams == 0) {
1133 avformat_close_input(&ic);
1139 if (o->start_time != AV_NOPTS_VALUE && o->start_time_eof != AV_NOPTS_VALUE) {
1140 av_log(NULL, AV_LOG_WARNING, "Cannot use -ss and -sseof both, using -ss for %s\n", filename);
1141 o->start_time_eof = AV_NOPTS_VALUE;
1144 if (o->start_time_eof != AV_NOPTS_VALUE) {
1145 if (o->start_time_eof >= 0) {
1146 av_log(NULL, AV_LOG_ERROR, "-sseof value must be negative; aborting\n");
1149 if (ic->duration > 0) {
1150 o->start_time = o->start_time_eof + ic->duration;
1151 if (o->start_time < 0) {
1152 av_log(NULL, AV_LOG_WARNING, "-sseof value seeks to before start of file %s; ignored\n", filename);
1153 o->start_time = AV_NOPTS_VALUE;
1156 av_log(NULL, AV_LOG_WARNING, "Cannot use -sseof, duration of %s not known\n", filename);
1158 timestamp = (o->start_time == AV_NOPTS_VALUE) ? 0 : o->start_time;
1159 /* add the stream start time */
1160 if (!o->seek_timestamp && ic->start_time != AV_NOPTS_VALUE)
1161 timestamp += ic->start_time;
1163 /* if seeking requested, we execute it */
1164 if (o->start_time != AV_NOPTS_VALUE) {
1165 int64_t seek_timestamp = timestamp;
1167 if (!(ic->iformat->flags & AVFMT_SEEK_TO_PTS)) {
1168 int dts_heuristic = 0;
1169 for (i=0; i<ic->nb_streams; i++) {
1170 const AVCodecParameters *par = ic->streams[i]->codecpar;
1171 if (par->video_delay) {
1176 if (dts_heuristic) {
1177 seek_timestamp -= 3*AV_TIME_BASE / 23;
1180 ret = avformat_seek_file(ic, -1, INT64_MIN, seek_timestamp, seek_timestamp, 0);
1182 av_log(NULL, AV_LOG_WARNING, "%s: could not seek to position %0.3f\n",
1183 filename, (double)timestamp / AV_TIME_BASE);
1187 /* update the current parameters so that they match the one of the input stream */
1188 add_input_streams(o, ic);
1190 /* dump the file content */
1191 av_dump_format(ic, nb_input_files, filename, 0);
1193 GROW_ARRAY(input_files, nb_input_files);
1194 f = av_mallocz(sizeof(*f));
1197 input_files[nb_input_files - 1] = f;
1200 f->ist_index = nb_input_streams - ic->nb_streams;
1201 f->start_time = o->start_time;
1202 f->recording_time = o->recording_time;
1203 f->input_ts_offset = o->input_ts_offset;
1204 f->ts_offset = o->input_ts_offset - (copy_ts ? (start_at_zero && ic->start_time != AV_NOPTS_VALUE ? ic->start_time : 0) : timestamp);
1205 f->nb_streams = ic->nb_streams;
1206 f->rate_emu = o->rate_emu;
1207 f->accurate_seek = o->accurate_seek;
1210 f->time_base = (AVRational){ 1, 1 };
1212 f->thread_queue_size = o->thread_queue_size > 0 ? o->thread_queue_size : 8;
1215 /* check if all codec options have been used */
1216 unused_opts = strip_specifiers(o->g->codec_opts);
1217 for (i = f->ist_index; i < nb_input_streams; i++) {
1219 while ((e = av_dict_get(input_streams[i]->decoder_opts, "", e,
1220 AV_DICT_IGNORE_SUFFIX)))
1221 av_dict_set(&unused_opts, e->key, NULL, 0);
1225 while ((e = av_dict_get(unused_opts, "", e, AV_DICT_IGNORE_SUFFIX))) {
1226 const AVClass *class = avcodec_get_class();
1227 const AVOption *option = av_opt_find(&class, e->key, NULL, 0,
1228 AV_OPT_SEARCH_CHILDREN | AV_OPT_SEARCH_FAKE_OBJ);
1229 const AVClass *fclass = avformat_get_class();
1230 const AVOption *foption = av_opt_find(&fclass, e->key, NULL, 0,
1231 AV_OPT_SEARCH_CHILDREN | AV_OPT_SEARCH_FAKE_OBJ);
1232 if (!option || foption)
1236 if (!(option->flags & AV_OPT_FLAG_DECODING_PARAM)) {
1237 av_log(NULL, AV_LOG_ERROR, "Codec AVOption %s (%s) specified for "
1238 "input file #%d (%s) is not a decoding option.\n", e->key,
1239 option->help ? option->help : "", nb_input_files - 1,
1244 av_log(NULL, AV_LOG_WARNING, "Codec AVOption %s (%s) specified for "
1245 "input file #%d (%s) has not been used for any stream. The most "
1246 "likely reason is either wrong type (e.g. a video option with "
1247 "no video streams) or that it is a private option of some decoder "
1248 "which was not actually used for any stream.\n", e->key,
1249 option->help ? option->help : "", nb_input_files - 1, filename);
1251 av_dict_free(&unused_opts);
1253 for (i = 0; i < o->nb_dump_attachment; i++) {
1256 for (j = 0; j < ic->nb_streams; j++) {
1257 AVStream *st = ic->streams[j];
1259 if (check_stream_specifier(ic, st, o->dump_attachment[i].specifier) == 1)
1260 dump_attachment(st, o->dump_attachment[i].u.str);
1264 input_stream_potentially_available = 1;
1269 static uint8_t *get_line(AVIOContext *s)
1275 if (avio_open_dyn_buf(&line) < 0) {
1276 av_log(NULL, AV_LOG_FATAL, "Could not alloc buffer for reading preset.\n");
1280 while ((c = avio_r8(s)) && c != '\n')
1283 avio_close_dyn_buf(line, &buf);
1288 static int get_preset_file_2(const char *preset_name, const char *codec_name, AVIOContext **s)
1291 char filename[1000];
1292 const char *base[3] = { getenv("AVCONV_DATADIR"),
1297 for (i = 0; i < FF_ARRAY_ELEMS(base) && ret < 0; i++) {
1301 snprintf(filename, sizeof(filename), "%s%s/%s-%s.avpreset", base[i],
1302 i != 1 ? "" : "/.avconv", codec_name, preset_name);
1303 ret = avio_open2(s, filename, AVIO_FLAG_READ, &int_cb, NULL);
1306 snprintf(filename, sizeof(filename), "%s%s/%s.avpreset", base[i],
1307 i != 1 ? "" : "/.avconv", preset_name);
1308 ret = avio_open2(s, filename, AVIO_FLAG_READ, &int_cb, NULL);
1314 static int choose_encoder(OptionsContext *o, AVFormatContext *s, OutputStream *ost)
1316 enum AVMediaType type = ost->st->codecpar->codec_type;
1317 char *codec_name = NULL;
1319 if (type == AVMEDIA_TYPE_VIDEO || type == AVMEDIA_TYPE_AUDIO || type == AVMEDIA_TYPE_SUBTITLE) {
1320 MATCH_PER_STREAM_OPT(codec_names, str, codec_name, s, ost->st);
1322 ost->st->codecpar->codec_id = av_guess_codec(s->oformat, NULL, s->url,
1323 NULL, ost->st->codecpar->codec_type);
1324 ost->enc = avcodec_find_encoder(ost->st->codecpar->codec_id);
1326 av_log(NULL, AV_LOG_FATAL, "Automatic encoder selection failed for "
1327 "output stream #%d:%d. Default encoder for format %s (codec %s) is "
1328 "probably disabled. Please choose an encoder manually.\n",
1329 ost->file_index, ost->index, s->oformat->name,
1330 avcodec_get_name(ost->st->codecpar->codec_id));
1331 return AVERROR_ENCODER_NOT_FOUND;
1333 } else if (!strcmp(codec_name, "copy"))
1334 ost->stream_copy = 1;
1336 ost->enc = find_codec_or_die(codec_name, ost->st->codecpar->codec_type, 1);
1337 ost->st->codecpar->codec_id = ost->enc->id;
1339 ost->encoding_needed = !ost->stream_copy;
1341 /* no encoding supported for other media types */
1342 ost->stream_copy = 1;
1343 ost->encoding_needed = 0;
1349 static OutputStream *new_output_stream(OptionsContext *o, AVFormatContext *oc, enum AVMediaType type, int source_index)
1352 AVStream *st = avformat_new_stream(oc, NULL);
1353 int idx = oc->nb_streams - 1, ret = 0;
1354 const char *bsfs = NULL, *time_base = NULL;
1355 char *next, *codec_tag = NULL;
1360 av_log(NULL, AV_LOG_FATAL, "Could not alloc stream.\n");
1364 if (oc->nb_streams - 1 < o->nb_streamid_map)
1365 st->id = o->streamid_map[oc->nb_streams - 1];
1367 GROW_ARRAY(output_streams, nb_output_streams);
1368 if (!(ost = av_mallocz(sizeof(*ost))))
1370 output_streams[nb_output_streams - 1] = ost;
1372 ost->file_index = nb_output_files - 1;
1375 ost->forced_kf_ref_pts = AV_NOPTS_VALUE;
1376 st->codecpar->codec_type = type;
1378 ret = choose_encoder(o, oc, ost);
1380 av_log(NULL, AV_LOG_FATAL, "Error selecting an encoder for stream "
1381 "%d:%d\n", ost->file_index, ost->index);
1385 ost->enc_ctx = avcodec_alloc_context3(ost->enc);
1386 if (!ost->enc_ctx) {
1387 av_log(NULL, AV_LOG_ERROR, "Error allocating the encoding context.\n");
1390 ost->enc_ctx->codec_type = type;
1392 ost->ref_par = avcodec_parameters_alloc();
1393 if (!ost->ref_par) {
1394 av_log(NULL, AV_LOG_ERROR, "Error allocating the encoding parameters.\n");
1399 AVIOContext *s = NULL;
1400 char *buf = NULL, *arg = NULL, *preset = NULL;
1402 ost->encoder_opts = filter_codec_opts(o->g->codec_opts, ost->enc->id, oc, st, ost->enc);
1404 MATCH_PER_STREAM_OPT(presets, str, preset, oc, st);
1405 if (preset && (!(ret = get_preset_file_2(preset, ost->enc->name, &s)))) {
1408 if (!buf[0] || buf[0] == '#') {
1412 if (!(arg = strchr(buf, '='))) {
1413 av_log(NULL, AV_LOG_FATAL, "Invalid line found in the preset file.\n");
1417 av_dict_set(&ost->encoder_opts, buf, arg, AV_DICT_DONT_OVERWRITE);
1419 } while (!s->eof_reached);
1423 av_log(NULL, AV_LOG_FATAL,
1424 "Preset %s specified for stream %d:%d, but could not be opened.\n",
1425 preset, ost->file_index, ost->index);
1429 ost->encoder_opts = filter_codec_opts(o->g->codec_opts, AV_CODEC_ID_NONE, oc, st, NULL);
1434 ost->enc_ctx->flags |= AV_CODEC_FLAG_BITEXACT;
1436 MATCH_PER_STREAM_OPT(time_bases, str, time_base, oc, st);
1439 if (av_parse_ratio(&q, time_base, INT_MAX, 0, NULL) < 0 ||
1440 q.num <= 0 || q.den <= 0) {
1441 av_log(NULL, AV_LOG_FATAL, "Invalid time base: %s\n", time_base);
1447 MATCH_PER_STREAM_OPT(enc_time_bases, str, time_base, oc, st);
1450 if (av_parse_ratio(&q, time_base, INT_MAX, 0, NULL) < 0 ||
1452 av_log(NULL, AV_LOG_FATAL, "Invalid time base: %s\n", time_base);
1455 ost->enc_timebase = q;
1458 ost->max_frames = INT64_MAX;
1459 MATCH_PER_STREAM_OPT(max_frames, i64, ost->max_frames, oc, st);
1460 for (i = 0; i<o->nb_max_frames; i++) {
1461 char *p = o->max_frames[i].specifier;
1462 if (!*p && type != AVMEDIA_TYPE_VIDEO) {
1463 av_log(NULL, AV_LOG_WARNING, "Applying unspecific -frames to non video streams, maybe you meant -vframes ?\n");
1468 ost->copy_prior_start = -1;
1469 MATCH_PER_STREAM_OPT(copy_prior_start, i, ost->copy_prior_start, oc ,st);
1471 MATCH_PER_STREAM_OPT(bitstream_filters, str, bsfs, oc, st);
1472 while (bsfs && *bsfs) {
1473 const AVBitStreamFilter *filter;
1474 char *bsf, *bsf_options_str, *bsf_name;
1476 bsf = av_get_token(&bsfs, ",");
1479 bsf_name = av_strtok(bsf, "=", &bsf_options_str);
1483 filter = av_bsf_get_by_name(bsf_name);
1485 av_log(NULL, AV_LOG_FATAL, "Unknown bitstream filter %s\n", bsf_name);
1489 ost->bsf_ctx = av_realloc_array(ost->bsf_ctx,
1490 ost->nb_bitstream_filters + 1,
1491 sizeof(*ost->bsf_ctx));
1495 ret = av_bsf_alloc(filter, &ost->bsf_ctx[ost->nb_bitstream_filters]);
1497 av_log(NULL, AV_LOG_ERROR, "Error allocating a bitstream filter context\n");
1501 ost->nb_bitstream_filters++;
1503 if (bsf_options_str && filter->priv_class) {
1504 const AVOption *opt = av_opt_next(ost->bsf_ctx[ost->nb_bitstream_filters-1]->priv_data, NULL);
1505 const char * shorthand[2] = {NULL};
1508 shorthand[0] = opt->name;
1510 ret = av_opt_set_from_string(ost->bsf_ctx[ost->nb_bitstream_filters-1]->priv_data, bsf_options_str, shorthand, "=", ":");
1512 av_log(NULL, AV_LOG_ERROR, "Error parsing options for bitstream filter %s\n", bsf_name);
1522 MATCH_PER_STREAM_OPT(codec_tags, str, codec_tag, oc, st);
1524 uint32_t tag = strtol(codec_tag, &next, 0);
1526 tag = AV_RL32(codec_tag);
1527 ost->st->codecpar->codec_tag =
1528 ost->enc_ctx->codec_tag = tag;
1531 MATCH_PER_STREAM_OPT(qscale, dbl, qscale, oc, st);
1533 ost->enc_ctx->flags |= AV_CODEC_FLAG_QSCALE;
1534 ost->enc_ctx->global_quality = FF_QP2LAMBDA * qscale;
1537 MATCH_PER_STREAM_OPT(disposition, str, ost->disposition, oc, st);
1538 ost->disposition = av_strdup(ost->disposition);
1540 ost->max_muxing_queue_size = 128;
1541 MATCH_PER_STREAM_OPT(max_muxing_queue_size, i, ost->max_muxing_queue_size, oc, st);
1542 ost->max_muxing_queue_size *= sizeof(AVPacket);
1544 if (oc->oformat->flags & AVFMT_GLOBALHEADER)
1545 ost->enc_ctx->flags |= AV_CODEC_FLAG_GLOBAL_HEADER;
1547 av_dict_copy(&ost->sws_dict, o->g->sws_dict, 0);
1549 av_dict_copy(&ost->swr_opts, o->g->swr_opts, 0);
1550 if (ost->enc && av_get_exact_bits_per_sample(ost->enc->id) == 24)
1551 av_dict_set(&ost->swr_opts, "output_sample_bits", "24", 0);
1553 av_dict_copy(&ost->resample_opts, o->g->resample_opts, 0);
1555 ost->source_index = source_index;
1556 if (source_index >= 0) {
1557 ost->sync_ist = input_streams[source_index];
1558 input_streams[source_index]->discard = 0;
1559 input_streams[source_index]->st->discard = input_streams[source_index]->user_set_discard;
1561 ost->last_mux_dts = AV_NOPTS_VALUE;
1563 ost->muxing_queue = av_fifo_alloc(8 * sizeof(AVPacket));
1564 if (!ost->muxing_queue)
1570 static void parse_matrix_coeffs(uint16_t *dest, const char *str)
1573 const char *p = str;
1580 av_log(NULL, AV_LOG_FATAL, "Syntax error in matrix \"%s\" at coeff %d\n", str, i);
1587 /* read file contents into a string */
1588 static uint8_t *read_file(const char *filename)
1590 AVIOContext *pb = NULL;
1591 AVIOContext *dyn_buf = NULL;
1592 int ret = avio_open(&pb, filename, AVIO_FLAG_READ);
1593 uint8_t buf[1024], *str;
1596 av_log(NULL, AV_LOG_ERROR, "Error opening file %s.\n", filename);
1600 ret = avio_open_dyn_buf(&dyn_buf);
1605 while ((ret = avio_read(pb, buf, sizeof(buf))) > 0)
1606 avio_write(dyn_buf, buf, ret);
1607 avio_w8(dyn_buf, 0);
1610 ret = avio_close_dyn_buf(dyn_buf, &str);
1616 static char *get_ost_filters(OptionsContext *o, AVFormatContext *oc,
1619 AVStream *st = ost->st;
1621 if (ost->filters_script && ost->filters) {
1622 av_log(NULL, AV_LOG_ERROR, "Both -filter and -filter_script set for "
1623 "output stream #%d:%d.\n", nb_output_files, st->index);
1627 if (ost->filters_script)
1628 return read_file(ost->filters_script);
1629 else if (ost->filters)
1630 return av_strdup(ost->filters);
1632 return av_strdup(st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO ?
1636 static void check_streamcopy_filters(OptionsContext *o, AVFormatContext *oc,
1637 const OutputStream *ost, enum AVMediaType type)
1639 if (ost->filters_script || ost->filters) {
1640 av_log(NULL, AV_LOG_ERROR,
1641 "%s '%s' was defined for %s output stream %d:%d but codec copy was selected.\n"
1642 "Filtering and streamcopy cannot be used together.\n",
1643 ost->filters ? "Filtergraph" : "Filtergraph script",
1644 ost->filters ? ost->filters : ost->filters_script,
1645 av_get_media_type_string(type), ost->file_index, ost->index);
1650 static OutputStream *new_video_stream(OptionsContext *o, AVFormatContext *oc, int source_index)
1654 AVCodecContext *video_enc;
1655 char *frame_rate = NULL, *frame_aspect_ratio = NULL;
1657 ost = new_output_stream(o, oc, AVMEDIA_TYPE_VIDEO, source_index);
1659 video_enc = ost->enc_ctx;
1661 MATCH_PER_STREAM_OPT(frame_rates, str, frame_rate, oc, st);
1662 if (frame_rate && av_parse_video_rate(&ost->frame_rate, frame_rate) < 0) {
1663 av_log(NULL, AV_LOG_FATAL, "Invalid framerate value: %s\n", frame_rate);
1666 if (frame_rate && video_sync_method == VSYNC_PASSTHROUGH)
1667 av_log(NULL, AV_LOG_ERROR, "Using -vsync 0 and -r can produce invalid output files\n");
1669 MATCH_PER_STREAM_OPT(frame_aspect_ratios, str, frame_aspect_ratio, oc, st);
1670 if (frame_aspect_ratio) {
1672 if (av_parse_ratio(&q, frame_aspect_ratio, 255, 0, NULL) < 0 ||
1673 q.num <= 0 || q.den <= 0) {
1674 av_log(NULL, AV_LOG_FATAL, "Invalid aspect ratio: %s\n", frame_aspect_ratio);
1677 ost->frame_aspect_ratio = q;
1680 MATCH_PER_STREAM_OPT(filter_scripts, str, ost->filters_script, oc, st);
1681 MATCH_PER_STREAM_OPT(filters, str, ost->filters, oc, st);
1682 if (o->nb_filters > 1)
1683 av_log(NULL, AV_LOG_ERROR, "Only '-vf %s' read, ignoring remaining -vf options: Use ',' to separate filters\n", ost->filters);
1685 if (!ost->stream_copy) {
1686 const char *p = NULL;
1687 char *frame_size = NULL;
1688 char *frame_pix_fmt = NULL;
1689 char *intra_matrix = NULL, *inter_matrix = NULL;
1690 char *chroma_intra_matrix = NULL;
1694 MATCH_PER_STREAM_OPT(frame_sizes, str, frame_size, oc, st);
1695 if (frame_size && av_parse_video_size(&video_enc->width, &video_enc->height, frame_size) < 0) {
1696 av_log(NULL, AV_LOG_FATAL, "Invalid frame size: %s.\n", frame_size);
1700 video_enc->bits_per_raw_sample = frame_bits_per_raw_sample;
1701 MATCH_PER_STREAM_OPT(frame_pix_fmts, str, frame_pix_fmt, oc, st);
1702 if (frame_pix_fmt && *frame_pix_fmt == '+') {
1703 ost->keep_pix_fmt = 1;
1704 if (!*++frame_pix_fmt)
1705 frame_pix_fmt = NULL;
1707 if (frame_pix_fmt && (video_enc->pix_fmt = av_get_pix_fmt(frame_pix_fmt)) == AV_PIX_FMT_NONE) {
1708 av_log(NULL, AV_LOG_FATAL, "Unknown pixel format requested: %s.\n", frame_pix_fmt);
1711 st->sample_aspect_ratio = video_enc->sample_aspect_ratio;
1714 video_enc->gop_size = 0;
1715 MATCH_PER_STREAM_OPT(intra_matrices, str, intra_matrix, oc, st);
1717 if (!(video_enc->intra_matrix = av_mallocz(sizeof(*video_enc->intra_matrix) * 64))) {
1718 av_log(NULL, AV_LOG_FATAL, "Could not allocate memory for intra matrix.\n");
1721 parse_matrix_coeffs(video_enc->intra_matrix, intra_matrix);
1723 MATCH_PER_STREAM_OPT(chroma_intra_matrices, str, chroma_intra_matrix, oc, st);
1724 if (chroma_intra_matrix) {
1725 uint16_t *p = av_mallocz(sizeof(*video_enc->chroma_intra_matrix) * 64);
1727 av_log(NULL, AV_LOG_FATAL, "Could not allocate memory for intra matrix.\n");
1730 video_enc->chroma_intra_matrix = p;
1731 parse_matrix_coeffs(p, chroma_intra_matrix);
1733 MATCH_PER_STREAM_OPT(inter_matrices, str, inter_matrix, oc, st);
1735 if (!(video_enc->inter_matrix = av_mallocz(sizeof(*video_enc->inter_matrix) * 64))) {
1736 av_log(NULL, AV_LOG_FATAL, "Could not allocate memory for inter matrix.\n");
1739 parse_matrix_coeffs(video_enc->inter_matrix, inter_matrix);
1742 MATCH_PER_STREAM_OPT(rc_overrides, str, p, oc, st);
1743 for (i = 0; p; i++) {
1745 int e = sscanf(p, "%d,%d,%d", &start, &end, &q);
1747 av_log(NULL, AV_LOG_FATAL, "error parsing rc_override\n");
1750 video_enc->rc_override =
1751 av_realloc_array(video_enc->rc_override,
1752 i + 1, sizeof(RcOverride));
1753 if (!video_enc->rc_override) {
1754 av_log(NULL, AV_LOG_FATAL, "Could not (re)allocate memory for rc_override.\n");
1757 video_enc->rc_override[i].start_frame = start;
1758 video_enc->rc_override[i].end_frame = end;
1760 video_enc->rc_override[i].qscale = q;
1761 video_enc->rc_override[i].quality_factor = 1.0;
1764 video_enc->rc_override[i].qscale = 0;
1765 video_enc->rc_override[i].quality_factor = -q/100.0;
1770 video_enc->rc_override_count = i;
1773 video_enc->flags|= AV_CODEC_FLAG_PSNR;
1776 MATCH_PER_STREAM_OPT(pass, i, do_pass, oc, st);
1779 video_enc->flags |= AV_CODEC_FLAG_PASS1;
1780 av_dict_set(&ost->encoder_opts, "flags", "+pass1", AV_DICT_APPEND);
1783 video_enc->flags |= AV_CODEC_FLAG_PASS2;
1784 av_dict_set(&ost->encoder_opts, "flags", "+pass2", AV_DICT_APPEND);
1788 MATCH_PER_STREAM_OPT(passlogfiles, str, ost->logfile_prefix, oc, st);
1789 if (ost->logfile_prefix &&
1790 !(ost->logfile_prefix = av_strdup(ost->logfile_prefix)))
1794 char logfilename[1024];
1797 snprintf(logfilename, sizeof(logfilename), "%s-%d.log",
1798 ost->logfile_prefix ? ost->logfile_prefix :
1799 DEFAULT_PASS_LOGFILENAME_PREFIX,
1801 if (!strcmp(ost->enc->name, "libx264")) {
1802 av_dict_set(&ost->encoder_opts, "stats", logfilename, AV_DICT_DONT_OVERWRITE);
1804 if (video_enc->flags & AV_CODEC_FLAG_PASS2) {
1805 char *logbuffer = read_file(logfilename);
1808 av_log(NULL, AV_LOG_FATAL, "Error reading log file '%s' for pass-2 encoding\n",
1812 video_enc->stats_in = logbuffer;
1814 if (video_enc->flags & AV_CODEC_FLAG_PASS1) {
1815 f = av_fopen_utf8(logfilename, "wb");
1817 av_log(NULL, AV_LOG_FATAL,
1818 "Cannot write log file '%s' for pass-1 encoding: %s\n",
1819 logfilename, strerror(errno));
1827 MATCH_PER_STREAM_OPT(forced_key_frames, str, ost->forced_keyframes, oc, st);
1828 if (ost->forced_keyframes)
1829 ost->forced_keyframes = av_strdup(ost->forced_keyframes);
1831 MATCH_PER_STREAM_OPT(force_fps, i, ost->force_fps, oc, st);
1833 ost->top_field_first = -1;
1834 MATCH_PER_STREAM_OPT(top_field_first, i, ost->top_field_first, oc, st);
1837 ost->avfilter = get_ost_filters(o, oc, ost);
1841 MATCH_PER_STREAM_OPT(copy_initial_nonkeyframes, i, ost->copy_initial_nonkeyframes, oc ,st);
1844 if (ost->stream_copy)
1845 check_streamcopy_filters(o, oc, ost, AVMEDIA_TYPE_VIDEO);
1850 static OutputStream *new_audio_stream(OptionsContext *o, AVFormatContext *oc, int source_index)
1855 AVCodecContext *audio_enc;
1857 ost = new_output_stream(o, oc, AVMEDIA_TYPE_AUDIO, source_index);
1860 audio_enc = ost->enc_ctx;
1861 audio_enc->codec_type = AVMEDIA_TYPE_AUDIO;
1863 MATCH_PER_STREAM_OPT(filter_scripts, str, ost->filters_script, oc, st);
1864 MATCH_PER_STREAM_OPT(filters, str, ost->filters, oc, st);
1865 if (o->nb_filters > 1)
1866 av_log(NULL, AV_LOG_ERROR, "Only '-af %s' read, ignoring remaining -af options: Use ',' to separate filters\n", ost->filters);
1868 if (!ost->stream_copy) {
1869 char *sample_fmt = NULL;
1871 MATCH_PER_STREAM_OPT(audio_channels, i, audio_enc->channels, oc, st);
1873 MATCH_PER_STREAM_OPT(sample_fmts, str, sample_fmt, oc, st);
1875 (audio_enc->sample_fmt = av_get_sample_fmt(sample_fmt)) == AV_SAMPLE_FMT_NONE) {
1876 av_log(NULL, AV_LOG_FATAL, "Invalid sample format '%s'\n", sample_fmt);
1880 MATCH_PER_STREAM_OPT(audio_sample_rate, i, audio_enc->sample_rate, oc, st);
1882 MATCH_PER_STREAM_OPT(apad, str, ost->apad, oc, st);
1883 ost->apad = av_strdup(ost->apad);
1885 ost->avfilter = get_ost_filters(o, oc, ost);
1889 /* check for channel mapping for this audio stream */
1890 for (n = 0; n < o->nb_audio_channel_maps; n++) {
1891 AudioChannelMap *map = &o->audio_channel_maps[n];
1892 if ((map->ofile_idx == -1 || ost->file_index == map->ofile_idx) &&
1893 (map->ostream_idx == -1 || ost->st->index == map->ostream_idx)) {
1896 if (map->channel_idx == -1) {
1898 } else if (ost->source_index < 0) {
1899 av_log(NULL, AV_LOG_FATAL, "Cannot determine input stream for channel mapping %d.%d\n",
1900 ost->file_index, ost->st->index);
1903 ist = input_streams[ost->source_index];
1906 if (!ist || (ist->file_index == map->file_idx && ist->st->index == map->stream_idx)) {
1907 if (av_reallocp_array(&ost->audio_channels_map,
1908 ost->audio_channels_mapped + 1,
1909 sizeof(*ost->audio_channels_map)
1913 ost->audio_channels_map[ost->audio_channels_mapped++] = map->channel_idx;
1919 if (ost->stream_copy)
1920 check_streamcopy_filters(o, oc, ost, AVMEDIA_TYPE_AUDIO);
1925 static OutputStream *new_data_stream(OptionsContext *o, AVFormatContext *oc, int source_index)
1929 ost = new_output_stream(o, oc, AVMEDIA_TYPE_DATA, source_index);
1930 if (!ost->stream_copy) {
1931 av_log(NULL, AV_LOG_FATAL, "Data stream encoding not supported yet (only streamcopy)\n");
1938 static OutputStream *new_unknown_stream(OptionsContext *o, AVFormatContext *oc, int source_index)
1942 ost = new_output_stream(o, oc, AVMEDIA_TYPE_UNKNOWN, source_index);
1943 if (!ost->stream_copy) {
1944 av_log(NULL, AV_LOG_FATAL, "Unknown stream encoding not supported yet (only streamcopy)\n");
1951 static OutputStream *new_attachment_stream(OptionsContext *o, AVFormatContext *oc, int source_index)
1953 OutputStream *ost = new_output_stream(o, oc, AVMEDIA_TYPE_ATTACHMENT, source_index);
1954 ost->stream_copy = 1;
1959 static OutputStream *new_subtitle_stream(OptionsContext *o, AVFormatContext *oc, int source_index)
1963 AVCodecContext *subtitle_enc;
1965 ost = new_output_stream(o, oc, AVMEDIA_TYPE_SUBTITLE, source_index);
1967 subtitle_enc = ost->enc_ctx;
1969 subtitle_enc->codec_type = AVMEDIA_TYPE_SUBTITLE;
1971 MATCH_PER_STREAM_OPT(copy_initial_nonkeyframes, i, ost->copy_initial_nonkeyframes, oc, st);
1973 if (!ost->stream_copy) {
1974 char *frame_size = NULL;
1976 MATCH_PER_STREAM_OPT(frame_sizes, str, frame_size, oc, st);
1977 if (frame_size && av_parse_video_size(&subtitle_enc->width, &subtitle_enc->height, frame_size) < 0) {
1978 av_log(NULL, AV_LOG_FATAL, "Invalid frame size: %s.\n", frame_size);
1986 /* arg format is "output-stream-index:streamid-value". */
1987 static int opt_streamid(void *optctx, const char *opt, const char *arg)
1989 OptionsContext *o = optctx;
1994 av_strlcpy(idx_str, arg, sizeof(idx_str));
1995 p = strchr(idx_str, ':');
1997 av_log(NULL, AV_LOG_FATAL,
1998 "Invalid value '%s' for option '%s', required syntax is 'index:value'\n",
2003 idx = parse_number_or_die(opt, idx_str, OPT_INT, 0, MAX_STREAMS-1);
2004 o->streamid_map = grow_array(o->streamid_map, sizeof(*o->streamid_map), &o->nb_streamid_map, idx+1);
2005 o->streamid_map[idx] = parse_number_or_die(opt, p, OPT_INT, 0, INT_MAX);
2009 static int copy_chapters(InputFile *ifile, OutputFile *ofile, int copy_metadata)
2011 AVFormatContext *is = ifile->ctx;
2012 AVFormatContext *os = ofile->ctx;
2016 tmp = av_realloc_f(os->chapters, is->nb_chapters + os->nb_chapters, sizeof(*os->chapters));
2018 return AVERROR(ENOMEM);
2021 for (i = 0; i < is->nb_chapters; i++) {
2022 AVChapter *in_ch = is->chapters[i], *out_ch;
2023 int64_t start_time = (ofile->start_time == AV_NOPTS_VALUE) ? 0 : ofile->start_time;
2024 int64_t ts_off = av_rescale_q(start_time - ifile->ts_offset,
2025 AV_TIME_BASE_Q, in_ch->time_base);
2026 int64_t rt = (ofile->recording_time == INT64_MAX) ? INT64_MAX :
2027 av_rescale_q(ofile->recording_time, AV_TIME_BASE_Q, in_ch->time_base);
2030 if (in_ch->end < ts_off)
2032 if (rt != INT64_MAX && in_ch->start > rt + ts_off)
2035 out_ch = av_mallocz(sizeof(AVChapter));
2037 return AVERROR(ENOMEM);
2039 out_ch->id = in_ch->id;
2040 out_ch->time_base = in_ch->time_base;
2041 out_ch->start = FFMAX(0, in_ch->start - ts_off);
2042 out_ch->end = FFMIN(rt, in_ch->end - ts_off);
2045 av_dict_copy(&out_ch->metadata, in_ch->metadata, 0);
2047 os->chapters[os->nb_chapters++] = out_ch;
2052 static void init_output_filter(OutputFilter *ofilter, OptionsContext *o,
2053 AVFormatContext *oc)
2057 switch (ofilter->type) {
2058 case AVMEDIA_TYPE_VIDEO: ost = new_video_stream(o, oc, -1); break;
2059 case AVMEDIA_TYPE_AUDIO: ost = new_audio_stream(o, oc, -1); break;
2061 av_log(NULL, AV_LOG_FATAL, "Only video and audio filters are supported "
2066 ost->source_index = -1;
2067 ost->filter = ofilter;
2070 ofilter->format = -1;
2072 if (ost->stream_copy) {
2073 av_log(NULL, AV_LOG_ERROR, "Streamcopy requested for output stream %d:%d, "
2074 "which is fed from a complex filtergraph. Filtering and streamcopy "
2075 "cannot be used together.\n", ost->file_index, ost->index);
2079 if (ost->avfilter && (ost->filters || ost->filters_script)) {
2080 const char *opt = ost->filters ? "-vf/-af/-filter" : "-filter_script";
2081 av_log(NULL, AV_LOG_ERROR,
2082 "%s '%s' was specified through the %s option "
2083 "for output stream %d:%d, which is fed from a complex filtergraph.\n"
2084 "%s and -filter_complex cannot be used together for the same stream.\n",
2085 ost->filters ? "Filtergraph" : "Filtergraph script",
2086 ost->filters ? ost->filters : ost->filters_script,
2087 opt, ost->file_index, ost->index, opt);
2091 avfilter_inout_free(&ofilter->out_tmp);
2094 static int init_complex_filters(void)
2098 for (i = 0; i < nb_filtergraphs; i++) {
2099 ret = init_complex_filtergraph(filtergraphs[i]);
2106 static int open_output_file(OptionsContext *o, const char *filename)
2108 AVFormatContext *oc;
2113 AVDictionary *unused_opts = NULL;
2114 AVDictionaryEntry *e = NULL;
2115 int format_flags = 0;
2117 if (o->stop_time != INT64_MAX && o->recording_time != INT64_MAX) {
2118 o->stop_time = INT64_MAX;
2119 av_log(NULL, AV_LOG_WARNING, "-t and -to cannot be used together; using -t.\n");
2122 if (o->stop_time != INT64_MAX && o->recording_time == INT64_MAX) {
2123 int64_t start_time = o->start_time == AV_NOPTS_VALUE ? 0 : o->start_time;
2124 if (o->stop_time <= start_time) {
2125 av_log(NULL, AV_LOG_ERROR, "-to value smaller than -ss; aborting.\n");
2128 o->recording_time = o->stop_time - start_time;
2132 GROW_ARRAY(output_files, nb_output_files);
2133 of = av_mallocz(sizeof(*of));
2136 output_files[nb_output_files - 1] = of;
2138 of->ost_index = nb_output_streams;
2139 of->recording_time = o->recording_time;
2140 of->start_time = o->start_time;
2141 of->limit_filesize = o->limit_filesize;
2142 of->shortest = o->shortest;
2143 av_dict_copy(&of->opts, o->g->format_opts, 0);
2145 if (!strcmp(filename, "-"))
2148 err = avformat_alloc_output_context2(&oc, NULL, o->format, filename);
2150 print_error(filename, err);
2155 if (o->recording_time != INT64_MAX)
2156 oc->duration = o->recording_time;
2158 oc->interrupt_callback = int_cb;
2160 e = av_dict_get(o->g->format_opts, "fflags", NULL, 0);
2162 const AVOption *o = av_opt_find(oc, "fflags", NULL, 0, 0);
2163 av_opt_eval_flags(oc, o, e->value, &format_flags);
2166 format_flags |= AVFMT_FLAG_BITEXACT;
2167 oc->flags |= AVFMT_FLAG_BITEXACT;
2170 /* create streams for all unlabeled output pads */
2171 for (i = 0; i < nb_filtergraphs; i++) {
2172 FilterGraph *fg = filtergraphs[i];
2173 for (j = 0; j < fg->nb_outputs; j++) {
2174 OutputFilter *ofilter = fg->outputs[j];
2176 if (!ofilter->out_tmp || ofilter->out_tmp->name)
2179 switch (ofilter->type) {
2180 case AVMEDIA_TYPE_VIDEO: o->video_disable = 1; break;
2181 case AVMEDIA_TYPE_AUDIO: o->audio_disable = 1; break;
2182 case AVMEDIA_TYPE_SUBTITLE: o->subtitle_disable = 1; break;
2184 init_output_filter(ofilter, o, oc);
2188 if (!o->nb_stream_maps) {
2189 char *subtitle_codec_name = NULL;
2190 /* pick the "best" stream of each type */
2192 /* video: highest resolution */
2193 if (!o->video_disable && av_guess_codec(oc->oformat, NULL, filename, NULL, AVMEDIA_TYPE_VIDEO) != AV_CODEC_ID_NONE) {
2194 int area = 0, idx = -1;
2195 int qcr = avformat_query_codec(oc->oformat, oc->oformat->video_codec, 0);
2196 for (i = 0; i < nb_input_streams; i++) {
2198 ist = input_streams[i];
2199 new_area = ist->st->codecpar->width * ist->st->codecpar->height + 100000000*!!ist->st->codec_info_nb_frames
2200 + 5000000*!!(ist->st->disposition & AV_DISPOSITION_DEFAULT);
2201 if (ist->user_set_discard == AVDISCARD_ALL)
2203 if((qcr!=MKTAG('A', 'P', 'I', 'C')) && (ist->st->disposition & AV_DISPOSITION_ATTACHED_PIC))
2205 if (ist->st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO &&
2207 if((qcr==MKTAG('A', 'P', 'I', 'C')) && !(ist->st->disposition & AV_DISPOSITION_ATTACHED_PIC))
2214 new_video_stream(o, oc, idx);
2217 /* audio: most channels */
2218 if (!o->audio_disable && av_guess_codec(oc->oformat, NULL, filename, NULL, AVMEDIA_TYPE_AUDIO) != AV_CODEC_ID_NONE) {
2219 int best_score = 0, idx = -1;
2220 for (i = 0; i < nb_input_streams; i++) {
2222 ist = input_streams[i];
2223 score = ist->st->codecpar->channels + 100000000*!!ist->st->codec_info_nb_frames
2224 + 5000000*!!(ist->st->disposition & AV_DISPOSITION_DEFAULT);
2225 if (ist->user_set_discard == AVDISCARD_ALL)
2227 if (ist->st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO &&
2228 score > best_score) {
2234 new_audio_stream(o, oc, idx);
2237 /* subtitles: pick first */
2238 MATCH_PER_TYPE_OPT(codec_names, str, subtitle_codec_name, oc, "s");
2239 if (!o->subtitle_disable && (avcodec_find_encoder(oc->oformat->subtitle_codec) || subtitle_codec_name)) {
2240 for (i = 0; i < nb_input_streams; i++)
2241 if (input_streams[i]->st->codecpar->codec_type == AVMEDIA_TYPE_SUBTITLE) {
2242 AVCodecDescriptor const *input_descriptor =
2243 avcodec_descriptor_get(input_streams[i]->st->codecpar->codec_id);
2244 AVCodecDescriptor const *output_descriptor = NULL;
2245 AVCodec const *output_codec =
2246 avcodec_find_encoder(oc->oformat->subtitle_codec);
2247 int input_props = 0, output_props = 0;
2248 if (input_streams[i]->user_set_discard == AVDISCARD_ALL)
2251 output_descriptor = avcodec_descriptor_get(output_codec->id);
2252 if (input_descriptor)
2253 input_props = input_descriptor->props & (AV_CODEC_PROP_TEXT_SUB | AV_CODEC_PROP_BITMAP_SUB);
2254 if (output_descriptor)
2255 output_props = output_descriptor->props & (AV_CODEC_PROP_TEXT_SUB | AV_CODEC_PROP_BITMAP_SUB);
2256 if (subtitle_codec_name ||
2257 input_props & output_props ||
2258 // Map dvb teletext which has neither property to any output subtitle encoder
2259 input_descriptor && output_descriptor &&
2260 (!input_descriptor->props ||
2261 !output_descriptor->props)) {
2262 new_subtitle_stream(o, oc, i);
2267 /* Data only if codec id match */
2268 if (!o->data_disable ) {
2269 enum AVCodecID codec_id = av_guess_codec(oc->oformat, NULL, filename, NULL, AVMEDIA_TYPE_DATA);
2270 for (i = 0; codec_id != AV_CODEC_ID_NONE && i < nb_input_streams; i++) {
2271 if (input_streams[i]->user_set_discard == AVDISCARD_ALL)
2273 if (input_streams[i]->st->codecpar->codec_type == AVMEDIA_TYPE_DATA
2274 && input_streams[i]->st->codecpar->codec_id == codec_id )
2275 new_data_stream(o, oc, i);
2279 for (i = 0; i < o->nb_stream_maps; i++) {
2280 StreamMap *map = &o->stream_maps[i];
2285 if (map->linklabel) {
2287 OutputFilter *ofilter = NULL;
2290 for (j = 0; j < nb_filtergraphs; j++) {
2291 fg = filtergraphs[j];
2292 for (k = 0; k < fg->nb_outputs; k++) {
2293 AVFilterInOut *out = fg->outputs[k]->out_tmp;
2294 if (out && !strcmp(out->name, map->linklabel)) {
2295 ofilter = fg->outputs[k];
2302 av_log(NULL, AV_LOG_FATAL, "Output with label '%s' does not exist "
2303 "in any defined filter graph, or was already used elsewhere.\n", map->linklabel);
2306 init_output_filter(ofilter, o, oc);
2308 int src_idx = input_files[map->file_index]->ist_index + map->stream_index;
2310 ist = input_streams[input_files[map->file_index]->ist_index + map->stream_index];
2311 if (ist->user_set_discard == AVDISCARD_ALL) {
2312 av_log(NULL, AV_LOG_FATAL, "Stream #%d:%d is disabled and cannot be mapped.\n",
2313 map->file_index, map->stream_index);
2316 if(o->subtitle_disable && ist->st->codecpar->codec_type == AVMEDIA_TYPE_SUBTITLE)
2318 if(o-> audio_disable && ist->st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO)
2320 if(o-> video_disable && ist->st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO)
2322 if(o-> data_disable && ist->st->codecpar->codec_type == AVMEDIA_TYPE_DATA)
2326 switch (ist->st->codecpar->codec_type) {
2327 case AVMEDIA_TYPE_VIDEO: ost = new_video_stream (o, oc, src_idx); break;
2328 case AVMEDIA_TYPE_AUDIO: ost = new_audio_stream (o, oc, src_idx); break;
2329 case AVMEDIA_TYPE_SUBTITLE: ost = new_subtitle_stream (o, oc, src_idx); break;
2330 case AVMEDIA_TYPE_DATA: ost = new_data_stream (o, oc, src_idx); break;
2331 case AVMEDIA_TYPE_ATTACHMENT: ost = new_attachment_stream(o, oc, src_idx); break;
2332 case AVMEDIA_TYPE_UNKNOWN:
2333 if (copy_unknown_streams) {
2334 ost = new_unknown_stream (o, oc, src_idx);
2338 av_log(NULL, ignore_unknown_streams ? AV_LOG_WARNING : AV_LOG_FATAL,
2339 "Cannot map stream #%d:%d - unsupported type.\n",
2340 map->file_index, map->stream_index);
2341 if (!ignore_unknown_streams) {
2342 av_log(NULL, AV_LOG_FATAL,
2343 "If you want unsupported types ignored instead "
2344 "of failing, please use the -ignore_unknown option\n"
2345 "If you want them copied, please use -copy_unknown\n");
2350 ost->sync_ist = input_streams[ input_files[map->sync_file_index]->ist_index
2351 + map->sync_stream_index];
2356 /* handle attached files */
2357 for (i = 0; i < o->nb_attachments; i++) {
2359 uint8_t *attachment;
2363 if ((err = avio_open2(&pb, o->attachments[i], AVIO_FLAG_READ, &int_cb, NULL)) < 0) {
2364 av_log(NULL, AV_LOG_FATAL, "Could not open attachment file %s.\n",
2368 if ((len = avio_size(pb)) <= 0) {
2369 av_log(NULL, AV_LOG_FATAL, "Could not get size of the attachment %s.\n",
2373 if (!(attachment = av_malloc(len))) {
2374 av_log(NULL, AV_LOG_FATAL, "Attachment %s too large to fit into memory.\n",
2378 avio_read(pb, attachment, len);
2380 ost = new_attachment_stream(o, oc, -1);
2381 ost->stream_copy = 0;
2382 ost->attachment_filename = o->attachments[i];
2383 ost->st->codecpar->extradata = attachment;
2384 ost->st->codecpar->extradata_size = len;
2386 p = strrchr(o->attachments[i], '/');
2387 av_dict_set(&ost->st->metadata, "filename", (p && *p) ? p + 1 : o->attachments[i], AV_DICT_DONT_OVERWRITE);
2391 #if FF_API_LAVF_AVCTX
2392 for (i = nb_output_streams - oc->nb_streams; i < nb_output_streams; i++) { //for all streams of this output file
2393 AVDictionaryEntry *e;
2394 ost = output_streams[i];
2396 if ((ost->stream_copy || ost->attachment_filename)
2397 && (e = av_dict_get(o->g->codec_opts, "flags", NULL, AV_DICT_IGNORE_SUFFIX))
2398 && (!e->key[5] || check_stream_specifier(oc, ost->st, e->key+6)))
2399 if (av_opt_set(ost->st->codec, "flags", e->value, 0) < 0)
2404 if (!oc->nb_streams && !(oc->oformat->flags & AVFMT_NOSTREAMS)) {
2405 av_dump_format(oc, nb_output_files - 1, oc->url, 1);
2406 av_log(NULL, AV_LOG_ERROR, "Output file #%d does not contain any stream\n", nb_output_files - 1);
2410 /* check if all codec options have been used */
2411 unused_opts = strip_specifiers(o->g->codec_opts);
2412 for (i = of->ost_index; i < nb_output_streams; i++) {
2414 while ((e = av_dict_get(output_streams[i]->encoder_opts, "", e,
2415 AV_DICT_IGNORE_SUFFIX)))
2416 av_dict_set(&unused_opts, e->key, NULL, 0);
2420 while ((e = av_dict_get(unused_opts, "", e, AV_DICT_IGNORE_SUFFIX))) {
2421 const AVClass *class = avcodec_get_class();
2422 const AVOption *option = av_opt_find(&class, e->key, NULL, 0,
2423 AV_OPT_SEARCH_CHILDREN | AV_OPT_SEARCH_FAKE_OBJ);
2424 const AVClass *fclass = avformat_get_class();
2425 const AVOption *foption = av_opt_find(&fclass, e->key, NULL, 0,
2426 AV_OPT_SEARCH_CHILDREN | AV_OPT_SEARCH_FAKE_OBJ);
2427 if (!option || foption)
2431 if (!(option->flags & AV_OPT_FLAG_ENCODING_PARAM)) {
2432 av_log(NULL, AV_LOG_ERROR, "Codec AVOption %s (%s) specified for "
2433 "output file #%d (%s) is not an encoding option.\n", e->key,
2434 option->help ? option->help : "", nb_output_files - 1,
2439 // gop_timecode is injected by generic code but not always used
2440 if (!strcmp(e->key, "gop_timecode"))
2443 av_log(NULL, AV_LOG_WARNING, "Codec AVOption %s (%s) specified for "
2444 "output file #%d (%s) has not been used for any stream. The most "
2445 "likely reason is either wrong type (e.g. a video option with "
2446 "no video streams) or that it is a private option of some encoder "
2447 "which was not actually used for any stream.\n", e->key,
2448 option->help ? option->help : "", nb_output_files - 1, filename);
2450 av_dict_free(&unused_opts);
2452 /* set the decoding_needed flags and create simple filtergraphs */
2453 for (i = of->ost_index; i < nb_output_streams; i++) {
2454 OutputStream *ost = output_streams[i];
2456 if (ost->encoding_needed && ost->source_index >= 0) {
2457 InputStream *ist = input_streams[ost->source_index];
2458 ist->decoding_needed |= DECODING_FOR_OST;
2460 if (ost->st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO ||
2461 ost->st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) {
2462 err = init_simple_filtergraph(ist, ost);
2464 av_log(NULL, AV_LOG_ERROR,
2465 "Error initializing a simple filtergraph between streams "
2466 "%d:%d->%d:%d\n", ist->file_index, ost->source_index,
2467 nb_output_files - 1, ost->st->index);
2473 /* set the filter output constraints */
2475 OutputFilter *f = ost->filter;
2477 switch (ost->enc_ctx->codec_type) {
2478 case AVMEDIA_TYPE_VIDEO:
2479 f->frame_rate = ost->frame_rate;
2480 f->width = ost->enc_ctx->width;
2481 f->height = ost->enc_ctx->height;
2482 if (ost->enc_ctx->pix_fmt != AV_PIX_FMT_NONE) {
2483 f->format = ost->enc_ctx->pix_fmt;
2484 } else if (ost->enc->pix_fmts) {
2486 while (ost->enc->pix_fmts[count] != AV_PIX_FMT_NONE)
2488 f->formats = av_mallocz_array(count + 1, sizeof(*f->formats));
2491 memcpy(f->formats, ost->enc->pix_fmts, (count + 1) * sizeof(*f->formats));
2494 case AVMEDIA_TYPE_AUDIO:
2495 if (ost->enc_ctx->sample_fmt != AV_SAMPLE_FMT_NONE) {
2496 f->format = ost->enc_ctx->sample_fmt;
2497 } else if (ost->enc->sample_fmts) {
2499 while (ost->enc->sample_fmts[count] != AV_SAMPLE_FMT_NONE)
2501 f->formats = av_mallocz_array(count + 1, sizeof(*f->formats));
2504 memcpy(f->formats, ost->enc->sample_fmts, (count + 1) * sizeof(*f->formats));
2506 if (ost->enc_ctx->sample_rate) {
2507 f->sample_rate = ost->enc_ctx->sample_rate;
2508 } else if (ost->enc->supported_samplerates) {
2510 while (ost->enc->supported_samplerates[count])
2512 f->sample_rates = av_mallocz_array(count + 1, sizeof(*f->sample_rates));
2513 if (!f->sample_rates)
2515 memcpy(f->sample_rates, ost->enc->supported_samplerates,
2516 (count + 1) * sizeof(*f->sample_rates));
2518 if (ost->enc_ctx->channels) {
2519 f->channel_layout = av_get_default_channel_layout(ost->enc_ctx->channels);
2520 } else if (ost->enc->channel_layouts) {
2522 while (ost->enc->channel_layouts[count])
2524 f->channel_layouts = av_mallocz_array(count + 1, sizeof(*f->channel_layouts));
2525 if (!f->channel_layouts)
2527 memcpy(f->channel_layouts, ost->enc->channel_layouts,
2528 (count + 1) * sizeof(*f->channel_layouts));
2535 /* check filename in case of an image number is expected */
2536 if (oc->oformat->flags & AVFMT_NEEDNUMBER) {
2537 if (!av_filename_number_test(oc->url)) {
2538 print_error(oc->url, AVERROR(EINVAL));
2543 if (!(oc->oformat->flags & AVFMT_NOSTREAMS) && !input_stream_potentially_available) {
2544 av_log(NULL, AV_LOG_ERROR,
2545 "No input streams but output needs an input stream\n");
2549 if (!(oc->oformat->flags & AVFMT_NOFILE)) {
2550 /* test if it already exists to avoid losing precious files */
2551 assert_file_overwrite(filename);
2554 if ((err = avio_open2(&oc->pb, filename, AVIO_FLAG_WRITE,
2555 &oc->interrupt_callback,
2557 print_error(filename, err);
2560 } else if (strcmp(oc->oformat->name, "image2")==0 && !av_filename_number_test(filename))
2561 assert_file_overwrite(filename);
2563 if (o->mux_preload) {
2564 av_dict_set_int(&of->opts, "preload", o->mux_preload*AV_TIME_BASE, 0);
2566 oc->max_delay = (int)(o->mux_max_delay * AV_TIME_BASE);
2569 for (i = 0; i < o->nb_metadata_map; i++) {
2571 int in_file_index = strtol(o->metadata_map[i].u.str, &p, 0);
2573 if (in_file_index >= nb_input_files) {
2574 av_log(NULL, AV_LOG_FATAL, "Invalid input file index %d while processing metadata maps\n", in_file_index);
2577 copy_metadata(o->metadata_map[i].specifier, *p ? p + 1 : p, oc,
2578 in_file_index >= 0 ?
2579 input_files[in_file_index]->ctx : NULL, o);
2583 if (o->chapters_input_file >= nb_input_files) {
2584 if (o->chapters_input_file == INT_MAX) {
2585 /* copy chapters from the first input file that has them*/
2586 o->chapters_input_file = -1;
2587 for (i = 0; i < nb_input_files; i++)
2588 if (input_files[i]->ctx->nb_chapters) {
2589 o->chapters_input_file = i;
2593 av_log(NULL, AV_LOG_FATAL, "Invalid input file index %d in chapter mapping.\n",
2594 o->chapters_input_file);
2598 if (o->chapters_input_file >= 0)
2599 copy_chapters(input_files[o->chapters_input_file], of,
2600 !o->metadata_chapters_manual);
2602 /* copy global metadata by default */
2603 if (!o->metadata_global_manual && nb_input_files){
2604 av_dict_copy(&oc->metadata, input_files[0]->ctx->metadata,
2605 AV_DICT_DONT_OVERWRITE);
2606 if(o->recording_time != INT64_MAX)
2607 av_dict_set(&oc->metadata, "duration", NULL, 0);
2608 av_dict_set(&oc->metadata, "creation_time", NULL, 0);
2610 if (!o->metadata_streams_manual)
2611 for (i = of->ost_index; i < nb_output_streams; i++) {
2613 if (output_streams[i]->source_index < 0) /* this is true e.g. for attached files */
2615 ist = input_streams[output_streams[i]->source_index];
2616 av_dict_copy(&output_streams[i]->st->metadata, ist->st->metadata, AV_DICT_DONT_OVERWRITE);
2617 if (!output_streams[i]->stream_copy) {
2618 av_dict_set(&output_streams[i]->st->metadata, "encoder", NULL, 0);
2622 /* process manually set programs */
2623 for (i = 0; i < o->nb_program; i++) {
2624 const char *p = o->program[i].u.str;
2629 const char *p2 = av_get_token(&p, ":");
2630 const char *to_dealloc = p2;
2637 key = av_get_token(&p2, "=");
2639 av_freep(&to_dealloc);
2645 if (!strcmp(key, "program_num"))
2646 progid = strtol(p2, NULL, 0);
2647 av_freep(&to_dealloc);
2651 program = av_new_program(oc, progid);
2653 p = o->program[i].u.str;
2655 const char *p2 = av_get_token(&p, ":");
2656 const char *to_dealloc = p2;
2662 key = av_get_token(&p2, "=");
2664 av_log(NULL, AV_LOG_FATAL,
2665 "No '=' character in program string %s.\n",
2673 if (!strcmp(key, "title")) {
2674 av_dict_set(&program->metadata, "title", p2, 0);
2675 } else if (!strcmp(key, "program_num")) {
2676 } else if (!strcmp(key, "st")) {
2677 int st_num = strtol(p2, NULL, 0);
2678 av_program_add_stream_index(oc, progid, st_num);
2680 av_log(NULL, AV_LOG_FATAL, "Unknown program key %s.\n", key);
2683 av_freep(&to_dealloc);
2688 /* process manually set metadata */
2689 for (i = 0; i < o->nb_metadata; i++) {
2692 const char *stream_spec;
2693 int index = 0, j, ret = 0;
2695 val = strchr(o->metadata[i].u.str, '=');
2697 av_log(NULL, AV_LOG_FATAL, "No '=' character in metadata string %s.\n",
2698 o->metadata[i].u.str);
2703 parse_meta_type(o->metadata[i].specifier, &type, &index, &stream_spec);
2705 for (j = 0; j < oc->nb_streams; j++) {
2706 ost = output_streams[nb_output_streams - oc->nb_streams + j];
2707 if ((ret = check_stream_specifier(oc, oc->streams[j], stream_spec)) > 0) {
2708 if (!strcmp(o->metadata[i].u.str, "rotate")) {
2710 double theta = av_strtod(val, &tail);
2712 ost->rotate_overridden = 1;
2713 ost->rotate_override_value = theta;
2716 av_dict_set(&oc->streams[j]->metadata, o->metadata[i].u.str, *val ? val : NULL, 0);
2728 if (index < 0 || index >= oc->nb_chapters) {
2729 av_log(NULL, AV_LOG_FATAL, "Invalid chapter index %d in metadata specifier.\n", index);
2732 m = &oc->chapters[index]->metadata;
2735 if (index < 0 || index >= oc->nb_programs) {
2736 av_log(NULL, AV_LOG_FATAL, "Invalid program index %d in metadata specifier.\n", index);
2739 m = &oc->programs[index]->metadata;
2742 av_log(NULL, AV_LOG_FATAL, "Invalid metadata specifier %s.\n", o->metadata[i].specifier);
2745 av_dict_set(m, o->metadata[i].u.str, *val ? val : NULL, 0);
2752 static int opt_target(void *optctx, const char *opt, const char *arg)
2754 OptionsContext *o = optctx;
2755 enum { PAL, NTSC, FILM, UNKNOWN } norm = UNKNOWN;
2756 static const char *const frame_rates[] = { "25", "30000/1001", "24000/1001" };
2758 if (!strncmp(arg, "pal-", 4)) {
2761 } else if (!strncmp(arg, "ntsc-", 5)) {
2764 } else if (!strncmp(arg, "film-", 5)) {
2768 /* Try to determine PAL/NTSC by peeking in the input files */
2769 if (nb_input_files) {
2771 for (j = 0; j < nb_input_files; j++) {
2772 for (i = 0; i < input_files[j]->nb_streams; i++) {
2773 AVStream *st = input_files[j]->ctx->streams[i];
2775 if (st->codecpar->codec_type != AVMEDIA_TYPE_VIDEO)
2777 fr = st->time_base.den * 1000LL / st->time_base.num;
2781 } else if ((fr == 29970) || (fr == 23976)) {
2786 if (norm != UNKNOWN)
2790 if (norm != UNKNOWN)
2791 av_log(NULL, AV_LOG_INFO, "Assuming %s for target.\n", norm == PAL ? "PAL" : "NTSC");
2794 if (norm == UNKNOWN) {
2795 av_log(NULL, AV_LOG_FATAL, "Could not determine norm (PAL/NTSC/NTSC-Film) for target.\n");
2796 av_log(NULL, AV_LOG_FATAL, "Please prefix target with \"pal-\", \"ntsc-\" or \"film-\",\n");
2797 av_log(NULL, AV_LOG_FATAL, "or set a framerate with \"-r xxx\".\n");
2801 if (!strcmp(arg, "vcd")) {
2802 opt_video_codec(o, "c:v", "mpeg1video");
2803 opt_audio_codec(o, "c:a", "mp2");
2804 parse_option(o, "f", "vcd", options);
2806 parse_option(o, "s", norm == PAL ? "352x288" : "352x240", options);
2807 parse_option(o, "r", frame_rates[norm], options);
2808 opt_default(NULL, "g", norm == PAL ? "15" : "18");
2810 opt_default(NULL, "b:v", "1150000");
2811 opt_default(NULL, "maxrate:v", "1150000");
2812 opt_default(NULL, "minrate:v", "1150000");
2813 opt_default(NULL, "bufsize:v", "327680"); // 40*1024*8;
2815 opt_default(NULL, "b:a", "224000");
2816 parse_option(o, "ar", "44100", options);
2817 parse_option(o, "ac", "2", options);
2819 opt_default(NULL, "packetsize", "2324");
2820 opt_default(NULL, "muxrate", "1411200"); // 2352 * 75 * 8;
2822 /* We have to offset the PTS, so that it is consistent with the SCR.
2823 SCR starts at 36000, but the first two packs contain only padding
2824 and the first pack from the other stream, respectively, may also have
2825 been written before.
2826 So the real data starts at SCR 36000+3*1200. */
2827 o->mux_preload = (36000 + 3 * 1200) / 90000.0; // 0.44
2828 } else if (!strcmp(arg, "svcd")) {
2830 opt_video_codec(o, "c:v", "mpeg2video");
2831 opt_audio_codec(o, "c:a", "mp2");
2832 parse_option(o, "f", "svcd", options);
2834 parse_option(o, "s", norm == PAL ? "480x576" : "480x480", options);
2835 parse_option(o, "r", frame_rates[norm], options);
2836 parse_option(o, "pix_fmt", "yuv420p", options);
2837 opt_default(NULL, "g", norm == PAL ? "15" : "18");
2839 opt_default(NULL, "b:v", "2040000");
2840 opt_default(NULL, "maxrate:v", "2516000");
2841 opt_default(NULL, "minrate:v", "0"); // 1145000;
2842 opt_default(NULL, "bufsize:v", "1835008"); // 224*1024*8;
2843 opt_default(NULL, "scan_offset", "1");
2845 opt_default(NULL, "b:a", "224000");
2846 parse_option(o, "ar", "44100", options);
2848 opt_default(NULL, "packetsize", "2324");
2850 } else if (!strcmp(arg, "dvd")) {
2852 opt_video_codec(o, "c:v", "mpeg2video");
2853 opt_audio_codec(o, "c:a", "ac3");
2854 parse_option(o, "f", "dvd", options);
2856 parse_option(o, "s", norm == PAL ? "720x576" : "720x480", options);
2857 parse_option(o, "r", frame_rates[norm], options);
2858 parse_option(o, "pix_fmt", "yuv420p", options);
2859 opt_default(NULL, "g", norm == PAL ? "15" : "18");
2861 opt_default(NULL, "b:v", "6000000");
2862 opt_default(NULL, "maxrate:v", "9000000");
2863 opt_default(NULL, "minrate:v", "0"); // 1500000;
2864 opt_default(NULL, "bufsize:v", "1835008"); // 224*1024*8;
2866 opt_default(NULL, "packetsize", "2048"); // from www.mpucoder.com: DVD sectors contain 2048 bytes of data, this is also the size of one pack.
2867 opt_default(NULL, "muxrate", "10080000"); // from mplex project: data_rate = 1260000. mux_rate = data_rate * 8
2869 opt_default(NULL, "b:a", "448000");
2870 parse_option(o, "ar", "48000", options);
2872 } else if (!strncmp(arg, "dv", 2)) {
2874 parse_option(o, "f", "dv", options);
2876 parse_option(o, "s", norm == PAL ? "720x576" : "720x480", options);
2877 parse_option(o, "pix_fmt", !strncmp(arg, "dv50", 4) ? "yuv422p" :
2878 norm == PAL ? "yuv420p" : "yuv411p", options);
2879 parse_option(o, "r", frame_rates[norm], options);
2881 parse_option(o, "ar", "48000", options);
2882 parse_option(o, "ac", "2", options);
2885 av_log(NULL, AV_LOG_ERROR, "Unknown target: %s\n", arg);
2886 return AVERROR(EINVAL);
2889 av_dict_copy(&o->g->codec_opts, codec_opts, AV_DICT_DONT_OVERWRITE);
2890 av_dict_copy(&o->g->format_opts, format_opts, AV_DICT_DONT_OVERWRITE);
2895 static int opt_vstats_file(void *optctx, const char *opt, const char *arg)
2897 av_free (vstats_filename);
2898 vstats_filename = av_strdup (arg);
2902 static int opt_vstats(void *optctx, const char *opt, const char *arg)
2905 time_t today2 = time(NULL);
2906 struct tm *today = localtime(&today2);
2908 if (!today) { // maybe tomorrow
2909 av_log(NULL, AV_LOG_FATAL, "Unable to get current time: %s\n", strerror(errno));
2913 snprintf(filename, sizeof(filename), "vstats_%02d%02d%02d.log", today->tm_hour, today->tm_min,
2915 return opt_vstats_file(NULL, opt, filename);
2918 static int opt_video_frames(void *optctx, const char *opt, const char *arg)
2920 OptionsContext *o = optctx;
2921 return parse_option(o, "frames:v", arg, options);
2924 static int opt_audio_frames(void *optctx, const char *opt, const char *arg)
2926 OptionsContext *o = optctx;
2927 return parse_option(o, "frames:a", arg, options);
2930 static int opt_data_frames(void *optctx, const char *opt, const char *arg)
2932 OptionsContext *o = optctx;
2933 return parse_option(o, "frames:d", arg, options);
2936 static int opt_default_new(OptionsContext *o, const char *opt, const char *arg)
2939 AVDictionary *cbak = codec_opts;
2940 AVDictionary *fbak = format_opts;
2944 ret = opt_default(NULL, opt, arg);
2946 av_dict_copy(&o->g->codec_opts , codec_opts, 0);
2947 av_dict_copy(&o->g->format_opts, format_opts, 0);
2948 av_dict_free(&codec_opts);
2949 av_dict_free(&format_opts);
2956 static int opt_preset(void *optctx, const char *opt, const char *arg)
2958 OptionsContext *o = optctx;
2960 char filename[1000], line[1000], tmp_line[1000];
2961 const char *codec_name = NULL;
2965 MATCH_PER_TYPE_OPT(codec_names, str, codec_name, NULL, tmp_line);
2967 if (!(f = get_preset_file(filename, sizeof(filename), arg, *opt == 'f', codec_name))) {
2968 if(!strncmp(arg, "libx264-lossless", strlen("libx264-lossless"))){
2969 av_log(NULL, AV_LOG_FATAL, "Please use -preset <speed> -qp 0\n");
2971 av_log(NULL, AV_LOG_FATAL, "File for preset '%s' not found\n", arg);
2975 while (fgets(line, sizeof(line), f)) {
2976 char *key = tmp_line, *value, *endptr;
2978 if (strcspn(line, "#\n\r") == 0)
2980 av_strlcpy(tmp_line, line, sizeof(tmp_line));
2981 if (!av_strtok(key, "=", &value) ||
2982 !av_strtok(value, "\r\n", &endptr)) {
2983 av_log(NULL, AV_LOG_FATAL, "%s: Invalid syntax: '%s'\n", filename, line);
2986 av_log(NULL, AV_LOG_DEBUG, "ffpreset[%s]: set '%s' = '%s'\n", filename, key, value);
2988 if (!strcmp(key, "acodec")) opt_audio_codec (o, key, value);
2989 else if (!strcmp(key, "vcodec")) opt_video_codec (o, key, value);
2990 else if (!strcmp(key, "scodec")) opt_subtitle_codec(o, key, value);
2991 else if (!strcmp(key, "dcodec")) opt_data_codec (o, key, value);
2992 else if (opt_default_new(o, key, value) < 0) {
2993 av_log(NULL, AV_LOG_FATAL, "%s: Invalid option or argument: '%s', parsed as '%s' = '%s'\n",
2994 filename, line, key, value);
3004 static int opt_old2new(void *optctx, const char *opt, const char *arg)
3006 OptionsContext *o = optctx;
3008 char *s = av_asprintf("%s:%c", opt + 1, *opt);
3010 return AVERROR(ENOMEM);
3011 ret = parse_option(o, s, arg, options);
3016 static int opt_bitrate(void *optctx, const char *opt, const char *arg)
3018 OptionsContext *o = optctx;
3020 if(!strcmp(opt, "ab")){
3021 av_dict_set(&o->g->codec_opts, "b:a", arg, 0);
3023 } else if(!strcmp(opt, "b")){
3024 av_log(NULL, AV_LOG_WARNING, "Please use -b:a or -b:v, -b is ambiguous\n");
3025 av_dict_set(&o->g->codec_opts, "b:v", arg, 0);
3028 av_dict_set(&o->g->codec_opts, opt, arg, 0);
3032 static int opt_qscale(void *optctx, const char *opt, const char *arg)
3034 OptionsContext *o = optctx;
3037 if(!strcmp(opt, "qscale")){
3038 av_log(NULL, AV_LOG_WARNING, "Please use -q:a or -q:v, -qscale is ambiguous\n");
3039 return parse_option(o, "q:v", arg, options);
3041 s = av_asprintf("q%s", opt + 6);
3043 return AVERROR(ENOMEM);
3044 ret = parse_option(o, s, arg, options);
3049 static int opt_profile(void *optctx, const char *opt, const char *arg)
3051 OptionsContext *o = optctx;
3052 if(!strcmp(opt, "profile")){
3053 av_log(NULL, AV_LOG_WARNING, "Please use -profile:a or -profile:v, -profile is ambiguous\n");
3054 av_dict_set(&o->g->codec_opts, "profile:v", arg, 0);
3057 av_dict_set(&o->g->codec_opts, opt, arg, 0);
3061 static int opt_video_filters(void *optctx, const char *opt, const char *arg)
3063 OptionsContext *o = optctx;
3064 return parse_option(o, "filter:v", arg, options);
3067 static int opt_audio_filters(void *optctx, const char *opt, const char *arg)
3069 OptionsContext *o = optctx;
3070 return parse_option(o, "filter:a", arg, options);
3073 static int opt_vsync(void *optctx, const char *opt, const char *arg)
3075 if (!av_strcasecmp(arg, "cfr")) video_sync_method = VSYNC_CFR;
3076 else if (!av_strcasecmp(arg, "vfr")) video_sync_method = VSYNC_VFR;
3077 else if (!av_strcasecmp(arg, "passthrough")) video_sync_method = VSYNC_PASSTHROUGH;
3078 else if (!av_strcasecmp(arg, "drop")) video_sync_method = VSYNC_DROP;
3080 if (video_sync_method == VSYNC_AUTO)
3081 video_sync_method = parse_number_or_die("vsync", arg, OPT_INT, VSYNC_AUTO, VSYNC_VFR);
3085 static int opt_timecode(void *optctx, const char *opt, const char *arg)
3087 OptionsContext *o = optctx;
3089 char *tcr = av_asprintf("timecode=%s", arg);
3091 return AVERROR(ENOMEM);
3092 ret = parse_option(o, "metadata:g", tcr, options);
3094 ret = av_dict_set(&o->g->codec_opts, "gop_timecode", arg, 0);
3099 static int opt_channel_layout(void *optctx, const char *opt, const char *arg)
3101 OptionsContext *o = optctx;
3102 char layout_str[32];
3105 int ret, channels, ac_str_size;
3108 layout = av_get_channel_layout(arg);
3110 av_log(NULL, AV_LOG_ERROR, "Unknown channel layout: %s\n", arg);
3111 return AVERROR(EINVAL);
3113 snprintf(layout_str, sizeof(layout_str), "%"PRIu64, layout);
3114 ret = opt_default_new(o, opt, layout_str);
3118 /* set 'ac' option based on channel layout */
3119 channels = av_get_channel_layout_nb_channels(layout);
3120 snprintf(layout_str, sizeof(layout_str), "%d", channels);
3121 stream_str = strchr(opt, ':');
3122 ac_str_size = 3 + (stream_str ? strlen(stream_str) : 0);
3123 ac_str = av_mallocz(ac_str_size);
3125 return AVERROR(ENOMEM);
3126 av_strlcpy(ac_str, "ac", 3);
3128 av_strlcat(ac_str, stream_str, ac_str_size);
3129 ret = parse_option(o, ac_str, layout_str, options);
3135 static int opt_audio_qscale(void *optctx, const char *opt, const char *arg)
3137 OptionsContext *o = optctx;
3138 return parse_option(o, "q:a", arg, options);
3141 static int opt_filter_complex(void *optctx, const char *opt, const char *arg)
3143 GROW_ARRAY(filtergraphs, nb_filtergraphs);
3144 if (!(filtergraphs[nb_filtergraphs - 1] = av_mallocz(sizeof(*filtergraphs[0]))))
3145 return AVERROR(ENOMEM);
3146 filtergraphs[nb_filtergraphs - 1]->index = nb_filtergraphs - 1;
3147 filtergraphs[nb_filtergraphs - 1]->graph_desc = av_strdup(arg);
3148 if (!filtergraphs[nb_filtergraphs - 1]->graph_desc)
3149 return AVERROR(ENOMEM);
3151 input_stream_potentially_available = 1;
3156 static int opt_filter_complex_script(void *optctx, const char *opt, const char *arg)
3158 uint8_t *graph_desc = read_file(arg);
3160 return AVERROR(EINVAL);
3162 GROW_ARRAY(filtergraphs, nb_filtergraphs);
3163 if (!(filtergraphs[nb_filtergraphs - 1] = av_mallocz(sizeof(*filtergraphs[0]))))
3164 return AVERROR(ENOMEM);
3165 filtergraphs[nb_filtergraphs - 1]->index = nb_filtergraphs - 1;
3166 filtergraphs[nb_filtergraphs - 1]->graph_desc = graph_desc;
3168 input_stream_potentially_available = 1;
3173 void show_help_default(const char *opt, const char *arg)
3175 /* per-file options have at least one of those set */
3176 const int per_file = OPT_SPEC | OPT_OFFSET | OPT_PERFILE;
3177 int show_advanced = 0, show_avoptions = 0;
3180 if (!strcmp(opt, "long"))
3182 else if (!strcmp(opt, "full"))
3183 show_advanced = show_avoptions = 1;
3185 av_log(NULL, AV_LOG_ERROR, "Unknown help option '%s'.\n", opt);
3190 printf("Getting help:\n"
3191 " -h -- print basic options\n"
3192 " -h long -- print more options\n"
3193 " -h full -- print all options (including all format and codec specific options, very long)\n"
3194 " -h type=name -- print all options for the named decoder/encoder/demuxer/muxer/filter/bsf/protocol\n"
3195 " See man %s for detailed description of the options.\n"
3196 "\n", program_name);
3198 show_help_options(options, "Print help / information / capabilities:",
3201 show_help_options(options, "Global options (affect whole program "
3202 "instead of just one file):",
3203 0, per_file | OPT_EXIT | OPT_EXPERT, 0);
3205 show_help_options(options, "Advanced global options:", OPT_EXPERT,
3206 per_file | OPT_EXIT, 0);
3208 show_help_options(options, "Per-file main options:", 0,
3209 OPT_EXPERT | OPT_AUDIO | OPT_VIDEO | OPT_SUBTITLE |
3210 OPT_EXIT, per_file);
3212 show_help_options(options, "Advanced per-file options:",
3213 OPT_EXPERT, OPT_AUDIO | OPT_VIDEO | OPT_SUBTITLE, per_file);
3215 show_help_options(options, "Video options:",
3216 OPT_VIDEO, OPT_EXPERT | OPT_AUDIO, 0);
3218 show_help_options(options, "Advanced Video options:",
3219 OPT_EXPERT | OPT_VIDEO, OPT_AUDIO, 0);
3221 show_help_options(options, "Audio options:",
3222 OPT_AUDIO, OPT_EXPERT | OPT_VIDEO, 0);
3224 show_help_options(options, "Advanced Audio options:",
3225 OPT_EXPERT | OPT_AUDIO, OPT_VIDEO, 0);
3226 show_help_options(options, "Subtitle options:",
3227 OPT_SUBTITLE, 0, 0);
3230 if (show_avoptions) {
3231 int flags = AV_OPT_FLAG_DECODING_PARAM | AV_OPT_FLAG_ENCODING_PARAM;
3232 show_help_children(avcodec_get_class(), flags);
3233 show_help_children(avformat_get_class(), flags);
3235 show_help_children(sws_get_class(), flags);
3237 #if CONFIG_SWRESAMPLE
3238 show_help_children(swr_get_class(), AV_OPT_FLAG_AUDIO_PARAM);
3240 show_help_children(avfilter_get_class(), AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_AUDIO_PARAM | AV_OPT_FLAG_FILTERING_PARAM);
3241 show_help_children(av_bsf_get_class(), AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_AUDIO_PARAM | AV_OPT_FLAG_BSF_PARAM);
3245 void show_usage(void)
3247 av_log(NULL, AV_LOG_INFO, "Hyper fast Audio and Video encoder\n");
3248 av_log(NULL, AV_LOG_INFO, "usage: %s [options] [[infile options] -i infile]... {[outfile options] outfile}...\n", program_name);
3249 av_log(NULL, AV_LOG_INFO, "\n");
3257 static const OptionGroupDef groups[] = {
3258 [GROUP_OUTFILE] = { "output url", NULL, OPT_OUTPUT },
3259 [GROUP_INFILE] = { "input url", "i", OPT_INPUT },
3262 static int open_files(OptionGroupList *l, const char *inout,
3263 int (*open_file)(OptionsContext*, const char*))
3267 for (i = 0; i < l->nb_groups; i++) {
3268 OptionGroup *g = &l->groups[i];
3274 ret = parse_optgroup(&o, g);
3276 av_log(NULL, AV_LOG_ERROR, "Error parsing options for %s file "
3277 "%s.\n", inout, g->arg);
3282 av_log(NULL, AV_LOG_DEBUG, "Opening an %s file: %s.\n", inout, g->arg);
3283 ret = open_file(&o, g->arg);
3286 av_log(NULL, AV_LOG_ERROR, "Error opening %s file %s.\n",
3290 av_log(NULL, AV_LOG_DEBUG, "Successfully opened the file.\n");
3296 int ffmpeg_parse_options(int argc, char **argv)
3298 OptionParseContext octx;
3302 memset(&octx, 0, sizeof(octx));
3304 /* split the commandline into an internal representation */
3305 ret = split_commandline(&octx, argc, argv, options, groups,
3306 FF_ARRAY_ELEMS(groups));
3308 av_log(NULL, AV_LOG_FATAL, "Error splitting the argument list: ");
3312 /* apply global options */
3313 ret = parse_optgroup(NULL, &octx.global_opts);
3315 av_log(NULL, AV_LOG_FATAL, "Error parsing global options: ");
3319 /* configure terminal and setup signal handlers */
3322 /* open input files */
3323 ret = open_files(&octx.groups[GROUP_INFILE], "input", open_input_file);
3325 av_log(NULL, AV_LOG_FATAL, "Error opening input files: ");
3329 /* create the complex filtergraphs */
3330 ret = init_complex_filters();
3332 av_log(NULL, AV_LOG_FATAL, "Error initializing complex filters.\n");
3336 /* open output files */
3337 ret = open_files(&octx.groups[GROUP_OUTFILE], "output", open_output_file);
3339 av_log(NULL, AV_LOG_FATAL, "Error opening output files: ");
3343 check_filter_outputs();
3346 uninit_parse_context(&octx);
3348 av_strerror(ret, error, sizeof(error));
3349 av_log(NULL, AV_LOG_FATAL, "%s\n", error);
3354 static int opt_progress(void *optctx, const char *opt, const char *arg)
3356 AVIOContext *avio = NULL;
3359 if (!strcmp(arg, "-"))
3361 ret = avio_open2(&avio, arg, AVIO_FLAG_WRITE, &int_cb, NULL);
3363 av_log(NULL, AV_LOG_ERROR, "Failed to open progress URL \"%s\": %s\n",
3364 arg, av_err2str(ret));
3367 progress_avio = avio;
3371 #define OFFSET(x) offsetof(OptionsContext, x)
3372 const OptionDef options[] = {
3374 CMDUTILS_COMMON_OPTIONS
3375 { "f", HAS_ARG | OPT_STRING | OPT_OFFSET |
3376 OPT_INPUT | OPT_OUTPUT, { .off = OFFSET(format) },
3377 "force format", "fmt" },
3378 { "y", OPT_BOOL, { &file_overwrite },
3379 "overwrite output files" },
3380 { "n", OPT_BOOL, { &no_file_overwrite },
3381 "never overwrite output files" },
3382 { "ignore_unknown", OPT_BOOL, { &ignore_unknown_streams },
3383 "Ignore unknown stream types" },
3384 { "copy_unknown", OPT_BOOL | OPT_EXPERT, { ©_unknown_streams },
3385 "Copy unknown stream types" },
3386 { "c", HAS_ARG | OPT_STRING | OPT_SPEC |
3387 OPT_INPUT | OPT_OUTPUT, { .off = OFFSET(codec_names) },
3388 "codec name", "codec" },
3389 { "codec", HAS_ARG | OPT_STRING | OPT_SPEC |
3390 OPT_INPUT | OPT_OUTPUT, { .off = OFFSET(codec_names) },
3391 "codec name", "codec" },
3392 { "pre", HAS_ARG | OPT_STRING | OPT_SPEC |
3393 OPT_OUTPUT, { .off = OFFSET(presets) },
3394 "preset name", "preset" },
3395 { "map", HAS_ARG | OPT_EXPERT | OPT_PERFILE |
3396 OPT_OUTPUT, { .func_arg = opt_map },
3397 "set input stream mapping",
3398 "[-]input_file_id[:stream_specifier][,sync_file_id[:stream_specifier]]" },
3399 { "map_channel", HAS_ARG | OPT_EXPERT | OPT_PERFILE | OPT_OUTPUT, { .func_arg = opt_map_channel },
3400 "map an audio channel from one stream to another", "file.stream.channel[:syncfile.syncstream]" },
3401 { "map_metadata", HAS_ARG | OPT_STRING | OPT_SPEC |
3402 OPT_OUTPUT, { .off = OFFSET(metadata_map) },
3403 "set metadata information of outfile from infile",
3404 "outfile[,metadata]:infile[,metadata]" },
3405 { "map_chapters", HAS_ARG | OPT_INT | OPT_EXPERT | OPT_OFFSET |
3406 OPT_OUTPUT, { .off = OFFSET(chapters_input_file) },
3407 "set chapters mapping", "input_file_index" },
3408 { "t", HAS_ARG | OPT_TIME | OPT_OFFSET |
3409 OPT_INPUT | OPT_OUTPUT, { .off = OFFSET(recording_time) },
3410 "record or transcode \"duration\" seconds of audio/video",
3412 { "to", HAS_ARG | OPT_TIME | OPT_OFFSET | OPT_INPUT | OPT_OUTPUT, { .off = OFFSET(stop_time) },
3413 "record or transcode stop time", "time_stop" },
3414 { "fs", HAS_ARG | OPT_INT64 | OPT_OFFSET | OPT_OUTPUT, { .off = OFFSET(limit_filesize) },
3415 "set the limit file size in bytes", "limit_size" },
3416 { "ss", HAS_ARG | OPT_TIME | OPT_OFFSET |
3417 OPT_INPUT | OPT_OUTPUT, { .off = OFFSET(start_time) },
3418 "set the start time offset", "time_off" },
3419 { "sseof", HAS_ARG | OPT_TIME | OPT_OFFSET |
3420 OPT_INPUT, { .off = OFFSET(start_time_eof) },
3421 "set the start time offset relative to EOF", "time_off" },
3422 { "seek_timestamp", HAS_ARG | OPT_INT | OPT_OFFSET |
3423 OPT_INPUT, { .off = OFFSET(seek_timestamp) },
3424 "enable/disable seeking by timestamp with -ss" },
3425 { "accurate_seek", OPT_BOOL | OPT_OFFSET | OPT_EXPERT |
3426 OPT_INPUT, { .off = OFFSET(accurate_seek) },
3427 "enable/disable accurate seeking with -ss" },
3428 { "itsoffset", HAS_ARG | OPT_TIME | OPT_OFFSET |
3429 OPT_EXPERT | OPT_INPUT, { .off = OFFSET(input_ts_offset) },
3430 "set the input ts offset", "time_off" },
3431 { "itsscale", HAS_ARG | OPT_DOUBLE | OPT_SPEC |
3432 OPT_EXPERT | OPT_INPUT, { .off = OFFSET(ts_scale) },
3433 "set the input ts scale", "scale" },
3434 { "timestamp", HAS_ARG | OPT_PERFILE | OPT_OUTPUT, { .func_arg = opt_recording_timestamp },
3435 "set the recording timestamp ('now' to set the current time)", "time" },
3436 { "metadata", HAS_ARG | OPT_STRING | OPT_SPEC | OPT_OUTPUT, { .off = OFFSET(metadata) },
3437 "add metadata", "string=string" },
3438 { "program", HAS_ARG | OPT_STRING | OPT_SPEC | OPT_OUTPUT, { .off = OFFSET(program) },
3439 "add program with specified streams", "title=string:st=number..." },
3440 { "dframes", HAS_ARG | OPT_PERFILE | OPT_EXPERT |
3441 OPT_OUTPUT, { .func_arg = opt_data_frames },
3442 "set the number of data frames to output", "number" },
3443 { "benchmark", OPT_BOOL | OPT_EXPERT, { &do_benchmark },
3444 "add timings for benchmarking" },
3445 { "benchmark_all", OPT_BOOL | OPT_EXPERT, { &do_benchmark_all },
3446 "add timings for each task" },
3447 { "progress", HAS_ARG | OPT_EXPERT, { .func_arg = opt_progress },
3448 "write program-readable progress information", "url" },
3449 { "stdin", OPT_BOOL | OPT_EXPERT, { &stdin_interaction },
3450 "enable or disable interaction on standard input" },
3451 { "timelimit", HAS_ARG | OPT_EXPERT, { .func_arg = opt_timelimit },
3452 "set max runtime in seconds in CPU user time", "limit" },
3453 { "dump", OPT_BOOL | OPT_EXPERT, { &do_pkt_dump },
3454 "dump each input packet" },
3455 { "hex", OPT_BOOL | OPT_EXPERT, { &do_hex_dump },
3456 "when dumping packets, also dump the payload" },
3457 { "re", OPT_BOOL | OPT_EXPERT | OPT_OFFSET |
3458 OPT_INPUT, { .off = OFFSET(rate_emu) },
3459 "read input at native frame rate", "" },
3460 { "target", HAS_ARG | OPT_PERFILE | OPT_OUTPUT, { .func_arg = opt_target },
3461 "specify target file type (\"vcd\", \"svcd\", \"dvd\", \"dv\" or \"dv50\" "
3462 "with optional prefixes \"pal-\", \"ntsc-\" or \"film-\")", "type" },
3463 { "vsync", HAS_ARG | OPT_EXPERT, { .func_arg = opt_vsync },
3464 "video sync method", "" },
3465 { "frame_drop_threshold", HAS_ARG | OPT_FLOAT | OPT_EXPERT, { &frame_drop_threshold },
3466 "frame drop threshold", "" },
3467 { "async", HAS_ARG | OPT_INT | OPT_EXPERT, { &audio_sync_method },
3468 "audio sync method", "" },
3469 { "adrift_threshold", HAS_ARG | OPT_FLOAT | OPT_EXPERT, { &audio_drift_threshold },
3470 "audio drift threshold", "threshold" },
3471 { "copyts", OPT_BOOL | OPT_EXPERT, { ©_ts },
3472 "copy timestamps" },
3473 { "start_at_zero", OPT_BOOL | OPT_EXPERT, { &start_at_zero },
3474 "shift input timestamps to start at 0 when using copyts" },
3475 { "copytb", HAS_ARG | OPT_INT | OPT_EXPERT, { ©_tb },
3476 "copy input stream time base when stream copying", "mode" },
3477 { "shortest", OPT_BOOL | OPT_EXPERT | OPT_OFFSET |
3478 OPT_OUTPUT, { .off = OFFSET(shortest) },
3479 "finish encoding within shortest input" },
3480 { "bitexact", OPT_BOOL | OPT_EXPERT | OPT_OFFSET |
3481 OPT_OUTPUT | OPT_INPUT, { .off = OFFSET(bitexact) },
3483 { "apad", OPT_STRING | HAS_ARG | OPT_SPEC |
3484 OPT_OUTPUT, { .off = OFFSET(apad) },
3486 { "dts_delta_threshold", HAS_ARG | OPT_FLOAT | OPT_EXPERT, { &dts_delta_threshold },
3487 "timestamp discontinuity delta threshold", "threshold" },
3488 { "dts_error_threshold", HAS_ARG | OPT_FLOAT | OPT_EXPERT, { &dts_error_threshold },
3489 "timestamp error delta threshold", "threshold" },
3490 { "xerror", OPT_BOOL | OPT_EXPERT, { &exit_on_error },
3491 "exit on error", "error" },
3492 { "abort_on", HAS_ARG | OPT_EXPERT, { .func_arg = opt_abort_on },
3493 "abort on the specified condition flags", "flags" },
3494 { "copyinkf", OPT_BOOL | OPT_EXPERT | OPT_SPEC |
3495 OPT_OUTPUT, { .off = OFFSET(copy_initial_nonkeyframes) },
3496 "copy initial non-keyframes" },
3497 { "copypriorss", OPT_INT | HAS_ARG | OPT_EXPERT | OPT_SPEC | OPT_OUTPUT, { .off = OFFSET(copy_prior_start) },
3498 "copy or discard frames before start time" },
3499 { "frames", OPT_INT64 | HAS_ARG | OPT_SPEC | OPT_OUTPUT, { .off = OFFSET(max_frames) },
3500 "set the number of frames to output", "number" },
3501 { "tag", OPT_STRING | HAS_ARG | OPT_SPEC |
3502 OPT_EXPERT | OPT_OUTPUT | OPT_INPUT, { .off = OFFSET(codec_tags) },
3503 "force codec tag/fourcc", "fourcc/tag" },
3504 { "q", HAS_ARG | OPT_EXPERT | OPT_DOUBLE |
3505 OPT_SPEC | OPT_OUTPUT, { .off = OFFSET(qscale) },
3506 "use fixed quality scale (VBR)", "q" },
3507 { "qscale", HAS_ARG | OPT_EXPERT | OPT_PERFILE |
3508 OPT_OUTPUT, { .func_arg = opt_qscale },
3509 "use fixed quality scale (VBR)", "q" },
3510 { "profile", HAS_ARG | OPT_EXPERT | OPT_PERFILE | OPT_OUTPUT, { .func_arg = opt_profile },
3511 "set profile", "profile" },
3512 { "filter", HAS_ARG | OPT_STRING | OPT_SPEC | OPT_OUTPUT, { .off = OFFSET(filters) },
3513 "set stream filtergraph", "filter_graph" },
3514 { "filter_threads", HAS_ARG | OPT_INT, { &filter_nbthreads },
3515 "number of non-complex filter threads" },
3516 { "filter_script", HAS_ARG | OPT_STRING | OPT_SPEC | OPT_OUTPUT, { .off = OFFSET(filter_scripts) },
3517 "read stream filtergraph description from a file", "filename" },
3518 { "reinit_filter", HAS_ARG | OPT_INT | OPT_SPEC | OPT_INPUT, { .off = OFFSET(reinit_filters) },
3519 "reinit filtergraph on input parameter changes", "" },
3520 { "filter_complex", HAS_ARG | OPT_EXPERT, { .func_arg = opt_filter_complex },
3521 "create a complex filtergraph", "graph_description" },
3522 { "filter_complex_threads", HAS_ARG | OPT_INT, { &filter_complex_nbthreads },
3523 "number of threads for -filter_complex" },
3524 { "lavfi", HAS_ARG | OPT_EXPERT, { .func_arg = opt_filter_complex },
3525 "create a complex filtergraph", "graph_description" },
3526 { "filter_complex_script", HAS_ARG | OPT_EXPERT, { .func_arg = opt_filter_complex_script },
3527 "read complex filtergraph description from a file", "filename" },
3528 { "stats", OPT_BOOL, { &print_stats },
3529 "print progress report during encoding", },
3530 { "attach", HAS_ARG | OPT_PERFILE | OPT_EXPERT |
3531 OPT_OUTPUT, { .func_arg = opt_attach },
3532 "add an attachment to the output file", "filename" },
3533 { "dump_attachment", HAS_ARG | OPT_STRING | OPT_SPEC |
3534 OPT_EXPERT | OPT_INPUT, { .off = OFFSET(dump_attachment) },
3535 "extract an attachment into a file", "filename" },
3536 { "stream_loop", OPT_INT | HAS_ARG | OPT_EXPERT | OPT_INPUT |
3537 OPT_OFFSET, { .off = OFFSET(loop) }, "set number of times input stream shall be looped", "loop count" },
3538 { "debug_ts", OPT_BOOL | OPT_EXPERT, { &debug_ts },
3539 "print timestamp debugging info" },
3540 { "max_error_rate", HAS_ARG | OPT_FLOAT, { &max_error_rate },
3541 "ratio of errors (0.0: no errors, 1.0: 100% errors) above which ffmpeg returns an error instead of success.", "maximum error rate" },
3542 { "discard", OPT_STRING | HAS_ARG | OPT_SPEC |
3543 OPT_INPUT, { .off = OFFSET(discard) },
3545 { "disposition", OPT_STRING | HAS_ARG | OPT_SPEC |
3546 OPT_OUTPUT, { .off = OFFSET(disposition) },
3547 "disposition", "" },
3548 { "thread_queue_size", HAS_ARG | OPT_INT | OPT_OFFSET | OPT_EXPERT | OPT_INPUT,
3549 { .off = OFFSET(thread_queue_size) },
3550 "set the maximum number of queued packets from the demuxer" },
3551 { "find_stream_info", OPT_BOOL | OPT_PERFILE | OPT_INPUT | OPT_EXPERT, { &find_stream_info },
3552 "read and decode the streams to fill missing information with heuristics" },
3555 { "vframes", OPT_VIDEO | HAS_ARG | OPT_PERFILE | OPT_OUTPUT, { .func_arg = opt_video_frames },
3556 "set the number of video frames to output", "number" },
3557 { "r", OPT_VIDEO | HAS_ARG | OPT_STRING | OPT_SPEC |
3558 OPT_INPUT | OPT_OUTPUT, { .off = OFFSET(frame_rates) },
3559 "set frame rate (Hz value, fraction or abbreviation)", "rate" },
3560 { "s", OPT_VIDEO | HAS_ARG | OPT_SUBTITLE | OPT_STRING | OPT_SPEC |
3561 OPT_INPUT | OPT_OUTPUT, { .off = OFFSET(frame_sizes) },
3562 "set frame size (WxH or abbreviation)", "size" },
3563 { "aspect", OPT_VIDEO | HAS_ARG | OPT_STRING | OPT_SPEC |
3564 OPT_OUTPUT, { .off = OFFSET(frame_aspect_ratios) },
3565 "set aspect ratio (4:3, 16:9 or 1.3333, 1.7777)", "aspect" },
3566 { "pix_fmt", OPT_VIDEO | HAS_ARG | OPT_EXPERT | OPT_STRING | OPT_SPEC |
3567 OPT_INPUT | OPT_OUTPUT, { .off = OFFSET(frame_pix_fmts) },
3568 "set pixel format", "format" },
3569 { "bits_per_raw_sample", OPT_VIDEO | OPT_INT | HAS_ARG, { &frame_bits_per_raw_sample },
3570 "set the number of bits per raw sample", "number" },
3571 { "intra", OPT_VIDEO | OPT_BOOL | OPT_EXPERT, { &intra_only },
3572 "deprecated use -g 1" },
3573 { "vn", OPT_VIDEO | OPT_BOOL | OPT_OFFSET | OPT_INPUT | OPT_OUTPUT,{ .off = OFFSET(video_disable) },
3575 { "rc_override", OPT_VIDEO | HAS_ARG | OPT_EXPERT | OPT_STRING | OPT_SPEC |
3576 OPT_OUTPUT, { .off = OFFSET(rc_overrides) },
3577 "rate control override for specific intervals", "override" },
3578 { "vcodec", OPT_VIDEO | HAS_ARG | OPT_PERFILE | OPT_INPUT |
3579 OPT_OUTPUT, { .func_arg = opt_video_codec },
3580 "force video codec ('copy' to copy stream)", "codec" },
3581 { "sameq", OPT_VIDEO | OPT_EXPERT , { .func_arg = opt_sameq },
3583 { "same_quant", OPT_VIDEO | OPT_EXPERT , { .func_arg = opt_sameq },
3585 { "timecode", OPT_VIDEO | HAS_ARG | OPT_PERFILE | OPT_OUTPUT, { .func_arg = opt_timecode },
3586 "set initial TimeCode value.", "hh:mm:ss[:;.]ff" },
3587 { "pass", OPT_VIDEO | HAS_ARG | OPT_SPEC | OPT_INT | OPT_OUTPUT, { .off = OFFSET(pass) },
3588 "select the pass number (1 to 3)", "n" },
3589 { "passlogfile", OPT_VIDEO | HAS_ARG | OPT_STRING | OPT_EXPERT | OPT_SPEC |
3590 OPT_OUTPUT, { .off = OFFSET(passlogfiles) },
3591 "select two pass log file name prefix", "prefix" },
3592 { "deinterlace", OPT_VIDEO | OPT_BOOL | OPT_EXPERT, { &do_deinterlace },
3593 "this option is deprecated, use the yadif filter instead" },
3594 { "psnr", OPT_VIDEO | OPT_BOOL | OPT_EXPERT, { &do_psnr },
3595 "calculate PSNR of compressed frames" },
3596 { "vstats", OPT_VIDEO | OPT_EXPERT , { .func_arg = opt_vstats },
3597 "dump video coding statistics to file" },
3598 { "vstats_file", OPT_VIDEO | HAS_ARG | OPT_EXPERT , { .func_arg = opt_vstats_file },
3599 "dump video coding statistics to file", "file" },
3600 { "vstats_version", OPT_VIDEO | OPT_INT | HAS_ARG | OPT_EXPERT , { &vstats_version },
3601 "Version of the vstats format to use."},
3602 { "vf", OPT_VIDEO | HAS_ARG | OPT_PERFILE | OPT_OUTPUT, { .func_arg = opt_video_filters },
3603 "set video filters", "filter_graph" },
3604 { "intra_matrix", OPT_VIDEO | HAS_ARG | OPT_EXPERT | OPT_STRING | OPT_SPEC |
3605 OPT_OUTPUT, { .off = OFFSET(intra_matrices) },
3606 "specify intra matrix coeffs", "matrix" },
3607 { "inter_matrix", OPT_VIDEO | HAS_ARG | OPT_EXPERT | OPT_STRING | OPT_SPEC |
3608 OPT_OUTPUT, { .off = OFFSET(inter_matrices) },
3609 "specify inter matrix coeffs", "matrix" },
3610 { "chroma_intra_matrix", OPT_VIDEO | HAS_ARG | OPT_EXPERT | OPT_STRING | OPT_SPEC |
3611 OPT_OUTPUT, { .off = OFFSET(chroma_intra_matrices) },
3612 "specify intra matrix coeffs", "matrix" },
3613 { "top", OPT_VIDEO | HAS_ARG | OPT_EXPERT | OPT_INT| OPT_SPEC |
3614 OPT_INPUT | OPT_OUTPUT, { .off = OFFSET(top_field_first) },
3615 "top=1/bottom=0/auto=-1 field first", "" },
3616 { "vtag", OPT_VIDEO | HAS_ARG | OPT_EXPERT | OPT_PERFILE |
3617 OPT_INPUT | OPT_OUTPUT, { .func_arg = opt_old2new },
3618 "force video tag/fourcc", "fourcc/tag" },
3619 { "qphist", OPT_VIDEO | OPT_BOOL | OPT_EXPERT , { &qp_hist },
3620 "show QP histogram" },
3621 { "force_fps", OPT_VIDEO | OPT_BOOL | OPT_EXPERT | OPT_SPEC |
3622 OPT_OUTPUT, { .off = OFFSET(force_fps) },
3623 "force the selected framerate, disable the best supported framerate selection" },
3624 { "streamid", OPT_VIDEO | HAS_ARG | OPT_EXPERT | OPT_PERFILE |
3625 OPT_OUTPUT, { .func_arg = opt_streamid },
3626 "set the value of an outfile streamid", "streamIndex:value" },
3627 { "force_key_frames", OPT_VIDEO | OPT_STRING | HAS_ARG | OPT_EXPERT |
3628 OPT_SPEC | OPT_OUTPUT, { .off = OFFSET(forced_key_frames) },
3629 "force key frames at specified timestamps", "timestamps" },
3630 { "ab", OPT_VIDEO | HAS_ARG | OPT_PERFILE | OPT_OUTPUT, { .func_arg = opt_bitrate },
3631 "audio bitrate (please use -b:a)", "bitrate" },
3632 { "b", OPT_VIDEO | HAS_ARG | OPT_PERFILE | OPT_OUTPUT, { .func_arg = opt_bitrate },
3633 "video bitrate (please use -b:v)", "bitrate" },
3634 { "hwaccel", OPT_VIDEO | OPT_STRING | HAS_ARG | OPT_EXPERT |
3635 OPT_SPEC | OPT_INPUT, { .off = OFFSET(hwaccels) },
3636 "use HW accelerated decoding", "hwaccel name" },
3637 { "hwaccel_device", OPT_VIDEO | OPT_STRING | HAS_ARG | OPT_EXPERT |
3638 OPT_SPEC | OPT_INPUT, { .off = OFFSET(hwaccel_devices) },
3639 "select a device for HW acceleration", "devicename" },
3640 { "hwaccel_output_format", OPT_VIDEO | OPT_STRING | HAS_ARG | OPT_EXPERT |
3641 OPT_SPEC | OPT_INPUT, { .off = OFFSET(hwaccel_output_formats) },
3642 "select output format used with HW accelerated decoding", "format" },
3643 #if CONFIG_VIDEOTOOLBOX
3644 { "videotoolbox_pixfmt", HAS_ARG | OPT_STRING | OPT_EXPERT, { &videotoolbox_pixfmt}, "" },
3646 { "hwaccels", OPT_EXIT, { .func_arg = show_hwaccels },
3647 "show available HW acceleration methods" },
3648 { "autorotate", HAS_ARG | OPT_BOOL | OPT_SPEC |
3649 OPT_EXPERT | OPT_INPUT, { .off = OFFSET(autorotate) },
3650 "automatically insert correct rotate filters" },
3653 { "aframes", OPT_AUDIO | HAS_ARG | OPT_PERFILE | OPT_OUTPUT, { .func_arg = opt_audio_frames },
3654 "set the number of audio frames to output", "number" },
3655 { "aq", OPT_AUDIO | HAS_ARG | OPT_PERFILE | OPT_OUTPUT, { .func_arg = opt_audio_qscale },
3656 "set audio quality (codec-specific)", "quality", },
3657 { "ar", OPT_AUDIO | HAS_ARG | OPT_INT | OPT_SPEC |
3658 OPT_INPUT | OPT_OUTPUT, { .off = OFFSET(audio_sample_rate) },
3659 "set audio sampling rate (in Hz)", "rate" },
3660 { "ac", OPT_AUDIO | HAS_ARG | OPT_INT | OPT_SPEC |
3661 OPT_INPUT | OPT_OUTPUT, { .off = OFFSET(audio_channels) },
3662 "set number of audio channels", "channels" },
3663 { "an", OPT_AUDIO | OPT_BOOL | OPT_OFFSET | OPT_INPUT | OPT_OUTPUT,{ .off = OFFSET(audio_disable) },
3665 { "acodec", OPT_AUDIO | HAS_ARG | OPT_PERFILE |
3666 OPT_INPUT | OPT_OUTPUT, { .func_arg = opt_audio_codec },
3667 "force audio codec ('copy' to copy stream)", "codec" },
3668 { "atag", OPT_AUDIO | HAS_ARG | OPT_EXPERT | OPT_PERFILE |
3669 OPT_OUTPUT, { .func_arg = opt_old2new },
3670 "force audio tag/fourcc", "fourcc/tag" },
3671 { "vol", OPT_AUDIO | HAS_ARG | OPT_INT, { &audio_volume },
3672 "change audio volume (256=normal)" , "volume" },
3673 { "sample_fmt", OPT_AUDIO | HAS_ARG | OPT_EXPERT | OPT_SPEC |
3674 OPT_STRING | OPT_INPUT | OPT_OUTPUT, { .off = OFFSET(sample_fmts) },
3675 "set sample format", "format" },
3676 { "channel_layout", OPT_AUDIO | HAS_ARG | OPT_EXPERT | OPT_PERFILE |
3677 OPT_INPUT | OPT_OUTPUT, { .func_arg = opt_channel_layout },
3678 "set channel layout", "layout" },
3679 { "af", OPT_AUDIO | HAS_ARG | OPT_PERFILE | OPT_OUTPUT, { .func_arg = opt_audio_filters },
3680 "set audio filters", "filter_graph" },
3681 { "guess_layout_max", OPT_AUDIO | HAS_ARG | OPT_INT | OPT_SPEC | OPT_EXPERT | OPT_INPUT, { .off = OFFSET(guess_layout_max) },
3682 "set the maximum number of channels to try to guess the channel layout" },
3684 /* subtitle options */
3685 { "sn", OPT_SUBTITLE | OPT_BOOL | OPT_OFFSET | OPT_INPUT | OPT_OUTPUT, { .off = OFFSET(subtitle_disable) },
3686 "disable subtitle" },
3687 { "scodec", OPT_SUBTITLE | HAS_ARG | OPT_PERFILE | OPT_INPUT | OPT_OUTPUT, { .func_arg = opt_subtitle_codec },
3688 "force subtitle codec ('copy' to copy stream)", "codec" },
3689 { "stag", OPT_SUBTITLE | HAS_ARG | OPT_EXPERT | OPT_PERFILE | OPT_OUTPUT, { .func_arg = opt_old2new }
3690 , "force subtitle tag/fourcc", "fourcc/tag" },
3691 { "fix_sub_duration", OPT_BOOL | OPT_EXPERT | OPT_SUBTITLE | OPT_SPEC | OPT_INPUT, { .off = OFFSET(fix_sub_duration) },
3692 "fix subtitles duration" },
3693 { "canvas_size", OPT_SUBTITLE | HAS_ARG | OPT_STRING | OPT_SPEC | OPT_INPUT, { .off = OFFSET(canvas_sizes) },
3694 "set canvas size (WxH or abbreviation)", "size" },
3697 { "vc", HAS_ARG | OPT_EXPERT | OPT_VIDEO, { .func_arg = opt_video_channel },
3698 "deprecated, use -channel", "channel" },
3699 { "tvstd", HAS_ARG | OPT_EXPERT | OPT_VIDEO, { .func_arg = opt_video_standard },
3700 "deprecated, use -standard", "standard" },
3701 { "isync", OPT_BOOL | OPT_EXPERT, { &input_sync }, "this option is deprecated and does nothing", "" },
3704 { "muxdelay", OPT_FLOAT | HAS_ARG | OPT_EXPERT | OPT_OFFSET | OPT_OUTPUT, { .off = OFFSET(mux_max_delay) },
3705 "set the maximum demux-decode delay", "seconds" },
3706 { "muxpreload", OPT_FLOAT | HAS_ARG | OPT_EXPERT | OPT_OFFSET | OPT_OUTPUT, { .off = OFFSET(mux_preload) },
3707 "set the initial demux-decode delay", "seconds" },
3708 { "sdp_file", HAS_ARG | OPT_EXPERT | OPT_OUTPUT, { .func_arg = opt_sdp_file },
3709 "specify a file in which to print sdp information", "file" },
3711 { "time_base", HAS_ARG | OPT_STRING | OPT_EXPERT | OPT_SPEC | OPT_OUTPUT, { .off = OFFSET(time_bases) },
3712 "set the desired time base hint for output stream (1:24, 1:48000 or 0.04166, 2.0833e-5)", "ratio" },
3713 { "enc_time_base", HAS_ARG | OPT_STRING | OPT_EXPERT | OPT_SPEC | OPT_OUTPUT, { .off = OFFSET(enc_time_bases) },
3714 "set the desired time base for the encoder (1:24, 1:48000 or 0.04166, 2.0833e-5). "
3715 "two special values are defined - "
3716 "0 = use frame rate (video) or sample rate (audio),"
3717 "-1 = match source time base", "ratio" },
3719 { "bsf", HAS_ARG | OPT_STRING | OPT_SPEC | OPT_EXPERT | OPT_OUTPUT, { .off = OFFSET(bitstream_filters) },
3720 "A comma-separated list of bitstream filters", "bitstream_filters" },
3721 { "absf", HAS_ARG | OPT_AUDIO | OPT_EXPERT| OPT_PERFILE | OPT_OUTPUT, { .func_arg = opt_old2new },
3722 "deprecated", "audio bitstream_filters" },
3723 { "vbsf", OPT_VIDEO | HAS_ARG | OPT_EXPERT| OPT_PERFILE | OPT_OUTPUT, { .func_arg = opt_old2new },
3724 "deprecated", "video bitstream_filters" },
3726 { "apre", HAS_ARG | OPT_AUDIO | OPT_EXPERT| OPT_PERFILE | OPT_OUTPUT, { .func_arg = opt_preset },
3727 "set the audio options to the indicated preset", "preset" },
3728 { "vpre", OPT_VIDEO | HAS_ARG | OPT_EXPERT| OPT_PERFILE | OPT_OUTPUT, { .func_arg = opt_preset },
3729 "set the video options to the indicated preset", "preset" },
3730 { "spre", HAS_ARG | OPT_SUBTITLE | OPT_EXPERT| OPT_PERFILE | OPT_OUTPUT, { .func_arg = opt_preset },
3731 "set the subtitle options to the indicated preset", "preset" },
3732 { "fpre", HAS_ARG | OPT_EXPERT| OPT_PERFILE | OPT_OUTPUT, { .func_arg = opt_preset },
3733 "set options from indicated preset file", "filename" },
3735 { "max_muxing_queue_size", HAS_ARG | OPT_INT | OPT_SPEC | OPT_EXPERT | OPT_OUTPUT, { .off = OFFSET(max_muxing_queue_size) },
3736 "maximum number of packets that can be buffered while waiting for all streams to initialize", "packets" },
3738 /* data codec support */
3739 { "dcodec", HAS_ARG | OPT_DATA | OPT_PERFILE | OPT_EXPERT | OPT_INPUT | OPT_OUTPUT, { .func_arg = opt_data_codec },
3740 "force data codec ('copy' to copy stream)", "codec" },
3741 { "dn", OPT_BOOL | OPT_VIDEO | OPT_OFFSET | OPT_INPUT | OPT_OUTPUT, { .off = OFFSET(data_disable) },
3745 { "vaapi_device", HAS_ARG | OPT_EXPERT, { .func_arg = opt_vaapi_device },
3746 "set VAAPI hardware device (DRM path or X11 display name)", "device" },
3750 { "qsv_device", HAS_ARG | OPT_STRING | OPT_EXPERT, { &qsv_device },
3751 "set QSV hardware device (DirectX adapter index, DRM path or X11 display name)", "device"},
3754 { "init_hw_device", HAS_ARG | OPT_EXPERT, { .func_arg = opt_init_hw_device },
3755 "initialise hardware device", "args" },
3756 { "filter_hw_device", HAS_ARG | OPT_EXPERT, { .func_arg = opt_filter_hw_device },
3757 "set hardware device used when filtering", "device" },