FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/fftools/ffmpeg_opt.c
Date: 2025-10-10 03:51:19
Exec Total Coverage
Lines: 334 800 41.8%
Functions: 30 57 52.6%
Branches: 182 458 39.7%

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