FFmpeg coverage


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