FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/fftools/ffmpeg_opt.c
Date: 2024-02-16 17:37:06
Exec Total Coverage
Lines: 308 767 40.2%
Functions: 27 54 50.0%
Branches: 157 434 36.2%

Line Branch Exec Source
1 /*
2 * ffmpeg option parsing
3 *
4 * This file is part of FFmpeg.
5 *
6 * FFmpeg is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * FFmpeg is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with FFmpeg; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21 #include "config.h"
22
23 #include <stdint.h>
24
25 #if HAVE_SYS_RESOURCE_H
26 #include <sys/time.h>
27 #include <sys/resource.h>
28 #endif
29
30 #include "ffmpeg.h"
31 #include "ffmpeg_sched.h"
32 #include "cmdutils.h"
33 #include "opt_common.h"
34 #include "sync_queue.h"
35
36 #include "libavformat/avformat.h"
37
38 #include "libavcodec/avcodec.h"
39 #include "libavcodec/bsf.h"
40
41 #include "libavfilter/avfilter.h"
42
43 #include "libavutil/avassert.h"
44 #include "libavutil/avstring.h"
45 #include "libavutil/avutil.h"
46 #include "libavutil/bprint.h"
47 #include "libavutil/channel_layout.h"
48 #include "libavutil/display.h"
49 #include "libavutil/intreadwrite.h"
50 #include "libavutil/fifo.h"
51 #include "libavutil/mathematics.h"
52 #include "libavutil/opt.h"
53 #include "libavutil/parseutils.h"
54 #include "libavutil/pixdesc.h"
55 #include "libavutil/pixfmt.h"
56
57 HWDevice *filter_hw_device;
58
59 char *vstats_filename;
60
61 float audio_drift_threshold = 0.1;
62 float dts_delta_threshold = 10;
63 float dts_error_threshold = 3600*30;
64
65 #if FFMPEG_OPT_VSYNC
66 enum VideoSyncMethod video_sync_method = VSYNC_AUTO;
67 #endif
68 float frame_drop_threshold = 0;
69 int do_benchmark = 0;
70 int do_benchmark_all = 0;
71 int do_hex_dump = 0;
72 int do_pkt_dump = 0;
73 int copy_ts = 0;
74 int start_at_zero = 0;
75 int copy_tb = -1;
76 int debug_ts = 0;
77 int exit_on_error = 0;
78 int abort_on_flags = 0;
79 int print_stats = -1;
80 int stdin_interaction = 1;
81 float max_error_rate = 2.0/3;
82 char *filter_nbthreads;
83 int filter_complex_nbthreads = 0;
84 int vstats_version = 2;
85 int auto_conversion_filters = 1;
86 int64_t stats_period = 500000;
87
88
89 static int file_overwrite = 0;
90 static int no_file_overwrite = 0;
91 #if FFMPEG_OPT_PSNR
92 int do_psnr = 0;
93 #endif
94 int ignore_unknown_streams = 0;
95 int copy_unknown_streams = 0;
96 int recast_media = 0;
97
98 13513 static void uninit_options(OptionsContext *o)
99 {
100 13513 const OptionDef *po = options;
101 int i;
102
103 /* all OPT_SPEC and OPT_TYPE_STRING can be freed in generic way */
104
2/2
✓ Branch 0 taken 2580983 times.
✓ Branch 1 taken 13513 times.
2594496 while (po->name) {
105 2580983 void *dst = (uint8_t*)o + po->u.off;
106
107
2/2
✓ Branch 0 taken 864832 times.
✓ Branch 1 taken 1716151 times.
2580983 if (po->flags & OPT_FLAG_SPEC) {
108 864832 SpecifierOptList *so = dst;
109
2/2
✓ Branch 0 taken 27833 times.
✓ Branch 1 taken 864832 times.
892665 for (int i = 0; i < so->nb_opt; i++) {
110 27833 av_freep(&so->opt[i].specifier);
111
2/2
✓ Branch 0 taken 22618 times.
✓ Branch 1 taken 5215 times.
27833 if (po->type == OPT_TYPE_STRING)
112 22618 av_freep(&so->opt[i].u.str);
113 }
114 864832 av_freep(&so->opt);
115 864832 so->nb_opt = 0;
116
4/4
✓ Branch 0 taken 351338 times.
✓ Branch 1 taken 1364813 times.
✓ Branch 2 taken 13513 times.
✓ Branch 3 taken 337825 times.
1716151 } else if (po->flags & OPT_FLAG_OFFSET && po->type == OPT_TYPE_STRING)
117 13513 av_freep(dst);
118 2580983 po++;
119 }
120
121
2/2
✓ Branch 0 taken 293 times.
✓ Branch 1 taken 13513 times.
13806 for (i = 0; i < o->nb_stream_maps; i++)
122 293 av_freep(&o->stream_maps[i].linklabel);
123 13513 av_freep(&o->stream_maps);
124 #if FFMPEG_OPT_MAP_CHANNEL
125 13513 av_freep(&o->audio_channel_maps);
126 #endif
127
128
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 13513 times.
13514 for (i = 0; i < o->nb_attachments; i++)
129 1 av_freep(&o->attachments[i]);
130 13513 av_freep(&o->attachments);
131
132 13513 av_dict_free(&o->streamid);
133 13513 }
134
135 13513 static void init_options(OptionsContext *o)
136 {
137 13513 memset(o, 0, sizeof(*o));
138
139 13513 o->stop_time = INT64_MAX;
140 13513 o->mux_max_delay = 0.7;
141 13513 o->start_time = AV_NOPTS_VALUE;
142 13513 o->start_time_eof = AV_NOPTS_VALUE;
143 13513 o->recording_time = INT64_MAX;
144 13513 o->limit_filesize = INT64_MAX;
145 13513 o->chapters_input_file = INT_MAX;
146 13513 o->accurate_seek = 1;
147 13513 o->thread_queue_size = 0;
148 13513 o->input_sync_ref = -1;
149 13513 o->find_stream_info = 1;
150 13513 o->shortest_buf_duration = 10.f;
151 13513 }
152
153 static int show_hwaccels(void *optctx, const char *opt, const char *arg)
154 {
155 enum AVHWDeviceType type = AV_HWDEVICE_TYPE_NONE;
156
157 printf("Hardware acceleration methods:\n");
158 while ((type = av_hwdevice_iterate_types(type)) !=
159 AV_HWDEVICE_TYPE_NONE)
160 printf("%s\n", av_hwdevice_get_type_name(type));
161 printf("\n");
162 return 0;
163 }
164
165 /* return a copy of the input with the stream specifiers removed from the keys */
166 13513 AVDictionary *strip_specifiers(const AVDictionary *dict)
167 {
168 13513 const AVDictionaryEntry *e = NULL;
169 13513 AVDictionary *ret = NULL;
170
171
2/2
✓ Branch 1 taken 38268 times.
✓ Branch 2 taken 13513 times.
51781 while ((e = av_dict_iterate(dict, e))) {
172 38268 char *p = strchr(e->key, ':');
173
174
2/2
✓ Branch 0 taken 220 times.
✓ Branch 1 taken 38048 times.
38268 if (p)
175 220 *p = 0;
176 38268 av_dict_set(&ret, e->key, e->value, 0);
177
2/2
✓ Branch 0 taken 220 times.
✓ Branch 1 taken 38048 times.
38268 if (p)
178 220 *p = ':';
179 }
180 13513 return ret;
181 }
182
183 33692 const char *opt_match_per_type_str(const SpecifierOptList *sol,
184 char mediatype)
185 {
186
3/4
✓ Branch 0 taken 14769 times.
✓ Branch 1 taken 18923 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 14769 times.
33692 av_assert0(!sol->nb_opt || sol->type == OPT_TYPE_STRING);
187
188
2/2
✓ Branch 0 taken 14863 times.
✓ Branch 1 taken 30962 times.
45825 for (int i = 0; i < sol->nb_opt; i++) {
189 14863 const char *spec = sol->opt[i].specifier;
190
3/4
✓ Branch 0 taken 2730 times.
✓ Branch 1 taken 12133 times.
✓ Branch 2 taken 2730 times.
✗ Branch 3 not taken.
14863 if (spec[0] == mediatype && !spec[1])
191 2730 return sol->opt[i].u.str;
192 }
193 30962 return NULL;
194 }
195
196 514 int parse_and_set_vsync(const char *arg, int *vsync_var, int file_idx, int st_idx, int is_global)
197 {
198
2/2
✓ Branch 1 taken 6 times.
✓ Branch 2 taken 508 times.
514 if (!av_strcasecmp(arg, "cfr")) *vsync_var = VSYNC_CFR;
199
2/2
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 507 times.
508 else if (!av_strcasecmp(arg, "vfr")) *vsync_var = VSYNC_VFR;
200
1/2
✓ Branch 1 taken 507 times.
✗ Branch 2 not taken.
507 else if (!av_strcasecmp(arg, "passthrough")) *vsync_var = VSYNC_PASSTHROUGH;
201 #if FFMPEG_OPT_VSYNC_DROP
202 else if (!av_strcasecmp(arg, "drop")) {
203 av_log(NULL, AV_LOG_WARNING, "-vsync/fps_mode drop is deprecated\n");
204 *vsync_var = VSYNC_DROP;
205 }
206 #endif
207 else if (!is_global && !av_strcasecmp(arg, "auto")) *vsync_var = VSYNC_AUTO;
208 else if (!is_global) {
209 av_log(NULL, AV_LOG_FATAL, "Invalid value %s specified for fps_mode of #%d:%d.\n", arg, file_idx, st_idx);
210 return AVERROR(EINVAL);
211 }
212
213 #if FFMPEG_OPT_VSYNC
214
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 514 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
514 if (is_global && *vsync_var == VSYNC_AUTO) {
215 int ret;
216 double num;
217
218 ret = parse_number("vsync", arg, OPT_TYPE_INT, VSYNC_AUTO, VSYNC_VFR, &num);
219 if (ret < 0)
220 return ret;
221
222 video_sync_method = num;
223 av_log(NULL, AV_LOG_WARNING, "Passing a number to -vsync is deprecated,"
224 " use a string argument as described in the manual.\n");
225 }
226 #endif
227
228 514 return 0;
229 }
230
231 /* Correct input file start times based on enabled streams */
232 6740 static void correct_input_start_times(void)
233 {
234
2/2
✓ Branch 0 taken 6771 times.
✓ Branch 1 taken 6740 times.
13511 for (int i = 0; i < nb_input_files; i++) {
235 6771 InputFile *ifile = input_files[i];
236 6771 AVFormatContext *is = ifile->ctx;
237 6771 int64_t new_start_time = INT64_MAX, diff, abs_start_seek;
238
239 6771 ifile->start_time_effective = is->start_time;
240
241
2/2
✓ Branch 0 taken 5086 times.
✓ Branch 1 taken 1685 times.
6771 if (is->start_time == AV_NOPTS_VALUE ||
242
2/2
✓ Branch 0 taken 4981 times.
✓ Branch 1 taken 105 times.
5086 !(is->iformat->flags & AVFMT_TS_DISCONT))
243 6666 continue;
244
245
2/2
✓ Branch 0 taken 155 times.
✓ Branch 1 taken 105 times.
260 for (int j = 0; j < is->nb_streams; j++) {
246 155 AVStream *st = is->streams[j];
247
3/4
✓ Branch 0 taken 120 times.
✓ Branch 1 taken 35 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 120 times.
155 if(st->discard == AVDISCARD_ALL || st->start_time == AV_NOPTS_VALUE)
248 35 continue;
249
2/2
✓ Branch 0 taken 117 times.
✓ Branch 1 taken 3 times.
120 new_start_time = FFMIN(new_start_time, av_rescale_q(st->start_time, st->time_base, AV_TIME_BASE_Q));
250 }
251
252 105 diff = new_start_time - is->start_time;
253
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 102 times.
105 if (diff) {
254 3 av_log(NULL, AV_LOG_VERBOSE, "Correcting start time of Input #%d by %"PRId64" us.\n", i, diff);
255 3 ifile->start_time_effective = new_start_time;
256
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
3 if (copy_ts && start_at_zero)
257 ifile->ts_offset = -new_start_time;
258
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
3 else if (!copy_ts) {
259
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
3 abs_start_seek = is->start_time + (ifile->start_time != AV_NOPTS_VALUE) ? ifile->start_time : 0;
260
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
3 ifile->ts_offset = abs_start_seek > new_start_time ? -abs_start_seek : -new_start_time;
261 } else if (copy_ts)
262 ifile->ts_offset = 0;
263
264 3 ifile->ts_offset += ifile->input_ts_offset;
265 }
266 }
267 6740 }
268
269 6740 static int apply_sync_offsets(void)
270 {
271
2/2
✓ Branch 0 taken 6771 times.
✓ Branch 1 taken 6740 times.
13511 for (int i = 0; i < nb_input_files; i++) {
272 6771 InputFile *ref, *self = input_files[i];
273 int64_t adjustment;
274 int64_t self_start_time, ref_start_time, self_seek_start, ref_seek_start;
275 6771 int start_times_set = 1;
276
277
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6771 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6771 if (self->input_sync_ref == -1 || self->input_sync_ref == i) continue;
278 if (self->input_sync_ref >= nb_input_files || self->input_sync_ref < -1) {
279 av_log(NULL, AV_LOG_FATAL, "-isync for input %d references non-existent input %d.\n", i, self->input_sync_ref);
280 return AVERROR(EINVAL);
281 }
282
283 if (copy_ts && !start_at_zero) {
284 av_log(NULL, AV_LOG_FATAL, "Use of -isync requires that start_at_zero be set if copyts is set.\n");
285 return AVERROR(EINVAL);
286 }
287
288 ref = input_files[self->input_sync_ref];
289 if (ref->input_sync_ref != -1 && ref->input_sync_ref != self->input_sync_ref) {
290 av_log(NULL, AV_LOG_ERROR, "-isync for input %d references a resynced input %d. Sync not set.\n", i, self->input_sync_ref);
291 continue;
292 }
293
294 if (self->ctx->start_time_realtime != AV_NOPTS_VALUE && ref->ctx->start_time_realtime != AV_NOPTS_VALUE) {
295 self_start_time = self->ctx->start_time_realtime;
296 ref_start_time = ref->ctx->start_time_realtime;
297 } else if (self->start_time_effective != AV_NOPTS_VALUE && ref->start_time_effective != AV_NOPTS_VALUE) {
298 self_start_time = self->start_time_effective;
299 ref_start_time = ref->start_time_effective;
300 } else {
301 start_times_set = 0;
302 }
303
304 if (start_times_set) {
305 self_seek_start = self->start_time == AV_NOPTS_VALUE ? 0 : self->start_time;
306 ref_seek_start = ref->start_time == AV_NOPTS_VALUE ? 0 : ref->start_time;
307
308 adjustment = (self_start_time - ref_start_time) + !copy_ts*(self_seek_start - ref_seek_start) + ref->input_ts_offset;
309
310 self->ts_offset += adjustment;
311
312 av_log(NULL, AV_LOG_INFO, "Adjusted ts offset for Input #%d by %"PRId64" us to sync with Input #%d.\n", i, adjustment, self->input_sync_ref);
313 } else {
314 av_log(NULL, AV_LOG_INFO, "Unable to identify start times for Inputs #%d and %d both. No sync adjustment made.\n", i, self->input_sync_ref);
315 }
316 }
317
318 6740 return 0;
319 }
320
321 316 static int opt_filter_threads(void *optctx, const char *opt, const char *arg)
322 {
323 316 av_free(filter_nbthreads);
324 316 filter_nbthreads = av_strdup(arg);
325 316 return 0;
326 }
327
328 static int opt_abort_on(void *optctx, const char *opt, const char *arg)
329 {
330 static const AVOption opts[] = {
331 { "abort_on" , NULL, 0, AV_OPT_TYPE_FLAGS, { .i64 = 0 }, INT64_MIN, INT64_MAX, .unit = "flags" },
332 { "empty_output" , NULL, 0, AV_OPT_TYPE_CONST, { .i64 = ABORT_ON_FLAG_EMPTY_OUTPUT }, .unit = "flags" },
333 { "empty_output_stream", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = ABORT_ON_FLAG_EMPTY_OUTPUT_STREAM }, .unit = "flags" },
334 { NULL },
335 };
336 static const AVClass class = {
337 .class_name = "",
338 .item_name = av_default_item_name,
339 .option = opts,
340 .version = LIBAVUTIL_VERSION_INT,
341 };
342 const AVClass *pclass = &class;
343
344 return av_opt_eval_flags(&pclass, &opts[0], arg, &abort_on_flags);
345 }
346
347 static int opt_stats_period(void *optctx, const char *opt, const char *arg)
348 {
349 int64_t user_stats_period;
350 int ret = av_parse_time(&user_stats_period, arg, 1);
351 if (ret < 0)
352 return ret;
353
354 if (user_stats_period <= 0) {
355 av_log(NULL, AV_LOG_ERROR, "stats_period %s must be positive.\n", arg);
356 return AVERROR(EINVAL);
357 }
358
359 stats_period = user_stats_period;
360 av_log(NULL, AV_LOG_INFO, "ffmpeg stats and -progress period set to %s.\n", arg);
361
362 return 0;
363 }
364
365 15 static int opt_audio_codec(void *optctx, const char *opt, const char *arg)
366 {
367 15 OptionsContext *o = optctx;
368 15 return parse_option(o, "codec:a", arg, options);
369 }
370
371 4716 static int opt_video_codec(void *optctx, const char *opt, const char *arg)
372 {
373 4716 OptionsContext *o = optctx;
374 4716 return parse_option(o, "codec:v", arg, options);
375 }
376
377 2 static int opt_subtitle_codec(void *optctx, const char *opt, const char *arg)
378 {
379 2 OptionsContext *o = optctx;
380 2 return parse_option(o, "codec:s", arg, options);
381 }
382
383 static int opt_data_codec(void *optctx, const char *opt, const char *arg)
384 {
385 OptionsContext *o = optctx;
386 return parse_option(o, "codec:d", arg, options);
387 }
388
389 208 static int opt_map(void *optctx, const char *opt, const char *arg)
390 {
391 208 OptionsContext *o = optctx;
392 208 StreamMap *m = NULL;
393 208 int i, negative = 0, file_idx, disabled = 0;
394 int ret;
395 char *map, *p;
396 char *allow_unused;
397
398
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 208 times.
208 if (*arg == '-') {
399 negative = 1;
400 arg++;
401 }
402 208 map = av_strdup(arg);
403
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 208 times.
208 if (!map)
404 return AVERROR(ENOMEM);
405
406 #if FFMPEG_OPT_MAP_SYNC
407 {
408 /* parse sync stream first, just pick first matching stream */
409 208 char *sync = strchr(map, ',');
410
411
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 208 times.
208 if (sync) {
412 *sync = 0;
413 av_log(NULL, AV_LOG_WARNING, "Specifying a sync stream is deprecated and has no effect\n");
414 }
415 }
416 #endif
417
418
419
2/2
✓ Branch 0 taken 36 times.
✓ Branch 1 taken 172 times.
208 if (map[0] == '[') {
420 /* this mapping refers to lavfi output */
421 36 const char *c = map + 1;
422
423 36 ret = GROW_ARRAY(o->stream_maps, o->nb_stream_maps);
424
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 36 times.
36 if (ret < 0)
425 goto fail;
426
427 36 m = &o->stream_maps[o->nb_stream_maps - 1];
428 36 m->linklabel = av_get_token(&c, "]");
429
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 36 times.
36 if (!m->linklabel) {
430 av_log(NULL, AV_LOG_ERROR, "Invalid output link label: %s.\n", map);
431 ret = AVERROR(EINVAL);
432 goto fail;
433 }
434 } else {
435
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 172 times.
172 if (allow_unused = strchr(map, '?'))
436 *allow_unused = 0;
437 172 file_idx = strtol(map, &p, 0);
438
2/4
✓ Branch 0 taken 172 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 172 times.
172 if (file_idx >= nb_input_files || file_idx < 0) {
439 av_log(NULL, AV_LOG_FATAL, "Invalid input file index: %d.\n", file_idx);
440 ret = AVERROR(EINVAL);
441 goto fail;
442 }
443
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 172 times.
172 if (negative)
444 /* disable some already defined maps */
445 for (i = 0; i < o->nb_stream_maps; i++) {
446 m = &o->stream_maps[i];
447 if (file_idx == m->file_index &&
448 check_stream_specifier(input_files[m->file_index]->ctx,
449 input_files[m->file_index]->ctx->streams[m->stream_index],
450 *p == ':' ? p + 1 : p) > 0)
451 m->disabled = 1;
452 }
453 else
454
2/2
✓ Branch 0 taken 386 times.
✓ Branch 1 taken 172 times.
558 for (i = 0; i < input_files[file_idx]->nb_streams; i++) {
455
2/2
✓ Branch 1 taken 129 times.
✓ Branch 2 taken 257 times.
386 if (check_stream_specifier(input_files[file_idx]->ctx, input_files[file_idx]->ctx->streams[i],
456
2/2
✓ Branch 0 taken 197 times.
✓ Branch 1 taken 189 times.
386 *p == ':' ? p + 1 : p) <= 0)
457 129 continue;
458
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 257 times.
257 if (input_files[file_idx]->streams[i]->user_set_discard == AVDISCARD_ALL) {
459 disabled = 1;
460 continue;
461 }
462 257 ret = GROW_ARRAY(o->stream_maps, o->nb_stream_maps);
463
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 257 times.
257 if (ret < 0)
464 goto fail;
465
466 257 m = &o->stream_maps[o->nb_stream_maps - 1];
467
468 257 m->file_index = file_idx;
469 257 m->stream_index = i;
470 }
471 }
472
473
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 208 times.
208 if (!m) {
474 if (allow_unused) {
475 av_log(NULL, AV_LOG_VERBOSE, "Stream map '%s' matches no streams; ignoring.\n", arg);
476 } else if (disabled) {
477 av_log(NULL, AV_LOG_FATAL, "Stream map '%s' matches disabled streams.\n"
478 "To ignore this, add a trailing '?' to the map.\n", arg);
479 ret = AVERROR(EINVAL);
480 goto fail;
481 } else {
482 av_log(NULL, AV_LOG_FATAL, "Stream map '%s' matches no streams.\n"
483 "To ignore this, add a trailing '?' to the map.\n", arg);
484 ret = AVERROR(EINVAL);
485 goto fail;
486 }
487 }
488 208 ret = 0;
489 208 fail:
490 208 av_freep(&map);
491 208 return ret;
492 }
493
494 1 static int opt_attach(void *optctx, const char *opt, const char *arg)
495 {
496 1 OptionsContext *o = optctx;
497 1 int ret = GROW_ARRAY(o->attachments, o->nb_attachments);
498
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 if (ret < 0)
499 return ret;
500
501 1 o->attachments[o->nb_attachments - 1] = av_strdup(arg);
502
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 if (!o->attachments[o->nb_attachments - 1])
503 return AVERROR(ENOMEM);
504
505 1 return 0;
506 }
507
508 #if FFMPEG_OPT_MAP_CHANNEL
509 10 static int opt_map_channel(void *optctx, const char *opt, const char *arg)
510 {
511 10 OptionsContext *o = optctx;
512 int n, ret;
513 AVStream *st;
514 AudioChannelMap *m;
515 char *allow_unused;
516 char *mapchan;
517
518 10 av_log(NULL, AV_LOG_WARNING,
519 "The -%s option is deprecated and will be removed. "
520 "It can be replaced by the 'pan' filter, or in some cases by "
521 "combinations of 'channelsplit', 'channelmap', 'amerge' filters.\n", opt);
522
523 10 mapchan = av_strdup(arg);
524
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 10 times.
10 if (!mapchan)
525 return AVERROR(ENOMEM);
526
527 10 ret = GROW_ARRAY(o->audio_channel_maps, o->nb_audio_channel_maps);
528
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 10 times.
10 if (ret < 0)
529 goto end;
530
531 10 m = &o->audio_channel_maps[o->nb_audio_channel_maps - 1];
532
533 /* muted channel syntax */
534 10 n = sscanf(arg, "%d:%d.%d", &m->channel_idx, &m->ofile_idx, &m->ostream_idx);
535
3/6
✗ Branch 0 not taken.
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✓ Branch 5 taken 9 times.
10 if ((n == 1 || n == 3) && m->channel_idx == -1) {
536 1 m->file_idx = m->stream_idx = -1;
537
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if (n == 1)
538 1 m->ofile_idx = m->ostream_idx = -1;
539 1 av_free(mapchan);
540 1 return 0;
541 }
542
543 /* normal syntax */
544 9 n = sscanf(arg, "%d.%d.%d:%d.%d",
545 &m->file_idx, &m->stream_idx, &m->channel_idx,
546 &m->ofile_idx, &m->ostream_idx);
547
548
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if (n != 3 && n != 5) {
549 av_log(NULL, AV_LOG_FATAL, "Syntax error, mapchan usage: "
550 "[file.stream.channel|-1][:syncfile:syncstream]\n");
551 goto fail;
552 }
553
554
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if (n != 5) // only file.stream.channel specified
555 9 m->ofile_idx = m->ostream_idx = -1;
556
557 /* check input */
558
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 9 times.
9 if (m->file_idx < 0 || m->file_idx >= nb_input_files) {
559 av_log(NULL, AV_LOG_FATAL, "mapchan: invalid input file index: %d\n",
560 m->file_idx);
561 goto fail;
562 }
563
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if (m->stream_idx < 0 ||
564
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 m->stream_idx >= input_files[m->file_idx]->nb_streams) {
565 av_log(NULL, AV_LOG_FATAL, "mapchan: invalid input file stream index #%d.%d\n",
566 m->file_idx, m->stream_idx);
567 goto fail;
568 }
569 9 st = input_files[m->file_idx]->ctx->streams[m->stream_idx];
570
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if (st->codecpar->codec_type != AVMEDIA_TYPE_AUDIO) {
571 av_log(NULL, AV_LOG_FATAL, "mapchan: stream #%d.%d is not an audio stream.\n",
572 m->file_idx, m->stream_idx);
573 goto fail;
574 }
575 /* allow trailing ? to map_channel */
576
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 7 times.
9 if (allow_unused = strchr(mapchan, '?'))
577 2 *allow_unused = 0;
578
3/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 8 times.
✓ Branch 3 taken 1 times.
9 if (m->channel_idx < 0 || m->channel_idx >= st->codecpar->ch_layout.nb_channels ||
579
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8 times.
8 input_files[m->file_idx]->streams[m->stream_idx]->user_set_discard == AVDISCARD_ALL) {
580
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if (allow_unused) {
581 1 av_log(NULL, AV_LOG_VERBOSE, "mapchan: invalid audio channel #%d.%d.%d\n",
582 m->file_idx, m->stream_idx, m->channel_idx);
583 } else {
584 av_log(NULL, AV_LOG_FATAL, "mapchan: invalid audio channel #%d.%d.%d\n"
585 "To ignore this, add a trailing '?' to the map_channel.\n",
586 m->file_idx, m->stream_idx, m->channel_idx);
587 goto fail;
588 }
589
590 }
591 9 ret = 0;
592 9 end:
593 9 av_free(mapchan);
594 9 return ret;
595 fail:
596 ret = AVERROR(EINVAL);
597 goto end;
598 }
599 #endif
600
601 static int opt_sdp_file(void *optctx, const char *opt, const char *arg)
602 {
603 Scheduler *sch = optctx;
604 return sch_sdp_filename(sch, arg);
605 }
606
607 #if CONFIG_VAAPI
608 static int opt_vaapi_device(void *optctx, const char *opt, const char *arg)
609 {
610 const char *prefix = "vaapi:";
611 char *tmp;
612 int err;
613 tmp = av_asprintf("%s%s", prefix, arg);
614 if (!tmp)
615 return AVERROR(ENOMEM);
616 err = hw_device_init_from_string(tmp, NULL);
617 av_free(tmp);
618 return err;
619 }
620 #endif
621
622 #if CONFIG_QSV
623 static int opt_qsv_device(void *optctx, const char *opt, const char *arg)
624 {
625 const char *prefix = "qsv=__qsv_device:hw_any,child_device=";
626 int err;
627 char *tmp = av_asprintf("%s%s", prefix, arg);
628
629 if (!tmp)
630 return AVERROR(ENOMEM);
631
632 err = hw_device_init_from_string(tmp, NULL);
633 av_free(tmp);
634
635 return err;
636 }
637 #endif
638
639 static int opt_init_hw_device(void *optctx, const char *opt, const char *arg)
640 {
641 if (!strcmp(arg, "list")) {
642 enum AVHWDeviceType type = AV_HWDEVICE_TYPE_NONE;
643 printf("Supported hardware device types:\n");
644 while ((type = av_hwdevice_iterate_types(type)) !=
645 AV_HWDEVICE_TYPE_NONE)
646 printf("%s\n", av_hwdevice_get_type_name(type));
647 printf("\n");
648 return AVERROR_EXIT;
649 } else {
650 return hw_device_init_from_string(arg, NULL);
651 }
652 }
653
654 static int opt_filter_hw_device(void *optctx, const char *opt, const char *arg)
655 {
656 if (filter_hw_device) {
657 av_log(NULL, AV_LOG_ERROR, "Only one filter device can be used.\n");
658 return AVERROR(EINVAL);
659 }
660 filter_hw_device = hw_device_get_by_name(arg);
661 if (!filter_hw_device) {
662 av_log(NULL, AV_LOG_ERROR, "Invalid filter device %s.\n", arg);
663 return AVERROR(EINVAL);
664 }
665 return 0;
666 }
667
668 static int opt_recording_timestamp(void *optctx, const char *opt, const char *arg)
669 {
670 OptionsContext *o = optctx;
671 char buf[128];
672 int64_t recording_timestamp;
673 int ret;
674 struct tm time;
675
676 ret = av_parse_time(&recording_timestamp, arg, 0);
677 if (ret < 0)
678 return ret;
679
680 recording_timestamp /= 1e6;
681 time = *gmtime((time_t*)&recording_timestamp);
682 if (!strftime(buf, sizeof(buf), "creation_time=%Y-%m-%dT%H:%M:%S%z", &time))
683 return -1;
684 parse_option(o, "metadata", buf, options);
685
686 av_log(NULL, AV_LOG_WARNING, "%s is deprecated, set the 'creation_time' metadata "
687 "tag instead.\n", opt);
688 return 0;
689 }
690
691 11756 int find_codec(void *logctx, const char *name,
692 enum AVMediaType type, int encoder, const AVCodec **pcodec)
693 {
694 const AVCodecDescriptor *desc;
695
2/2
✓ Branch 0 taken 3580 times.
✓ Branch 1 taken 8176 times.
11756 const char *codec_string = encoder ? "encoder" : "decoder";
696 const AVCodec *codec;
697
698 11756 codec = encoder ?
699
2/2
✓ Branch 0 taken 3580 times.
✓ Branch 1 taken 8176 times.
11756 avcodec_find_encoder_by_name(name) :
700 8176 avcodec_find_decoder_by_name(name);
701
702
3/4
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 11755 times.
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
11756 if (!codec && (desc = avcodec_descriptor_get_by_name(name))) {
703
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 codec = encoder ? avcodec_find_encoder(desc->id) :
704 avcodec_find_decoder(desc->id);
705
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if (codec)
706 1 av_log(logctx, AV_LOG_VERBOSE, "Matched %s '%s' for codec '%s'.\n",
707 1 codec_string, codec->name, desc->name);
708 }
709
710
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 11756 times.
11756 if (!codec) {
711 av_log(logctx, AV_LOG_FATAL, "Unknown %s '%s'\n", codec_string, name);
712 return encoder ? AVERROR_ENCODER_NOT_FOUND :
713 AVERROR_DECODER_NOT_FOUND;
714 }
715
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 11756 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
11756 if (codec->type != type && !recast_media) {
716 av_log(logctx, AV_LOG_FATAL, "Invalid %s type '%s'\n", codec_string, name);
717 return AVERROR(EINVAL);
718 }
719
720 11756 *pcodec = codec;
721 11756 return 0;;
722 }
723
724 6659 int assert_file_overwrite(const char *filename)
725 {
726 6659 const char *proto_name = avio_find_protocol_name(filename);
727
728
3/4
✓ Branch 0 taken 1833 times.
✓ Branch 1 taken 4826 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1833 times.
6659 if (file_overwrite && no_file_overwrite) {
729 fprintf(stderr, "Error, both -y and -n supplied. Exiting.\n");
730 return AVERROR(EINVAL);
731 }
732
733
2/2
✓ Branch 0 taken 4826 times.
✓ Branch 1 taken 1833 times.
6659 if (!file_overwrite) {
734
2/6
✓ Branch 0 taken 4826 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 4826 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
4826 if (proto_name && !strcmp(proto_name, "file") && avio_check(filename, 0) == 0) {
735 if (stdin_interaction && !no_file_overwrite) {
736 fprintf(stderr,"File '%s' already exists. Overwrite? [y/N] ", filename);
737 fflush(stderr);
738 term_exit();
739 signal(SIGINT, SIG_DFL);
740 if (!read_yesno()) {
741 av_log(NULL, AV_LOG_FATAL, "Not overwriting - exiting\n");
742 return AVERROR_EXIT;
743 }
744 term_init();
745 }
746 else {
747 av_log(NULL, AV_LOG_FATAL, "File '%s' already exists. Exiting.\n", filename);
748 return AVERROR_EXIT;
749 }
750 }
751 }
752
753
3/4
✓ Branch 0 taken 6659 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1696 times.
✓ Branch 3 taken 4963 times.
6659 if (proto_name && !strcmp(proto_name, "file")) {
754
2/2
✓ Branch 0 taken 1742 times.
✓ Branch 1 taken 1696 times.
3438 for (int i = 0; i < nb_input_files; i++) {
755 1742 InputFile *file = input_files[i];
756
2/2
✓ Branch 0 taken 86 times.
✓ Branch 1 taken 1656 times.
1742 if (file->ctx->iformat->flags & AVFMT_NOFILE)
757 86 continue;
758
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1656 times.
1656 if (!strcmp(filename, file->ctx->url)) {
759 av_log(NULL, AV_LOG_FATAL, "Output %s same as Input #%d - exiting\n", filename, i);
760 av_log(NULL, AV_LOG_WARNING, "FFmpeg cannot edit existing files in-place.\n");
761 return AVERROR(EINVAL);
762 }
763 }
764 }
765
766 6659 return 0;
767 }
768
769 /* arg format is "output-stream-index:streamid-value". */
770 18 static int opt_streamid(void *optctx, const char *opt, const char *arg)
771 {
772 18 OptionsContext *o = optctx;
773 char *p;
774 char idx_str[16];
775
776 18 av_strlcpy(idx_str, arg, sizeof(idx_str));
777 18 p = strchr(idx_str, ':');
778
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
18 if (!p) {
779 av_log(NULL, AV_LOG_FATAL,
780 "Invalid value '%s' for option '%s', required syntax is 'index:value'\n",
781 arg, opt);
782 return AVERROR(EINVAL);
783 }
784 18 *p++ = '\0';
785
786 18 return av_dict_set(&o->streamid, idx_str, p, 0);
787 }
788
789 6740 static int init_complex_filters(void)
790 {
791 6740 int i, ret = 0;
792
793
2/2
✓ Branch 0 taken 113 times.
✓ Branch 1 taken 6740 times.
6853 for (i = 0; i < nb_filtergraphs; i++) {
794 113 ret = init_complex_filtergraph(filtergraphs[i]);
795
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 113 times.
113 if (ret < 0)
796 return ret;
797 }
798 6740 return 0;
799 }
800
801 static int opt_target(void *optctx, const char *opt, const char *arg)
802 {
803 OptionsContext *o = optctx;
804 enum { PAL, NTSC, FILM, UNKNOWN } norm = UNKNOWN;
805 static const char *const frame_rates[] = { "25", "30000/1001", "24000/1001" };
806
807 if (!strncmp(arg, "pal-", 4)) {
808 norm = PAL;
809 arg += 4;
810 } else if (!strncmp(arg, "ntsc-", 5)) {
811 norm = NTSC;
812 arg += 5;
813 } else if (!strncmp(arg, "film-", 5)) {
814 norm = FILM;
815 arg += 5;
816 } else {
817 /* Try to determine PAL/NTSC by peeking in the input files */
818 if (nb_input_files) {
819 int i, j;
820 for (j = 0; j < nb_input_files; j++) {
821 for (i = 0; i < input_files[j]->nb_streams; i++) {
822 AVStream *st = input_files[j]->ctx->streams[i];
823 int64_t fr;
824 if (st->codecpar->codec_type != AVMEDIA_TYPE_VIDEO)
825 continue;
826 fr = st->time_base.den * 1000LL / st->time_base.num;
827 if (fr == 25000) {
828 norm = PAL;
829 break;
830 } else if ((fr == 29970) || (fr == 23976)) {
831 norm = NTSC;
832 break;
833 }
834 }
835 if (norm != UNKNOWN)
836 break;
837 }
838 }
839 if (norm != UNKNOWN)
840 av_log(NULL, AV_LOG_INFO, "Assuming %s for target.\n", norm == PAL ? "PAL" : "NTSC");
841 }
842
843 if (norm == UNKNOWN) {
844 av_log(NULL, AV_LOG_FATAL, "Could not determine norm (PAL/NTSC/NTSC-Film) for target.\n");
845 av_log(NULL, AV_LOG_FATAL, "Please prefix target with \"pal-\", \"ntsc-\" or \"film-\",\n");
846 av_log(NULL, AV_LOG_FATAL, "or set a framerate with \"-r xxx\".\n");
847 return AVERROR(EINVAL);
848 }
849
850 if (!strcmp(arg, "vcd")) {
851 opt_video_codec(o, "c:v", "mpeg1video");
852 opt_audio_codec(o, "c:a", "mp2");
853 parse_option(o, "f", "vcd", options);
854
855 parse_option(o, "s", norm == PAL ? "352x288" : "352x240", options);
856 parse_option(o, "r", frame_rates[norm], options);
857 opt_default(NULL, "g", norm == PAL ? "15" : "18");
858
859 opt_default(NULL, "b:v", "1150000");
860 opt_default(NULL, "maxrate:v", "1150000");
861 opt_default(NULL, "minrate:v", "1150000");
862 opt_default(NULL, "bufsize:v", "327680"); // 40*1024*8;
863
864 opt_default(NULL, "b:a", "224000");
865 parse_option(o, "ar", "44100", options);
866 parse_option(o, "ac", "2", options);
867
868 opt_default(NULL, "packetsize", "2324");
869 opt_default(NULL, "muxrate", "1411200"); // 2352 * 75 * 8;
870
871 /* We have to offset the PTS, so that it is consistent with the SCR.
872 SCR starts at 36000, but the first two packs contain only padding
873 and the first pack from the other stream, respectively, may also have
874 been written before.
875 So the real data starts at SCR 36000+3*1200. */
876 o->mux_preload = (36000 + 3 * 1200) / 90000.0; // 0.44
877 } else if (!strcmp(arg, "svcd")) {
878
879 opt_video_codec(o, "c:v", "mpeg2video");
880 opt_audio_codec(o, "c:a", "mp2");
881 parse_option(o, "f", "svcd", options);
882
883 parse_option(o, "s", norm == PAL ? "480x576" : "480x480", options);
884 parse_option(o, "r", frame_rates[norm], options);
885 parse_option(o, "pix_fmt", "yuv420p", options);
886 opt_default(NULL, "g", norm == PAL ? "15" : "18");
887
888 opt_default(NULL, "b:v", "2040000");
889 opt_default(NULL, "maxrate:v", "2516000");
890 opt_default(NULL, "minrate:v", "0"); // 1145000;
891 opt_default(NULL, "bufsize:v", "1835008"); // 224*1024*8;
892 opt_default(NULL, "scan_offset", "1");
893
894 opt_default(NULL, "b:a", "224000");
895 parse_option(o, "ar", "44100", options);
896
897 opt_default(NULL, "packetsize", "2324");
898
899 } else if (!strcmp(arg, "dvd")) {
900
901 opt_video_codec(o, "c:v", "mpeg2video");
902 opt_audio_codec(o, "c:a", "ac3");
903 parse_option(o, "f", "dvd", options);
904
905 parse_option(o, "s", norm == PAL ? "720x576" : "720x480", options);
906 parse_option(o, "r", frame_rates[norm], options);
907 parse_option(o, "pix_fmt", "yuv420p", options);
908 opt_default(NULL, "g", norm == PAL ? "15" : "18");
909
910 opt_default(NULL, "b:v", "6000000");
911 opt_default(NULL, "maxrate:v", "9000000");
912 opt_default(NULL, "minrate:v", "0"); // 1500000;
913 opt_default(NULL, "bufsize:v", "1835008"); // 224*1024*8;
914
915 opt_default(NULL, "packetsize", "2048"); // from www.mpucoder.com: DVD sectors contain 2048 bytes of data, this is also the size of one pack.
916 opt_default(NULL, "muxrate", "10080000"); // from mplex project: data_rate = 1260000. mux_rate = data_rate * 8
917
918 opt_default(NULL, "b:a", "448000");
919 parse_option(o, "ar", "48000", options);
920
921 } else if (!strncmp(arg, "dv", 2)) {
922
923 parse_option(o, "f", "dv", options);
924
925 parse_option(o, "s", norm == PAL ? "720x576" : "720x480", options);
926 parse_option(o, "pix_fmt", !strncmp(arg, "dv50", 4) ? "yuv422p" :
927 norm == PAL ? "yuv420p" : "yuv411p", options);
928 parse_option(o, "r", frame_rates[norm], options);
929
930 parse_option(o, "ar", "48000", options);
931 parse_option(o, "ac", "2", options);
932
933 } else {
934 av_log(NULL, AV_LOG_ERROR, "Unknown target: %s\n", arg);
935 return AVERROR(EINVAL);
936 }
937
938 av_dict_copy(&o->g->codec_opts, codec_opts, AV_DICT_DONT_OVERWRITE);
939 av_dict_copy(&o->g->format_opts, format_opts, AV_DICT_DONT_OVERWRITE);
940
941 return 0;
942 }
943
944 static int opt_vstats_file(void *optctx, const char *opt, const char *arg)
945 {
946 av_free (vstats_filename);
947 vstats_filename = av_strdup (arg);
948 return 0;
949 }
950
951 static int opt_vstats(void *optctx, const char *opt, const char *arg)
952 {
953 char filename[40];
954 time_t today2 = time(NULL);
955 struct tm *today = localtime(&today2);
956
957 if (!today) { // maybe tomorrow
958 av_log(NULL, AV_LOG_FATAL, "Unable to get current time: %s\n", strerror(errno));
959 return AVERROR(errno);
960 }
961
962 snprintf(filename, sizeof(filename), "vstats_%02d%02d%02d.log", today->tm_hour, today->tm_min,
963 today->tm_sec);
964 return opt_vstats_file(NULL, opt, filename);
965 }
966
967 static int opt_video_frames(void *optctx, const char *opt, const char *arg)
968 {
969 OptionsContext *o = optctx;
970 return parse_option(o, "frames:v", arg, options);
971 }
972
973 static int opt_audio_frames(void *optctx, const char *opt, const char *arg)
974 {
975 OptionsContext *o = optctx;
976 return parse_option(o, "frames:a", arg, options);
977 }
978
979 static int opt_data_frames(void *optctx, const char *opt, const char *arg)
980 {
981 OptionsContext *o = optctx;
982 return parse_option(o, "frames:d", arg, options);
983 }
984
985 static int opt_default_new(OptionsContext *o, const char *opt, const char *arg)
986 {
987 int ret;
988 AVDictionary *cbak = codec_opts;
989 AVDictionary *fbak = format_opts;
990 codec_opts = NULL;
991 format_opts = NULL;
992
993 ret = opt_default(NULL, opt, arg);
994
995 av_dict_copy(&o->g->codec_opts , codec_opts, 0);
996 av_dict_copy(&o->g->format_opts, format_opts, 0);
997 av_dict_free(&codec_opts);
998 av_dict_free(&format_opts);
999 codec_opts = cbak;
1000 format_opts = fbak;
1001
1002 return ret;
1003 }
1004
1005 static int opt_preset(void *optctx, const char *opt, const char *arg)
1006 {
1007 OptionsContext *o = optctx;
1008 FILE *f=NULL;
1009 char filename[1000], line[1000], tmp_line[1000];
1010 const char *codec_name = NULL;
1011 int ret = 0;
1012
1013 codec_name = opt_match_per_type_str(&o->codec_names, *opt);
1014
1015 if (!(f = get_preset_file(filename, sizeof(filename), arg, *opt == 'f', codec_name))) {
1016 if(!strncmp(arg, "libx264-lossless", strlen("libx264-lossless"))){
1017 av_log(NULL, AV_LOG_FATAL, "Please use -preset <speed> -qp 0\n");
1018 }else
1019 av_log(NULL, AV_LOG_FATAL, "File for preset '%s' not found\n", arg);
1020 return AVERROR(ENOENT);
1021 }
1022
1023 while (fgets(line, sizeof(line), f)) {
1024 char *key = tmp_line, *value, *endptr;
1025
1026 if (strcspn(line, "#\n\r") == 0)
1027 continue;
1028 av_strlcpy(tmp_line, line, sizeof(tmp_line));
1029 if (!av_strtok(key, "=", &value) ||
1030 !av_strtok(value, "\r\n", &endptr)) {
1031 av_log(NULL, AV_LOG_FATAL, "%s: Invalid syntax: '%s'\n", filename, line);
1032 ret = AVERROR(EINVAL);
1033 goto fail;
1034 }
1035 av_log(NULL, AV_LOG_DEBUG, "ffpreset[%s]: set '%s' = '%s'\n", filename, key, value);
1036
1037 if (!strcmp(key, "acodec")) opt_audio_codec (o, key, value);
1038 else if (!strcmp(key, "vcodec")) opt_video_codec (o, key, value);
1039 else if (!strcmp(key, "scodec")) opt_subtitle_codec(o, key, value);
1040 else if (!strcmp(key, "dcodec")) opt_data_codec (o, key, value);
1041 else if (opt_default_new(o, key, value) < 0) {
1042 av_log(NULL, AV_LOG_FATAL, "%s: Invalid option or argument: '%s', parsed as '%s' = '%s'\n",
1043 filename, line, key, value);
1044 ret = AVERROR(EINVAL);
1045 goto fail;
1046 }
1047 }
1048
1049 fail:
1050 fclose(f);
1051
1052 return ret;
1053 }
1054
1055 static int opt_old2new(void *optctx, const char *opt, const char *arg)
1056 {
1057 OptionsContext *o = optctx;
1058 int ret;
1059 char *s = av_asprintf("%s:%c", opt + 1, *opt);
1060 if (!s)
1061 return AVERROR(ENOMEM);
1062 ret = parse_option(o, s, arg, options);
1063 av_free(s);
1064 return ret;
1065 }
1066
1067 166 static int opt_bitrate(void *optctx, const char *opt, const char *arg)
1068 {
1069 166 OptionsContext *o = optctx;
1070
1071
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 165 times.
166 if(!strcmp(opt, "ab")){
1072 1 av_dict_set(&o->g->codec_opts, "b:a", arg, 0);
1073 1 return 0;
1074
2/2
✓ Branch 0 taken 43 times.
✓ Branch 1 taken 122 times.
165 } else if(!strcmp(opt, "b")){
1075 43 av_log(NULL, AV_LOG_WARNING, "Please use -b:a or -b:v, -b is ambiguous\n");
1076 43 av_dict_set(&o->g->codec_opts, "b:v", arg, 0);
1077 43 return 0;
1078 }
1079 122 av_dict_set(&o->g->codec_opts, opt, arg, 0);
1080 122 return 0;
1081 }
1082
1083 288 static int opt_qscale(void *optctx, const char *opt, const char *arg)
1084 {
1085 288 OptionsContext *o = optctx;
1086 char *s;
1087 int ret;
1088
2/2
✓ Branch 0 taken 247 times.
✓ Branch 1 taken 41 times.
288 if(!strcmp(opt, "qscale")){
1089 247 av_log(NULL, AV_LOG_WARNING, "Please use -q:a or -q:v, -qscale is ambiguous\n");
1090 247 return parse_option(o, "q:v", arg, options);
1091 }
1092 41 s = av_asprintf("q%s", opt + 6);
1093
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 41 times.
41 if (!s)
1094 return AVERROR(ENOMEM);
1095 41 ret = parse_option(o, s, arg, options);
1096 41 av_free(s);
1097 41 return ret;
1098 }
1099
1100 45 static int opt_profile(void *optctx, const char *opt, const char *arg)
1101 {
1102 45 OptionsContext *o = optctx;
1103
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 41 times.
45 if(!strcmp(opt, "profile")){
1104 4 av_log(NULL, AV_LOG_WARNING, "Please use -profile:a or -profile:v, -profile is ambiguous\n");
1105 4 av_dict_set(&o->g->codec_opts, "profile:v", arg, 0);
1106 4 return 0;
1107 }
1108 41 av_dict_set(&o->g->codec_opts, opt, arg, 0);
1109 41 return 0;
1110 }
1111
1112 2815 static int opt_video_filters(void *optctx, const char *opt, const char *arg)
1113 {
1114 2815 OptionsContext *o = optctx;
1115 2815 return parse_option(o, "filter:v", arg, options);
1116 }
1117
1118 570 static int opt_audio_filters(void *optctx, const char *opt, const char *arg)
1119 {
1120 570 OptionsContext *o = optctx;
1121 570 return parse_option(o, "filter:a", arg, options);
1122 }
1123
1124 #if FFMPEG_OPT_VSYNC
1125 static int opt_vsync(void *optctx, const char *opt, const char *arg)
1126 {
1127 av_log(NULL, AV_LOG_WARNING, "-vsync is deprecated. Use -fps_mode\n");
1128 return parse_and_set_vsync(arg, &video_sync_method, -1, -1, 1);
1129 }
1130 #endif
1131
1132 15 static int opt_timecode(void *optctx, const char *opt, const char *arg)
1133 {
1134 15 OptionsContext *o = optctx;
1135 int ret;
1136 15 char *tcr = av_asprintf("timecode=%s", arg);
1137
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 15 times.
15 if (!tcr)
1138 return AVERROR(ENOMEM);
1139 15 ret = parse_option(o, "metadata:g", tcr, options);
1140
1/2
✓ Branch 0 taken 15 times.
✗ Branch 1 not taken.
15 if (ret >= 0)
1141 15 ret = av_dict_set(&o->g->codec_opts, "gop_timecode", arg, 0);
1142 15 av_free(tcr);
1143 15 return ret;
1144 }
1145
1146 static int opt_audio_qscale(void *optctx, const char *opt, const char *arg)
1147 {
1148 OptionsContext *o = optctx;
1149 return parse_option(o, "q:a", arg, options);
1150 }
1151
1152 113 static int opt_filter_complex(void *optctx, const char *opt, const char *arg)
1153 {
1154 113 Scheduler *sch = optctx;
1155 113 char *graph_desc = av_strdup(arg);
1156
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 113 times.
113 if (!graph_desc)
1157 return AVERROR(ENOMEM);
1158
1159 113 return fg_create(NULL, graph_desc, sch);
1160 }
1161
1162 #if FFMPEG_OPT_FILTER_SCRIPT
1163 static int opt_filter_complex_script(void *optctx, const char *opt, const char *arg)
1164 {
1165 Scheduler *sch = optctx;
1166 char *graph_desc = file_read(arg);
1167 if (!graph_desc)
1168 return AVERROR(EINVAL);
1169
1170 av_log(NULL, AV_LOG_WARNING, "-%s is deprecated, use -/filter_complex %s instead\n",
1171 opt, arg);
1172
1173 return fg_create(NULL, graph_desc, sch);
1174 }
1175 #endif
1176
1177 void show_help_default(const char *opt, const char *arg)
1178 {
1179 int show_advanced = 0, show_avoptions = 0;
1180
1181 if (opt && *opt) {
1182 if (!strcmp(opt, "long"))
1183 show_advanced = 1;
1184 else if (!strcmp(opt, "full"))
1185 show_advanced = show_avoptions = 1;
1186 else
1187 av_log(NULL, AV_LOG_ERROR, "Unknown help option '%s'.\n", opt);
1188 }
1189
1190 show_usage();
1191
1192 printf("Getting help:\n"
1193 " -h -- print basic options\n"
1194 " -h long -- print more options\n"
1195 " -h full -- print all options (including all format and codec specific options, very long)\n"
1196 " -h type=name -- print all options for the named decoder/encoder/demuxer/muxer/filter/bsf/protocol\n"
1197 " See man %s for detailed description of the options.\n"
1198 "\n"
1199 "Per-stream options can be followed by :<stream_spec> to apply that option to specific streams only. "
1200 "<stream_spec> can be a stream index, or v/a/s for video/audio/subtitle (see manual for full syntax).\n"
1201 "\n", program_name);
1202
1203 show_help_options(options, "Print help / information / capabilities:",
1204 OPT_EXIT, OPT_EXPERT);
1205 if (show_advanced)
1206 show_help_options(options, "Advanced information / capabilities:",
1207 OPT_EXIT | OPT_EXPERT, 0);
1208
1209 show_help_options(options, "Global options (affect whole program "
1210 "instead of just one file):",
1211 0, OPT_PERFILE | OPT_EXIT | OPT_EXPERT);
1212 if (show_advanced)
1213 show_help_options(options, "Advanced global options:", OPT_EXPERT,
1214 OPT_PERFILE | OPT_EXIT);
1215
1216 show_help_options(options, "Per-file options (input and output):",
1217 OPT_PERFILE | OPT_INPUT | OPT_OUTPUT,
1218 OPT_EXIT | OPT_FLAG_PERSTREAM | OPT_EXPERT |
1219 OPT_VIDEO | OPT_AUDIO | OPT_SUBTITLE | OPT_DATA);
1220 if (show_advanced)
1221 show_help_options(options, "Advanced per-file options (input and output):",
1222 OPT_PERFILE | OPT_INPUT | OPT_OUTPUT | OPT_EXPERT,
1223 OPT_EXIT | OPT_FLAG_PERSTREAM |
1224 OPT_VIDEO | OPT_AUDIO | OPT_SUBTITLE | OPT_DATA);
1225
1226 show_help_options(options, "Per-file options (input-only):",
1227 OPT_PERFILE | OPT_INPUT,
1228 OPT_EXIT | OPT_FLAG_PERSTREAM | OPT_OUTPUT | OPT_EXPERT |
1229 OPT_VIDEO | OPT_AUDIO | OPT_SUBTITLE | OPT_DATA);
1230 if (show_advanced)
1231 show_help_options(options, "Advanced per-file options (input-only):",
1232 OPT_PERFILE | OPT_INPUT | OPT_EXPERT,
1233 OPT_EXIT | OPT_FLAG_PERSTREAM | OPT_OUTPUT |
1234 OPT_VIDEO | OPT_AUDIO | OPT_SUBTITLE | OPT_DATA);
1235
1236 show_help_options(options, "Per-file options (output-only):",
1237 OPT_PERFILE | OPT_OUTPUT,
1238 OPT_EXIT | OPT_FLAG_PERSTREAM | OPT_INPUT | OPT_EXPERT |
1239 OPT_VIDEO | OPT_AUDIO | OPT_SUBTITLE | OPT_DATA);
1240 if (show_advanced)
1241 show_help_options(options, "Advanced per-file options (output-only):",
1242 OPT_PERFILE | OPT_OUTPUT | OPT_EXPERT,
1243 OPT_EXIT | OPT_FLAG_PERSTREAM | OPT_INPUT |
1244 OPT_VIDEO | OPT_AUDIO | OPT_SUBTITLE | OPT_DATA);
1245
1246 show_help_options(options, "Per-stream options:",
1247 OPT_FLAG_PERSTREAM,
1248 OPT_EXIT | OPT_EXPERT |
1249 OPT_VIDEO | OPT_AUDIO | OPT_SUBTITLE | OPT_DATA);
1250 if (show_advanced)
1251 show_help_options(options, "Advanced per-stream options:",
1252 OPT_FLAG_PERSTREAM | OPT_EXPERT,
1253 OPT_EXIT |
1254 OPT_VIDEO | OPT_AUDIO | OPT_SUBTITLE | OPT_DATA);
1255
1256 show_help_options(options, "Video options:",
1257 OPT_VIDEO, OPT_EXPERT | OPT_AUDIO | OPT_SUBTITLE | OPT_DATA);
1258 if (show_advanced)
1259 show_help_options(options, "Advanced Video options:",
1260 OPT_EXPERT | OPT_VIDEO, OPT_AUDIO | OPT_SUBTITLE | OPT_DATA);
1261
1262 show_help_options(options, "Audio options:",
1263 OPT_AUDIO, OPT_EXPERT | OPT_VIDEO | OPT_SUBTITLE | OPT_DATA);
1264 if (show_advanced)
1265 show_help_options(options, "Advanced Audio options:",
1266 OPT_EXPERT | OPT_AUDIO, OPT_VIDEO | OPT_SUBTITLE | OPT_DATA);
1267
1268 show_help_options(options, "Subtitle options:",
1269 OPT_SUBTITLE, OPT_EXPERT | OPT_VIDEO | OPT_AUDIO | OPT_DATA);
1270 if (show_advanced)
1271 show_help_options(options, "Advanced Subtitle options:",
1272 OPT_EXPERT | OPT_SUBTITLE, OPT_VIDEO | OPT_AUDIO | OPT_DATA);
1273
1274 if (show_advanced)
1275 show_help_options(options, "Data stream options:",
1276 OPT_DATA, OPT_VIDEO | OPT_AUDIO | OPT_SUBTITLE);
1277 printf("\n");
1278
1279 if (show_avoptions) {
1280 int flags = AV_OPT_FLAG_DECODING_PARAM | AV_OPT_FLAG_ENCODING_PARAM;
1281 show_help_children(avcodec_get_class(), flags);
1282 show_help_children(avformat_get_class(), flags);
1283 #if CONFIG_SWSCALE
1284 show_help_children(sws_get_class(), flags);
1285 #endif
1286 #if CONFIG_SWRESAMPLE
1287 show_help_children(swr_get_class(), AV_OPT_FLAG_AUDIO_PARAM);
1288 #endif
1289 show_help_children(avfilter_get_class(), AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_AUDIO_PARAM | AV_OPT_FLAG_FILTERING_PARAM);
1290 show_help_children(av_bsf_get_class(), AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_AUDIO_PARAM | AV_OPT_FLAG_BSF_PARAM);
1291 }
1292 }
1293
1294 void show_usage(void)
1295 {
1296 av_log(NULL, AV_LOG_INFO, "Universal media converter\n");
1297 av_log(NULL, AV_LOG_INFO, "usage: %s [options] [[infile options] -i infile]... {[outfile options] outfile}...\n", program_name);
1298 av_log(NULL, AV_LOG_INFO, "\n");
1299 }
1300
1301 enum OptGroup {
1302 GROUP_OUTFILE,
1303 GROUP_INFILE,
1304 };
1305
1306 static const OptionGroupDef groups[] = {
1307 [GROUP_OUTFILE] = { "output url", NULL, OPT_OUTPUT },
1308 [GROUP_INFILE] = { "input url", "i", OPT_INPUT },
1309 };
1310
1311 13480 static int open_files(OptionGroupList *l, const char *inout, Scheduler *sch,
1312 int (*open_file)(const OptionsContext*, const char*,
1313 Scheduler*))
1314 {
1315 int i, ret;
1316
1317
2/2
✓ Branch 0 taken 13513 times.
✓ Branch 1 taken 13480 times.
26993 for (i = 0; i < l->nb_groups; i++) {
1318 13513 OptionGroup *g = &l->groups[i];
1319 OptionsContext o;
1320
1321 13513 init_options(&o);
1322 13513 o.g = g;
1323
1324 13513 ret = parse_optgroup(&o, g, options);
1325
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 13513 times.
13513 if (ret < 0) {
1326 av_log(NULL, AV_LOG_ERROR, "Error parsing options for %s file "
1327 "%s.\n", inout, g->arg);
1328 uninit_options(&o);
1329 return ret;
1330 }
1331
1332 13513 av_log(NULL, AV_LOG_DEBUG, "Opening an %s file: %s.\n", inout, g->arg);
1333 13513 ret = open_file(&o, g->arg, sch);
1334 13513 uninit_options(&o);
1335
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 13513 times.
13513 if (ret < 0) {
1336 av_log(NULL, AV_LOG_ERROR, "Error opening %s file %s.\n",
1337 inout, g->arg);
1338 return ret;
1339 }
1340 13513 av_log(NULL, AV_LOG_DEBUG, "Successfully opened the file.\n");
1341 }
1342
1343 13480 return 0;
1344 }
1345
1346 6741 int ffmpeg_parse_options(int argc, char **argv, Scheduler *sch)
1347 {
1348 OptionParseContext octx;
1349 6741 const char *errmsg = NULL;
1350 int ret;
1351
1352 6741 memset(&octx, 0, sizeof(octx));
1353
1354 /* split the commandline into an internal representation */
1355 6741 ret = split_commandline(&octx, argc, argv, options, groups,
1356 FF_ARRAY_ELEMS(groups));
1357
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6741 times.
6741 if (ret < 0) {
1358 errmsg = "splitting the argument list";
1359 goto fail;
1360 }
1361
1362 /* apply global options */
1363 6741 ret = parse_optgroup(sch, &octx.global_opts, options);
1364
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 6740 times.
6741 if (ret < 0) {
1365 1 errmsg = "parsing global options";
1366 1 goto fail;
1367 }
1368
1369 /* configure terminal and setup signal handlers */
1370 6740 term_init();
1371
1372 /* open input files */
1373 6740 ret = open_files(&octx.groups[GROUP_INFILE], "input", sch, ifile_open);
1374
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6740 times.
6740 if (ret < 0) {
1375 errmsg = "opening input files";
1376 goto fail;
1377 }
1378
1379 /* create the complex filtergraphs */
1380 6740 ret = init_complex_filters();
1381
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6740 times.
6740 if (ret < 0) {
1382 errmsg = "initializing complex filters";
1383 goto fail;
1384 }
1385
1386 /* open output files */
1387 6740 ret = open_files(&octx.groups[GROUP_OUTFILE], "output", sch, of_open);
1388
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6740 times.
6740 if (ret < 0) {
1389 errmsg = "opening output files";
1390 goto fail;
1391 }
1392
1393 6740 correct_input_start_times();
1394
1395 6740 ret = apply_sync_offsets();
1396
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6740 times.
6740 if (ret < 0)
1397 goto fail;
1398
1399 6740 ret = check_filter_outputs();
1400
1/2
✓ Branch 0 taken 6740 times.
✗ Branch 1 not taken.
6740 if (ret < 0)
1401 goto fail;
1402
1403 6740 fail:
1404 6741 uninit_parse_context(&octx);
1405
3/4
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 6740 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
6741 if (ret < 0 && ret != AVERROR_EXIT) {
1406 av_log(NULL, AV_LOG_FATAL, "Error %s: %s\n",
1407 errmsg ? errmsg : "", av_err2str(ret));
1408 }
1409 6741 return ret;
1410 }
1411
1412 static int opt_progress(void *optctx, const char *opt, const char *arg)
1413 {
1414 AVIOContext *avio = NULL;
1415 int ret;
1416
1417 if (!strcmp(arg, "-"))
1418 arg = "pipe:";
1419 ret = avio_open2(&avio, arg, AVIO_FLAG_WRITE, &int_cb, NULL);
1420 if (ret < 0) {
1421 av_log(NULL, AV_LOG_ERROR, "Failed to open progress URL \"%s\": %s\n",
1422 arg, av_err2str(ret));
1423 return ret;
1424 }
1425 progress_avio = avio;
1426 return 0;
1427 }
1428
1429 int opt_timelimit(void *optctx, const char *opt, const char *arg)
1430 {
1431 #if HAVE_SETRLIMIT
1432 int ret;
1433 double lim;
1434 struct rlimit rl;
1435
1436 ret = parse_number(opt, arg, OPT_TYPE_INT64, 0, INT_MAX, &lim);
1437 if (ret < 0)
1438 return ret;
1439
1440 rl = (struct rlimit){ lim, lim + 1 };
1441 if (setrlimit(RLIMIT_CPU, &rl))
1442 perror("setrlimit");
1443 #else
1444 av_log(NULL, AV_LOG_WARNING, "-%s not implemented on this OS\n", opt);
1445 #endif
1446 return 0;
1447 }
1448
1449 #if FFMPEG_OPT_QPHIST
1450 static int opt_qphist(void *optctx, const char *opt, const char *arg)
1451 {
1452 av_log(NULL, AV_LOG_WARNING, "Option -%s is deprecated and has no effect\n", opt);
1453 return 0;
1454 }
1455 #endif
1456
1457 #if FFMPEG_OPT_ADRIFT_THRESHOLD
1458 static int opt_adrift_threshold(void *optctx, const char *opt, const char *arg)
1459 {
1460 av_log(NULL, AV_LOG_WARNING, "Option -%s is deprecated and has no effect\n", opt);
1461 return 0;
1462 }
1463 #endif
1464
1465 static const char *const alt_bsf[] = { "absf", "vbsf", NULL };
1466 static const char *const alt_channel_layout[] = { "ch_layout", NULL};
1467 static const char *const alt_codec[] = { "c", "acodec", "vcodec", "scodec", "dcodec", NULL };
1468 static const char *const alt_filter[] = { "af", "vf", NULL };
1469 static const char *const alt_frames[] = { "aframes", "vframes", "dframes", NULL };
1470 static const char *const alt_pre[] = { "apre", "vpre", "spre", NULL};
1471 static const char *const alt_qscale[] = { "q", NULL};
1472 static const char *const alt_tag[] = { "atag", "vtag", "stag", NULL };
1473
1474 #define OFFSET(x) offsetof(OptionsContext, x)
1475 const OptionDef options[] = {
1476 /* main options */
1477 CMDUTILS_COMMON_OPTIONS
1478 { "f", OPT_TYPE_STRING, OPT_OFFSET | OPT_INPUT | OPT_OUTPUT,
1479 { .off = OFFSET(format) },
1480 "force container format (auto-detected otherwise)", "fmt" },
1481 { "y", OPT_TYPE_BOOL, 0,
1482 { &file_overwrite },
1483 "overwrite output files" },
1484 { "n", OPT_TYPE_BOOL, 0,
1485 { &no_file_overwrite },
1486 "never overwrite output files" },
1487 { "ignore_unknown", OPT_TYPE_BOOL, OPT_EXPERT,
1488 { &ignore_unknown_streams },
1489 "Ignore unknown stream types" },
1490 { "copy_unknown", OPT_TYPE_BOOL, OPT_EXPERT,
1491 { &copy_unknown_streams },
1492 "Copy unknown stream types" },
1493 { "recast_media", OPT_TYPE_BOOL, OPT_EXPERT,
1494 { &recast_media },
1495 "allow recasting stream type in order to force a decoder of different media type" },
1496 { "c", OPT_TYPE_STRING, OPT_PERSTREAM | OPT_INPUT | OPT_OUTPUT | OPT_HAS_CANON,
1497 { .off = OFFSET(codec_names) },
1498 "select encoder/decoder ('copy' to copy stream without reencoding)", "codec",
1499 .u1.name_canon = "codec", },
1500 { "codec", OPT_TYPE_STRING, OPT_PERSTREAM | OPT_INPUT | OPT_OUTPUT | OPT_EXPERT | OPT_HAS_ALT,
1501 { .off = OFFSET(codec_names) },
1502 "alias for -c (select encoder/decoder)", "codec",
1503 .u1.names_alt = alt_codec, },
1504 { "pre", OPT_TYPE_STRING, OPT_PERSTREAM | OPT_OUTPUT | OPT_EXPERT | OPT_HAS_ALT,
1505 { .off = OFFSET(presets) },
1506 "preset name", "preset",
1507 .u1.names_alt = alt_pre, },
1508 { "map", OPT_TYPE_FUNC, OPT_FUNC_ARG | OPT_EXPERT | OPT_PERFILE | OPT_OUTPUT,
1509 { .func_arg = opt_map },
1510 "set input stream mapping",
1511 "[-]input_file_id[:stream_specifier][,sync_file_id[:stream_specifier]]" },
1512 { "map_metadata", OPT_TYPE_STRING, OPT_SPEC | OPT_OUTPUT | OPT_EXPERT,
1513 { .off = OFFSET(metadata_map) },
1514 "set metadata information of outfile from infile",
1515 "outfile[,metadata]:infile[,metadata]" },
1516 { "map_chapters", OPT_TYPE_INT, OPT_EXPERT | OPT_OFFSET | OPT_OUTPUT,
1517 { .off = OFFSET(chapters_input_file) },
1518 "set chapters mapping", "input_file_index" },
1519 { "t", OPT_TYPE_TIME, OPT_OFFSET | OPT_INPUT | OPT_OUTPUT,
1520 { .off = OFFSET(recording_time) },
1521 "stop transcoding after specified duration",
1522 "duration" },
1523 { "to", OPT_TYPE_TIME, OPT_OFFSET | OPT_INPUT | OPT_OUTPUT,
1524 { .off = OFFSET(stop_time) },
1525 "stop transcoding after specified time is reached",
1526 "time_stop" },
1527 { "fs", OPT_TYPE_INT64, OPT_OFFSET | OPT_OUTPUT | OPT_EXPERT,
1528 { .off = OFFSET(limit_filesize) },
1529 "set the limit file size in bytes", "limit_size" },
1530 { "ss", OPT_TYPE_TIME, OPT_OFFSET | OPT_INPUT | OPT_OUTPUT,
1531 { .off = OFFSET(start_time) },
1532 "start transcoding at specified time", "time_off" },
1533 { "sseof", OPT_TYPE_TIME, OPT_OFFSET | OPT_INPUT | OPT_EXPERT,
1534 { .off = OFFSET(start_time_eof) },
1535 "set the start time offset relative to EOF", "time_off" },
1536 { "seek_timestamp", OPT_TYPE_INT, OPT_OFFSET | OPT_INPUT | OPT_EXPERT,
1537 { .off = OFFSET(seek_timestamp) },
1538 "enable/disable seeking by timestamp with -ss" },
1539 { "accurate_seek", OPT_TYPE_BOOL, OPT_OFFSET | OPT_EXPERT | OPT_INPUT,
1540 { .off = OFFSET(accurate_seek) },
1541 "enable/disable accurate seeking with -ss" },
1542 { "isync", OPT_TYPE_INT, OPT_OFFSET | OPT_EXPERT | OPT_INPUT,
1543 { .off = OFFSET(input_sync_ref) },
1544 "Indicate the input index for sync reference", "sync ref" },
1545 { "itsoffset", OPT_TYPE_TIME, OPT_OFFSET | OPT_EXPERT | OPT_INPUT,
1546 { .off = OFFSET(input_ts_offset) },
1547 "set the input ts offset", "time_off" },
1548 { "itsscale", OPT_TYPE_DOUBLE, OPT_PERSTREAM | OPT_EXPERT | OPT_INPUT,
1549 { .off = OFFSET(ts_scale) },
1550 "set the input ts scale", "scale" },
1551 { "timestamp", OPT_TYPE_FUNC, OPT_FUNC_ARG | OPT_PERFILE | OPT_EXPERT | OPT_OUTPUT,
1552 { .func_arg = opt_recording_timestamp },
1553 "set the recording timestamp ('now' to set the current time)", "time" },
1554 { "metadata", OPT_TYPE_STRING, OPT_SPEC | OPT_OUTPUT,
1555 { .off = OFFSET(metadata) },
1556 "add metadata", "key=value" },
1557 { "program", OPT_TYPE_STRING, OPT_SPEC | OPT_EXPERT | OPT_OUTPUT,
1558 { .off = OFFSET(program) },
1559 "add program with specified streams", "title=string:st=number..." },
1560 { "stream_group", OPT_TYPE_STRING, OPT_SPEC | OPT_OUTPUT | OPT_EXPERT,
1561 { .off = OFFSET(stream_groups) },
1562 "add stream group with specified streams and group type-specific arguments", "id=number:st=number..." },
1563 { "dframes", OPT_TYPE_FUNC, OPT_FUNC_ARG | OPT_PERFILE | OPT_EXPERT | OPT_OUTPUT | OPT_HAS_CANON,
1564 { .func_arg = opt_data_frames },
1565 "set the number of data frames to output", "number",
1566 .u1.name_canon = "frames" },
1567 { "benchmark", OPT_TYPE_BOOL, OPT_EXPERT,
1568 { &do_benchmark },
1569 "add timings for benchmarking" },
1570 { "benchmark_all", OPT_TYPE_BOOL, OPT_EXPERT,
1571 { &do_benchmark_all },
1572 "add timings for each task" },
1573 { "progress", OPT_TYPE_FUNC, OPT_FUNC_ARG | OPT_EXPERT,
1574 { .func_arg = opt_progress },
1575 "write program-readable progress information", "url" },
1576 { "stdin", OPT_TYPE_BOOL, OPT_EXPERT,
1577 { &stdin_interaction },
1578 "enable or disable interaction on standard input" },
1579 { "timelimit", OPT_TYPE_FUNC, OPT_FUNC_ARG | OPT_EXPERT,
1580 { .func_arg = opt_timelimit },
1581 "set max runtime in seconds in CPU user time", "limit" },
1582 { "dump", OPT_TYPE_BOOL, OPT_EXPERT,
1583 { &do_pkt_dump },
1584 "dump each input packet" },
1585 { "hex", OPT_TYPE_BOOL, OPT_EXPERT,
1586 { &do_hex_dump },
1587 "when dumping packets, also dump the payload" },
1588 { "re", OPT_TYPE_BOOL, OPT_EXPERT | OPT_OFFSET | OPT_INPUT,
1589 { .off = OFFSET(rate_emu) },
1590 "read input at native frame rate; equivalent to -readrate 1", "" },
1591 { "readrate", OPT_TYPE_FLOAT, OPT_OFFSET | OPT_EXPERT | OPT_INPUT,
1592 { .off = OFFSET(readrate) },
1593 "read input at specified rate", "speed" },
1594 { "readrate_initial_burst", OPT_TYPE_DOUBLE, OPT_OFFSET | OPT_EXPERT | OPT_INPUT,
1595 { .off = OFFSET(readrate_initial_burst) },
1596 "The initial amount of input to burst read before imposing any readrate", "seconds" },
1597 { "target", OPT_TYPE_FUNC, OPT_FUNC_ARG | OPT_PERFILE | OPT_EXPERT | OPT_OUTPUT,
1598 { .func_arg = opt_target },
1599 "specify target file type (\"vcd\", \"svcd\", \"dvd\", \"dv\" or \"dv50\" "
1600 "with optional prefixes \"pal-\", \"ntsc-\" or \"film-\")", "type" },
1601 { "frame_drop_threshold", OPT_TYPE_FLOAT, OPT_EXPERT,
1602 { &frame_drop_threshold },
1603 "frame drop threshold", "" },
1604 { "copyts", OPT_TYPE_BOOL, OPT_EXPERT,
1605 { &copy_ts },
1606 "copy timestamps" },
1607 { "start_at_zero", OPT_TYPE_BOOL, OPT_EXPERT,
1608 { &start_at_zero },
1609 "shift input timestamps to start at 0 when using copyts" },
1610 { "copytb", OPT_TYPE_INT, OPT_EXPERT,
1611 { &copy_tb },
1612 "copy input stream time base when stream copying", "mode" },
1613 { "shortest", OPT_TYPE_BOOL, OPT_EXPERT | OPT_OFFSET | OPT_OUTPUT,
1614 { .off = OFFSET(shortest) },
1615 "finish encoding within shortest input" },
1616 { "shortest_buf_duration", OPT_TYPE_FLOAT, OPT_EXPERT | OPT_OFFSET | OPT_OUTPUT,
1617 { .off = OFFSET(shortest_buf_duration) },
1618 "maximum buffering duration (in seconds) for the -shortest option" },
1619 { "bitexact", OPT_TYPE_BOOL, OPT_EXPERT | OPT_OFFSET | OPT_OUTPUT | OPT_INPUT,
1620 { .off = OFFSET(bitexact) },
1621 "bitexact mode" },
1622 { "apad", OPT_TYPE_STRING, OPT_PERSTREAM | OPT_EXPERT | OPT_OUTPUT,
1623 { .off = OFFSET(apad) },
1624 "audio pad", "" },
1625 { "dts_delta_threshold", OPT_TYPE_FLOAT, OPT_EXPERT,
1626 { &dts_delta_threshold },
1627 "timestamp discontinuity delta threshold", "threshold" },
1628 { "dts_error_threshold", OPT_TYPE_FLOAT, OPT_EXPERT,
1629 { &dts_error_threshold },
1630 "timestamp error delta threshold", "threshold" },
1631 { "xerror", OPT_TYPE_BOOL, OPT_EXPERT,
1632 { &exit_on_error },
1633 "exit on error", "error" },
1634 { "abort_on", OPT_TYPE_FUNC, OPT_FUNC_ARG | OPT_EXPERT,
1635 { .func_arg = opt_abort_on },
1636 "abort on the specified condition flags", "flags" },
1637 { "copyinkf", OPT_TYPE_BOOL, OPT_EXPERT | OPT_PERSTREAM | OPT_OUTPUT,
1638 { .off = OFFSET(copy_initial_nonkeyframes) },
1639 "copy initial non-keyframes" },
1640 { "copypriorss", OPT_TYPE_INT, OPT_EXPERT | OPT_PERSTREAM | OPT_OUTPUT,
1641 { .off = OFFSET(copy_prior_start) },
1642 "copy or discard frames before start time" },
1643 { "frames", OPT_TYPE_INT64, OPT_PERSTREAM | OPT_OUTPUT | OPT_EXPERT | OPT_HAS_ALT,
1644 { .off = OFFSET(max_frames) },
1645 "set the number of frames to output", "number",
1646 .u1.names_alt = alt_frames, },
1647 { "tag", OPT_TYPE_STRING, OPT_PERSTREAM | OPT_EXPERT | OPT_OUTPUT | OPT_INPUT | OPT_HAS_ALT,
1648 { .off = OFFSET(codec_tags) },
1649 "force codec tag/fourcc", "fourcc/tag",
1650 .u1.names_alt = alt_tag, },
1651 { "q", OPT_TYPE_DOUBLE, OPT_EXPERT | OPT_PERSTREAM | OPT_OUTPUT | OPT_HAS_CANON,
1652 { .off = OFFSET(qscale) },
1653 "use fixed quality scale (VBR)", "q",
1654 .u1.name_canon = "qscale", },
1655 { "qscale", OPT_TYPE_FUNC, OPT_FUNC_ARG | OPT_EXPERT | OPT_PERFILE | OPT_OUTPUT | OPT_HAS_ALT,
1656 { .func_arg = opt_qscale },
1657 "use fixed quality scale (VBR)", "q",
1658 .u1.names_alt = alt_qscale, },
1659 { "profile", OPT_TYPE_FUNC, OPT_FUNC_ARG | OPT_EXPERT | OPT_PERFILE | OPT_OUTPUT,
1660 { .func_arg = opt_profile },
1661 "set profile", "profile" },
1662 { "filter", OPT_TYPE_STRING, OPT_PERSTREAM | OPT_OUTPUT | OPT_HAS_ALT,
1663 { .off = OFFSET(filters) },
1664 "apply specified filters to audio/video", "filter_graph",
1665 .u1.names_alt = alt_filter, },
1666 { "filter_threads", OPT_TYPE_FUNC, OPT_FUNC_ARG | OPT_EXPERT,
1667 { .func_arg = opt_filter_threads },
1668 "number of non-complex filter threads" },
1669 #if FFMPEG_OPT_FILTER_SCRIPT
1670 { "filter_script", OPT_TYPE_STRING, OPT_PERSTREAM | OPT_EXPERT | OPT_OUTPUT,
1671 { .off = OFFSET(filter_scripts) },
1672 "deprecated, use -/filter", "filename" },
1673 #endif
1674 { "reinit_filter", OPT_TYPE_INT, OPT_PERSTREAM | OPT_INPUT | OPT_EXPERT,
1675 { .off = OFFSET(reinit_filters) },
1676 "reinit filtergraph on input parameter changes", "" },
1677 { "filter_complex", OPT_TYPE_FUNC, OPT_FUNC_ARG | OPT_EXPERT,
1678 { .func_arg = opt_filter_complex },
1679 "create a complex filtergraph", "graph_description" },
1680 { "filter_complex_threads", OPT_TYPE_INT, OPT_EXPERT,
1681 { &filter_complex_nbthreads },
1682 "number of threads for -filter_complex" },
1683 { "lavfi", OPT_TYPE_FUNC, OPT_FUNC_ARG | OPT_EXPERT,
1684 { .func_arg = opt_filter_complex },
1685 "create a complex filtergraph", "graph_description" },
1686 #if FFMPEG_OPT_FILTER_SCRIPT
1687 { "filter_complex_script", OPT_TYPE_FUNC, OPT_FUNC_ARG | OPT_EXPERT,
1688 { .func_arg = opt_filter_complex_script },
1689 "deprecated, use -/filter_complex instead", "filename" },
1690 #endif
1691 { "auto_conversion_filters", OPT_TYPE_BOOL, OPT_EXPERT,
1692 { &auto_conversion_filters },
1693 "enable automatic conversion filters globally" },
1694 { "stats", OPT_TYPE_BOOL, 0,
1695 { &print_stats },
1696 "print progress report during encoding", },
1697 { "stats_period", OPT_TYPE_FUNC, OPT_FUNC_ARG | OPT_EXPERT,
1698 { .func_arg = opt_stats_period },
1699 "set the period at which ffmpeg updates stats and -progress output", "time" },
1700 { "attach", OPT_TYPE_FUNC, OPT_FUNC_ARG | OPT_PERFILE | OPT_EXPERT | OPT_OUTPUT,
1701 { .func_arg = opt_attach },
1702 "add an attachment to the output file", "filename" },
1703 { "dump_attachment", OPT_TYPE_STRING, OPT_SPEC | OPT_EXPERT | OPT_INPUT,
1704 { .off = OFFSET(dump_attachment) },
1705 "extract an attachment into a file", "filename" },
1706 { "stream_loop", OPT_TYPE_INT, OPT_EXPERT | OPT_INPUT | OPT_OFFSET,
1707 { .off = OFFSET(loop) }, "set number of times input stream shall be looped", "loop count" },
1708 { "debug_ts", OPT_TYPE_BOOL, OPT_EXPERT,
1709 { &debug_ts },
1710 "print timestamp debugging info" },
1711 { "max_error_rate", OPT_TYPE_FLOAT, OPT_EXPERT,
1712 { &max_error_rate },
1713 "ratio of decoding errors (0.0: no errors, 1.0: 100% errors) above which ffmpeg returns an error instead of success.", "maximum error rate" },
1714 { "discard", OPT_TYPE_STRING, OPT_PERSTREAM | OPT_INPUT | OPT_EXPERT,
1715 { .off = OFFSET(discard) },
1716 "discard", "" },
1717 { "disposition", OPT_TYPE_STRING, OPT_PERSTREAM | OPT_OUTPUT | OPT_EXPERT,
1718 { .off = OFFSET(disposition) },
1719 "disposition", "" },
1720 { "thread_queue_size", OPT_TYPE_INT, OPT_OFFSET | OPT_EXPERT | OPT_INPUT | OPT_OUTPUT,
1721 { .off = OFFSET(thread_queue_size) },
1722 "set the maximum number of queued packets from the demuxer" },
1723 { "find_stream_info", OPT_TYPE_BOOL, OPT_INPUT | OPT_EXPERT | OPT_OFFSET,
1724 { .off = OFFSET(find_stream_info) },
1725 "read and decode the streams to fill missing information with heuristics" },
1726 { "bits_per_raw_sample", OPT_TYPE_INT, OPT_EXPERT | OPT_PERSTREAM | OPT_OUTPUT,
1727 { .off = OFFSET(bits_per_raw_sample) },
1728 "set the number of bits per raw sample", "number" },
1729
1730 { "stats_enc_pre", OPT_TYPE_STRING, OPT_PERSTREAM | OPT_EXPERT | OPT_OUTPUT,
1731 { .off = OFFSET(enc_stats_pre) },
1732 "write encoding stats before encoding" },
1733 { "stats_enc_post", OPT_TYPE_STRING, OPT_PERSTREAM | OPT_EXPERT | OPT_OUTPUT,
1734 { .off = OFFSET(enc_stats_post) },
1735 "write encoding stats after encoding" },
1736 { "stats_mux_pre", OPT_TYPE_STRING, OPT_PERSTREAM | OPT_EXPERT | OPT_OUTPUT,
1737 { .off = OFFSET(mux_stats) },
1738 "write packets stats before muxing" },
1739 { "stats_enc_pre_fmt", OPT_TYPE_STRING, OPT_PERSTREAM | OPT_EXPERT | OPT_OUTPUT,
1740 { .off = OFFSET(enc_stats_pre_fmt) },
1741 "format of the stats written with -stats_enc_pre" },
1742 { "stats_enc_post_fmt", OPT_TYPE_STRING, OPT_PERSTREAM | OPT_EXPERT | OPT_OUTPUT,
1743 { .off = OFFSET(enc_stats_post_fmt) },
1744 "format of the stats written with -stats_enc_post" },
1745 { "stats_mux_pre_fmt", OPT_TYPE_STRING, OPT_PERSTREAM | OPT_EXPERT | OPT_OUTPUT,
1746 { .off = OFFSET(mux_stats_fmt) },
1747 "format of the stats written with -stats_mux_pre" },
1748
1749 /* video options */
1750 { "vframes", OPT_TYPE_FUNC, OPT_VIDEO | OPT_FUNC_ARG | OPT_PERFILE | OPT_OUTPUT | OPT_EXPERT | OPT_HAS_CANON,
1751 { .func_arg = opt_video_frames },
1752 "set the number of video frames to output", "number",
1753 .u1.name_canon = "frames", },
1754 { "r", OPT_TYPE_STRING, OPT_VIDEO | OPT_PERSTREAM | OPT_INPUT | OPT_OUTPUT,
1755 { .off = OFFSET(frame_rates) },
1756 "override input framerate/convert to given output framerate (Hz value, fraction or abbreviation)", "rate" },
1757 { "fpsmax", OPT_TYPE_STRING, OPT_VIDEO | OPT_PERSTREAM | OPT_OUTPUT | OPT_EXPERT,
1758 { .off = OFFSET(max_frame_rates) },
1759 "set max frame rate (Hz value, fraction or abbreviation)", "rate" },
1760 { "s", OPT_TYPE_STRING, OPT_VIDEO | OPT_SUBTITLE | OPT_PERSTREAM | OPT_INPUT | OPT_OUTPUT,
1761 { .off = OFFSET(frame_sizes) },
1762 "set frame size (WxH or abbreviation)", "size" },
1763 { "aspect", OPT_TYPE_STRING, OPT_VIDEO | OPT_PERSTREAM | OPT_OUTPUT,
1764 { .off = OFFSET(frame_aspect_ratios) },
1765 "set aspect ratio (4:3, 16:9 or 1.3333, 1.7777)", "aspect" },
1766 { "pix_fmt", OPT_TYPE_STRING, OPT_VIDEO | OPT_EXPERT | OPT_PERSTREAM | OPT_INPUT | OPT_OUTPUT,
1767 { .off = OFFSET(frame_pix_fmts) },
1768 "set pixel format", "format" },
1769 { "display_rotation", OPT_TYPE_DOUBLE, OPT_VIDEO | OPT_PERSTREAM | OPT_INPUT | OPT_EXPERT,
1770 { .off = OFFSET(display_rotations) },
1771 "set pure counter-clockwise rotation in degrees for stream(s)",
1772 "angle" },
1773 { "display_hflip", OPT_TYPE_BOOL, OPT_VIDEO | OPT_PERSTREAM | OPT_INPUT | OPT_EXPERT,
1774 { .off = OFFSET(display_hflips) },
1775 "set display horizontal flip for stream(s) "
1776 "(overrides any display rotation if it is not set)"},
1777 { "display_vflip", OPT_TYPE_BOOL, OPT_VIDEO | OPT_PERSTREAM | OPT_INPUT | OPT_EXPERT,
1778 { .off = OFFSET(display_vflips) },
1779 "set display vertical flip for stream(s) "
1780 "(overrides any display rotation if it is not set)"},
1781 { "vn", OPT_TYPE_BOOL, OPT_VIDEO | OPT_OFFSET | OPT_INPUT | OPT_OUTPUT,
1782 { .off = OFFSET(video_disable) },
1783 "disable video" },
1784 { "rc_override", OPT_TYPE_STRING, OPT_VIDEO | OPT_EXPERT | OPT_PERSTREAM | OPT_OUTPUT,
1785 { .off = OFFSET(rc_overrides) },
1786 "rate control override for specific intervals", "override" },
1787 { "vcodec", OPT_TYPE_FUNC, OPT_VIDEO | OPT_FUNC_ARG | OPT_PERFILE | OPT_INPUT | OPT_OUTPUT | OPT_HAS_CANON,
1788 { .func_arg = opt_video_codec },
1789 "alias for -c:v (select encoder/decoder for video streams)", "codec",
1790 .u1.name_canon = "codec", },
1791 { "timecode", OPT_TYPE_FUNC, OPT_VIDEO | OPT_FUNC_ARG | OPT_PERFILE | OPT_OUTPUT | OPT_EXPERT,
1792 { .func_arg = opt_timecode },
1793 "set initial TimeCode value.", "hh:mm:ss[:;.]ff" },
1794 { "pass", OPT_TYPE_INT, OPT_VIDEO | OPT_PERSTREAM | OPT_OUTPUT | OPT_EXPERT,
1795 { .off = OFFSET(pass) },
1796 "select the pass number (1 to 3)", "n" },
1797 { "passlogfile", OPT_TYPE_STRING, OPT_VIDEO | OPT_EXPERT | OPT_PERSTREAM | OPT_OUTPUT,
1798 { .off = OFFSET(passlogfiles) },
1799 "select two pass log file name prefix", "prefix" },
1800 { "vstats", OPT_TYPE_FUNC, OPT_VIDEO | OPT_EXPERT,
1801 { .func_arg = opt_vstats },
1802 "dump video coding statistics to file" },
1803 { "vstats_file", OPT_TYPE_FUNC, OPT_VIDEO | OPT_FUNC_ARG | OPT_EXPERT,
1804 { .func_arg = opt_vstats_file },
1805 "dump video coding statistics to file", "file" },
1806 { "vstats_version", OPT_TYPE_INT, OPT_VIDEO | OPT_EXPERT,
1807 { &vstats_version },
1808 "Version of the vstats format to use."},
1809 { "vf", OPT_TYPE_FUNC, OPT_VIDEO | OPT_FUNC_ARG | OPT_PERFILE | OPT_OUTPUT | OPT_HAS_CANON,
1810 { .func_arg = opt_video_filters },
1811 "alias for -filter:v (apply filters to video streams)", "filter_graph",
1812 .u1.name_canon = "filter", },
1813 { "intra_matrix", OPT_TYPE_STRING, OPT_VIDEO | OPT_EXPERT | OPT_PERSTREAM | OPT_OUTPUT,
1814 { .off = OFFSET(intra_matrices) },
1815 "specify intra matrix coeffs", "matrix" },
1816 { "inter_matrix", OPT_TYPE_STRING, OPT_VIDEO | OPT_EXPERT | OPT_PERSTREAM | OPT_OUTPUT,
1817 { .off = OFFSET(inter_matrices) },
1818 "specify inter matrix coeffs", "matrix" },
1819 { "chroma_intra_matrix", OPT_TYPE_STRING, OPT_VIDEO | OPT_EXPERT | OPT_PERSTREAM | OPT_OUTPUT,
1820 { .off = OFFSET(chroma_intra_matrices) },
1821 "specify intra matrix coeffs", "matrix" },
1822 { "vtag", OPT_TYPE_FUNC, OPT_VIDEO | OPT_FUNC_ARG | OPT_EXPERT | OPT_PERFILE | OPT_INPUT | OPT_OUTPUT | OPT_HAS_CANON,
1823 { .func_arg = opt_old2new },
1824 "force video tag/fourcc", "fourcc/tag",
1825 .u1.name_canon = "tag", },
1826 { "fps_mode", OPT_TYPE_STRING, OPT_VIDEO | OPT_EXPERT | OPT_PERSTREAM | OPT_OUTPUT,
1827 { .off = OFFSET(fps_mode) },
1828 "set framerate mode for matching video streams; overrides vsync" },
1829 { "force_fps", OPT_TYPE_BOOL, OPT_VIDEO | OPT_EXPERT | OPT_PERSTREAM | OPT_OUTPUT,
1830 { .off = OFFSET(force_fps) },
1831 "force the selected framerate, disable the best supported framerate selection" },
1832 { "streamid", OPT_TYPE_FUNC, OPT_VIDEO | OPT_FUNC_ARG | OPT_EXPERT | OPT_PERFILE | OPT_OUTPUT,
1833 { .func_arg = opt_streamid },
1834 "set the value of an outfile streamid", "streamIndex:value" },
1835 { "force_key_frames", OPT_TYPE_STRING, OPT_VIDEO | OPT_EXPERT | OPT_PERSTREAM | OPT_OUTPUT,
1836 { .off = OFFSET(forced_key_frames) },
1837 "force key frames at specified timestamps", "timestamps" },
1838 { "b", OPT_TYPE_FUNC, OPT_VIDEO | OPT_FUNC_ARG | OPT_PERFILE | OPT_OUTPUT,
1839 { .func_arg = opt_bitrate },
1840 "video bitrate (please use -b:v)", "bitrate" },
1841 { "hwaccel", OPT_TYPE_STRING, OPT_VIDEO | OPT_EXPERT | OPT_PERSTREAM | OPT_INPUT,
1842 { .off = OFFSET(hwaccels) },
1843 "use HW accelerated decoding", "hwaccel name" },
1844 { "hwaccel_device", OPT_TYPE_STRING, OPT_VIDEO | OPT_EXPERT | OPT_PERSTREAM | OPT_INPUT,
1845 { .off = OFFSET(hwaccel_devices) },
1846 "select a device for HW acceleration", "devicename" },
1847 { "hwaccel_output_format", OPT_TYPE_STRING, OPT_VIDEO | OPT_EXPERT | OPT_PERSTREAM | OPT_INPUT,
1848 { .off = OFFSET(hwaccel_output_formats) },
1849 "select output format used with HW accelerated decoding", "format" },
1850 { "hwaccels", OPT_TYPE_FUNC, OPT_EXIT | OPT_EXPERT,
1851 { .func_arg = show_hwaccels },
1852 "show available HW acceleration methods" },
1853 { "autorotate", OPT_TYPE_BOOL, OPT_PERSTREAM | OPT_EXPERT | OPT_INPUT,
1854 { .off = OFFSET(autorotate) },
1855 "automatically insert correct rotate filters" },
1856 { "autoscale", OPT_TYPE_BOOL, OPT_PERSTREAM | OPT_EXPERT | OPT_OUTPUT,
1857 { .off = OFFSET(autoscale) },
1858 "automatically insert a scale filter at the end of the filter graph" },
1859 { "fix_sub_duration_heartbeat", OPT_TYPE_BOOL, OPT_VIDEO | OPT_EXPERT | OPT_PERSTREAM | OPT_OUTPUT,
1860 { .off = OFFSET(fix_sub_duration_heartbeat) },
1861 "set this video output stream to be a heartbeat stream for "
1862 "fix_sub_duration, according to which subtitles should be split at "
1863 "random access points" },
1864
1865 /* audio options */
1866 { "aframes", OPT_TYPE_FUNC, OPT_AUDIO | OPT_FUNC_ARG | OPT_PERFILE | OPT_OUTPUT | OPT_EXPERT | OPT_HAS_CANON,
1867 { .func_arg = opt_audio_frames },
1868 "set the number of audio frames to output", "number",
1869 .u1.name_canon = "frames", },
1870 { "aq", OPT_TYPE_FUNC, OPT_AUDIO | OPT_FUNC_ARG | OPT_PERFILE | OPT_OUTPUT,
1871 { .func_arg = opt_audio_qscale },
1872 "set audio quality (codec-specific)", "quality", },
1873 { "ar", OPT_TYPE_INT, OPT_AUDIO | OPT_PERSTREAM | OPT_INPUT | OPT_OUTPUT,
1874 { .off = OFFSET(audio_sample_rate) },
1875 "set audio sampling rate (in Hz)", "rate" },
1876 { "ac", OPT_TYPE_INT, OPT_AUDIO | OPT_PERSTREAM | OPT_INPUT | OPT_OUTPUT,
1877 { .off = OFFSET(audio_channels) },
1878 "set number of audio channels", "channels" },
1879 { "an", OPT_TYPE_BOOL, OPT_AUDIO | OPT_OFFSET | OPT_INPUT | OPT_OUTPUT,
1880 { .off = OFFSET(audio_disable) },
1881 "disable audio" },
1882 { "acodec", OPT_TYPE_FUNC, OPT_AUDIO | OPT_FUNC_ARG | OPT_PERFILE | OPT_INPUT | OPT_OUTPUT | OPT_HAS_CANON,
1883 { .func_arg = opt_audio_codec },
1884 "alias for -c:a (select encoder/decoder for audio streams)", "codec",
1885 .u1.name_canon = "codec", },
1886 { "ab", OPT_TYPE_FUNC, OPT_AUDIO | OPT_FUNC_ARG | OPT_PERFILE | OPT_OUTPUT,
1887 { .func_arg = opt_bitrate },
1888 "alias for -b:a (select bitrate for audio streams)", "bitrate" },
1889 { "atag", OPT_TYPE_FUNC, OPT_AUDIO | OPT_FUNC_ARG | OPT_EXPERT | OPT_PERFILE | OPT_OUTPUT | OPT_HAS_CANON,
1890 { .func_arg = opt_old2new },
1891 "force audio tag/fourcc", "fourcc/tag",
1892 .u1.name_canon = "tag", },
1893 { "sample_fmt", OPT_TYPE_STRING, OPT_AUDIO | OPT_EXPERT | OPT_PERSTREAM | OPT_INPUT | OPT_OUTPUT,
1894 { .off = OFFSET(sample_fmts) },
1895 "set sample format", "format" },
1896 { "channel_layout", OPT_TYPE_STRING, OPT_AUDIO | OPT_EXPERT | OPT_PERSTREAM | OPT_INPUT | OPT_OUTPUT | OPT_HAS_ALT,
1897 { .off = OFFSET(audio_ch_layouts) },
1898 "set channel layout", "layout",
1899 .u1.names_alt = alt_channel_layout, },
1900 { "ch_layout", OPT_TYPE_STRING, OPT_AUDIO | OPT_EXPERT | OPT_PERSTREAM | OPT_INPUT | OPT_OUTPUT | OPT_HAS_CANON,
1901 { .off = OFFSET(audio_ch_layouts) },
1902 "set channel layout", "layout",
1903 .u1.name_canon = "channel_layout", },
1904 { "af", OPT_TYPE_FUNC, OPT_AUDIO | OPT_FUNC_ARG | OPT_PERFILE | OPT_OUTPUT | OPT_HAS_CANON,
1905 { .func_arg = opt_audio_filters },
1906 "alias for -filter:a (apply filters to audio streams)", "filter_graph",
1907 .u1.name_canon = "filter", },
1908 { "guess_layout_max", OPT_TYPE_INT, OPT_AUDIO | OPT_PERSTREAM | OPT_EXPERT | OPT_INPUT,
1909 { .off = OFFSET(guess_layout_max) },
1910 "set the maximum number of channels to try to guess the channel layout" },
1911
1912 /* subtitle options */
1913 { "sn", OPT_TYPE_BOOL, OPT_SUBTITLE | OPT_OFFSET | OPT_INPUT | OPT_OUTPUT,
1914 { .off = OFFSET(subtitle_disable) },
1915 "disable subtitle" },
1916 { "scodec", OPT_TYPE_FUNC, OPT_SUBTITLE | OPT_FUNC_ARG | OPT_PERFILE | OPT_INPUT | OPT_OUTPUT | OPT_HAS_CANON,
1917 { .func_arg = opt_subtitle_codec },
1918 "alias for -c:s (select encoder/decoder for subtitle streams)", "codec",
1919 .u1.name_canon = "codec", },
1920 { "stag", OPT_TYPE_FUNC, OPT_SUBTITLE | OPT_FUNC_ARG | OPT_EXPERT | OPT_PERFILE | OPT_OUTPUT | OPT_HAS_CANON,
1921 { .func_arg = opt_old2new }
1922 , "force subtitle tag/fourcc", "fourcc/tag",
1923 .u1.name_canon = "tag" },
1924 { "fix_sub_duration", OPT_TYPE_BOOL, OPT_EXPERT | OPT_SUBTITLE | OPT_PERSTREAM | OPT_INPUT,
1925 { .off = OFFSET(fix_sub_duration) },
1926 "fix subtitles duration" },
1927 { "canvas_size", OPT_TYPE_STRING, OPT_SUBTITLE | OPT_PERSTREAM | OPT_INPUT | OPT_EXPERT,
1928 { .off = OFFSET(canvas_sizes) },
1929 "set canvas size (WxH or abbreviation)", "size" },
1930
1931 /* muxer options */
1932 { "muxdelay", OPT_TYPE_FLOAT, OPT_EXPERT | OPT_OFFSET | OPT_OUTPUT,
1933 { .off = OFFSET(mux_max_delay) },
1934 "set the maximum demux-decode delay", "seconds" },
1935 { "muxpreload", OPT_TYPE_FLOAT, OPT_EXPERT | OPT_OFFSET | OPT_OUTPUT,
1936 { .off = OFFSET(mux_preload) },
1937 "set the initial demux-decode delay", "seconds" },
1938 { "sdp_file", OPT_TYPE_FUNC, OPT_FUNC_ARG | OPT_EXPERT | OPT_OUTPUT,
1939 { .func_arg = opt_sdp_file },
1940 "specify a file in which to print sdp information", "file" },
1941
1942 { "time_base", OPT_TYPE_STRING, OPT_EXPERT | OPT_PERSTREAM | OPT_OUTPUT,
1943 { .off = OFFSET(time_bases) },
1944 "set the desired time base hint for output stream (1:24, 1:48000 or 0.04166, 2.0833e-5)", "ratio" },
1945 { "enc_time_base", OPT_TYPE_STRING, OPT_EXPERT | OPT_PERSTREAM | OPT_OUTPUT,
1946 { .off = OFFSET(enc_time_bases) },
1947 "set the desired time base for the encoder (1:24, 1:48000 or 0.04166, 2.0833e-5). "
1948 "two special values are defined - "
1949 "0 = use frame rate (video) or sample rate (audio),"
1950 "-1 = match source time base", "ratio" },
1951
1952 { "bsf", OPT_TYPE_STRING, OPT_PERSTREAM | OPT_EXPERT | OPT_OUTPUT | OPT_INPUT,
1953 { .off = OFFSET(bitstream_filters) },
1954 "A comma-separated list of bitstream filters", "bitstream_filters", },
1955
1956 { "apre", OPT_TYPE_FUNC, OPT_FUNC_ARG | OPT_AUDIO | OPT_EXPERT| OPT_PERFILE | OPT_OUTPUT | OPT_HAS_CANON,
1957 { .func_arg = opt_preset },
1958 "set the audio options to the indicated preset", "preset",
1959 .u1.name_canon = "pre", },
1960 { "vpre", OPT_TYPE_FUNC, OPT_VIDEO | OPT_FUNC_ARG | OPT_EXPERT| OPT_PERFILE | OPT_OUTPUT | OPT_HAS_CANON,
1961 { .func_arg = opt_preset },
1962 "set the video options to the indicated preset", "preset",
1963 .u1.name_canon = "pre", },
1964 { "spre", OPT_TYPE_FUNC, OPT_FUNC_ARG | OPT_SUBTITLE | OPT_EXPERT| OPT_PERFILE | OPT_OUTPUT | OPT_HAS_CANON,
1965 { .func_arg = opt_preset },
1966 "set the subtitle options to the indicated preset", "preset",
1967 .u1.name_canon = "pre", },
1968 { "fpre", OPT_TYPE_FUNC, OPT_FUNC_ARG | OPT_EXPERT| OPT_PERFILE | OPT_OUTPUT | OPT_HAS_CANON,
1969 { .func_arg = opt_preset },
1970 "set options from indicated preset file", "filename",
1971 .u1.name_canon = "pre", },
1972
1973 { "max_muxing_queue_size", OPT_TYPE_INT, OPT_PERSTREAM | OPT_EXPERT | OPT_OUTPUT,
1974 { .off = OFFSET(max_muxing_queue_size) },
1975 "maximum number of packets that can be buffered while waiting for all streams to initialize", "packets" },
1976 { "muxing_queue_data_threshold", OPT_TYPE_INT, OPT_PERSTREAM | OPT_EXPERT | OPT_OUTPUT,
1977 { .off = OFFSET(muxing_queue_data_threshold) },
1978 "set the threshold after which max_muxing_queue_size is taken into account", "bytes" },
1979
1980 /* data codec support */
1981 { "dcodec", OPT_TYPE_FUNC, OPT_FUNC_ARG | OPT_DATA | OPT_PERFILE | OPT_EXPERT | OPT_INPUT | OPT_OUTPUT | OPT_HAS_CANON,
1982 { .func_arg = opt_data_codec },
1983 "alias for -c:d (select encoder/decoder for data streams)", "codec",
1984 .u1.name_canon = "codec", },
1985 { "dn", OPT_TYPE_BOOL, OPT_DATA | OPT_OFFSET | OPT_INPUT | OPT_OUTPUT,
1986 { .off = OFFSET(data_disable) }, "disable data" },
1987
1988 #if CONFIG_VAAPI
1989 { "vaapi_device", OPT_TYPE_FUNC, OPT_FUNC_ARG | OPT_EXPERT,
1990 { .func_arg = opt_vaapi_device },
1991 "set VAAPI hardware device (DirectX adapter index, DRM path or X11 display name)", "device" },
1992 #endif
1993
1994 #if CONFIG_QSV
1995 { "qsv_device", OPT_TYPE_FUNC, OPT_FUNC_ARG | OPT_EXPERT,
1996 { .func_arg = opt_qsv_device },
1997 "set QSV hardware device (DirectX adapter index, DRM path or X11 display name)", "device"},
1998 #endif
1999
2000 { "init_hw_device", OPT_TYPE_FUNC, OPT_FUNC_ARG | OPT_EXPERT,
2001 { .func_arg = opt_init_hw_device },
2002 "initialise hardware device", "args" },
2003 { "filter_hw_device", OPT_TYPE_FUNC, OPT_FUNC_ARG | OPT_EXPERT,
2004 { .func_arg = opt_filter_hw_device },
2005 "set hardware device used when filtering", "device" },
2006
2007 // deprecated options
2008 #if FFMPEG_OPT_MAP_CHANNEL
2009 { "map_channel", OPT_TYPE_FUNC, OPT_FUNC_ARG | OPT_EXPERT | OPT_PERFILE | OPT_OUTPUT,
2010 { .func_arg = opt_map_channel },
2011 "map an audio channel from one stream to another (deprecated)", "file.stream.channel[:syncfile.syncstream]" },
2012 #endif
2013 #if FFMPEG_OPT_ADRIFT_THRESHOLD
2014 { "adrift_threshold", OPT_TYPE_FUNC, OPT_FUNC_ARG | OPT_EXPERT,
2015 { .func_arg = opt_adrift_threshold },
2016 "deprecated, does nothing", "threshold" },
2017 #endif
2018 #if FFMPEG_OPT_PSNR
2019 { "psnr", OPT_TYPE_BOOL, OPT_VIDEO | OPT_EXPERT,
2020 { &do_psnr },
2021 "calculate PSNR of compressed frames (deprecated, use -flags +psnr)" },
2022 #endif
2023 #if FFMPEG_OPT_TOP
2024 { "top", OPT_TYPE_INT, OPT_VIDEO | OPT_EXPERT | OPT_PERSTREAM | OPT_INPUT | OPT_OUTPUT,
2025 { .off = OFFSET(top_field_first) },
2026 "deprecated, use the setfield video filter", "" },
2027 #endif
2028 #if FFMPEG_OPT_QPHIST
2029 { "qphist", OPT_TYPE_FUNC, OPT_VIDEO | OPT_EXPERT,
2030 { .func_arg = opt_qphist },
2031 "deprecated, does nothing" },
2032 #endif
2033 #if FFMPEG_OPT_VSYNC
2034 { "vsync", OPT_TYPE_FUNC, OPT_FUNC_ARG | OPT_EXPERT,
2035 { .func_arg = opt_vsync },
2036 "set video sync method globally; deprecated, use -fps_mode", "" },
2037 #endif
2038
2039 { NULL, },
2040 };
2041