FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/fftools/ffmpeg_opt.c
Date: 2025-02-11 20:31:05
Exec Total Coverage
Lines: 334 799 41.8%
Functions: 30 57 52.6%
Branches: 182 456 39.9%

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