FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/fftools/ffmpeg_opt.c
Date: 2021-09-16 08:47:15
Exec Total Coverage
Lines: 1167 2008 58.1%
Branches: 934 2452 38.1%

Line Branch Exec Source
1
2 /*
3 * ffmpeg option parsing
4 *
5 * This file is part of FFmpeg.
6 *
7 * FFmpeg is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * FFmpeg is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with FFmpeg; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
22 #include <stdint.h>
23
24 #include "ffmpeg.h"
25 #include "cmdutils.h"
26
27 #include "libavformat/avformat.h"
28
29 #include "libavcodec/avcodec.h"
30 #include "libavcodec/bsf.h"
31
32 #include "libavfilter/avfilter.h"
33
34 #include "libavutil/avassert.h"
35 #include "libavutil/avstring.h"
36 #include "libavutil/avutil.h"
37 #include "libavutil/channel_layout.h"
38 #include "libavutil/intreadwrite.h"
39 #include "libavutil/fifo.h"
40 #include "libavutil/mathematics.h"
41 #include "libavutil/opt.h"
42 #include "libavutil/parseutils.h"
43 #include "libavutil/pixdesc.h"
44 #include "libavutil/pixfmt.h"
45
46 #define DEFAULT_PASS_LOGFILENAME_PREFIX "ffmpeg2pass"
47
48 #define SPECIFIER_OPT_FMT_str "%s"
49 #define SPECIFIER_OPT_FMT_i "%i"
50 #define SPECIFIER_OPT_FMT_i64 "%"PRId64
51 #define SPECIFIER_OPT_FMT_ui64 "%"PRIu64
52 #define SPECIFIER_OPT_FMT_f "%f"
53 #define SPECIFIER_OPT_FMT_dbl "%lf"
54
55 static const char *const opt_name_codec_names[] = {"c", "codec", "acodec", "vcodec", "scodec", "dcodec", NULL};
56 static const char *const opt_name_audio_channels[] = {"ac", NULL};
57 static const char *const opt_name_audio_sample_rate[] = {"ar", NULL};
58 static const char *const opt_name_frame_rates[] = {"r", NULL};
59 static const char *const opt_name_max_frame_rates[] = {"fpsmax", NULL};
60 static const char *const opt_name_frame_sizes[] = {"s", NULL};
61 static const char *const opt_name_frame_pix_fmts[] = {"pix_fmt", NULL};
62 static const char *const opt_name_ts_scale[] = {"itsscale", NULL};
63 static const char *const opt_name_hwaccels[] = {"hwaccel", NULL};
64 static const char *const opt_name_hwaccel_devices[] = {"hwaccel_device", NULL};
65 static const char *const opt_name_hwaccel_output_formats[] = {"hwaccel_output_format", NULL};
66 static const char *const opt_name_autorotate[] = {"autorotate", NULL};
67 static const char *const opt_name_autoscale[] = {"autoscale", NULL};
68 static const char *const opt_name_max_frames[] = {"frames", "aframes", "vframes", "dframes", NULL};
69 static const char *const opt_name_bitstream_filters[] = {"bsf", "absf", "vbsf", NULL};
70 static const char *const opt_name_codec_tags[] = {"tag", "atag", "vtag", "stag", NULL};
71 static const char *const opt_name_sample_fmts[] = {"sample_fmt", NULL};
72 static const char *const opt_name_qscale[] = {"q", "qscale", NULL};
73 static const char *const opt_name_forced_key_frames[] = {"forced_key_frames", NULL};
74 static const char *const opt_name_force_fps[] = {"force_fps", NULL};
75 static const char *const opt_name_frame_aspect_ratios[] = {"aspect", NULL};
76 static const char *const opt_name_rc_overrides[] = {"rc_override", NULL};
77 static const char *const opt_name_intra_matrices[] = {"intra_matrix", NULL};
78 static const char *const opt_name_inter_matrices[] = {"inter_matrix", NULL};
79 static const char *const opt_name_chroma_intra_matrices[] = {"chroma_intra_matrix", NULL};
80 static const char *const opt_name_top_field_first[] = {"top", NULL};
81 static const char *const opt_name_presets[] = {"pre", "apre", "vpre", "spre", NULL};
82 static const char *const opt_name_copy_initial_nonkeyframes[] = {"copyinkfr", NULL};
83 static const char *const opt_name_copy_prior_start[] = {"copypriorss", NULL};
84 static const char *const opt_name_filters[] = {"filter", "af", "vf", NULL};
85 static const char *const opt_name_filter_scripts[] = {"filter_script", NULL};
86 static const char *const opt_name_reinit_filters[] = {"reinit_filter", NULL};
87 static const char *const opt_name_fix_sub_duration[] = {"fix_sub_duration", NULL};
88 static const char *const opt_name_canvas_sizes[] = {"canvas_size", NULL};
89 static const char *const opt_name_pass[] = {"pass", NULL};
90 static const char *const opt_name_passlogfiles[] = {"passlogfile", NULL};
91 static const char *const opt_name_max_muxing_queue_size[] = {"max_muxing_queue_size", NULL};
92 static const char *const opt_name_muxing_queue_data_threshold[] = {"muxing_queue_data_threshold", NULL};
93 static const char *const opt_name_guess_layout_max[] = {"guess_layout_max", NULL};
94 static const char *const opt_name_apad[] = {"apad", NULL};
95 static const char *const opt_name_discard[] = {"discard", NULL};
96 static const char *const opt_name_disposition[] = {"disposition", NULL};
97 static const char *const opt_name_time_bases[] = {"time_base", NULL};
98 static const char *const opt_name_enc_time_bases[] = {"enc_time_base", NULL};
99
100 #define WARN_MULTIPLE_OPT_USAGE(name, type, so, st)\
101 {\
102 char namestr[128] = "";\
103 const char *spec = so->specifier && so->specifier[0] ? so->specifier : "";\
104 for (i = 0; opt_name_##name[i]; i++)\
105 av_strlcatf(namestr, sizeof(namestr), "-%s%s", opt_name_##name[i], opt_name_##name[i+1] ? (opt_name_##name[i+2] ? ", " : " or ") : "");\
106 av_log(NULL, AV_LOG_WARNING, "Multiple %s options specified for stream %d, only the last option '-%s%s%s "SPECIFIER_OPT_FMT_##type"' will be used.\n",\
107 namestr, st->index, opt_name_##name[0], spec[0] ? ":" : "", spec, so->u.type);\
108 }
109
110 #define MATCH_PER_STREAM_OPT(name, type, outvar, fmtctx, st)\
111 {\
112 int i, ret, matches = 0;\
113 SpecifierOpt *so;\
114 for (i = 0; i < o->nb_ ## name; i++) {\
115 char *spec = o->name[i].specifier;\
116 if ((ret = check_stream_specifier(fmtctx, st, spec)) > 0) {\
117 outvar = o->name[i].u.type;\
118 so = &o->name[i];\
119 matches++;\
120 } else if (ret < 0)\
121 exit_program(1);\
122 }\
123 if (matches > 1)\
124 WARN_MULTIPLE_OPT_USAGE(name, type, so, st);\
125 }
126
127 #define MATCH_PER_TYPE_OPT(name, type, outvar, fmtctx, mediatype)\
128 {\
129 int i;\
130 for (i = 0; i < o->nb_ ## name; i++) {\
131 char *spec = o->name[i].specifier;\
132 if (!strcmp(spec, mediatype))\
133 outvar = o->name[i].u.type;\
134 }\
135 }
136
137 const HWAccel hwaccels[] = {
138 #if CONFIG_VIDEOTOOLBOX
139 { "videotoolbox", videotoolbox_init, HWACCEL_VIDEOTOOLBOX, AV_PIX_FMT_VIDEOTOOLBOX },
140 #endif
141 { 0 },
142 };
143 HWDevice *filter_hw_device;
144
145 char *vstats_filename;
146 char *sdp_filename;
147
148 float audio_drift_threshold = 0.1;
149 float dts_delta_threshold = 10;
150 float dts_error_threshold = 3600*30;
151
152 int audio_volume = 256;
153 int audio_sync_method = 0;
154 int video_sync_method = VSYNC_AUTO;
155 float frame_drop_threshold = 0;
156 int do_deinterlace = 0;
157 int do_benchmark = 0;
158 int do_benchmark_all = 0;
159 int do_hex_dump = 0;
160 int do_pkt_dump = 0;
161 int copy_ts = 0;
162 int start_at_zero = 0;
163 int copy_tb = -1;
164 int debug_ts = 0;
165 int exit_on_error = 0;
166 int abort_on_flags = 0;
167 int print_stats = -1;
168 int qp_hist = 0;
169 int stdin_interaction = 1;
170 int frame_bits_per_raw_sample = 0;
171 float max_error_rate = 2.0/3;
172 char *filter_nbthreads;
173 int filter_complex_nbthreads = 0;
174 int vstats_version = 2;
175 int auto_conversion_filters = 1;
176 int64_t stats_period = 500000;
177
178
179 static int intra_only = 0;
180 static int file_overwrite = 0;
181 static int no_file_overwrite = 0;
182 static int do_psnr = 0;
183 static int input_sync;
184 static int input_stream_potentially_available = 0;
185 static int ignore_unknown_streams = 0;
186 static int copy_unknown_streams = 0;
187 static int recast_media = 0;
188 static int find_stream_info = 1;
189
190 12063 static void uninit_options(OptionsContext *o)
191 {
192 12063 const OptionDef *po = options;
193 int i;
194
195 /* all OPT_SPEC and OPT_STRING can be freed in generic way */
196
2/2
✓ Branch 0 taken 2231655 times.
✓ Branch 1 taken 12063 times.
2243718 while (po->name) {
197 2231655 void *dst = (uint8_t*)o + po->u.off;
198
199
2/2
✓ Branch 0 taken 591087 times.
✓ Branch 1 taken 1640568 times.
2231655 if (po->flags & OPT_SPEC) {
200 591087 SpecifierOpt **so = dst;
201 591087 int i, *count = (int*)(so + 1);
202
2/2
✓ Branch 0 taken 24718 times.
✓ Branch 1 taken 591087 times.
615805 for (i = 0; i < *count; i++) {
203 24718 av_freep(&(*so)[i].specifier);
204
2/2
✓ Branch 0 taken 20075 times.
✓ Branch 1 taken 4643 times.
24718 if (po->flags & OPT_STRING)
205 20075 av_freep(&(*so)[i].u.str);
206 }
207 591087 av_freep(so);
208 591087 *count = 0;
209
4/4
✓ Branch 0 taken 265386 times.
✓ Branch 1 taken 1375182 times.
✓ Branch 2 taken 12063 times.
✓ Branch 3 taken 253323 times.
1640568 } else if (po->flags & OPT_OFFSET && po->flags & OPT_STRING)
210 12063 av_freep(dst);
211 2231655 po++;
212 }
213
214
2/2
✓ Branch 0 taken 141 times.
✓ Branch 1 taken 12063 times.
12204 for (i = 0; i < o->nb_stream_maps; i++)
215 141 av_freep(&o->stream_maps[i].linklabel);
216 12063 av_freep(&o->stream_maps);
217 12063 av_freep(&o->audio_channel_maps);
218 12063 av_freep(&o->streamid_map);
219 12063 av_freep(&o->attachments);
220 12063 }
221
222 12064 static void init_options(OptionsContext *o)
223 {
224 12064 memset(o, 0, sizeof(*o));
225
226 12064 o->stop_time = INT64_MAX;
227 12064 o->mux_max_delay = 0.7;
228 12064 o->start_time = AV_NOPTS_VALUE;
229 12064 o->start_time_eof = AV_NOPTS_VALUE;
230 12064 o->recording_time = INT64_MAX;
231 12064 o->limit_filesize = UINT64_MAX;
232 12064 o->chapters_input_file = INT_MAX;
233 12064 o->accurate_seek = 1;
234 12064 o->thread_queue_size = -1;
235 12064 }
236
237 static int show_hwaccels(void *optctx, const char *opt, const char *arg)
238 {
239 enum AVHWDeviceType type = AV_HWDEVICE_TYPE_NONE;
240
241 printf("Hardware acceleration methods:\n");
242 while ((type = av_hwdevice_iterate_types(type)) !=
243 AV_HWDEVICE_TYPE_NONE)
244 printf("%s\n", av_hwdevice_get_type_name(type));
245 printf("\n");
246 return 0;
247 }
248
249 /* return a copy of the input with the stream specifiers removed from the keys */
250 12063 static AVDictionary *strip_specifiers(AVDictionary *dict)
251 {
252 12063 AVDictionaryEntry *e = NULL;
253 12063 AVDictionary *ret = NULL;
254
255
2/2
✓ Branch 1 taken 33422 times.
✓ Branch 2 taken 12063 times.
45485 while ((e = av_dict_get(dict, "", e, AV_DICT_IGNORE_SUFFIX))) {
256 33422 char *p = strchr(e->key, ':');
257
258
2/2
✓ Branch 0 taken 210 times.
✓ Branch 1 taken 33212 times.
33422 if (p)
259 210 *p = 0;
260 33422 av_dict_set(&ret, e->key, e->value, 0);
261
2/2
✓ Branch 0 taken 210 times.
✓ Branch 1 taken 33212 times.
33422 if (p)
262 210 *p = ':';
263 }
264 12063 return ret;
265 }
266
267 267 static int opt_filter_threads(void *optctx, const char *opt, const char *arg)
268 {
269 267 av_free(filter_nbthreads);
270 267 filter_nbthreads = av_strdup(arg);
271 267 return 0;
272 }
273
274 static int opt_abort_on(void *optctx, const char *opt, const char *arg)
275 {
276 static const AVOption opts[] = {
277 { "abort_on" , NULL, 0, AV_OPT_TYPE_FLAGS, { .i64 = 0 }, INT64_MIN, INT64_MAX, .unit = "flags" },
278 { "empty_output" , NULL, 0, AV_OPT_TYPE_CONST, { .i64 = ABORT_ON_FLAG_EMPTY_OUTPUT }, .unit = "flags" },
279 { "empty_output_stream", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = ABORT_ON_FLAG_EMPTY_OUTPUT_STREAM }, .unit = "flags" },
280 { NULL },
281 };
282 static const AVClass class = {
283 .class_name = "",
284 .item_name = av_default_item_name,
285 .option = opts,
286 .version = LIBAVUTIL_VERSION_INT,
287 };
288 const AVClass *pclass = &class;
289
290 return av_opt_eval_flags(&pclass, &opts[0], arg, &abort_on_flags);
291 }
292
293 static int opt_stats_period(void *optctx, const char *opt, const char *arg)
294 {
295 int64_t user_stats_period = parse_time_or_die(opt, arg, 1);
296
297 if (user_stats_period <= 0) {
298 av_log(NULL, AV_LOG_ERROR, "stats_period %s must be positive.\n", arg);
299 return AVERROR(EINVAL);
300 }
301
302 stats_period = user_stats_period;
303 av_log(NULL, AV_LOG_INFO, "ffmpeg stats and -progress period set to %s.\n", arg);
304
305 return 0;
306 }
307
308 static int opt_sameq(void *optctx, const char *opt, const char *arg)
309 {
310 av_log(NULL, AV_LOG_ERROR, "Option '%s' was removed. "
311 "If you are looking for an option to preserve the quality (which is not "
312 "what -%s was for), use -qscale 0 or an equivalent quality factor option.\n",
313 opt, opt);
314 return AVERROR(EINVAL);
315 }
316
317 static int opt_video_channel(void *optctx, const char *opt, const char *arg)
318 {
319 av_log(NULL, AV_LOG_WARNING, "This option is deprecated, use -channel.\n");
320 return opt_default(optctx, "channel", arg);
321 }
322
323 static int opt_video_standard(void *optctx, const char *opt, const char *arg)
324 {
325 av_log(NULL, AV_LOG_WARNING, "This option is deprecated, use -standard.\n");
326 return opt_default(optctx, "standard", arg);
327 }
328
329 14 static int opt_audio_codec(void *optctx, const char *opt, const char *arg)
330 {
331 14 OptionsContext *o = optctx;
332 14 return parse_option(o, "codec:a", arg, options);
333 }
334
335 4183 static int opt_video_codec(void *optctx, const char *opt, const char *arg)
336 {
337 4183 OptionsContext *o = optctx;
338 4183 return parse_option(o, "codec:v", arg, options);
339 }
340
341 2 static int opt_subtitle_codec(void *optctx, const char *opt, const char *arg)
342 {
343 2 OptionsContext *o = optctx;
344 2 return parse_option(o, "codec:s", arg, options);
345 }
346
347 static int opt_data_codec(void *optctx, const char *opt, const char *arg)
348 {
349 OptionsContext *o = optctx;
350 return parse_option(o, "codec:d", arg, options);
351 }
352
353 106 static int opt_map(void *optctx, const char *opt, const char *arg)
354 {
355 106 OptionsContext *o = optctx;
356 106 StreamMap *m = NULL;
357 106 int i, negative = 0, file_idx, disabled = 0;
358 106 int sync_file_idx = -1, sync_stream_idx = 0;
359 char *p, *sync;
360 char *map;
361 char *allow_unused;
362
363
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 106 times.
106 if (*arg == '-') {
364 negative = 1;
365 arg++;
366 }
367 106 map = av_strdup(arg);
368
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 106 times.
106 if (!map)
369 return AVERROR(ENOMEM);
370
371 /* parse sync stream first, just pick first matching stream */
372
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 106 times.
106 if (sync = strchr(map, ',')) {
373 *sync = 0;
374 sync_file_idx = strtol(sync + 1, &sync, 0);
375 if (sync_file_idx >= nb_input_files || sync_file_idx < 0) {
376 av_log(NULL, AV_LOG_FATAL, "Invalid sync file index: %d.\n", sync_file_idx);
377 exit_program(1);
378 }
379 if (*sync)
380 sync++;
381 for (i = 0; i < input_files[sync_file_idx]->nb_streams; i++)
382 if (check_stream_specifier(input_files[sync_file_idx]->ctx,
383 input_files[sync_file_idx]->ctx->streams[i], sync) == 1) {
384 sync_stream_idx = i;
385 break;
386 }
387 if (i == input_files[sync_file_idx]->nb_streams) {
388 av_log(NULL, AV_LOG_FATAL, "Sync stream specification in map %s does not "
389 "match any streams.\n", arg);
390 exit_program(1);
391 }
392 if (input_streams[input_files[sync_file_idx]->ist_index + sync_stream_idx]->user_set_discard == AVDISCARD_ALL) {
393 av_log(NULL, AV_LOG_FATAL, "Sync stream specification in map %s matches a disabled input "
394 "stream.\n", arg);
395 exit_program(1);
396 }
397 }
398
399
400
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 103 times.
106 if (map[0] == '[') {
401 /* this mapping refers to lavfi output */
402 3 const char *c = map + 1;
403 3 GROW_ARRAY(o->stream_maps, o->nb_stream_maps);
404 3 m = &o->stream_maps[o->nb_stream_maps - 1];
405 3 m->linklabel = av_get_token(&c, "]");
406
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
3 if (!m->linklabel) {
407 av_log(NULL, AV_LOG_ERROR, "Invalid output link label: %s.\n", map);
408 exit_program(1);
409 }
410 } else {
411
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 103 times.
103 if (allow_unused = strchr(map, '?'))
412 *allow_unused = 0;
413 103 file_idx = strtol(map, &p, 0);
414
2/4
✓ Branch 0 taken 103 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 103 times.
103 if (file_idx >= nb_input_files || file_idx < 0) {
415 av_log(NULL, AV_LOG_FATAL, "Invalid input file index: %d.\n", file_idx);
416 exit_program(1);
417 }
418
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 103 times.
103 if (negative)
419 /* disable some already defined maps */
420 for (i = 0; i < o->nb_stream_maps; i++) {
421 m = &o->stream_maps[i];
422 if (file_idx == m->file_index &&
423 check_stream_specifier(input_files[m->file_index]->ctx,
424 input_files[m->file_index]->ctx->streams[m->stream_index],
425 *p == ':' ? p + 1 : p) > 0)
426 m->disabled = 1;
427 }
428 else
429
2/2
✓ Branch 0 taken 217 times.
✓ Branch 1 taken 103 times.
320 for (i = 0; i < input_files[file_idx]->nb_streams; i++) {
430
2/2
✓ Branch 1 taken 79 times.
✓ Branch 2 taken 138 times.
217 if (check_stream_specifier(input_files[file_idx]->ctx, input_files[file_idx]->ctx->streams[i],
431
2/2
✓ Branch 0 taken 118 times.
✓ Branch 1 taken 99 times.
217 *p == ':' ? p + 1 : p) <= 0)
432 79 continue;
433
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 138 times.
138 if (input_streams[input_files[file_idx]->ist_index + i]->user_set_discard == AVDISCARD_ALL) {
434 disabled = 1;
435 continue;
436 }
437 138 GROW_ARRAY(o->stream_maps, o->nb_stream_maps);
438 138 m = &o->stream_maps[o->nb_stream_maps - 1];
439
440 138 m->file_index = file_idx;
441 138 m->stream_index = i;
442
443
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 138 times.
138 if (sync_file_idx >= 0) {
444 m->sync_file_index = sync_file_idx;
445 m->sync_stream_index = sync_stream_idx;
446 } else {
447 138 m->sync_file_index = file_idx;
448 138 m->sync_stream_index = i;
449 }
450 }
451 }
452
453
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 106 times.
106 if (!m) {
454 if (allow_unused) {
455 av_log(NULL, AV_LOG_VERBOSE, "Stream map '%s' matches no streams; ignoring.\n", arg);
456 } else if (disabled) {
457 av_log(NULL, AV_LOG_FATAL, "Stream map '%s' matches disabled streams.\n"
458 "To ignore this, add a trailing '?' to the map.\n", arg);
459 exit_program(1);
460 } else {
461 av_log(NULL, AV_LOG_FATAL, "Stream map '%s' matches no streams.\n"
462 "To ignore this, add a trailing '?' to the map.\n", arg);
463 exit_program(1);
464 }
465 }
466
467 106 av_freep(&map);
468 106 return 0;
469 }
470
471 1 static int opt_attach(void *optctx, const char *opt, const char *arg)
472 {
473 1 OptionsContext *o = optctx;
474 1 GROW_ARRAY(o->attachments, o->nb_attachments);
475 1 o->attachments[o->nb_attachments - 1] = arg;
476 1 return 0;
477 }
478
479 10 static int opt_map_channel(void *optctx, const char *opt, const char *arg)
480 {
481 10 OptionsContext *o = optctx;
482 int n;
483 AVStream *st;
484 AudioChannelMap *m;
485 char *allow_unused;
486 char *mapchan;
487 10 mapchan = av_strdup(arg);
488
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 10 times.
10 if (!mapchan)
489 return AVERROR(ENOMEM);
490
491 10 GROW_ARRAY(o->audio_channel_maps, o->nb_audio_channel_maps);
492 10 m = &o->audio_channel_maps[o->nb_audio_channel_maps - 1];
493
494 /* muted channel syntax */
495 10 n = sscanf(arg, "%d:%d.%d", &m->channel_idx, &m->ofile_idx, &m->ostream_idx);
496
3/6
✗ Branch 0 not taken.
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✓ Branch 5 taken 9 times.
10 if ((n == 1 || n == 3) && m->channel_idx == -1) {
497 1 m->file_idx = m->stream_idx = -1;
498
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if (n == 1)
499 1 m->ofile_idx = m->ostream_idx = -1;
500 1 av_free(mapchan);
501 1 return 0;
502 }
503
504 /* normal syntax */
505 9 n = sscanf(arg, "%d.%d.%d:%d.%d",
506 &m->file_idx, &m->stream_idx, &m->channel_idx,
507 &m->ofile_idx, &m->ostream_idx);
508
509
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if (n != 3 && n != 5) {
510 av_log(NULL, AV_LOG_FATAL, "Syntax error, mapchan usage: "
511 "[file.stream.channel|-1][:syncfile:syncstream]\n");
512 exit_program(1);
513 }
514
515
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if (n != 5) // only file.stream.channel specified
516 9 m->ofile_idx = m->ostream_idx = -1;
517
518 /* check input */
519
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 9 times.
9 if (m->file_idx < 0 || m->file_idx >= nb_input_files) {
520 av_log(NULL, AV_LOG_FATAL, "mapchan: invalid input file index: %d\n",
521 m->file_idx);
522 exit_program(1);
523 }
524
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if (m->stream_idx < 0 ||
525
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 m->stream_idx >= input_files[m->file_idx]->nb_streams) {
526 av_log(NULL, AV_LOG_FATAL, "mapchan: invalid input file stream index #%d.%d\n",
527 m->file_idx, m->stream_idx);
528 exit_program(1);
529 }
530 9 st = input_files[m->file_idx]->ctx->streams[m->stream_idx];
531
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if (st->codecpar->codec_type != AVMEDIA_TYPE_AUDIO) {
532 av_log(NULL, AV_LOG_FATAL, "mapchan: stream #%d.%d is not an audio stream.\n",
533 m->file_idx, m->stream_idx);
534 exit_program(1);
535 }
536 /* allow trailing ? to map_channel */
537
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 7 times.
9 if (allow_unused = strchr(mapchan, '?'))
538 2 *allow_unused = 0;
539
3/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 8 times.
✓ Branch 3 taken 1 times.
9 if (m->channel_idx < 0 || m->channel_idx >= st->codecpar->channels ||
540
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8 times.
8 input_streams[input_files[m->file_idx]->ist_index + m->stream_idx]->user_set_discard == AVDISCARD_ALL) {
541
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if (allow_unused) {
542 1 av_log(NULL, AV_LOG_VERBOSE, "mapchan: invalid audio channel #%d.%d.%d\n",
543 m->file_idx, m->stream_idx, m->channel_idx);
544 } else {
545 av_log(NULL, AV_LOG_FATAL, "mapchan: invalid audio channel #%d.%d.%d\n"
546 "To ignore this, add a trailing '?' to the map_channel.\n",
547 m->file_idx, m->stream_idx, m->channel_idx);
548 exit_program(1);
549 }
550
551 }
552 9 av_free(mapchan);
553 9 return 0;
554 }
555
556 static int opt_sdp_file(void *optctx, const char *opt, const char *arg)
557 {
558 av_free(sdp_filename);
559 sdp_filename = av_strdup(arg);
560 return 0;
561 }
562
563 #if CONFIG_VAAPI
564 static int opt_vaapi_device(void *optctx, const char *opt, const char *arg)
565 {
566 const char *prefix = "vaapi:";
567 char *tmp;
568 int err;
569 tmp = av_asprintf("%s%s", prefix, arg);
570 if (!tmp)
571 return AVERROR(ENOMEM);
572 err = hw_device_init_from_string(tmp, NULL);
573 av_free(tmp);
574 return err;
575 }
576 #endif
577
578 #if CONFIG_QSV
579 static int opt_qsv_device(void *optctx, const char *opt, const char *arg)
580 {
581 const char *prefix = "qsv=__qsv_device:hw_any,child_device=";
582 int err;
583 char *tmp = av_asprintf("%s%s", prefix, arg);
584
585 if (!tmp)
586 return AVERROR(ENOMEM);
587
588 err = hw_device_init_from_string(tmp, NULL);
589 av_free(tmp);
590
591 return err;
592 }
593 #endif
594
595 static int opt_init_hw_device(void *optctx, const char *opt, const char *arg)
596 {
597 if (!strcmp(arg, "list")) {
598 enum AVHWDeviceType type = AV_HWDEVICE_TYPE_NONE;
599 printf("Supported hardware device types:\n");
600 while ((type = av_hwdevice_iterate_types(type)) !=
601 AV_HWDEVICE_TYPE_NONE)
602 printf("%s\n", av_hwdevice_get_type_name(type));
603 printf("\n");
604 exit_program(0);
605 } else {
606 return hw_device_init_from_string(arg, NULL);
607 }
608 }
609
610 static int opt_filter_hw_device(void *optctx, const char *opt, const char *arg)
611 {
612 if (filter_hw_device) {
613 av_log(NULL, AV_LOG_ERROR, "Only one filter device can be used.\n");
614 return AVERROR(EINVAL);
615 }
616 filter_hw_device = hw_device_get_by_name(arg);
617 if (!filter_hw_device) {
618 av_log(NULL, AV_LOG_ERROR, "Invalid filter device %s.\n", arg);
619 return AVERROR(EINVAL);
620 }
621 return 0;
622 }
623
624 /**
625 * Parse a metadata specifier passed as 'arg' parameter.
626 * @param arg metadata string to parse
627 * @param type metadata type is written here -- g(lobal)/s(tream)/c(hapter)/p(rogram)
628 * @param index for type c/p, chapter/program index is written here
629 * @param stream_spec for type s, the stream specifier is written here
630 */
631 171 static void parse_meta_type(char *arg, char *type, int *index, const char **stream_spec)
632 {
633
2/2
✓ Branch 0 taken 44 times.
✓ Branch 1 taken 127 times.
171 if (*arg) {
634 44 *type = *arg;
635
3/4
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 22 times.
✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
44 switch (*arg) {
636 18 case 'g':
637 18 break;
638 22 case 's':
639
2/4
✓ Branch 0 taken 22 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 22 times.
22 if (*(++arg) && *arg != ':') {
640 av_log(NULL, AV_LOG_FATAL, "Invalid metadata specifier %s.\n", arg);
641 exit_program(1);
642 }
643
1/2
✓ Branch 0 taken 22 times.
✗ Branch 1 not taken.
22 *stream_spec = *arg == ':' ? arg + 1 : "";
644 22 break;
645 4 case 'c':
646 case 'p':
647
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 1 times.
4 if (*(++arg) == ':')
648 3 *index = strtol(++arg, NULL, 0);
649 4 break;
650 default:
651 av_log(NULL, AV_LOG_FATAL, "Invalid metadata type %c.\n", *arg);
652 exit_program(1);
653 }
654 } else
655 127 *type = 'g';
656 171 }
657
658 5 static int copy_metadata(char *outspec, char *inspec, AVFormatContext *oc, AVFormatContext *ic, OptionsContext *o)
659 {
660 5 AVDictionary **meta_in = NULL;
661 5 AVDictionary **meta_out = NULL;
662 5 int i, ret = 0;
663 char type_in, type_out;
664 5 const char *istream_spec = NULL, *ostream_spec = NULL;
665 5 int idx_in = 0, idx_out = 0;
666
667 5 parse_meta_type(inspec, &type_in, &idx_in, &istream_spec);
668 5 parse_meta_type(outspec, &type_out, &idx_out, &ostream_spec);
669
670
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 3 times.
5 if (!ic) {
671
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
2 if (type_out == 'g' || !*outspec)
672 2 o->metadata_global_manual = 1;
673
2/4
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 2 times.
2 if (type_out == 's' || !*outspec)
674 o->metadata_streams_manual = 1;
675
2/4
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 2 times.
2 if (type_out == 'c' || !*outspec)
676 o->metadata_chapters_manual = 1;
677 2 return 0;
678 }
679
680
3/4
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 2 times.
3 if (type_in == 'g' || type_out == 'g')
681 1 o->metadata_global_manual = 1;
682
3/4
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
3 if (type_in == 's' || type_out == 's')
683 2 o->metadata_streams_manual = 1;
684
2/4
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 3 times.
3 if (type_in == 'c' || type_out == 'c')
685 o->metadata_chapters_manual = 1;
686
687 /* ic is NULL when just disabling automatic mappings */
688
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
3 if (!ic)
689 return 0;
690
691 #define METADATA_CHECK_INDEX(index, nb_elems, desc)\
692 if ((index) < 0 || (index) >= (nb_elems)) {\
693 av_log(NULL, AV_LOG_FATAL, "Invalid %s index %d while processing metadata maps.\n",\
694 (desc), (index));\
695 exit_program(1);\
696 }
697
698 #define SET_DICT(type, meta, context, index)\
699 switch (type) {\
700 case 'g':\
701 meta = &context->metadata;\
702 break;\
703 case 'c':\
704 METADATA_CHECK_INDEX(index, context->nb_chapters, "chapter")\
705 meta = &context->chapters[index]->metadata;\
706 break;\
707 case 'p':\
708 METADATA_CHECK_INDEX(index, context->nb_programs, "program")\
709 meta = &context->programs[index]->metadata;\
710 break;\
711 case 's':\
712 break; /* handled separately below */ \
713 default: av_assert0(0);\
714 }\
715
716
2/13
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 2 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
3 SET_DICT(type_in, meta_in, ic, idx_in);
717
2/13
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 2 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
3 SET_DICT(type_out, meta_out, oc, idx_out);
718
719 /* for input streams choose first matching stream */
720
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 1 times.
3 if (type_in == 's') {
721
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
3 for (i = 0; i < ic->nb_streams; i++) {
722
2/2
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 1 times.
3 if ((ret = check_stream_specifier(ic, ic->streams[i], istream_spec)) > 0) {
723 2 meta_in = &ic->streams[i]->metadata;
724 2 break;
725
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 } else if (ret < 0)
726 exit_program(1);
727 }
728
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 if (!meta_in) {
729 av_log(NULL, AV_LOG_FATAL, "Stream specifier %s does not match any streams.\n", istream_spec);
730 exit_program(1);
731 }
732 }
733
734
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 1 times.
3 if (type_out == 's') {
735
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 2 times.
8 for (i = 0; i < oc->nb_streams; i++) {
736
2/2
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 4 times.
6 if ((ret = check_stream_specifier(oc, oc->streams[i], ostream_spec)) > 0) {
737 2 meta_out = &oc->streams[i]->metadata;
738 2 av_dict_copy(meta_out, *meta_in, AV_DICT_DONT_OVERWRITE);
739
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
4 } else if (ret < 0)
740 exit_program(1);
741 }
742 } else
743 1 av_dict_copy(meta_out, *meta_in, AV_DICT_DONT_OVERWRITE);
744
745 3 return 0;
746 }
747
748 static int opt_recording_timestamp(void *optctx, const char *opt, const char *arg)
749 {
750 OptionsContext *o = optctx;
751 char buf[128];
752 int64_t recording_timestamp = parse_time_or_die(opt, arg, 0) / 1E6;
753 struct tm time = *gmtime((time_t*)&recording_timestamp);
754 if (!strftime(buf, sizeof(buf), "creation_time=%Y-%m-%dT%H:%M:%S%z", &time))
755 return -1;
756 parse_option(o, "metadata", buf, options);
757
758 av_log(NULL, AV_LOG_WARNING, "%s is deprecated, set the 'creation_time' metadata "
759 "tag instead.\n", opt);
760 return 0;
761 }
762
763 10499 static const AVCodec *find_codec_or_die(const char *name, enum AVMediaType type, int encoder)
764 {
765 const AVCodecDescriptor *desc;
766
2/2
✓ Branch 0 taken 3193 times.
✓ Branch 1 taken 7306 times.
10499 const char *codec_string = encoder ? "encoder" : "decoder";
767 const AVCodec *codec;
768
769 10499 codec = encoder ?
770
2/2
✓ Branch 0 taken 3193 times.
✓ Branch 1 taken 7306 times.
10499 avcodec_find_encoder_by_name(name) :
771 7306 avcodec_find_decoder_by_name(name);
772
773
3/4
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 10498 times.
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
10499 if (!codec && (desc = avcodec_descriptor_get_by_name(name))) {
774
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 codec = encoder ? avcodec_find_encoder(desc->id) :
775 avcodec_find_decoder(desc->id);
776
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if (codec)
777 1 av_log(NULL, AV_LOG_VERBOSE, "Matched %s '%s' for codec '%s'.\n",
778 1 codec_string, codec->name, desc->name);
779 }
780
781
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 10499 times.
10499 if (!codec) {
782 av_log(NULL, AV_LOG_FATAL, "Unknown %s '%s'\n", codec_string, name);
783 exit_program(1);
784 }
785
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 10499 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
10499 if (codec->type != type && !recast_media) {
786 av_log(NULL, AV_LOG_FATAL, "Invalid %s type '%s'\n", codec_string, name);
787 exit_program(1);
788 }
789 10499 return codec;
790 }
791
792 12719 static const AVCodec *choose_decoder(OptionsContext *o, AVFormatContext *s, AVStream *st)
793 {
794 12719 char *codec_name = NULL;
795
796
6/20
✓ Branch 1 taken 4882 times.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 6 times.
✓ Branch 6 taken 4888 times.
✓ Branch 7 taken 12719 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 12719 times.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
17607 MATCH_PER_STREAM_OPT(codec_names, str, codec_name, s, st);
797
2/2
✓ Branch 0 taken 4882 times.
✓ Branch 1 taken 7837 times.
12719 if (codec_name) {
798 4882 const AVCodec *codec = find_codec_or_die(codec_name, st->codecpar->codec_type, 0);
799 4882 st->codecpar->codec_id = codec->id;
800
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 4882 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
4882 if (recast_media && st->codecpar->codec_type != codec->type)
801 st->codecpar->codec_type = codec->type;
802 4882 return codec;
803 } else
804 7837 return avcodec_find_decoder(st->codecpar->codec_id);
805 }
806
807 /* Add all the streams from the given input file to the global
808 * list of input streams. */
809 6045 static void add_input_streams(OptionsContext *o, AVFormatContext *ic)
810 {
811 int i, ret;
812
813
2/2
✓ Branch 0 taken 6409 times.
✓ Branch 1 taken 6045 times.
12454 for (i = 0; i < ic->nb_streams; i++) {
814 6409 AVStream *st = ic->streams[i];
815 6409 AVCodecParameters *par = st->codecpar;
816 6409 InputStream *ist = av_mallocz(sizeof(*ist));
817 6409 char *framerate = NULL, *hwaccel_device = NULL;
818 6409 const char *hwaccel = NULL;
819 6409 char *hwaccel_output_format = NULL;
820 6409 char *codec_tag = NULL;
821 char *next;
822 6409 char *discard_str = NULL;
823 6409 const AVClass *cc = avcodec_get_class();
824 6409 const AVOption *discard_opt = av_opt_find(&cc, "skip_frame", NULL, 0, 0);
825
826
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6409 times.
6409 if (!ist)
827 exit_program(1);
828
829 6409 GROW_ARRAY(input_streams, nb_input_streams);
830 6409 input_streams[nb_input_streams - 1] = ist;
831
832 6409 ist->st = st;
833 6409 ist->file_index = nb_input_files;
834 6409 ist->discard = 1;
835 6409 st->discard = AVDISCARD_ALL;
836 6409 ist->nb_samples = 0;
837 6409 ist->first_dts = AV_NOPTS_VALUE;
838 6409 ist->min_pts = INT64_MAX;
839 6409 ist->max_pts = INT64_MIN;
840
841 6409 ist->ts_scale = 1.0;
842
2/20
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 6409 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 6409 times.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
6409 MATCH_PER_STREAM_OPT(ts_scale, dbl, ist->ts_scale, ic, st);
843
844 6409 ist->autorotate = 1;
845
2/20
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 6409 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 6409 times.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
6409 MATCH_PER_STREAM_OPT(autorotate, i, ist->autorotate, ic, st);
846
847
4/20
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 6 taken 2 times.
✓ Branch 7 taken 6409 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 6409 times.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
6411 MATCH_PER_STREAM_OPT(codec_tags, str, codec_tag, ic, st);
848
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 6407 times.
6409 if (codec_tag) {
849 2 uint32_t tag = strtol(codec_tag, &next, 0);
850
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 if (*next)
851 2 tag = AV_RL32(codec_tag);
852 2 st->codecpar->codec_tag = tag;
853 }
854
855 6409 ist->dec = choose_decoder(o, ic, st);
856 6409 ist->decoder_opts = filter_codec_opts(o->g->codec_opts, ist->st->codecpar->codec_id, ic, st, ist->dec);
857
858 6409 ist->reinit_filters = -1;
859
2/20
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 6409 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 6409 times.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
6409 MATCH_PER_STREAM_OPT(reinit_filters, i, ist->reinit_filters, ic, st);
860
861
2/20
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 6409 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 6409 times.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
6409 MATCH_PER_STREAM_OPT(discard, str, discard_str, ic, st);
862 6409 ist->user_set_discard = AVDISCARD_NONE;
863
864
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6409 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6409 if ((o->video_disable && ist->st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) ||
865
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6409 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6409 (o->audio_disable && ist->st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) ||
866
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6409 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6409 (o->subtitle_disable && ist->st->codecpar->codec_type == AVMEDIA_TYPE_SUBTITLE) ||
867
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6409 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6409 (o->data_disable && ist->st->codecpar->codec_type == AVMEDIA_TYPE_DATA))
868 ist->user_set_discard = AVDISCARD_ALL;
869
870
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6409 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
6409 if (discard_str && av_opt_eval_int(&cc, discard_opt, discard_str, &ist->user_set_discard) < 0) {
871 av_log(NULL, AV_LOG_ERROR, "Error parsing discard %s.\n",
872 discard_str);
873 exit_program(1);
874 }
875
876 6409 ist->filter_in_rescale_delta_last = AV_NOPTS_VALUE;
877
878 6409 ist->dec_ctx = avcodec_alloc_context3(ist->dec);
879
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6409 times.
6409 if (!ist->dec_ctx) {
880 av_log(NULL, AV_LOG_ERROR, "Error allocating the decoder context.\n");
881 exit_program(1);
882 }
883
884 6409 ret = avcodec_parameters_to_context(ist->dec_ctx, par);
885
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6409 times.
6409 if (ret < 0) {
886 av_log(NULL, AV_LOG_ERROR, "Error initializing the decoder context.\n");
887 exit_program(1);
888 }
889
890
2/2
✓ Branch 0 taken 85 times.
✓ Branch 1 taken 6324 times.
6409 if (o->bitexact)
891 85 ist->dec_ctx->flags |= AV_CODEC_FLAG_BITEXACT;
892
893
4/5
✓ Branch 0 taken 4894 times.
✓ Branch 1 taken 1406 times.
✓ Branch 2 taken 108 times.
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
6409 switch (par->codec_type) {
894 4894 case AVMEDIA_TYPE_VIDEO:
895
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4894 times.
4894 if(!ist->dec)
896 ist->dec = avcodec_find_decoder(par->codec_id);
897
898 // avformat_find_stream_info() doesn't set this for us anymore.
899 4894 ist->dec_ctx->framerate = st->avg_frame_rate;
900
901
4/20
✓ Branch 1 taken 25 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 6 taken 25 times.
✓ Branch 7 taken 4894 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 4894 times.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
4919 MATCH_PER_STREAM_OPT(frame_rates, str, framerate, ic, st);
902
3/4
✓ Branch 0 taken 25 times.
✓ Branch 1 taken 4869 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 25 times.
4894 if (framerate && av_parse_video_rate(&ist->framerate,
903 framerate) < 0) {
904 av_log(NULL, AV_LOG_ERROR, "Error parsing framerate %s.\n",
905 framerate);
906 exit_program(1);
907 }
908
909 4894 ist->top_field_first = -1;
910
2/20
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 4894 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 4894 times.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
4894 MATCH_PER_STREAM_OPT(top_field_first, i, ist->top_field_first, ic, st);
911
912
4/20
✓ Branch 1 taken 4651 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 6 taken 4651 times.
✓ Branch 7 taken 4894 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 4894 times.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
9545 MATCH_PER_STREAM_OPT(hwaccels, str, hwaccel, ic, st);
913
2/20
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 4894 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 4894 times.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
4894 MATCH_PER_STREAM_OPT(hwaccel_output_formats, str,
914 hwaccel_output_format, ic, st);
915
916
4/6
✓ Branch 0 taken 4894 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4651 times.
✓ Branch 3 taken 243 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 4651 times.
4894 if (!hwaccel_output_format && hwaccel && !strcmp(hwaccel, "cuvid")) {
917 av_log(NULL, AV_LOG_WARNING,
918 "WARNING: defaulting hwaccel_output_format to cuda for compatibility "
919 "with old commandlines. This behaviour is DEPRECATED and will be removed "
920 "in the future. Please explicitly set \"-hwaccel_output_format cuda\".\n");
921 ist->hwaccel_output_format = AV_PIX_FMT_CUDA;
922
4/6
✓ Branch 0 taken 4894 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4651 times.
✓ Branch 3 taken 243 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 4651 times.
4894 } else if (!hwaccel_output_format && hwaccel && !strcmp(hwaccel, "qsv")) {
923 av_log(NULL, AV_LOG_WARNING,
924 "WARNING: defaulting hwaccel_output_format to qsv for compatibility "
925 "with old commandlines. This behaviour is DEPRECATED and will be removed "
926 "in the future. Please explicitly set \"-hwaccel_output_format qsv\".\n");
927 ist->hwaccel_output_format = AV_PIX_FMT_QSV;
928
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4894 times.
4894 } else if (hwaccel_output_format) {
929 ist->hwaccel_output_format = av_get_pix_fmt(hwaccel_output_format);
930 if (ist->hwaccel_output_format == AV_PIX_FMT_NONE) {
931 av_log(NULL, AV_LOG_FATAL, "Unrecognised hwaccel output "
932 "format: %s", hwaccel_output_format);
933 }
934 } else {
935 4894 ist->hwaccel_output_format = AV_PIX_FMT_NONE;
936 }
937
938
2/2
✓ Branch 0 taken 4651 times.
✓ Branch 1 taken 243 times.
4894 if (hwaccel) {
939 // The NVDEC hwaccels use a CUDA device, so remap the name here.
940
2/4
✓ Branch 0 taken 4651 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 4651 times.
4651 if (!strcmp(hwaccel, "nvdec") || !strcmp(hwaccel, "cuvid"))
941 hwaccel = "cuda";
942
943
1/2
✓ Branch 0 taken 4651 times.
✗ Branch 1 not taken.
4651 if (!strcmp(hwaccel, "none"))
944 4651 ist->hwaccel_id = HWACCEL_NONE;
945 else if (!strcmp(hwaccel, "auto"))
946 ist->hwaccel_id = HWACCEL_AUTO;
947 else {
948 enum AVHWDeviceType type;
949 int i;
950 for (i = 0; hwaccels[i].name; i++) {
951 if (!strcmp(hwaccels[i].name, hwaccel)) {
952 ist->hwaccel_id = hwaccels[i].id;
953 break;
954 }
955 }
956
957 if (!ist->hwaccel_id) {
958 type = av_hwdevice_find_type_by_name(hwaccel);
959 if (type != AV_HWDEVICE_TYPE_NONE) {
960 ist->hwaccel_id = HWACCEL_GENERIC;
961 ist->hwaccel_device_type = type;
962 }
963 }
964
965 if (!ist->hwaccel_id) {
966 av_log(NULL, AV_LOG_FATAL, "Unrecognized hwaccel: %s.\n",
967 hwaccel);
968 av_log(NULL, AV_LOG_FATAL, "Supported hwaccels: ");
969 type = AV_HWDEVICE_TYPE_NONE;
970 while ((type = av_hwdevice_iterate_types(type)) !=
971 AV_HWDEVICE_TYPE_NONE)
972 av_log(NULL, AV_LOG_FATAL, "%s ",
973 av_hwdevice_get_type_name(type));
974 av_log(NULL, AV_LOG_FATAL, "\n");
975 exit_program(1);
976 }
977 }
978 }
979
980
2/20
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 4894 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 4894 times.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
4894 MATCH_PER_STREAM_OPT(hwaccel_devices, str, hwaccel_device, ic, st);
981
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4894 times.
4894 if (hwaccel_device) {
982 ist->hwaccel_device = av_strdup(hwaccel_device);
983 if (!ist->hwaccel_device)
984 exit_program(1);
985 }
986
987 4894 ist->hwaccel_pix_fmt = AV_PIX_FMT_NONE;
988
989 4894 break;
990 1406 case AVMEDIA_TYPE_AUDIO:
991 1406 ist->guess_layout_max = INT_MAX;
992
4/20
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 6 taken 4 times.
✓ Branch 7 taken 1406 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 1406 times.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
1410 MATCH_PER_STREAM_OPT(guess_layout_max, i, ist->guess_layout_max, ic, st);
993 1406 guess_input_channel_layout(ist);
994 1406 break;
995 108 case AVMEDIA_TYPE_DATA:
996 case AVMEDIA_TYPE_SUBTITLE: {
997 108 char *canvas_size = NULL;
998
2/2
✓ Branch 0 taken 52 times.
✓ Branch 1 taken 56 times.
108 if(!ist->dec)
999 52 ist->dec = avcodec_find_decoder(par->codec_id);
1000
2/20
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 108 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 108 times.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
108 MATCH_PER_STREAM_OPT(fix_sub_duration, i, ist->fix_sub_duration, ic, st);
1001
2/20
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 108 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 108 times.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
108 MATCH_PER_STREAM_OPT(canvas_sizes, str, canvas_size, ic, st);
1002
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 108 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
108 if (canvas_size &&
1003 av_parse_video_size(&ist->dec_ctx->width, &ist->dec_ctx->height, canvas_size) < 0) {
1004 av_log(NULL, AV_LOG_FATAL, "Invalid canvas size: %s.\n", canvas_size);
1005 exit_program(1);
1006 }
1007 108 break;
1008 }
1009 1 case AVMEDIA_TYPE_ATTACHMENT:
1010 case AVMEDIA_TYPE_UNKNOWN:
1011 1 break;
1012 default:
1013 abort();
1014 }
1015
1016 6409 ret = avcodec_parameters_from_context(par, ist->dec_ctx);
1017
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6409 times.
6409 if (ret < 0) {
1018 av_log(NULL, AV_LOG_ERROR, "Error initializing the decoder context.\n");
1019 exit_program(1);
1020 }
1021 }
1022 6045 }
1023
1024 5964 static void assert_file_overwrite(const char *filename)
1025 {
1026 5964 const char *proto_name = avio_find_protocol_name(filename);
1027
1028
3/4
✓ Branch 0 taken 1626 times.
✓ Branch 1 taken 4338 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1626 times.
5964 if (file_overwrite && no_file_overwrite) {
1029 fprintf(stderr, "Error, both -y and -n supplied. Exiting.\n");
1030 exit_program(1);
1031 }
1032
1033
2/2
✓ Branch 0 taken 4338 times.
✓ Branch 1 taken 1626 times.
5964 if (!file_overwrite) {
1034
2/6
✓ Branch 0 taken 4338 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 4338 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
4338 if (proto_name && !strcmp(proto_name, "file") && avio_check(filename, 0) == 0) {
1035 if (stdin_interaction && !no_file_overwrite) {
1036 fprintf(stderr,"File '%s' already exists. Overwrite? [y/N] ", filename);
1037 fflush(stderr);
1038 term_exit();
1039 signal(SIGINT, SIG_DFL);
1040 if (!read_yesno()) {
1041 av_log(NULL, AV_LOG_FATAL, "Not overwriting - exiting\n");
1042 exit_program(1);
1043 }
1044 term_init();
1045 }
1046 else {
1047 av_log(NULL, AV_LOG_FATAL, "File '%s' already exists. Exiting.\n", filename);
1048 exit_program(1);
1049 }
1050 }
1051 }
1052
1053
3/4
✓ Branch 0 taken 5964 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1626 times.
✓ Branch 3 taken 4338 times.
5964 if (proto_name && !strcmp(proto_name, "file")) {
1054
2/2
✓ Branch 0 taken 1667 times.
✓ Branch 1 taken 1626 times.
3293 for (int i = 0; i < nb_input_files; i++) {
1055 1667 InputFile *file = input_files[i];
1056
2/2
✓ Branch 0 taken 109 times.
✓ Branch 1 taken 1558 times.
1667 if (file->ctx->iformat->flags & AVFMT_NOFILE)
1057 109 continue;
1058
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1558 times.
1558 if (!strcmp(filename, file->ctx->url)) {
1059 av_log(NULL, AV_LOG_FATAL, "Output %s same as Input #%d - exiting\n", filename, i);
1060 av_log(NULL, AV_LOG_WARNING, "FFmpeg cannot edit existing files in-place.\n");
1061 exit_program(1);
1062 }
1063 }
1064 }
1065 5964 }
1066
1067 static void dump_attachment(AVStream *st, const char *filename)
1068 {
1069 int ret;
1070 AVIOContext *out = NULL;
1071 AVDictionaryEntry *e;
1072
1073 if (!st->codecpar->extradata_size) {
1074 av_log(NULL, AV_LOG_WARNING, "No extradata to dump in stream #%d:%d.\n",
1075 nb_input_files - 1, st->index);
1076 return;
1077 }
1078 if (!*filename && (e = av_dict_get(st->metadata, "filename", NULL, 0)))
1079 filename = e->value;
1080 if (!*filename) {
1081 av_log(NULL, AV_LOG_FATAL, "No filename specified and no 'filename' tag"
1082 "in stream #%d:%d.\n", nb_input_files - 1, st->index);
1083 exit_program(1);
1084 }
1085
1086 assert_file_overwrite(filename);
1087
1088 if ((ret = avio_open2(&out, filename, AVIO_FLAG_WRITE, &int_cb, NULL)) < 0) {
1089 av_log(NULL, AV_LOG_FATAL, "Could not open file %s for writing.\n",
1090 filename);
1091 exit_program(1);
1092 }
1093
1094 avio_write(out, st->codecpar->extradata, st->codecpar->extradata_size);
1095 avio_flush(out);
1096 avio_close(out);
1097 }
1098
1099 6046 static int open_input_file(OptionsContext *o, const char *filename)
1100 {
1101 InputFile *f;
1102 AVFormatContext *ic;
1103 6046 const AVInputFormat *file_iformat = NULL;
1104 int err, i, ret;
1105 int64_t timestamp;
1106 6046 AVDictionary *unused_opts = NULL;
1107 6046 AVDictionaryEntry *e = NULL;
1108 6046 char * video_codec_name = NULL;
1109 6046 char * audio_codec_name = NULL;
1110 6046 char *subtitle_codec_name = NULL;
1111 6046 char * data_codec_name = NULL;
1112 6046 int scan_all_pmts_set = 0;
1113
1114
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6046 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6046 if (o->stop_time != INT64_MAX && o->recording_time != INT64_MAX) {
1115 o->stop_time = INT64_MAX;
1116 av_log(NULL, AV_LOG_WARNING, "-t and -to cannot be used together; using -t.\n");
1117 }
1118
1119
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6046 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6046 if (o->stop_time != INT64_MAX && o->recording_time == INT64_MAX) {
1120 int64_t start_time = o->start_time == AV_NOPTS_VALUE ? 0 : o->start_time;
1121 if (o->stop_time <= start_time) {
1122 av_log(NULL, AV_LOG_ERROR, "-to value smaller than -ss; aborting.\n");
1123 exit_program(1);
1124 } else {
1125 o->recording_time = o->stop_time - start_time;
1126 }
1127 }
1128
1129
2/2
✓ Branch 0 taken 2895 times.
✓ Branch 1 taken 3151 times.
6046 if (o->format) {
1130
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2895 times.
2895 if (!(file_iformat = av_find_input_format(o->format))) {
1131 av_log(NULL, AV_LOG_FATAL, "Unknown input format: '%s'\n", o->format);
1132 exit_program(1);
1133 }
1134 }
1135
1136
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6046 times.
6046 if (!strcmp(filename, "-"))
1137 filename = "pipe:";
1138
1139
1/2
✓ Branch 0 taken 6046 times.
✗ Branch 1 not taken.
12092 stdin_interaction &= strncmp(filename, "pipe:", 5) &&
1140
1/2
✓ Branch 0 taken 6046 times.
✗ Branch 1 not taken.
6046 strcmp(filename, "/dev/stdin");
1141
1142 /* get default parameters from command line */
1143 6046 ic = avformat_alloc_context();
1144
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6046 times.
6046 if (!ic) {
1145 print_error(filename, AVERROR(ENOMEM));
1146 exit_program(1);
1147 }
1148
2/2
✓ Branch 0 taken 63 times.
✓ Branch 1 taken 5983 times.
6046 if (o->nb_audio_sample_rate) {
1149 63 av_dict_set_int(&o->g->format_opts, "sample_rate", o->audio_sample_rate[o->nb_audio_sample_rate - 1].u.i, 0);
1150 }
1151
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 6037 times.
6046 if (o->nb_audio_channels) {
1152 const AVClass *priv_class;
1153 /* because we set audio_channels based on both the "ac" and
1154 * "channel_layout" options, we need to check that the specified
1155 * demuxer actually has the "channels" option before setting it */
1156
3/6
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 9 times.
✗ Branch 5 not taken.
18 if (file_iformat && (priv_class = file_iformat->priv_class) &&
1157 9 av_opt_find(&priv_class, "channels", NULL, 0,
1158 AV_OPT_SEARCH_FAKE_OBJ)) {
1159 9 av_dict_set_int(&o->g->format_opts, "channels", o->audio_channels[o->nb_audio_channels - 1].u.i, 0);
1160 }
1161 }
1162
2/2
✓ Branch 0 taken 25 times.
✓ Branch 1 taken 6021 times.
6046 if (o->nb_frame_rates) {
1163 const AVClass *priv_class;
1164 /* set the format-level framerate option;
1165 * this is important for video grabbers, e.g. x11 */
1166
3/6
✓ Branch 0 taken 25 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 25 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 25 times.
✗ Branch 5 not taken.
50 if (file_iformat && (priv_class = file_iformat->priv_class) &&
1167 25 av_opt_find(&priv_class, "framerate", NULL, 0,
1168 AV_OPT_SEARCH_FAKE_OBJ)) {
1169 25 av_dict_set(&o->g->format_opts, "framerate",
1170 25 o->frame_rates[o->nb_frame_rates - 1].u.str, 0);
1171 }
1172 }
1173
2/2
✓ Branch 0 taken 493 times.
✓ Branch 1 taken 5553 times.
6046 if (o->nb_frame_sizes) {
1174 493 av_dict_set(&o->g->format_opts, "video_size", o->frame_sizes[o->nb_frame_sizes - 1].u.str, 0);
1175 }
1176
2/2
✓ Branch 0 taken 498 times.
✓ Branch 1 taken 5548 times.
6046 if (o->nb_frame_pix_fmts)
1177 498 av_dict_set(&o->g->format_opts, "pixel_format", o->frame_pix_fmts[o->nb_frame_pix_fmts - 1].u.str, 0);
1178
1179
4/4
✓ Branch 0 taken 2408 times.
✓ Branch 1 taken 33 times.
✓ Branch 2 taken 2441 times.
✓ Branch 3 taken 6046 times.
8487 MATCH_PER_TYPE_OPT(codec_names, str, video_codec_name, ic, "v");
1180
4/4
✓ Branch 0 taken 16 times.
✓ Branch 1 taken 2425 times.
✓ Branch 2 taken 2441 times.
✓ Branch 3 taken 6046 times.
8487 MATCH_PER_TYPE_OPT(codec_names, str, audio_codec_name, ic, "a");
1181
3/4
✗ Branch 0 not taken.
✓ Branch 1 taken 2441 times.
✓ Branch 2 taken 2441 times.
✓ Branch 3 taken 6046 times.
8487 MATCH_PER_TYPE_OPT(codec_names, str, subtitle_codec_name, ic, "s");
1182
3/4
✗ Branch 0 not taken.
✓ Branch 1 taken 2441 times.
✓ Branch 2 taken 2441 times.
✓ Branch 3 taken 6046 times.
8487 MATCH_PER_TYPE_OPT(codec_names, str, data_codec_name, ic, "d");
1183
1184
2/2
✓ Branch 0 taken 2408 times.
✓ Branch 1 taken 3638 times.
6046 if (video_codec_name)
1185 2408 ic->video_codec = find_codec_or_die(video_codec_name , AVMEDIA_TYPE_VIDEO , 0);
1186
2/2
✓ Branch 0 taken 16 times.
✓ Branch 1 taken 6030 times.
6046 if (audio_codec_name)
1187 16 ic->audio_codec = find_codec_or_die(audio_codec_name , AVMEDIA_TYPE_AUDIO , 0);
1188
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6046 times.
6046 if (subtitle_codec_name)
1189 ic->subtitle_codec = find_codec_or_die(subtitle_codec_name, AVMEDIA_TYPE_SUBTITLE, 0);
1190
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6046 times.
6046 if (data_codec_name)
1191 ic->data_codec = find_codec_or_die(data_codec_name , AVMEDIA_TYPE_DATA , 0);
1192
1193
2/2
✓ Branch 0 taken 2408 times.
✓ Branch 1 taken 3638 times.
6046 ic->video_codec_id = video_codec_name ? ic->video_codec->id : AV_CODEC_ID_NONE;
1194
2/2
✓ Branch 0 taken 16 times.
✓ Branch 1 taken 6030 times.
6046 ic->audio_codec_id = audio_codec_name ? ic->audio_codec->id : AV_CODEC_ID_NONE;
1195
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6046 times.
6046 ic->subtitle_codec_id = subtitle_codec_name ? ic->subtitle_codec->id : AV_CODEC_ID_NONE;
1196
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6046 times.
6046 ic->data_codec_id = data_codec_name ? ic->data_codec->id : AV_CODEC_ID_NONE;
1197
1198 6046 ic->flags |= AVFMT_FLAG_NONBLOCK;
1199
2/2
✓ Branch 0 taken 76 times.
✓ Branch 1 taken 5970 times.
6046 if (o->bitexact)
1200 76 ic->flags |= AVFMT_FLAG_BITEXACT;
1201 6046 ic->interrupt_callback = int_cb;
1202
1203
1/2
✓ Branch 1 taken 6046 times.
✗ Branch 2 not taken.
6046 if (!av_dict_get(o->g->format_opts, "scan_all_pmts", NULL, AV_DICT_MATCH_CASE)) {
1204 6046 av_dict_set(&o->g->format_opts, "scan_all_pmts", "1", AV_DICT_DONT_OVERWRITE);
1205 6046 scan_all_pmts_set = 1;
1206 }
1207 /* open the input file with generic avformat function */
1208 6046 err = avformat_open_input(&ic, filename, file_iformat, &o->g->format_opts);
1209
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 6045 times.
6046 if (err < 0) {
1210 1 print_error(filename, err);
1211
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 if (err == AVERROR_PROTOCOL_NOT_FOUND)
1212 av_log(NULL, AV_LOG_ERROR, "Did you mean file:%s?\n", filename);
1213 1 exit_program(1);
1214 }
1215
1/2
✓ Branch 0 taken 6045 times.
✗ Branch 1 not taken.
6045 if (scan_all_pmts_set)
1216 6045 av_dict_set(&o->g->format_opts, "scan_all_pmts", NULL, AV_DICT_MATCH_CASE);
1217 6045 remove_avoptions(&o->g->format_opts, o->g->codec_opts);
1218 6045 assert_avoptions(o->g->format_opts);
1219
1220 /* apply forced codec ids */
1221
2/2
✓ Branch 0 taken 6310 times.
✓ Branch 1 taken 6045 times.
12355 for (i = 0; i < ic->nb_streams; i++)
1222 6310 choose_decoder(o, ic, ic->streams[i]);
1223
1224
1/2
✓ Branch 0 taken 6045 times.
✗ Branch 1 not taken.
6045 if (find_stream_info) {
1225 6045 AVDictionary **opts = setup_find_stream_info_opts(ic, o->g->codec_opts);
1226 6045 int orig_nb_streams = ic->nb_streams;
1227
1228 /* If not enough info to get the stream parameters, we decode the
1229 first frames to get it. (used in mpeg case for example) */
1230 6045 ret = avformat_find_stream_info(ic, opts);
1231
1232
2/2
✓ Branch 0 taken 6310 times.
✓ Branch 1 taken 6045 times.
12355 for (i = 0; i < orig_nb_streams; i++)
1233 6310 av_dict_free(&opts[i]);
1234 6045 av_freep(&opts);
1235
1236
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6045 times.
6045 if (ret < 0) {
1237 av_log(NULL, AV_LOG_FATAL, "%s: could not find codec parameters\n", filename);
1238 if (ic->nb_streams == 0) {
1239 avformat_close_input(&ic);
1240 exit_program(1);
1241 }
1242 }
1243 }
1244
1245
3/4
✓ Branch 0 taken 21 times.
✓ Branch 1 taken 6024 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 21 times.
6045 if (o->start_time != AV_NOPTS_VALUE && o->start_time_eof != AV_NOPTS_VALUE) {
1246 av_log(NULL, AV_LOG_WARNING, "Cannot use -ss and -sseof both, using -ss for %s\n", filename);
1247 o->start_time_eof = AV_NOPTS_VALUE;
1248 }
1249
1250
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6045 times.
6045 if (o->start_time_eof != AV_NOPTS_VALUE) {
1251 if (o->start_time_eof >= 0) {
1252 av_log(NULL, AV_LOG_ERROR, "-sseof value must be negative; aborting\n");
1253 exit_program(1);
1254 }
1255 if (ic->duration > 0) {
1256 o->start_time = o->start_time_eof + ic->duration;
1257 if (o->start_time < 0) {
1258 av_log(NULL, AV_LOG_WARNING, "-sseof value seeks to before start of file %s; ignored\n", filename);
1259 o->start_time = AV_NOPTS_VALUE;
1260 }
1261 } else
1262 av_log(NULL, AV_LOG_WARNING, "Cannot use -sseof, duration of %s not known\n", filename);
1263 }
1264
2/2
✓ Branch 0 taken 21 times.
✓ Branch 1 taken 6024 times.
6045 timestamp = (o->start_time == AV_NOPTS_VALUE) ? 0 : o->start_time;
1265 /* add the stream start time */
1266
4/4
✓ Branch 0 taken 6042 times.
✓ Branch 1 taken 3 times.
✓ Branch 2 taken 4546 times.
✓ Branch 3 taken 1496 times.
6045 if (!o->seek_timestamp && ic->start_time != AV_NOPTS_VALUE)
1267 4546 timestamp += ic->start_time;
1268
1269 /* if seeking requested, we execute it */
1270
2/2
✓ Branch 0 taken 21 times.
✓ Branch 1 taken 6024 times.
6045 if (o->start_time != AV_NOPTS_VALUE) {
1271 21 int64_t seek_timestamp = timestamp;
1272
1273
1/2
✓ Branch 0 taken 21 times.
✗ Branch 1 not taken.
21 if (!(ic->iformat->flags & AVFMT_SEEK_TO_PTS)) {
1274 21 int dts_heuristic = 0;
1275
2/2
✓ Branch 0 taken 21 times.
✓ Branch 1 taken 21 times.
42 for (i=0; i<ic->nb_streams; i++) {
1276 21 const AVCodecParameters *par = ic->streams[i]->codecpar;
1277
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 21 times.
21 if (par->video_delay) {
1278 dts_heuristic = 1;
1279 break;
1280 }
1281 }
1282
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 21 times.
21 if (dts_heuristic) {
1283 seek_timestamp -= 3*AV_TIME_BASE / 23;
1284 }
1285 }
1286 21 ret = avformat_seek_file(ic, -1, INT64_MIN, seek_timestamp, seek_timestamp, 0);
1287
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 20 times.
21 if (ret < 0) {
1288 1 av_log(NULL, AV_LOG_WARNING, "%s: could not seek to position %0.3f\n",
1289 1 filename, (double)timestamp / AV_TIME_BASE);
1290 }
1291 }
1292
1293 /* update the current parameters so that they match the one of the input stream */
1294 6045 add_input_streams(o, ic);
1295
1296 /* dump the file content */
1297 6045 av_dump_format(ic, nb_input_files, filename, 0);
1298
1299 6045 GROW_ARRAY(input_files, nb_input_files);
1300 6045 f = av_mallocz(sizeof(*f));
1301
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6045 times.
6045 if (!f)
1302 exit_program(1);
1303 6045 input_files[nb_input_files - 1] = f;
1304
1305 6045 f->ctx = ic;
1306 6045 f->ist_index = nb_input_streams - ic->nb_streams;
1307 6045 f->start_time = o->start_time;
1308 6045 f->recording_time = o->recording_time;
1309 6045 f->input_ts_offset = o->input_ts_offset;
1310
3/6
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 6042 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 3 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
6045 f->ts_offset = o->input_ts_offset - (copy_ts ? (start_at_zero && ic->start_time != AV_NOPTS_VALUE ? ic->start_time : 0) : timestamp);
1311 6045 f->nb_streams = ic->nb_streams;
1312 6045 f->rate_emu = o->rate_emu;
1313 6045 f->accurate_seek = o->accurate_seek;
1314 6045 f->loop = o->loop;
1315 6045 f->duration = 0;
1316 6045 f->time_base = (AVRational){ 1, 1 };
1317
1318 6045 f->readrate = o->readrate ? o->readrate : 0.0;
1319
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6045 times.
6045 if (f->readrate < 0.0f) {
1320 av_log(NULL, AV_LOG_ERROR, "Option -readrate for Input #%d is %0.3f; it must be non-negative.\n", nb_input_files, f->readrate);
1321 exit_program(1);
1322 }
1323
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6045 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6045 if (f->readrate && f->rate_emu) {
1324 av_log(NULL, AV_LOG_WARNING, "Both -readrate and -re set for Input #%d. Using -readrate %0.3f.\n", nb_input_files, f->readrate);
1325 f->rate_emu = 0;
1326 }
1327
1328 6045 f->pkt = av_packet_alloc();
1329
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6045 times.
6045 if (!f->pkt)
1330 exit_program(1);
1331 #if HAVE_THREADS
1332 6045 f->thread_queue_size = o->thread_queue_size;
1333 #endif
1334
1335 /* check if all codec options have been used */
1336 6045 unused_opts = strip_specifiers(o->g->codec_opts);
1337
2/2
✓ Branch 0 taken 6409 times.
✓ Branch 1 taken 6045 times.
12454 for (i = f->ist_index; i < nb_input_streams; i++) {
1338 6409 e = NULL;
1339
2/2
✓ Branch 1 taken 19639 times.
✓ Branch 2 taken 6409 times.
26048 while ((e = av_dict_get(input_streams[i]->decoder_opts, "", e,
1340 AV_DICT_IGNORE_SUFFIX)))
1341 19639 av_dict_set(&unused_opts, e->key, NULL, 0);
1342 }
1343
1344 6045 e = NULL;
1345
2/2
✓ Branch 1 taken 297 times.
✓ Branch 2 taken 6045 times.
6342 while ((e = av_dict_get(unused_opts, "", e, AV_DICT_IGNORE_SUFFIX))) {
1346 297 const AVClass *class = avcodec_get_class();
1347 297 const AVOption *option = av_opt_find(&class, e->key, NULL, 0,
1348 AV_OPT_SEARCH_CHILDREN | AV_OPT_SEARCH_FAKE_OBJ);
1349 297 const AVClass *fclass = avformat_get_class();
1350 297 const AVOption *foption = av_opt_find(&fclass, e->key, NULL, 0,
1351 AV_OPT_SEARCH_CHILDREN | AV_OPT_SEARCH_FAKE_OBJ);
1352
2/4
✓ Branch 0 taken 297 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 297 times.
297 if (!option || foption)
1353 continue;
1354
1355
1356
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 297 times.
297 if (!(option->flags & AV_OPT_FLAG_DECODING_PARAM)) {
1357 av_log(NULL, AV_LOG_ERROR, "Codec AVOption %s (%s) specified for "
1358 "input file #%d (%s) is not a decoding option.\n", e->key,
1359 option->help ? option->help : "", nb_input_files - 1,
1360 filename);
1361 exit_program(1);
1362 }
1363
1364 297 av_log(NULL, AV_LOG_WARNING, "Codec AVOption %s (%s) specified for "
1365 "input file #%d (%s) has not been used for any stream. The most "
1366 "likely reason is either wrong type (e.g. a video option with "
1367 "no video streams) or that it is a private option of some decoder "
1368 "which was not actually used for any stream.\n", e->key,
1369
1/2
✓ Branch 0 taken 297 times.
✗ Branch 1 not taken.
297 option->help ? option->help : "", nb_input_files - 1, filename);
1370 }
1371 6045 av_dict_free(&unused_opts);
1372
1373
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6045 times.
6045 for (i = 0; i < o->nb_dump_attachment; i++) {
1374 int j;
1375
1376 for (j = 0; j < ic->nb_streams; j++) {
1377 AVStream *st = ic->streams[j];
1378
1379 if (check_stream_specifier(ic, st, o->dump_attachment[i].specifier) == 1)
1380 dump_attachment(st, o->dump_attachment[i].u.str);
1381 }
1382 }
1383
1384 6045 input_stream_potentially_available = 1;
1385
1386 6045 return 0;
1387 }
1388
1389 static uint8_t *get_line(AVIOContext *s)
1390 {
1391 AVIOContext *line;
1392 uint8_t *buf;
1393 char c;
1394
1395 if (avio_open_dyn_buf(&line) < 0) {
1396 av_log(NULL, AV_LOG_FATAL, "Could not alloc buffer for reading preset.\n");
1397 exit_program(1);
1398 }
1399
1400 while ((c = avio_r8(s)) && c != '\n')
1401 avio_w8(line, c);
1402 avio_w8(line, 0);
1403 avio_close_dyn_buf(line, &buf);
1404
1405 return buf;
1406 }
1407
1408 static int get_preset_file_2(const char *preset_name, const char *codec_name, AVIOContext **s)
1409 {
1410 int i, ret = -1;
1411 char filename[1000];
1412 const char *base[3] = { getenv("AVCONV_DATADIR"),
1413 getenv("HOME"),
1414 AVCONV_DATADIR,
1415 };
1416
1417 for (i = 0; i < FF_ARRAY_ELEMS(base) && ret < 0; i++) {
1418 if (!base[i])
1419 continue;
1420 if (codec_name) {
1421 snprintf(filename, sizeof(filename), "%s%s/%s-%s.avpreset", base[i],
1422 i != 1 ? "" : "/.avconv", codec_name, preset_name);
1423 ret = avio_open2(s, filename, AVIO_FLAG_READ, &int_cb, NULL);
1424 }
1425 if (ret < 0) {
1426 snprintf(filename, sizeof(filename), "%s%s/%s.avpreset", base[i],
1427 i != 1 ? "" : "/.avconv", preset_name);
1428 ret = avio_open2(s, filename, AVIO_FLAG_READ, &int_cb, NULL);
1429 }
1430 }
1431 return ret;
1432 }
1433
1434 6198 static int choose_encoder(OptionsContext *o, AVFormatContext *s, OutputStream *ost)
1435 {
1436 6198 enum AVMediaType type = ost->st->codecpar->codec_type;
1437 6198 char *codec_name = NULL;
1438
1439
6/6
✓ Branch 0 taken 1315 times.
✓ Branch 1 taken 4883 times.
✓ Branch 2 taken 62 times.
✓ Branch 3 taken 1253 times.
✓ Branch 4 taken 49 times.
✓ Branch 5 taken 13 times.
6198 if (type == AVMEDIA_TYPE_VIDEO || type == AVMEDIA_TYPE_AUDIO || type == AVMEDIA_TYPE_SUBTITLE) {
1440
16/20
✓ Branch 1 taken 3582 times.
✓ Branch 2 taken 126 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 126 times.
✓ Branch 6 taken 3708 times.
✓ Branch 7 taken 6185 times.
✓ Branch 8 taken 61 times.
✓ Branch 9 taken 6124 times.
✓ Branch 10 taken 61 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 61 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 305 times.
✓ Branch 15 taken 61 times.
✓ Branch 16 taken 244 times.
✓ Branch 17 taken 61 times.
✓ Branch 19 taken 366 times.
✓ Branch 20 taken 61 times.
✓ Branch 21 taken 61 times.
✗ Branch 22 not taken.
10259 MATCH_PER_STREAM_OPT(codec_names, str, codec_name, s, ost->st);
1441
2/2
✓ Branch 0 taken 2664 times.
✓ Branch 1 taken 3521 times.
6185 if (!codec_name) {
1442 5328 ost->st->codecpar->codec_id = av_guess_codec(s->oformat, NULL, s->url,
1443 2664 NULL, ost->st->codecpar->codec_type);
1444 2664 ost->enc = avcodec_find_encoder(ost->st->codecpar->codec_id);
1445
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2664 times.
2664 if (!ost->enc) {
1446 av_log(NULL, AV_LOG_FATAL, "Automatic encoder selection failed for "
1447 "output stream #%d:%d. Default encoder for format %s (codec %s) is "
1448 "probably disabled. Please choose an encoder manually.\n",
1449 ost->file_index, ost->index, s->oformat->name,
1450 avcodec_get_name(ost->st->codecpar->codec_id));
1451 return AVERROR_ENCODER_NOT_FOUND;
1452 }
1453
2/2
✓ Branch 0 taken 328 times.
✓ Branch 1 taken 3193 times.
3521 } else if (!strcmp(codec_name, "copy"))
1454 328 ost->stream_copy = 1;
1455 else {
1456 3193 ost->enc = find_codec_or_die(codec_name, ost->st->codecpar->codec_type, 1);
1457 3193 ost->st->codecpar->codec_id = ost->enc->id;
1458 }
1459 6185 ost->encoding_needed = !ost->stream_copy;
1460 } else {
1461 /* no encoding supported for other media types */
1462 13 ost->stream_copy = 1;
1463 13 ost->encoding_needed = 0;
1464 }
1465
1466 6198 return 0;
1467 }
1468
1469 6198 static OutputStream *new_output_stream(OptionsContext *o, AVFormatContext *oc, enum AVMediaType type, int source_index)
1470 {
1471 OutputStream *ost;
1472 6198 AVStream *st = avformat_new_stream(oc, NULL);
1473 6198 int idx = oc->nb_streams - 1, ret = 0;
1474 6198 const char *bsfs = NULL, *time_base = NULL;
1475 6198 char *next, *codec_tag = NULL;
1476 6198 double qscale = -1;
1477 int i;
1478
1479
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6198 times.
6198 if (!st) {
1480 av_log(NULL, AV_LOG_FATAL, "Could not alloc stream.\n");
1481 exit_program(1);
1482 }
1483
1484
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6198 times.
6198 if (oc->nb_streams - 1 < o->nb_streamid_map)
1485 st->id = o->streamid_map[oc->nb_streams - 1];
1486
1487 6198 GROW_ARRAY(output_streams, nb_output_streams);
1488
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 6198 times.
6198 if (!(ost = av_mallocz(sizeof(*ost))))
1489 exit_program(1);
1490 6198 output_streams[nb_output_streams - 1] = ost;
1491
1492 6198 ost->file_index = nb_output_files - 1;
1493 6198 ost->index = idx;
1494 6198 ost->st = st;
1495 6198 ost->forced_kf_ref_pts = AV_NOPTS_VALUE;
1496 6198 st->codecpar->codec_type = type;
1497
1498 6198 ret = choose_encoder(o, oc, ost);
1499
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6198 times.
6198 if (ret < 0) {
1500 av_log(NULL, AV_LOG_FATAL, "Error selecting an encoder for stream "
1501 "%d:%d\n", ost->file_index, ost->index);
1502 exit_program(1);
1503 }
1504
1505 6198 ost->enc_ctx = avcodec_alloc_context3(ost->enc);
1506
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6198 times.
6198 if (!ost->enc_ctx) {
1507 av_log(NULL, AV_LOG_ERROR, "Error allocating the encoding context.\n");
1508 exit_program(1);
1509 }
1510 6198 ost->enc_ctx->codec_type = type;
1511
1512 6198 ost->ref_par = avcodec_parameters_alloc();
1513
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6198 times.
6198 if (!ost->ref_par) {
1514 av_log(NULL, AV_LOG_ERROR, "Error allocating the encoding parameters.\n");
1515 exit_program(1);
1516 }
1517
1518
2/2
✓ Branch 0 taken 5857 times.
✓ Branch 1 taken 341 times.
6198 if (ost->enc) {
1519 5857 AVIOContext *s = NULL;
1520 5857 char *buf = NULL, *arg = NULL, *preset = NULL;
1521
1522 5857 ost->encoder_opts = filter_codec_opts(o->g->codec_opts, ost->enc->id, oc, st, ost->enc);
1523
1524
2/20
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 5857 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 5857 times.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
5857 MATCH_PER_STREAM_OPT(presets, str, preset, oc, st);
1525 5857 ost->autoscale = 1;
1526
2/20
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 5857 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 5857 times.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
5857 MATCH_PER_STREAM_OPT(autoscale, i, ost->autoscale, oc, st);
1527
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 5857 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
5857 if (preset && (!(ret = get_preset_file_2(preset, ost->enc->name, &s)))) {
1528 do {
1529 buf = get_line(s);
1530 if (!buf[0] || buf[0] == '#') {
1531 av_free(buf);
1532 continue;
1533 }
1534 if (!(arg = strchr(buf, '='))) {
1535 av_log(NULL, AV_LOG_FATAL, "Invalid line found in the preset file.\n");
1536 exit_program(1);
1537 }
1538 *arg++ = 0;
1539 av_dict_set(&ost->encoder_opts, buf, arg, AV_DICT_DONT_OVERWRITE);
1540 av_free(buf);
1541 } while (!s->eof_reached);
1542 avio_closep(&s);
1543 }
1544
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 5857 times.
5857 if (ret) {
1545 av_log(NULL, AV_LOG_FATAL,
1546 "Preset %s specified for stream %d:%d, but could not be opened.\n",
1547 preset, ost->file_index, ost->index);
1548 exit_program(1);
1549 }
1550 } else {
1551 341 ost->encoder_opts = filter_codec_opts(o->g->codec_opts, AV_CODEC_ID_NONE, oc, st, NULL);
1552 }
1553
1554
1555
2/2
✓ Branch 0 taken 1693 times.
✓ Branch 1 taken 4505 times.
6198 if (o->bitexact)
1556 1693 ost->enc_ctx->flags |= AV_CODEC_FLAG_BITEXACT;
1557
1558
4/20
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 6 taken 3 times.
✓ Branch 7 taken 6198 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 6198 times.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
6201 MATCH_PER_STREAM_OPT(time_bases, str, time_base, oc, st);
1559
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 6195 times.
6198 if (time_base) {
1560 AVRational q;
1561
1/2
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
3 if (av_parse_ratio(&q, time_base, INT_MAX, 0, NULL) < 0 ||
1562
2/4
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 3 times.
3 q.num <= 0 || q.den <= 0) {
1563 av_log(NULL, AV_LOG_FATAL, "Invalid time base: %s\n", time_base);
1564 exit_program(1);
1565 }
1566 3 st->time_base = q;
1567 }
1568
1569
2/20
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 6198 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 6198 times.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
6198 MATCH_PER_STREAM_OPT(enc_time_bases, str, time_base, oc, st);
1570
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 6195 times.
6198 if (time_base) {
1571 AVRational q;
1572
1/2
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
3 if (av_parse_ratio(&q, time_base, INT_MAX, 0, NULL) < 0 ||
1573
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
3 q.den <= 0) {
1574 av_log(NULL, AV_LOG_FATAL, "Invalid time base: %s\n", time_base);
1575 exit_program(1);
1576 }
1577 3 ost->enc_timebase = q;
1578 }
1579
1580 6198 ost->max_frames = INT64_MAX;
1581
16/20
✓ Branch 1 taken 4266 times.
✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 4 times.
✓ Branch 6 taken 4270 times.
✓ Branch 7 taken 6198 times.
✓ Branch 8 taken 1903 times.
✓ Branch 9 taken 4295 times.
✓ Branch 10 taken 1903 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 1903 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 5709 times.
✓ Branch 15 taken 1903 times.
✓ Branch 16 taken 3806 times.
✓ Branch 17 taken 1903 times.
✓ Branch 19 taken 7612 times.
✓ Branch 20 taken 1903 times.
✓ Branch 21 taken 1903 times.
✗ Branch 22 not taken.
18080 MATCH_PER_STREAM_OPT(max_frames, i64, ost->max_frames, oc, st);
1582
2/2
✓ Branch 0 taken 4270 times.
✓ Branch 1 taken 6192 times.
10462 for (i = 0; i<o->nb_max_frames; i++) {
1583 4270 char *p = o->max_frames[i].specifier;
1584
4/4
✓ Branch 0 taken 149 times.
✓ Branch 1 taken 4121 times.
✓ Branch 2 taken 6 times.
✓ Branch 3 taken 143 times.
4270 if (!*p && type != AVMEDIA_TYPE_VIDEO) {
1585 6 av_log(NULL, AV_LOG_WARNING, "Applying unspecific -frames to non video streams, maybe you meant -vframes ?\n");
1586 6 break;
1587 }
1588 }
1589
1590 6198 ost->copy_prior_start = -1;
1591
2/20
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 6198 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 6198 times.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
6198 MATCH_PER_STREAM_OPT(copy_prior_start, i, ost->copy_prior_start, oc ,st);
1592
1593
6/20
✓ Branch 1 taken 88 times.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 9 times.
✓ Branch 6 taken 97 times.
✓ Branch 7 taken 6198 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 6198 times.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
6295 MATCH_PER_STREAM_OPT(bitstream_filters, str, bsfs, oc, st);
1594
3/4
✓ Branch 0 taken 88 times.
✓ Branch 1 taken 6110 times.
✓ Branch 2 taken 88 times.
✗ Branch 3 not taken.
6198 if (bsfs && *bsfs) {
1595 88 ret = av_bsf_list_parse_str(bsfs, &ost->bsf_ctx);
1596
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 88 times.
88 if (ret < 0) {
1597 av_log(NULL, AV_LOG_ERROR, "Error parsing bitstream filter sequence '%s': %s\n", bsfs, av_err2str(ret));
1598 exit_program(1);
1599 }
1600 }
1601
1602
4/20
✓ Branch 1 taken 7 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 6 taken 7 times.
✓ Branch 7 taken 6198 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 6198 times.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
6205 MATCH_PER_STREAM_OPT(codec_tags, str, codec_tag, oc, st);
1603
2/2
✓ Branch 0 taken 7 times.
✓ Branch 1 taken 6191 times.
6198 if (codec_tag) {
1604 7 uint32_t tag = strtol(codec_tag, &next, 0);
1605
1/2
✓ Branch 0 taken 7 times.
✗ Branch 1 not taken.
7 if (*next)
1606 7 tag = AV_RL32(codec_tag);
1607 7 ost->st->codecpar->codec_tag =
1608 7 ost->enc_ctx->codec_tag = tag;
1609 }
1610
1611
15/20
✓ Branch 1 taken 233 times.
✓ Branch 2 taken 51 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 51 times.
✓ Branch 6 taken 284 times.
✓ Branch 7 taken 6198 times.
✓ Branch 8 taken 1 times.
✓ Branch 9 taken 6197 times.
✓ Branch 10 taken 1 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 1 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 1 times.
✓ Branch 15 taken 1 times.
✗ Branch 16 not taken.
✓ Branch 17 taken 1 times.
✓ Branch 19 taken 2 times.
✓ Branch 20 taken 1 times.
✓ Branch 21 taken 1 times.
✗ Branch 22 not taken.
6484 MATCH_PER_STREAM_OPT(qscale, dbl, qscale, oc, st);
1612
2/2
✓ Branch 0 taken 232 times.
✓ Branch 1 taken 5966 times.
6198 if (qscale >= 0) {
1613 232 ost->enc_ctx->flags |= AV_CODEC_FLAG_QSCALE;
1614 232 ost->enc_ctx->global_quality = FF_QP2LAMBDA * qscale;
1615 }
1616
1617
6/20
✓ Branch 1 taken 12 times.
✓ Branch 2 taken 23 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 23 times.
✓ Branch 6 taken 35 times.
✓ Branch 7 taken 6198 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 6198 times.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
6233 MATCH_PER_STREAM_OPT(disposition, str, ost->disposition, oc, st);
1618 6198 ost->disposition = av_strdup(ost->disposition);
1619
1620 6198 ost->max_muxing_queue_size = 128;
1621
4/20
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 6 taken 2 times.
✓ Branch 7 taken 6198 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 6198 times.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
6200 MATCH_PER_STREAM_OPT(max_muxing_queue_size, i, ost->max_muxing_queue_size, oc, st);
1622 6198 ost->max_muxing_queue_size *= sizeof(ost->pkt);
1623
1624 6198 ost->muxing_queue_data_size = 0;
1625
1626 6198 ost->muxing_queue_data_threshold = 50*1024*1024;
1627
2/20
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 6198 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 6198 times.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
6198 MATCH_PER_STREAM_OPT(muxing_queue_data_threshold, i, ost->muxing_queue_data_threshold, oc, st);
1628
1629
2/2
✓ Branch 0 taken 2367 times.
✓ Branch 1 taken 3831 times.
6198 if (oc->oformat->flags & AVFMT_GLOBALHEADER)
1630 2367 ost->enc_ctx->flags |= AV_CODEC_FLAG_GLOBAL_HEADER;
1631
1632 6198 av_dict_copy(&ost->sws_dict, o->g->sws_dict, 0);
1633
1634 6198 av_dict_copy(&ost->swr_opts, o->g->swr_opts, 0);
1635
4/4
✓ Branch 0 taken 5857 times.
✓ Branch 1 taken 341 times.
✓ Branch 3 taken 52 times.
✓ Branch 4 taken 5805 times.
6198 if (ost->enc && av_get_exact_bits_per_sample(ost->enc->id) == 24)
1636 52 av_dict_set(&ost->swr_opts, "output_sample_bits", "24", 0);
1637
1638 6198 ost->source_index = source_index;
1639
2/2
✓ Branch 0 taken 6114 times.
✓ Branch 1 taken 84 times.
6198 if (source_index >= 0) {
1640 6114 ost->sync_ist = input_streams[source_index];
1641 6114 input_streams[source_index]->discard = 0;
1642 6114 input_streams[source_index]->st->discard = input_streams[source_index]->user_set_discard;
1643 }
1644 6198 ost->last_mux_dts = AV_NOPTS_VALUE;
1645
1646 6198 ost->muxing_queue = av_fifo_alloc(8 * sizeof(AVPacket));
1647
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6198 times.
6198 if (!ost->muxing_queue)
1648 exit_program(1);
1649
1650 6198 return ost;
1651 }
1652
1653 static void parse_matrix_coeffs(uint16_t *dest, const char *str)
1654 {
1655 int i;
1656 const char *p = str;
1657 for (i = 0;; i++) {
1658 dest[i] = atoi(p);
1659 if (i == 63)
1660 break;
1661 p = strchr(p, ',');
1662 if (!p) {
1663 av_log(NULL, AV_LOG_FATAL, "Syntax error in matrix \"%s\" at coeff %d\n", str, i);
1664 exit_program(1);
1665 }
1666 p++;
1667 }
1668 }
1669
1670 /* read file contents into a string */
1671 28 static uint8_t *read_file(const char *filename)
1672 {
1673 28 AVIOContext *pb = NULL;
1674 28 AVIOContext *dyn_buf = NULL;
1675 28 int ret = avio_open(&pb, filename, AVIO_FLAG_READ);
1676 uint8_t buf[1024], *str;
1677
1678
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 28 times.
28 if (ret < 0) {
1679 av_log(NULL, AV_LOG_ERROR, "Error opening file %s.\n", filename);
1680 return NULL;
1681 }
1682
1683 28 ret = avio_open_dyn_buf(&dyn_buf);
1684
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 28 times.
28 if (ret < 0) {
1685 avio_closep(&pb);
1686 return NULL;
1687 }
1688
2/2
✓ Branch 1 taken 28 times.
✓ Branch 2 taken 28 times.
56 while ((ret = avio_read(pb, buf, sizeof(buf))) > 0)
1689 28 avio_write(dyn_buf, buf, ret);
1690 28 avio_w8(dyn_buf, 0);
1691 28 avio_closep(&pb);
1692
1693 28 ret = avio_close_dyn_buf(dyn_buf, &str);
1694
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 28 times.
28 if (ret < 0)
1695 return NULL;
1696 28 return str;
1697 }
1698
1699 5823 static char *get_ost_filters(OptionsContext *o, AVFormatContext *oc,
1700 OutputStream *ost)
1701 {
1702 5823 AVStream *st = ost->st;
1703
1704
3/4
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 5819 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 4 times.
5823 if (ost->filters_script && ost->filters) {
1705 av_log(NULL, AV_LOG_ERROR, "Both -filter and -filter_script set for "
1706 "output stream #%d:%d.\n", nb_output_files, st->index);
1707 exit_program(1);
1708 }
1709
1710
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 5819 times.
5823 if (ost->filters_script)
1711 4 return read_file(ost->filters_script);
1712
2/2
✓ Branch 0 taken 3089 times.
✓ Branch 1 taken 2730 times.
5819 else if (ost->filters)
1713 3089 return av_strdup(ost->filters);
1714
1715
2/2
✓ Branch 0 taken 2155 times.
✓ Branch 1 taken 575 times.
2730 return av_strdup(st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO ?
1716 "null" : "anull");
1717 }
1718
1719 313 static void check_streamcopy_filters(OptionsContext *o, AVFormatContext *oc,
1720 const OutputStream *ost, enum AVMediaType type)
1721 {
1722
2/4
✓ Branch 0 taken 313 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 313 times.
313 if (ost->filters_script || ost->filters) {
1723 av_log(NULL, AV_LOG_ERROR,
1724 "%s '%s' was defined for %s output stream %d:%d but codec copy was selected.\n"
1725 "Filtering and streamcopy cannot be used together.\n",
1726 ost->filters ? "Filtergraph" : "Filtergraph script",
1727 ost->filters ? ost->filters : ost->filters_script,
1728 av_get_media_type_string(type), ost->file_index, ost->index);
1729 exit_program(1);
1730 }
1731 313 }
1732
1733 4883 static OutputStream *new_video_stream(OptionsContext *o, AVFormatContext *oc, int source_index)
1734 {
1735 AVStream *st;
1736 OutputStream *ost;
1737 AVCodecContext *video_enc;
1738 4883 char *frame_rate = NULL, *max_frame_rate = NULL, *frame_aspect_ratio = NULL;
1739
1740 4883 ost = new_output_stream(o, oc, AVMEDIA_TYPE_VIDEO, source_index);
1741 4883 st = ost->st;
1742 4883 video_enc = ost->enc_ctx;
1743
1744
4/20
✓ Branch 1 taken 21 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 6 taken 21 times.
✓ Branch 7 taken 4883 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 4883 times.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
4904 MATCH_PER_STREAM_OPT(frame_rates, str, frame_rate, oc, st);
1745
3/4
✓ Branch 0 taken 21 times.
✓ Branch 1 taken 4862 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 21 times.
4883 if (frame_rate && av_parse_video_rate(&ost->frame_rate, frame_rate) < 0) {
1746 av_log(NULL, AV_LOG_FATAL, "Invalid framerate value: %s\n", frame_rate);
1747 exit_program(1);
1748 }
1749
1750
2/20
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 4883 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 4883 times.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
4883 MATCH_PER_STREAM_OPT(max_frame_rates, str, max_frame_rate, oc, st);
1751
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 4883 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
4883 if (max_frame_rate && av_parse_video_rate(&ost->max_frame_rate, max_frame_rate) < 0) {
1752 av_log(NULL, AV_LOG_FATAL, "Invalid maximum framerate value: %s\n", max_frame_rate);
1753 exit_program(1);
1754 }
1755
1756
3/4
✓ Branch 0 taken 21 times.
✓ Branch 1 taken 4862 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 21 times.
4883 if (frame_rate && max_frame_rate) {
1757 av_log(NULL, AV_LOG_ERROR, "Only one of -fpsmax and -r can be set for a stream.\n");
1758 exit_program(1);
1759 }
1760
1761
3/4
✓ Branch 0 taken 4862 times.
✓ Branch 1 taken 21 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 4862 times.
4883 if ((frame_rate || max_frame_rate) &&
1762
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 21 times.
21 video_sync_method == VSYNC_PASSTHROUGH)
1763 av_log(NULL, AV_LOG_ERROR, "Using -vsync 0 and -r/-fpsmax can produce invalid output files\n");
1764
1765
2/20
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 4883 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 4883 times.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
4883 MATCH_PER_STREAM_OPT(frame_aspect_ratios, str, frame_aspect_ratio, oc, st);
1766
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4883 times.
4883 if (frame_aspect_ratio) {
1767 AVRational q;
1768 if (av_parse_ratio(&q, frame_aspect_ratio, 255, 0, NULL) < 0 ||
1769 q.num <= 0 || q.den <= 0) {
1770 av_log(NULL, AV_LOG_FATAL, "Invalid aspect ratio: %s\n", frame_aspect_ratio);
1771 exit_program(1);
1772 }
1773 ost->frame_aspect_ratio = q;
1774 }
1775
1776
4/20
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 6 taken 3 times.
✓ Branch 7 taken 4883 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 4883 times.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
4886 MATCH_PER_STREAM_OPT(filter_scripts, str, ost->filters_script, oc, st);
1777
16/20
✓ Branch 1 taken 2535 times.
✓ Branch 2 taken 32 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 32 times.
✓ Branch 6 taken 2567 times.
✓ Branch 7 taken 4883 times.
✓ Branch 8 taken 1 times.
✓ Branch 9 taken 4882 times.
✓ Branch 10 taken 1 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 1 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 2 times.
✓ Branch 15 taken 1 times.
✓ Branch 16 taken 1 times.
✓ Branch 17 taken 1 times.
✓ Branch 19 taken 3 times.
✓ Branch 20 taken 1 times.
✓ Branch 21 taken 1 times.
✗ Branch 22 not taken.
7453 MATCH_PER_STREAM_OPT(filters, str, ost->filters, oc, st);
1778
1779
2/2
✓ Branch 0 taken 4692 times.
✓ Branch 1 taken 191 times.
4883 if (!ost->stream_copy) {
1780 4692 const char *p = NULL;
1781 4692 char *frame_size = NULL;
1782 4692 char *frame_pix_fmt = NULL;
1783 4692 char *intra_matrix = NULL, *inter_matrix = NULL;
1784 4692 char *chroma_intra_matrix = NULL;
1785 4692 int do_pass = 0;
1786 int i;
1787
1788
11/20
✓ Branch 1 taken 614 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 6 taken 614 times.
✓ Branch 7 taken 4692 times.
✓ Branch 8 taken 3 times.
✓ Branch 9 taken 4689 times.
✓ Branch 10 taken 3 times.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✓ Branch 13 taken 3 times.
✗ Branch 14 not taken.
✓ Branch 15 taken 3 times.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✓ Branch 19 taken 3 times.
✓ Branch 20 taken 3 times.
✗ Branch 21 not taken.
✓ Branch 22 taken 3 times.
5309 MATCH_PER_STREAM_OPT(frame_sizes, str, frame_size, oc, st);
1789
3/4
✓ Branch 0 taken 611 times.
✓ Branch 1 taken 4081 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 611 times.
4692 if (frame_size && av_parse_video_size(&video_enc->width, &video_enc->height, frame_size) < 0) {
1790 av_log(NULL, AV_LOG_FATAL, "Invalid frame size: %s.\n", frame_size);
1791 exit_program(1);
1792 }
1793
1794 4692 video_enc->bits_per_raw_sample = frame_bits_per_raw_sample;
1795
4/20
✓ Branch 1 taken 3367 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 6 taken 3367 times.
✓ Branch 7 taken 4692 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 4692 times.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
8059 MATCH_PER_STREAM_OPT(frame_pix_fmts, str, frame_pix_fmt, oc, st);
1796
3/4
✓ Branch 0 taken 3367 times.
✓ Branch 1 taken 1325 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 3367 times.
4692 if (frame_pix_fmt && *frame_pix_fmt == '+') {
1797 ost->keep_pix_fmt = 1;
1798 if (!*++frame_pix_fmt)
1799 frame_pix_fmt = NULL;
1800 }
1801
3/4
✓ Branch 0 taken 3367 times.
✓ Branch 1 taken 1325 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 3367 times.
4692 if (frame_pix_fmt && (video_enc->pix_fmt = av_get_pix_fmt(frame_pix_fmt)) == AV_PIX_FMT_NONE) {
1802 av_log(NULL, AV_LOG_FATAL, "Unknown pixel format requested: %s.\n", frame_pix_fmt);
1803 exit_program(1);
1804 }
1805 4692 st->sample_aspect_ratio = video_enc->sample_aspect_ratio;
1806
1807
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4692 times.
4692 if (intra_only)
1808 video_enc->gop_size = 0;
1809
2/20
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 4692 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 4692 times.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
4692 MATCH_PER_STREAM_OPT(intra_matrices, str, intra_matrix, oc, st);
1810
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4692 times.
4692 if (intra_matrix) {
1811 if (!(video_enc->intra_matrix = av_mallocz(sizeof(*video_enc->intra_matrix) * 64))) {
1812 av_log(NULL, AV_LOG_FATAL, "Could not allocate memory for intra matrix.\n");
1813 exit_program(1);
1814 }
1815 parse_matrix_coeffs(video_enc->intra_matrix, intra_matrix);
1816 }
1817
2/20
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 4692 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 4692 times.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
4692 MATCH_PER_STREAM_OPT(chroma_intra_matrices, str, chroma_intra_matrix, oc, st);
1818
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4692 times.
4692 if (chroma_intra_matrix) {
1819 uint16_t *p = av_mallocz(sizeof(*video_enc->chroma_intra_matrix) * 64);
1820 if (!p) {
1821 av_log(NULL, AV_LOG_FATAL, "Could not allocate memory for intra matrix.\n");
1822 exit_program(1);
1823 }
1824 video_enc->chroma_intra_matrix = p;
1825 parse_matrix_coeffs(p, chroma_intra_matrix);
1826 }
1827
2/20
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 4692 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 4692 times.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
4692 MATCH_PER_STREAM_OPT(inter_matrices, str, inter_matrix, oc, st);
1828
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4692 times.
4692 if (inter_matrix) {
1829 if (!(video_enc->inter_matrix = av_mallocz(sizeof(*video_enc->inter_matrix) * 64))) {
1830 av_log(NULL, AV_LOG_FATAL, "Could not allocate memory for inter matrix.\n");
1831 exit_program(1);
1832 }
1833 parse_matrix_coeffs(video_enc->inter_matrix, inter_matrix);
1834 }
1835
1836
2/20
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 4692 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 4692 times.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
4692 MATCH_PER_STREAM_OPT(rc_overrides, str, p, oc, st);
1837
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4692 times.
4692 for (i = 0; p; i++) {
1838 int start, end, q;
1839 int e = sscanf(p, "%d,%d,%d", &start, &end, &q);
1840 if (e != 3) {
1841 av_log(NULL, AV_LOG_FATAL, "error parsing rc_override\n");
1842 exit_program(1);
1843 }
1844 video_enc->rc_override =
1845 av_realloc_array(video_enc->rc_override,
1846 i + 1, sizeof(RcOverride));
1847 if (!video_enc->rc_override) {
1848 av_log(NULL, AV_LOG_FATAL, "Could not (re)allocate memory for rc_override.\n");
1849 exit_program(1);
1850 }
1851 video_enc->rc_override[i].start_frame = start;
1852 video_enc->rc_override[i].end_frame = end;
1853 if (q > 0) {
1854 video_enc->rc_override[i].qscale = q;
1855 video_enc->rc_override[i].quality_factor = 1.0;
1856 }
1857 else {
1858 video_enc->rc_override[i].qscale = 0;
1859 video_enc->rc_override[i].quality_factor = -q/100.0;
1860 }
1861 p = strchr(p, '/');
1862 if (p) p++;
1863 }
1864 4692 video_enc->rc_override_count = i;
1865
1866
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4692 times.
4692 if (do_psnr)
1867 video_enc->flags|= AV_CODEC_FLAG_PSNR;
1868
1869 /* two pass mode */
1870
2/20
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 4692 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 4692 times.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
4692 MATCH_PER_STREAM_OPT(pass, i, do_pass, oc, st);
1871
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4692 times.
4692 if (do_pass) {
1872 if (do_pass & 1) {
1873 video_enc->flags |= AV_CODEC_FLAG_PASS1;
1874 av_dict_set(&ost->encoder_opts, "flags", "+pass1", AV_DICT_APPEND);
1875 }
1876 if (do_pass & 2) {
1877 video_enc->flags |= AV_CODEC_FLAG_PASS2;
1878 av_dict_set(&ost->encoder_opts, "flags", "+pass2", AV_DICT_APPEND);
1879 }
1880 }
1881
1882
2/20
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 4692 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 4692 times.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
4692 MATCH_PER_STREAM_OPT(passlogfiles, str, ost->logfile_prefix, oc, st);
1883
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4692 times.
4692 if (ost->logfile_prefix &&
1884 !(ost->logfile_prefix = av_strdup(ost->logfile_prefix)))
1885 exit_program(1);
1886
1887
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4692 times.
4692 if (do_pass) {
1888 char logfilename[1024];
1889 FILE *f;
1890
1891 snprintf(logfilename, sizeof(logfilename), "%s-%d.log",
1892 ost->logfile_prefix ? ost->logfile_prefix :
1893 DEFAULT_PASS_LOGFILENAME_PREFIX,
1894 i);
1895 if (!strcmp(ost->enc->name, "libx264")) {
1896 av_dict_set(&ost->encoder_opts, "stats", logfilename, AV_DICT_DONT_OVERWRITE);
1897 } else {
1898 if (video_enc->flags & AV_CODEC_FLAG_PASS2) {
1899 char *logbuffer = read_file(logfilename);
1900
1901 if (!logbuffer) {
1902 av_log(NULL, AV_LOG_FATAL, "Error reading log file '%s' for pass-2 encoding\n",
1903 logfilename);
1904 exit_program(1);
1905 }
1906 video_enc->stats_in = logbuffer;
1907 }
1908 if (video_enc->flags & AV_CODEC_FLAG_PASS1) {
1909 f = av_fopen_utf8(logfilename, "wb");
1910 if (!f) {
1911 av_log(NULL, AV_LOG_FATAL,
1912 "Cannot write log file '%s' for pass-1 encoding: %s\n",
1913 logfilename, strerror(errno));
1914 exit_program(1);
1915 }
1916 ost->logfile = f;
1917 }
1918 }
1919 }
1920
1921
4/20
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 6 taken 1 times.
✓ Branch 7 taken 4692 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 4692 times.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
4693 MATCH_PER_STREAM_OPT(forced_key_frames, str, ost->forced_keyframes, oc, st);
1922
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 4691 times.
4692 if (ost->forced_keyframes)
1923 1 ost->forced_keyframes = av_strdup(ost->forced_keyframes);
1924
1925
2/20
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 4692 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 4692 times.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
4692 MATCH_PER_STREAM_OPT(force_fps, i, ost->force_fps, oc, st);
1926
1927 4692 ost->top_field_first = -1;
1928
4/20
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 6 taken 3 times.
✓ Branch 7 taken 4692 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 4692 times.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
4695 MATCH_PER_STREAM_OPT(top_field_first, i, ost->top_field_first, oc, st);
1929
1930
1931 4692 ost->avfilter = get_ost_filters(o, oc, ost);
1932
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4692 times.
4692 if (!ost->avfilter)
1933 exit_program(1);
1934 } else {
1935
2/20
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 191 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 191 times.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
191 MATCH_PER_STREAM_OPT(copy_initial_nonkeyframes, i, ost->copy_initial_nonkeyframes, oc ,st);
1936 }
1937
1938
2/2
✓ Branch 0 taken 191 times.
✓ Branch 1 taken 4692 times.
4883 if (ost->stream_copy)
1939 191 check_streamcopy_filters(o, oc, ost, AVMEDIA_TYPE_VIDEO);
1940
1941 4883 return ost;
1942 }
1943
1944 1253 static OutputStream *new_audio_stream(OptionsContext *o, AVFormatContext *oc, int source_index)
1945 {
1946 int n;
1947 AVStream *st;
1948 OutputStream *ost;
1949 AVCodecContext *audio_enc;
1950
1951 1253 ost = new_output_stream(o, oc, AVMEDIA_TYPE_AUDIO, source_index);
1952 1253 st = ost->st;
1953
1954 1253 audio_enc = ost->enc_ctx;
1955 1253 audio_enc->codec_type = AVMEDIA_TYPE_AUDIO;
1956
1957
4/20
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 6 taken 1 times.
✓ Branch 7 taken 1253 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 1253 times.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
1254 MATCH_PER_STREAM_OPT(filter_scripts, str, ost->filters_script, oc, st);
1958
6/20
✓ Branch 1 taken 555 times.
✓ Branch 2 taken 34 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 34 times.
✓ Branch 6 taken 589 times.
✓ Branch 7 taken 1253 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 1253 times.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
1842 MATCH_PER_STREAM_OPT(filters, str, ost->filters, oc, st);
1959
1960
2/2
✓ Branch 0 taken 1131 times.
✓ Branch 1 taken 122 times.
1253 if (!ost->stream_copy) {
1961 1131 char *sample_fmt = NULL;
1962
1963
4/20
✓ Branch 1 taken 12 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 6 taken 12 times.
✓ Branch 7 taken 1131 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 1131 times.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
1143 MATCH_PER_STREAM_OPT(audio_channels, i, audio_enc->channels, oc, st);
1964
1965
2/20
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 1131 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 1131 times.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
1131 MATCH_PER_STREAM_OPT(sample_fmts, str, sample_fmt, oc, st);
1966
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1131 times.
1131 if (sample_fmt &&
1967 (audio_enc->sample_fmt = av_get_sample_fmt(sample_fmt)) == AV_SAMPLE_FMT_NONE) {
1968 av_log(NULL, AV_LOG_FATAL, "Invalid sample format '%s'\n", sample_fmt);
1969 exit_program(1);
1970 }
1971
1972
4/20
✓ Branch 1 taken 25 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 6 taken 25 times.
✓ Branch 7 taken 1131 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 1131 times.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
1156 MATCH_PER_STREAM_OPT(audio_sample_rate, i, audio_enc->sample_rate, oc, st);
1973
1974
2/20
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 1131 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 1131 times.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
1131 MATCH_PER_STREAM_OPT(apad, str, ost->apad, oc, st);
1975 1131 ost->apad = av_strdup(ost->apad);
1976
1977 1131 ost->avfilter = get_ost_filters(o, oc, ost);
1978
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1131 times.
1131 if (!ost->avfilter)
1979 exit_program(1);
1980
1981 /* check for channel mapping for this audio stream */
1982
2/2
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 1131 times.
1141 for (n = 0; n < o->nb_audio_channel_maps; n++) {
1983 10 AudioChannelMap *map = &o->audio_channel_maps[n];
1984
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
10 if ((map->ofile_idx == -1 || ost->file_index == map->ofile_idx) &&
1985
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
10 (map->ostream_idx == -1 || ost->st->index == map->ostream_idx)) {
1986 InputStream *ist;
1987
1988
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 9 times.
10 if (map->channel_idx == -1) {
1989 1 ist = NULL;
1990
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 } else if (ost->source_index < 0) {
1991 av_log(NULL, AV_LOG_FATAL, "Cannot determine input stream for channel mapping %d.%d\n",
1992 ost->file_index, ost->st->index);
1993 continue;
1994 } else {
1995 9 ist = input_streams[ost->source_index];
1996 }
1997
1998
4/6
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 9 times.
✗ Branch 5 not taken.
10 if (!ist || (ist->file_index == map->file_idx && ist->st->index == map->stream_idx)) {
1999
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 10 times.
10 if (av_reallocp_array(&ost->audio_channels_map,
2000 10 ost->audio_channels_mapped + 1,
2001 sizeof(*ost->audio_channels_map)
2002 ) < 0 )
2003 exit_program(1);
2004
2005 10 ost->audio_channels_map[ost->audio_channels_mapped++] = map->channel_idx;
2006 }
2007 }
2008 }
2009 }
2010
2011
2/2
✓ Branch 0 taken 122 times.
✓ Branch 1 taken 1131 times.
1253 if (ost->stream_copy)
2012 122 check_streamcopy_filters(o, oc, ost, AVMEDIA_TYPE_AUDIO);
2013
2014 1253 return ost;
2015 }
2016
2017 12 static OutputStream *new_data_stream(OptionsContext *o, AVFormatContext *oc, int source_index)
2018 {
2019 OutputStream *ost;
2020
2021 12 ost = new_output_stream(o, oc, AVMEDIA_TYPE_DATA, source_index);
2022
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if (!ost->stream_copy) {
2023 av_log(NULL, AV_LOG_FATAL, "Data stream encoding not supported yet (only streamcopy)\n");
2024 exit_program(1);
2025 }
2026
2027 12 return ost;
2028 }
2029
2030 static OutputStream *new_unknown_stream(OptionsContext *o, AVFormatContext *oc, int source_index)
2031 {
2032 OutputStream *ost;
2033
2034 ost = new_output_stream(o, oc, AVMEDIA_TYPE_UNKNOWN, source_index);
2035 if (!ost->stream_copy) {
2036 av_log(NULL, AV_LOG_FATAL, "Unknown stream encoding not supported yet (only streamcopy)\n");
2037 exit_program(1);
2038 }
2039
2040 return ost;
2041 }
2042
2043 1 static OutputStream *new_attachment_stream(OptionsContext *o, AVFormatContext *oc, int source_index)
2044 {
2045 1 OutputStream *ost = new_output_stream(o, oc, AVMEDIA_TYPE_ATTACHMENT, source_index);
2046 1 ost->stream_copy = 1;
2047 1 ost->finished = 1;
2048 1 return ost;
2049 }
2050
2051 49 static OutputStream *new_subtitle_stream(OptionsContext *o, AVFormatContext *oc, int source_index)
2052 {
2053 AVStream *st;
2054 OutputStream *ost;
2055 AVCodecContext *subtitle_enc;
2056
2057 49 ost = new_output_stream(o, oc, AVMEDIA_TYPE_SUBTITLE, source_index);
2058 49 st = ost->st;
2059 49 subtitle_enc = ost->enc_ctx;
2060
2061 49 subtitle_enc->codec_type = AVMEDIA_TYPE_SUBTITLE;
2062
2063
2/20
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 49 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 49 times.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
49 MATCH_PER_STREAM_OPT(copy_initial_nonkeyframes, i, ost->copy_initial_nonkeyframes, oc, st);
2064
2065
2/2
✓ Branch 0 taken 34 times.
✓ Branch 1 taken 15 times.
49 if (!ost->stream_copy) {
2066 34 char *frame_size = NULL;
2067
2068
2/20
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 34 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 34 times.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
34 MATCH_PER_STREAM_OPT(frame_sizes, str, frame_size, oc, st);
2069
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 34 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
34 if (frame_size && av_parse_video_size(&subtitle_enc->width, &subtitle_enc->height, frame_size) < 0) {
2070 av_log(NULL, AV_LOG_FATAL, "Invalid frame size: %s.\n", frame_size);
2071 exit_program(1);
2072 }
2073 }
2074
2075 49 return ost;
2076 }
2077
2078 /* arg format is "output-stream-index:streamid-value". */
2079 static int opt_streamid(void *optctx, const char *opt, const char *arg)
2080 {
2081 OptionsContext *o = optctx;
2082 int idx;
2083 char *p;
2084 char idx_str[16];
2085
2086 av_strlcpy(idx_str, arg, sizeof(idx_str));
2087 p = strchr(idx_str, ':');
2088 if (!p) {
2089 av_log(NULL, AV_LOG_FATAL,
2090 "Invalid value '%s' for option '%s', required syntax is 'index:value'\n",
2091 arg, opt);
2092 exit_program(1);
2093 }
2094 *p++ = '\0';
2095 idx = parse_number_or_die(opt, idx_str, OPT_INT, 0, MAX_STREAMS-1);
2096 o->streamid_map = grow_array(o->streamid_map, sizeof(*o->streamid_map), &o->nb_streamid_map, idx+1);
2097 o->streamid_map[idx] = parse_number_or_die(opt, p, OPT_INT, 0, INT_MAX);
2098 return 0;
2099 }
2100
2101 15 static int copy_chapters(InputFile *ifile, OutputFile *ofile, int copy_metadata)
2102 {
2103 15 AVFormatContext *is = ifile->ctx;
2104 15 AVFormatContext *os = ofile->ctx;
2105 AVChapter **tmp;
2106 int i;
2107
2108 15 tmp = av_realloc_f(os->chapters, is->nb_chapters + os->nb_chapters, sizeof(*os->chapters));
2109
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 15 times.
15 if (!tmp)
2110 return AVERROR(ENOMEM);
2111 15 os->chapters = tmp;
2112
2113
2/2
✓ Branch 0 taken 24 times.
✓ Branch 1 taken 13 times.
37 for (i = 0; i < is->nb_chapters; i++) {
2114 24 AVChapter *in_ch = is->chapters[i], *out_ch;
2115
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 24 times.
24 int64_t start_time = (ofile->start_time == AV_NOPTS_VALUE) ? 0 : ofile->start_time;
2116 24 int64_t ts_off = av_rescale_q(start_time - ifile->ts_offset,
2117 24 AV_TIME_BASE_Q, in_ch->time_base);
2118
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 21 times.
24 int64_t rt = (ofile->recording_time == INT64_MAX) ? INT64_MAX :
2119 3 av_rescale_q(ofile->recording_time, AV_TIME_BASE_Q, in_ch->time_base);
2120
2121
2122
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 24 times.
24 if (in_ch->end < ts_off)
2123 continue;
2124
4/4
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 21 times.
✓ Branch 2 taken 2 times.
✓ Branch 3 taken 1 times.
24 if (rt != INT64_MAX && in_ch->start > rt + ts_off)
2125 2 break;
2126
2127 22 out_ch = av_mallocz(sizeof(AVChapter));
2128
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 22 times.
22 if (!out_ch)
2129 return AVERROR(ENOMEM);
2130
2131 22 out_ch->id = in_ch->id;
2132 22 out_ch->time_base = in_ch->time_base;
2133 22 out_ch->start = FFMAX(0, in_ch->start - ts_off);
2134 22 out_ch->end = FFMIN(rt, in_ch->end - ts_off);
2135
2136
1/2
✓ Branch 0 taken 22 times.
✗ Branch 1 not taken.
22 if (copy_metadata)
2137 22 av_dict_copy(&out_ch->metadata, in_ch->metadata, 0);
2138
2139 22 os->chapters[os->nb_chapters++] = out_ch;
2140 }
2141 15 return 0;
2142 }
2143
2144 83 static void init_output_filter(OutputFilter *ofilter, OptionsContext *o,
2145 AVFormatContext *oc)
2146 {
2147 OutputStream *ost;
2148
2149
2/3
✓ Branch 0 taken 68 times.
✓ Branch 1 taken 15 times.
✗ Branch 2 not taken.
83 switch (ofilter->type) {
2150 68 case AVMEDIA_TYPE_VIDEO: ost = new_video_stream(o, oc, -1); break;
2151 15 case AVMEDIA_TYPE_AUDIO: ost = new_audio_stream(o, oc, -1); break;
2152 default:
2153 av_log(NULL, AV_LOG_FATAL, "Only video and audio filters are supported "
2154 "currently.\n");
2155 exit_program(1);
2156 }
2157
2158 83 ost->source_index = -1;
2159 83 ost->filter = ofilter;
2160
2161 83 ofilter->ost = ost;
2162 83 ofilter->format = -1;
2163
2164
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 83 times.
83 if (ost->stream_copy) {
2165 av_log(NULL, AV_LOG_ERROR, "Streamcopy requested for output stream %d:%d, "
2166 "which is fed from a complex filtergraph. Filtering and streamcopy "
2167 "cannot be used together.\n", ost->file_index, ost->index);
2168 exit_program(1);
2169 }
2170
2171
3/6
✓ Branch 0 taken 83 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 83 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 83 times.
83 if (ost->avfilter && (ost->filters || ost->filters_script)) {
2172 const char *opt = ost->filters ? "-vf/-af/-filter" : "-filter_script";
2173 av_log(NULL, AV_LOG_ERROR,
2174 "%s '%s' was specified through the %s option "
2175 "for output stream %d:%d, which is fed from a complex filtergraph.\n"
2176 "%s and -filter_complex cannot be used together for the same stream.\n",
2177 ost->filters ? "Filtergraph" : "Filtergraph script",
2178 ost->filters ? ost->filters : ost->filters_script,
2179 opt, ost->file_index, ost->index, opt);
2180 exit_program(1);
2181 }
2182
2183 83 avfilter_inout_free(&ofilter->out_tmp);
2184 83 }
2185
2186 6017 static int init_complex_filters(void)
2187 {
2188 6017 int i, ret = 0;
2189
2190
2/2
✓ Branch 0 taken 80 times.
✓ Branch 1 taken 6017 times.
6097 for (i = 0; i < nb_filtergraphs; i++) {
2191 80 ret = init_complex_filtergraph(filtergraphs[i]);
2192
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 80 times.
80 if (ret < 0)
2193 return ret;
2194 }
2195 6017 return 0;
2196 }
2197
2198 6018 static int open_output_file(OptionsContext *o, const char *filename)
2199 {
2200 AVFormatContext *oc;
2201 int i, j, err;
2202 OutputFile *of;
2203 OutputStream *ost;
2204 InputStream *ist;
2205 6018 AVDictionary *unused_opts = NULL;
2206 6018 AVDictionaryEntry *e = NULL;
2207 6018 int format_flags = 0;
2208
2209
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6018 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6018 if (o->stop_time != INT64_MAX && o->recording_time != INT64_MAX) {
2210 o->stop_time = INT64_MAX;
2211 av_log(NULL, AV_LOG_WARNING, "-t and -to cannot be used together; using -t.\n");
2212 }
2213
2214
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6018 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6018 if (o->stop_time != INT64_MAX && o->recording_time == INT64_MAX) {
2215 int64_t start_time = o->start_time == AV_NOPTS_VALUE ? 0 : o->start_time;
2216 if (o->stop_time <= start_time) {
2217 av_log(NULL, AV_LOG_ERROR, "-to value smaller than -ss; aborting.\n");
2218 exit_program(1);
2219 } else {
2220 o->recording_time = o->stop_time - start_time;
2221 }
2222 }
2223
2224 6018 GROW_ARRAY(output_files, nb_output_files);
2225 6018 of = av_mallocz(sizeof(*of));
2226
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6018 times.
6018 if (!of)
2227 exit_program(1);
2228 6018 output_files[nb_output_files - 1] = of;
2229
2230 6018 of->ost_index = nb_output_streams;
2231 6018 of->recording_time = o->recording_time;
2232 6018 of->start_time = o->start_time;
2233 6018 of->limit_filesize = o->limit_filesize;
2234 6018 of->shortest = o->shortest;
2235 6018 av_dict_copy(&of->opts, o->g->format_opts, 0);
2236
2237
2/2
✓ Branch 0 taken 2240 times.
✓ Branch 1 taken 3778 times.
6018 if (!strcmp(filename, "-"))
2238 2240 filename = "pipe:";
2239
2240 6018 err = avformat_alloc_output_context2(&oc, NULL, o->format, filename);
2241
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6018 times.
6018 if (!oc) {
2242 print_error(filename, err);
2243 exit_program(1);
2244 }
2245
2246 6018 of->ctx = oc;
2247
2/2
✓ Branch 0 taken 138 times.
✓ Branch 1 taken 5880 times.
6018 if (o->recording_time != INT64_MAX)
2248 138 oc->duration = o->recording_time;
2249
2250 6018 oc->interrupt_callback = int_cb;
2251
2252 6018 e = av_dict_get(o->g->format_opts, "fflags", NULL, 0);
2253
2/2
✓ Branch 0 taken 3448 times.
✓ Branch 1 taken 2570 times.
6018 if (e) {
2254 3448 const AVOption *o = av_opt_find(oc, "fflags", NULL, 0, 0);
2255 3448 av_opt_eval_flags(oc, o, e->value, &format_flags);
2256 }
2257
2/2
✓ Branch 0 taken 1648 times.
✓ Branch 1 taken 4370 times.
6018 if (o->bitexact) {
2258 1648 format_flags |= AVFMT_FLAG_BITEXACT;
2259 1648 oc->flags |= AVFMT_FLAG_BITEXACT;
2260 }
2261
2262 /* create streams for all unlabeled output pads */
2263
2/2
✓ Branch 0 taken 81 times.
✓ Branch 1 taken 6018 times.
6099 for (i = 0; i < nb_filtergraphs; i++) {
2264 81 FilterGraph *fg = filtergraphs[i];
2265
2/2
✓ Branch 0 taken 84 times.
✓ Branch 1 taken 81 times.
165 for (j = 0; j < fg->nb_outputs; j++) {
2266 84 OutputFilter *ofilter = fg->outputs[j];
2267
2268
4/4
✓ Branch 0 taken 83 times.
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 3 times.
✓ Branch 3 taken 80 times.
84 if (!ofilter->out_tmp || ofilter->out_tmp->name)
2269 4 continue;
2270
2271
2/4
✓ Branch 0 taken 66 times.
✓ Branch 1 taken 14 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
80 switch (ofilter->type) {
2272 66 case AVMEDIA_TYPE_VIDEO: o->video_disable = 1; break;
2273 14 case AVMEDIA_TYPE_AUDIO: o->audio_disable = 1; break;
2274 case AVMEDIA_TYPE_SUBTITLE: o->subtitle_disable = 1; break;
2275 }
2276 80 init_output_filter(ofilter, o, oc);
2277 }
2278 }
2279
2280
2/2
✓ Branch 0 taken 5943 times.
✓ Branch 1 taken 75 times.
6018 if (!o->nb_stream_maps) {
2281 5943 char *subtitle_codec_name = NULL;
2282 /* pick the "best" stream of each type */
2283
2284 /* video: highest resolution */
2285
4/4
✓ Branch 0 taken 5718 times.
✓ Branch 1 taken 225 times.
✓ Branch 3 taken 5012 times.
✓ Branch 4 taken 706 times.
5943 if (!o->video_disable && av_guess_codec(oc->oformat, NULL, filename, NULL, AVMEDIA_TYPE_VIDEO) != AV_CODEC_ID_NONE) {
2286 5012 int best_score = 0, idx = -1;
2287 5012 int qcr = avformat_query_codec(oc->oformat, oc->oformat->video_codec, 0);
2288
2/2
✓ Branch 0 taken 5049 times.
✓ Branch 1 taken 5012 times.
10061 for (j = 0; j < nb_input_files; j++) {
2289 5049 InputFile *ifile = input_files[j];
2290 5049 int file_best_score = 0, file_best_idx = -1;
2291
2/2
✓ Branch 0 taken 5289 times.
✓ Branch 1 taken 5049 times.
10338 for (i = 0; i < ifile->nb_streams; i++) {
2292 int score;
2293 5289 ist = input_streams[ifile->ist_index + i];
2294 10578 score = ist->st->codecpar->width * ist->st->codecpar->height
2295
2/2
✓ Branch 0 taken 5261 times.
✓ Branch 1 taken 28 times.
5289 + 100000000 * !!(ist->st->event_flags & AVSTREAM_EVENT_FLAG_NEW_PACKETS)
2296
2/2
✓ Branch 0 taken 544 times.
✓ Branch 1 taken 4745 times.
5289 + 5000000*!!(ist->st->disposition & AV_DISPOSITION_DEFAULT);
2297
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 5289 times.
5289 if (ist->user_set_discard == AVDISCARD_ALL)
2298 continue;
2299
4/4
✓ Branch 0 taken 5287 times.
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 8 times.
✓ Branch 3 taken 5279 times.
5289 if((qcr!=MKTAG('A', 'P', 'I', 'C')) && (ist->st->disposition & AV_DISPOSITION_ATTACHED_PIC))
2300 8 score = 1;
2301
4/4
✓ Branch 0 taken 4763 times.
✓ Branch 1 taken 526 times.
✓ Branch 2 taken 4762 times.
✓ Branch 3 taken 1 times.
5289 if (ist->st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO &&
2302 score > file_best_score) {
2303
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 4762 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
4762 if((qcr==MKTAG('A', 'P', 'I', 'C')) && !(ist->st->disposition & AV_DISPOSITION_ATTACHED_PIC))
2304 continue;
2305 4762 file_best_score = score;
2306 4762 file_best_idx = ifile->ist_index + i;
2307 }
2308 }
2309
2/2
✓ Branch 0 taken 4762 times.
✓ Branch 1 taken 287 times.
5049 if (file_best_idx >= 0) {
2310
3/4
✓ Branch 0 taken 4762 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4756 times.
✓ Branch 3 taken 6 times.
4762 if((qcr == MKTAG('A', 'P', 'I', 'C')) || !(ist->st->disposition & AV_DISPOSITION_ATTACHED_PIC))
2311
2/2
✓ Branch 0 taken 472 times.
✓ Branch 1 taken 4284 times.
4756 file_best_score -= 5000000*!!(input_streams[file_best_idx]->st->disposition & AV_DISPOSITION_DEFAULT);
2312
1/2
✓ Branch 0 taken 4762 times.
✗ Branch 1 not taken.
4762 if (file_best_score > best_score) {
2313 4762 best_score = file_best_score;
2314 4762 idx = file_best_idx;
2315 }
2316 }
2317 }
2318
2/2
✓ Branch 0 taken 4762 times.
✓ Branch 1 taken 250 times.
5012 if (idx >= 0)
2319 4762 new_video_stream(o, oc, idx);
2320 }
2321
2322 /* audio: most channels */
2323
4/4
✓ Branch 0 taken 5789 times.
✓ Branch 1 taken 154 times.
✓ Branch 3 taken 5047 times.
✓ Branch 4 taken 742 times.
5943 if (!o->audio_disable && av_guess_codec(oc->oformat, NULL, filename, NULL, AVMEDIA_TYPE_AUDIO) != AV_CODEC_ID_NONE) {
2324 5047 int best_score = 0, idx = -1;
2325
2/2
✓ Branch 0 taken 5050 times.
✓ Branch 1 taken 5047 times.
10097 for (j = 0; j < nb_input_files; j++) {
2326 5050 InputFile *ifile = input_files[j];
2327 5050 int file_best_score = 0, file_best_idx = -1;
2328
2/2
✓ Branch 0 taken 5216 times.
✓ Branch 1 taken 5050 times.
10266 for (i = 0; i < ifile->nb_streams; i++) {
2329 int score;
2330 5216 ist = input_streams[ifile->ist_index + i];
2331 10432 score = ist->st->codecpar->channels
2332
2/2
✓ Branch 0 taken 5192 times.
✓ Branch 1 taken 24 times.
5216 + 100000000 * !!(ist->st->event_flags & AVSTREAM_EVENT_FLAG_NEW_PACKETS)
2333
2/2
✓ Branch 0 taken 503 times.
✓ Branch 1 taken 4713 times.
5216 + 5000000*!!(ist->st->disposition & AV_DISPOSITION_DEFAULT);
2334
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 5216 times.
5216 if (ist->user_set_discard == AVDISCARD_ALL)
2335 continue;
2336
4/4
✓ Branch 0 taken 1185 times.
✓ Branch 1 taken 4031 times.
✓ Branch 2 taken 1176 times.
✓ Branch 3 taken 9 times.
5216 if (ist->st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO &&
2337 score > file_best_score) {
2338 1176 file_best_score = score;
2339 1176 file_best_idx = ifile->ist_index + i;
2340 }
2341 }
2342
2/2
✓ Branch 0 taken 1176 times.
✓ Branch 1 taken 3874 times.
5050 if (file_best_idx >= 0) {
2343
2/2
✓ Branch 0 taken 155 times.
✓ Branch 1 taken 1021 times.
1176 file_best_score -= 5000000*!!(input_streams[file_best_idx]->st->disposition & AV_DISPOSITION_DEFAULT);
2344
1/2
✓ Branch 0 taken 1176 times.
✗ Branch 1 not taken.
1176 if (file_best_score > best_score) {
2345 1176 best_score = file_best_score;
2346 1176 idx = file_best_idx;
2347 }
2348 }
2349 }
2350
2/2
✓ Branch 0 taken 1176 times.
✓ Branch 1 taken 3871 times.
5047 if (idx >= 0)
2351 1176 new_audio_stream(o, oc, idx);
2352 }
2353
2354 /* subtitles: pick first */
2355
4/4
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 3454 times.
✓ Branch 2 taken 3463 times.
✓ Branch 3 taken 5943 times.
9406 MATCH_PER_TYPE_OPT(codec_names, str, subtitle_codec_name, oc, "s");
2356
6/6
✓ Branch 0 taken 5942 times.
✓ Branch 1 taken 1 times.
✓ Branch 3 taken 5897 times.
✓ Branch 4 taken 45 times.
✓ Branch 5 taken 3 times.
✓ Branch 6 taken 5894 times.
5943 if (!o->subtitle_disable && (avcodec_find_encoder(oc->oformat->subtitle_codec) || subtitle_codec_name)) {
2357
2/2
✓ Branch 0 taken 53 times.
✓ Branch 1 taken 10 times.
63 for (i = 0; i < nb_input_streams; i++)
2358
2/2
✓ Branch 0 taken 38 times.
✓ Branch 1 taken 15 times.
53 if (input_streams[i]->st->codecpar->codec_type == AVMEDIA_TYPE_SUBTITLE) {
2359 AVCodecDescriptor const *input_descriptor =
2360 38 avcodec_descriptor_get(input_streams[i]->st->codecpar->codec_id);
2361 38 AVCodecDescriptor const *output_descriptor = NULL;
2362 AVCodec const *output_codec =
2363 38 avcodec_find_encoder(oc->oformat->subtitle_codec);
2364 38 int input_props = 0, output_props = 0;
2365
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 38 times.
38 if (input_streams[i]->user_set_discard == AVDISCARD_ALL)
2366 continue;
2367
2/2
✓ Branch 0 taken 35 times.
✓ Branch 1 taken 3 times.
38 if (output_codec)
2368 35 output_descriptor = avcodec_descriptor_get(output_codec->id);
2369
1/2
✓ Branch 0 taken 38 times.
✗ Branch 1 not taken.
38 if (input_descriptor)
2370 38 input_props = input_descriptor->props & (AV_CODEC_PROP_TEXT_SUB | AV_CODEC_PROP_BITMAP_SUB);
2371
2/2
✓ Branch 0 taken 35 times.
✓ Branch 1 taken 3 times.
38 if (output_descriptor)
2372 35 output_props = output_descriptor->props & (AV_CODEC_PROP_TEXT_SUB | AV_CODEC_PROP_BITMAP_SUB);
2373
2/2
✓ Branch 0 taken 29 times.
✓ Branch 1 taken 9 times.
38 if (subtitle_codec_name ||
2374
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 29 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
29 input_props & output_props ||
2375 // Map dvb teletext which has neither property to any output subtitle encoder
2376 input_descriptor && output_descriptor &&
2377 (!input_descriptor->props ||
2378 !output_descriptor->props)) {
2379 38 new_subtitle_stream(o, oc, i);
2380 38 break;
2381 }
2382 }
2383 }
2384 /* Data only if codec id match */
2385
1/2
✓ Branch 0 taken 5943 times.
✗ Branch 1 not taken.
5943 if (!o->data_disable ) {
2386 5943 enum AVCodecID codec_id = av_guess_codec(oc->oformat, NULL, filename, NULL, AVMEDIA_TYPE_DATA);
2387
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 5943 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
5943 for (i = 0; codec_id != AV_CODEC_ID_NONE && i < nb_input_streams; i++) {
2388 if (input_streams[i]->user_set_discard == AVDISCARD_ALL)
2389 continue;
2390 if (input_streams[i]->st->codecpar->codec_type == AVMEDIA_TYPE_DATA
2391 && input_streams[i]->st->codecpar->codec_id == codec_id )
2392 new_data_stream(o, oc, i);
2393 }
2394 }
2395 } else {
2396
2/2
✓ Branch 0 taken 141 times.
✓ Branch 1 taken 75 times.
216 for (i = 0; i < o->nb_stream_maps; i++) {
2397 141 StreamMap *map = &o->stream_maps[i];
2398
2399
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 141 times.
141 if (map->disabled)
2400 continue;
2401
2402
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 138 times.
141 if (map->linklabel) {
2403 FilterGraph *fg;
2404 3 OutputFilter *ofilter = NULL;
2405 int j, k;
2406
2407
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
3 for (j = 0; j < nb_filtergraphs; j++) {
2408 3 fg = filtergraphs[j];
2409
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
3 for (k = 0; k < fg->nb_outputs; k++) {
2410 3 AVFilterInOut *out = fg->outputs[k]->out_tmp;
2411
2/4
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
3 if (out && !strcmp(out->name, map->linklabel)) {
2412 3 ofilter = fg->outputs[k];
2413 3 goto loop_end;
2414 }
2415 }
2416 }
2417 loop_end:
2418
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
3 if (!ofilter) {
2419 av_log(NULL, AV_LOG_FATAL, "Output with label '%s' does not exist "
2420 "in any defined filter graph, or was already used elsewhere.\n", map->linklabel);
2421 exit_program(1);
2422 }
2423 3 init_output_filter(ofilter, o, oc);
2424 } else {
2425 138 int src_idx = input_files[map->file_index]->ist_index + map->stream_index;
2426
2427 138 ist = input_streams[input_files[map->file_index]->ist_index + map->stream_index];
2428
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 138 times.
138 if (ist->user_set_discard == AVDISCARD_ALL) {
2429 av_log(NULL, AV_LOG_FATAL, "Stream #%d:%d is disabled and cannot be mapped.\n",
2430 map->file_index, map->stream_index);
2431 exit_program(1);
2432 }
2433
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 138 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
138 if(o->subtitle_disable && ist->st->codecpar->codec_type == AVMEDIA_TYPE_SUBTITLE)
2434 continue;
2435
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 138 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
138 if(o-> audio_disable && ist->st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO)
2436 continue;
2437
3/4
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 137 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
138 if(o-> video_disable && ist->st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO)
2438 continue;
2439
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 138 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
138 if(o-> data_disable && ist->st->codecpar->codec_type == AVMEDIA_TYPE_DATA)
2440 continue;
2441
2442 138 ost = NULL;
2443
4/7
✓ Branch 0 taken 53 times.
✓ Branch 1 taken 62 times.
✓ Branch 2 taken 11 times.
✓ Branch 3 taken 12 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
138 switch (ist->st->codecpar->codec_type) {
2444 53 case AVMEDIA_TYPE_VIDEO: ost = new_video_stream (o, oc, src_idx); break;
2445 62 case AVMEDIA_TYPE_AUDIO: ost = new_audio_stream (o, oc, src_idx); break;
2446 11 case AVMEDIA_TYPE_SUBTITLE: ost = new_subtitle_stream (o, oc, src_idx); break;
2447 12 case AVMEDIA_TYPE_DATA: ost = new_data_stream (o, oc, src_idx); break;
2448 case AVMEDIA_TYPE_ATTACHMENT: ost = new_attachment_stream(o, oc, src_idx); break;
2449 case AVMEDIA_TYPE_UNKNOWN:
2450 if (copy_unknown_streams) {
2451 ost = new_unknown_stream (o, oc, src_idx);
2452 break;
2453 }
2454 default:
2455 av_log(NULL, ignore_unknown_streams ? AV_LOG_WARNING : AV_LOG_FATAL,
2456 "Cannot map stream #%d:%d - unsupported type.\n",
2457 map->file_index, map->stream_index);
2458 if (!ignore_unknown_streams) {
2459 av_log(NULL, AV_LOG_FATAL,
2460 "If you want unsupported types ignored instead "
2461 "of failing, please use the -ignore_unknown option\n"
2462 "If you want them copied, please use -copy_unknown\n");
2463 exit_program(1);
2464 }
2465 }
2466
1/2
✓ Branch 0 taken 138 times.
✗ Branch 1 not taken.
138 if (ost)
2467 138 ost->sync_ist = input_streams[ input_files[map->sync_file_index]->ist_index
2468 138 + map->sync_stream_index];
2469 }
2470 }
2471 }
2472
2473 /* handle attached files */
2474
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 6018 times.
6019 for (i = 0; i < o->nb_attachments; i++) {
2475 AVIOContext *pb;
2476 uint8_t *attachment;
2477 const char *p;
2478 int64_t len;
2479
2480
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 if ((err = avio_open2(&pb, o->attachments[i], AVIO_FLAG_READ, &int_cb, NULL)) < 0) {
2481 av_log(NULL, AV_LOG_FATAL, "Could not open attachment file %s.\n",
2482 o->attachments[i]);
2483 exit_program(1);
2484 }
2485
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 if ((len = avio_size(pb)) <= 0) {
2486 av_log(NULL, AV_LOG_FATAL, "Could not get size of the attachment %s.\n",
2487 o->attachments[i]);
2488 exit_program(1);
2489 }
2490
2/4
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
2 if (len > INT_MAX - AV_INPUT_BUFFER_PADDING_SIZE ||
2491 1 !(attachment = av_malloc(len + AV_INPUT_BUFFER_PADDING_SIZE))) {
2492 av_log(NULL, AV_LOG_FATAL, "Attachment %s too large.\n",
2493 o->attachments[i]);
2494 exit_program(1);
2495 }
2496 1 avio_read(pb, attachment, len);
2497 1 memset(attachment + len, 0, AV_INPUT_BUFFER_PADDING_SIZE);
2498
2499 1 ost = new_attachment_stream(o, oc, -1);
2500 1 ost->stream_copy = 0;
2501 1 ost->attachment_filename = o->attachments[i];
2502 1 ost->st->codecpar->extradata = attachment;
2503 1 ost->st->codecpar->extradata_size = len;
2504
2505 1 p = strrchr(o->attachments[i], '/');
2506
2/4
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 av_dict_set(&ost->st->metadata, "filename", (p && *p) ? p + 1 : o->attachments[i], AV_DICT_DONT_OVERWRITE);
2507 1 avio_closep(&pb);
2508 }
2509
2510
3/4
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 6017 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
6018 if (!oc->nb_streams && !(oc->oformat->flags & AVFMT_NOSTREAMS)) {
2511 av_dump_format(oc, nb_output_files - 1, oc->url, 1);
2512 av_log(NULL, AV_LOG_ERROR, "Output file #%d does not contain any stream\n", nb_output_files - 1);
2513 exit_program(1);
2514 }
2515
2516 /* check if all codec options have been used */
2517 6018 unused_opts = strip_specifiers(o->g->codec_opts);
2518
2/2
✓ Branch 0 taken 6198 times.
✓ Branch 1 taken 6018 times.
12216 for (i = of->ost_index; i < nb_output_streams; i++) {
2519 6198 e = NULL;
2520
2/2
✓ Branch 1 taken 14294 times.
✓ Branch 2 taken 6198 times.
20492 while ((e = av_dict_get(output_streams[i]->encoder_opts, "", e,
2521 AV_DICT_IGNORE_SUFFIX)))
2522 14294 av_dict_set(&unused_opts, e->key, NULL, 0);
2523 }
2524
2525 6018 e = NULL;
2526
2/2
✓ Branch 1 taken 281 times.
✓ Branch 2 taken 6018 times.
6299 while ((e = av_dict_get(unused_opts, "", e, AV_DICT_IGNORE_SUFFIX))) {
2527 281 const AVClass *class = avcodec_get_class();
2528 281 const AVOption *option = av_opt_find(&class, e->key, NULL, 0,
2529 AV_OPT_SEARCH_CHILDREN | AV_OPT_SEARCH_FAKE_OBJ);
2530 281 const AVClass *fclass = avformat_get_class();
2531 281 const AVOption *foption = av_opt_find(&fclass, e->key, NULL, 0,
2532 AV_OPT_SEARCH_CHILDREN | AV_OPT_SEARCH_FAKE_OBJ);
2533
4/4
✓ Branch 0 taken 280 times.
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 279 times.
281 if (!option || foption)
2534 10 continue;
2535
2536
2537
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 279 times.
279 if (!(option->flags & AV_OPT_FLAG_ENCODING_PARAM)) {
2538 av_log(NULL, AV_LOG_ERROR, "Codec AVOption %s (%s) specified for "
2539 "output file #%d (%s) is not an encoding option.\n", e->key,
2540 option->help ? option->help : "", nb_output_files - 1,
2541 filename);
2542 exit_program(1);
2543 }
2544
2545 // gop_timecode is injected by generic code but not always used
2546
2/2
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 271 times.
279 if (!strcmp(e->key, "gop_timecode"))
2547 8 continue;
2548
2549 271 av_log(NULL, AV_LOG_WARNING, "Codec AVOption %s (%s) specified for "
2550 "output file #%d (%s) has not been used for any stream. The most "
2551 "likely reason is either wrong type (e.g. a video option with "
2552 "no video streams) or that it is a private option of some encoder "
2553 "which was not actually used for any stream.\n", e->key,
2554
1/2
✓ Branch 0 taken 271 times.
✗ Branch 1 not taken.
271 option->help ? option->help : "", nb_output_files - 1, filename);
2555 }
2556 6018 av_dict_free(&unused_opts);
2557
2558 /* set the decoding_needed flags and create simple filtergraphs */
2559
2/2
✓ Branch 0 taken 6198 times.
✓ Branch 1 taken 6018 times.
12216 for (i = of->ost_index; i < nb_output_streams; i++) {
2560 6198 OutputStream *ost = output_streams[i];
2561
2562
4/4
✓ Branch 0 taken 5857 times.
✓ Branch 1 taken 341 times.
✓ Branch 2 taken 5774 times.
✓ Branch 3 taken 83 times.
6198 if (ost->encoding_needed && ost->source_index >= 0) {
2563 5774 InputStream *ist = input_streams[ost->source_index];
2564 5774 ist->decoding_needed |= DECODING_FOR_OST;
2565
2566
2/2
✓ Branch 0 taken 1150 times.
✓ Branch 1 taken 4624 times.
5774 if (ost->st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO ||
2567
2/2
✓ Branch 0 taken 1116 times.
✓ Branch 1 taken 34 times.
1150 ost->st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) {
2568 5740 err = init_simple_filtergraph(ist, ost);
2569
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 5740 times.
5740 if (err < 0) {
2570 av_log(NULL, AV_LOG_ERROR,
2571 "Error initializing a simple filtergraph between streams "
2572 "%d:%d->%d:%d\n", ist->file_index, ost->source_index,
2573 nb_output_files - 1, ost->st->index);
2574 exit_program(1);
2575 }
2576 }
2577 }
2578
2579 /* set the filter output constraints */
2580
2/2
✓ Branch 0 taken 5823 times.
✓ Branch 1 taken 375 times.
6198 if (ost->filter) {
2581 5823 OutputFilter *f = ost->filter;
2582 int count;
2583
2/3
✓ Branch 0 taken 4692 times.
✓ Branch 1 taken 1131 times.
✗ Branch 2 not taken.
5823 switch (ost->enc_ctx->codec_type) {
2584 4692 case AVMEDIA_TYPE_VIDEO:
2585 4692 f->frame_rate = ost->frame_rate;
2586 4692 f->width = ost->enc_ctx->width;
2587 4692 f->height = ost->enc_ctx->height;
2588
2/2
✓ Branch 0 taken 3367 times.
✓ Branch 1 taken 1325 times.
4692 if (ost->enc_ctx->pix_fmt != AV_PIX_FMT_NONE) {
2589 3367 f->format = ost->enc_ctx->pix_fmt;
2590
2/2
✓ Branch 0 taken 297 times.
✓ Branch 1 taken 1028 times.
1325 } else if (ost->enc->pix_fmts) {
2591 297 count = 0;
2592
2/2
✓ Branch 0 taken 1296 times.
✓ Branch 1 taken 297 times.
1593 while (ost->enc->pix_fmts[count] != AV_PIX_FMT_NONE)
2593 1296 count++;
2594 297 f->formats = av_mallocz_array(count + 1, sizeof(*f->formats));
2595
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 297 times.
297 if (!f->formats)
2596 exit_program(1);
2597 297 memcpy(f->formats, ost->enc->pix_fmts, (count + 1) * sizeof(*f->formats));
2598 }
2599 4692 break;
2600 1131 case AVMEDIA_TYPE_AUDIO:
2601
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1131 times.
1131 if (ost->enc_ctx->sample_fmt != AV_SAMPLE_FMT_NONE) {
2602 f->format = ost->enc_ctx->sample_fmt;
2603
1/2
✓ Branch 0 taken 1131 times.
✗ Branch 1 not taken.
1131 } else if (ost->enc->sample_fmts) {
2604 1131 count = 0;
2605
2/2
✓ Branch 0 taken 1168 times.
✓ Branch 1 taken 1131 times.
2299 while (ost->enc->sample_fmts[count] != AV_SAMPLE_FMT_NONE)
2606 1168 count++;
2607 1131 f->formats = av_mallocz_array(count + 1, sizeof(*f->formats));
2608
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1131 times.
1131 if (!f->formats)
2609 exit_program(1);
2610 1131 memcpy(f->formats, ost->enc->sample_fmts, (count + 1) * sizeof(*f->formats));
2611 }
2612
2/2
✓ Branch 0 taken 25 times.
✓ Branch 1 taken 1106 times.
1131 if (ost->enc_ctx->sample_rate) {
2613 25 f->sample_rate = ost->enc_ctx->sample_rate;
2614
2/2
✓ Branch 0 taken 35 times.
✓ Branch 1 taken 1071 times.
1106 } else if (ost->enc->supported_samplerates) {
2615 35 count = 0;
2616
2/2
✓ Branch 0 taken 270 times.
✓ Branch 1 taken 35 times.
305 while (ost->enc->supported_samplerates[count])
2617 270 count++;
2618 35 f->sample_rates = av_mallocz_array(count + 1, sizeof(*f->sample_rates));
2619
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 35 times.
35 if (!f->sample_rates)
2620 exit_program(1);
2621 35 memcpy(f->sample_rates, ost->enc->supported_samplerates,
2622 35 (count + 1) * sizeof(*f->sample_rates));
2623 }
2624
2/2
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 1119 times.
1131 if (ost->enc_ctx->channels) {
2625 12 f->channel_layout = av_get_default_channel_layout(ost->enc_ctx->channels);
2626
2/2
✓ Branch 0 taken 42 times.
✓ Branch 1 taken 1077 times.
1119 } else if (ost->enc->channel_layouts) {
2627 42 count = 0;
2628
2/2
✓ Branch 0 taken 238 times.
✓ Branch 1 taken 42 times.
280 while (ost->enc->channel_layouts[count])
2629 238 count++;
2630 42 f->channel_layouts = av_mallocz_array(count + 1, sizeof(*f->channel_layouts));
2631
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 42 times.
42 if (!f->channel_layouts)
2632 exit_program(1);
2633 42 memcpy(f->channel_layouts, ost->enc->channel_layouts,
2634 42 (count + 1) * sizeof(*f->channel_layouts));
2635 }
2636 1131 break;
2637 }
2638 }
2639 }
2640
2641 /* check filename in case of an image number is expected */
2642
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6018 times.
6018 if (oc->oformat->flags & AVFMT_NEEDNUMBER) {
2643 if (!av_filename_number_test(oc->url)) {
2644 print_error(oc->url, AVERROR(EINVAL));
2645 exit_program(1);
2646 }
2647 }
2648
2649
3/4
✓ Branch 0 taken 6015 times.
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 6015 times.
6018 if (!(oc->oformat->flags & AVFMT_NOSTREAMS) && !input_stream_potentially_available) {
2650 av_log(NULL, AV_LOG_ERROR,
2651 "No input streams but output needs an input stream\n");
2652 exit_program(1);
2653 }
2654
2655
2/2
✓ Branch 0 taken 5964 times.
✓ Branch 1 taken 54 times.
6018 if (!(oc->oformat->flags & AVFMT_NOFILE)) {
2656 /* test if it already exists to avoid losing precious files */
2657 5964 assert_file_overwrite(filename);
2658
2659 /* open the file */
2660
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 5964 times.
5964 if ((err = avio_open2(&oc->pb, filename, AVIO_FLAG_WRITE,
2661 5964 &oc->interrupt_callback,
2662 &of->opts)) < 0) {
2663 print_error(filename, err);
2664 exit_program(1);
2665 }
2666
3/4
✓ Branch 0 taken 33 times.
✓ Branch 1 taken 21 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 33 times.
54 } else if (strcmp(oc->oformat->name, "image2")==0 && !av_filename_number_test(filename))
2667 assert_file_overwrite(filename);
2668
2669
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6018 times.
6018 if (o->mux_preload) {
2670 av_dict_set_int(&of->opts, "preload", o->mux_preload*AV_TIME_BASE, 0);
2671 }
2672 6018 oc->max_delay = (int)(o->mux_max_delay * AV_TIME_BASE);
2673
2674 /* copy metadata */
2675
2/2
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 6018 times.
6023 for (i = 0; i < o->nb_metadata_map; i++) {
2676 char *p;
2677 5 int in_file_index = strtol(o->metadata_map[i].u.str, &p, 0);
2678
2679
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 5 times.
5 if (in_file_index >= nb_input_files) {
2680 av_log(NULL, AV_LOG_FATAL, "Invalid input file index %d while processing metadata maps\n", in_file_index);
2681 exit_program(1);
2682 }
2683
4/4
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 2 times.
✓ Branch 3 taken 3 times.
8 copy_metadata(o->metadata_map[i].specifier, *p ? p + 1 : p, oc,
2684 in_file_index >= 0 ?
2685 3 input_files[in_file_index]->ctx : NULL, o);
2686 }
2687
2688 /* copy chapters */
2689
1/2
✓ Branch 0 taken 6018 times.
✗ Branch 1 not taken.
6018 if (o->chapters_input_file >= nb_input_files) {
2690
1/2
✓ Branch 0 taken 6018 times.
✗ Branch 1 not taken.
6018 if (o->chapters_input_file == INT_MAX) {
2691 /* copy chapters from the first input file that has them*/
2692 6018 o->chapters_input_file = -1;
2693
2/2
✓ Branch 0 taken 6046 times.
✓ Branch 1 taken 6003 times.
12049 for (i = 0; i < nb_input_files; i++)
2694
2/2
✓ Branch 0 taken 15 times.
✓ Branch 1 taken 6031 times.
6046 if (input_files[i]->ctx->nb_chapters) {
2695 15 o->chapters_input_file = i;
2696 15 break;
2697 }
2698 } else {
2699 av_log(NULL, AV_LOG_FATAL, "Invalid input file index %d in chapter mapping.\n",
2700 o->chapters_input_file);
2701 exit_program(1);
2702 }
2703 }
2704
2/2
✓ Branch 0 taken 15 times.
✓ Branch 1 taken 6003 times.
6018 if (o->chapters_input_file >= 0)
2705 15 copy_chapters(input_files[o->chapters_input_file], of,
2706 15 !o->metadata_chapters_manual);
2707
2708 /* copy global metadata by default */
2709
4/4
✓ Branch 0 taken 6015 times.
✓ Branch 1 taken 3 times.
✓ Branch 2 taken 5974 times.
✓ Branch 3 taken 41 times.
6018 if (!o->metadata_global_manual && nb_input_files){
2710 5974 av_dict_copy(&oc->metadata, input_files[0]->ctx->metadata,
2711 AV_DICT_DONT_OVERWRITE);
2712
2/2
✓ Branch 0 taken 132 times.
✓ Branch 1 taken 5842 times.
5974 if(o->recording_time != INT64_MAX)
2713 132 av_dict_set(&oc->metadata, "duration", NULL, 0);
2714 5974 av_dict_set(&oc->metadata, "creation_time", NULL, 0);
2715 5974 av_dict_set(&oc->metadata, "company_name", NULL, 0);
2716 5974 av_dict_set(&oc->metadata, "product_name", NULL, 0);
2717 5974 av_dict_set(&oc->metadata, "product_version", NULL, 0);
2718 }
2719
2/2
✓ Branch 0 taken 6017 times.
✓ Branch 1 taken 1 times.
6018 if (!o->metadata_streams_manual)
2720
2/2
✓ Branch 0 taken 6195 times.
✓ Branch 1 taken 6017 times.
12212 for (i = of->ost_index; i < nb_output_streams; i++) {
2721 InputStream *ist;
2722
2/2
✓ Branch 0 taken 84 times.
✓ Branch 1 taken 6111 times.
6195 if (output_streams[i]->source_index < 0) /* this is true e.g. for attached files */
2723 84 continue;
2724 6111 ist = input_streams[output_streams[i]->source_index];
2725 6111 av_dict_copy(&output_streams[i]->st->metadata, ist->st->metadata, AV_DICT_DONT_OVERWRITE);
2726
2/2
✓ Branch 0 taken 5771 times.
✓ Branch 1 taken 340 times.
6111 if (!output_streams[i]->stream_copy) {
2727 5771 av_dict_set(&output_streams[i]->st->metadata, "encoder", NULL, 0);
2728 }
2729 }
2730
2731 /* process manually set programs */
2732
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6018 times.
6018 for (i = 0; i < o->nb_program; i++) {
2733 const char *p = o->program[i].u.str;
2734 int progid = i+1;
2735 AVProgram *program;
2736
2737 while(*p) {
2738 const char *p2 = av_get_token(&p, ":");
2739 const char *to_dealloc = p2;
2740 char *key;
2741 if (!p2)
2742 break;
2743
2744 if(*p) p++;
2745
2746 key = av_get_token(&p2, "=");
2747 if (!key || !*p2) {
2748 av_freep(&to_dealloc);
2749 av_freep(&key);
2750 break;
2751 }
2752 p2++;
2753
2754 if (!strcmp(key, "program_num"))
2755 progid = strtol(p2, NULL, 0);
2756 av_freep(&to_dealloc);
2757 av_freep(&key);
2758 }
2759
2760 program = av_new_program(oc, progid);
2761
2762 p = o->program[i].u.str;
2763 while(*p) {
2764 const char *p2 = av_get_token(&p, ":");
2765 const char *to_dealloc = p2;
2766 char *key;
2767 if (!p2)
2768 break;
2769 if(*p) p++;
2770
2771 key = av_get_token(&p2, "=");
2772 if (!key) {
2773 av_log(NULL, AV_LOG_FATAL,
2774 "No '=' character in program string %s.\n",
2775 p2);
2776 exit_program(1);
2777 }
2778 if (!*p2)
2779 exit_program(1);
2780 p2++;
2781
2782 if (!strcmp(key, "title")) {
2783 av_dict_set(&program->metadata, "title", p2, 0);
2784 } else if (!strcmp(key, "program_num")) {
2785 } else if (!strcmp(key, "st")) {
2786 int st_num = strtol(p2, NULL, 0);
2787 av_program_add_stream_index(oc, progid, st_num);
2788 } else {
2789 av_log(NULL, AV_LOG_FATAL, "Unknown program key %s.\n", key);
2790 exit_program(1);
2791 }
2792 av_freep(&to_dealloc);
2793 av_freep(&key);
2794 }
2795 }
2796
2797 /* process manually set metadata */
2798
2/2
✓ Branch 0 taken 161 times.
✓ Branch 1 taken 6018 times.
6179 for (i = 0; i < o->nb_metadata; i++) {
2799 AVDictionary **m;
2800 char type, *val;
2801 const char *stream_spec;
2802 161 int index = 0, j, ret = 0;
2803
2804 161 val = strchr(o->metadata[i].u.str, '=');
2805
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 161 times.
161 if (!val) {
2806 av_log(NULL, AV_LOG_FATAL, "No '=' character in metadata string %s.\n",
2807 o->metadata[i].u.str);
2808 exit_program(1);
2809 }
2810 161 *val++ = 0;
2811
2812 161 parse_meta_type(o->metadata[i].specifier, &type, &index, &stream_spec);
2813
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 143 times.
161 if (type == 's') {
2814
2/2
✓ Branch 0 taken 58 times.
✓ Branch 1 taken 18 times.
76 for (j = 0; j < oc->nb_streams; j++) {
2815 58 ost = output_streams[nb_output_streams - oc->nb_streams + j];
2816
2/2
✓ Branch 1 taken 18 times.
✓ Branch 2 taken 40 times.
58 if ((ret = check_stream_specifier(oc, oc->streams[j], stream_spec)) > 0) {
2817
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 17 times.
18 if (!strcmp(o->metadata[i].u.str, "rotate")) {
2818 char *tail;
2819 1 double theta = av_strtod(val, &tail);
2820
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if (!*tail) {
2821 1 ost->rotate_overridden = 1;
2822 1 ost->rotate_override_value = theta;
2823 }
2824 } else {
2825
1/2
✓ Branch 0 taken 17 times.
✗ Branch 1 not taken.
17 av_dict_set(&oc->streams[j]->metadata, o->metadata[i].u.str, *val ? val : NULL, 0);
2826 }
2827
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 40 times.
40 } else if (ret < 0)
2828 exit_program(1);
2829 }
2830 }
2831 else {
2832
2/4
✓ Branch 0 taken 139 times.
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
143 switch (type) {
2833 139 case 'g':
2834 139 m = &oc->metadata;
2835 139 break;
2836 4 case 'c':
2837
2/4
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 4 times.
4 if (index < 0 || index >= oc->nb_chapters) {
2838 av_log(NULL, AV_LOG_FATAL, "Invalid chapter index %d in metadata specifier.\n", index);
2839 exit_program(1);
2840 }
2841 4 m = &oc->chapters[index]->metadata;
2842 4 break;
2843 case 'p':
2844 if (index < 0 || index >= oc->nb_programs) {
2845 av_log(NULL, AV_LOG_FATAL, "Invalid program index %d in metadata specifier.\n", index);
2846 exit_program(1);
2847 }
2848 m = &oc->programs[index]->metadata;
2849 break;
2850 default:
2851 av_log(NULL, AV_LOG_FATAL, "Invalid metadata specifier %s.\n", o->metadata[i].specifier);
2852 exit_program(1);
2853 }
2854
1/2
✓ Branch 0 taken 143 times.
✗ Branch 1 not taken.
143 av_dict_set(m, o->metadata[i].u.str, *val ? val : NULL, 0);
2855 }
2856 }
2857
2858 6018 return 0;
2859 }
2860
2861 static int opt_target(void *optctx, const char *opt, const char *arg)
2862 {
2863 OptionsContext *o = optctx;
2864 enum { PAL, NTSC, FILM, UNKNOWN } norm = UNKNOWN;
2865 static const char *const frame_rates[] = { "25", "30000/1001", "24000/1001" };
2866
2867 if (!strncmp(arg, "pal-", 4)) {
2868 norm = PAL;
2869 arg += 4;
2870 } else if (!strncmp(arg, "ntsc-", 5)) {
2871 norm = NTSC;
2872 arg += 5;
2873 } else if (!strncmp(arg, "film-", 5)) {
2874 norm = FILM;
2875 arg += 5;
2876 } else {
2877 /* Try to determine PAL/NTSC by peeking in the input files */
2878 if (nb_input_files) {
2879 int i, j;
2880 for (j = 0; j < nb_input_files; j++) {
2881 for (i = 0; i < input_files[j]->nb_streams; i++) {
2882 AVStream *st = input_files[j]->ctx->streams[i];
2883 int64_t fr;
2884 if (st->codecpar->codec_type != AVMEDIA_TYPE_VIDEO)
2885 continue;
2886 fr = st->time_base.den * 1000LL / st->time_base.num;
2887 if (fr == 25000) {
2888 norm = PAL;
2889 break;
2890 } else if ((fr == 29970) || (fr == 23976)) {
2891 norm = NTSC;
2892 break;
2893 }
2894 }
2895 if (norm != UNKNOWN)
2896 break;
2897 }
2898 }
2899 if (norm != UNKNOWN)
2900 av_log(NULL, AV_LOG_INFO, "Assuming %s for target.\n", norm == PAL ? "PAL" : "NTSC");
2901 }
2902
2903 if (norm == UNKNOWN) {
2904 av_log(NULL, AV_LOG_FATAL, "Could not determine norm (PAL/NTSC/NTSC-Film) for target.\n");
2905 av_log(NULL, AV_LOG_FATAL, "Please prefix target with \"pal-\", \"ntsc-\" or \"film-\",\n");
2906 av_log(NULL, AV_LOG_FATAL, "or set a framerate with \"-r xxx\".\n");
2907 exit_program(1);
2908 }
2909
2910 if (!strcmp(arg, "vcd")) {
2911 opt_video_codec(o, "c:v", "mpeg1video");
2912 opt_audio_codec(o, "c:a", "mp2");
2913 parse_option(o, "f", "vcd", options);
2914
2915 parse_option(o, "s", norm == PAL ? "352x288" : "352x240", options);
2916 parse_option(o, "r", frame_rates[norm], options);
2917 opt_default(NULL, "g", norm == PAL ? "15" : "18");
2918
2919 opt_default(NULL, "b:v", "1150000");
2920 opt_default(NULL, "maxrate:v", "1150000");
2921 opt_default(NULL, "minrate:v", "1150000");
2922 opt_default(NULL, "bufsize:v", "327680"); // 40*1024*8;
2923
2924 opt_default(NULL, "b:a", "224000");
2925 parse_option(o, "ar", "44100", options);
2926 parse_option(o, "ac", "2", options);
2927
2928 opt_default(NULL, "packetsize", "2324");
2929 opt_default(NULL, "muxrate", "1411200"); // 2352 * 75 * 8;
2930
2931 /* We have to offset the PTS, so that it is consistent with the SCR.
2932 SCR starts at 36000, but the first two packs contain only padding
2933 and the first pack from the other stream, respectively, may also have
2934 been written before.
2935 So the real data starts at SCR 36000+3*1200. */
2936 o->mux_preload = (36000 + 3 * 1200) / 90000.0; // 0.44
2937 } else if (!strcmp(arg, "svcd")) {
2938
2939 opt_video_codec(o, "c:v", "mpeg2video");
2940 opt_audio_codec(o, "c:a", "mp2");
2941 parse_option(o, "f", "svcd", options);
2942
2943 parse_option(o, "s", norm == PAL ? "480x576" : "480x480", options);
2944 parse_option(o, "r", frame_rates[norm], options);
2945 parse_option(o, "pix_fmt", "yuv420p", options);
2946 opt_default(NULL, "g", norm == PAL ? "15" : "18");
2947
2948 opt_default(NULL, "b:v", "2040000");
2949 opt_default(NULL, "maxrate:v", "2516000");
2950 opt_default(NULL, "minrate:v", "0"); // 1145000;
2951 opt_default(NULL, "bufsize:v", "1835008"); // 224*1024*8;
2952 opt_default(NULL, "scan_offset", "1");
2953
2954 opt_default(NULL, "b:a", "224000");
2955 parse_option(o, "ar", "44100", options);
2956
2957 opt_default(NULL, "packetsize", "2324");
2958
2959 } else if (!strcmp(arg, "dvd")) {
2960
2961 opt_video_codec(o, "c:v", "mpeg2video");
2962 opt_audio_codec(o, "c:a", "ac3");
2963 parse_option(o, "f", "dvd", options);
2964
2965 parse_option(o, "s", norm == PAL ? "720x576" : "720x480", options);
2966 parse_option(o, "r", frame_rates[norm], options);
2967 parse_option(o, "pix_fmt", "yuv420p", options);
2968 opt_default(NULL, "g", norm == PAL ? "15" : "18");
2969
2970 opt_default(NULL, "b:v", "6000000");
2971 opt_default(NULL, "maxrate:v", "9000000");
2972 opt_default(NULL, "minrate:v", "0"); // 1500000;
2973 opt_default(NULL, "bufsize:v", "1835008"); // 224*1024*8;
2974
2975 opt_default(NULL, "packetsize", "2048"); // from www.mpucoder.com: DVD sectors contain 2048 bytes of data, this is also the size of one pack.
2976 opt_default(NULL, "muxrate", "10080000"); // from mplex project: data_rate = 1260000. mux_rate = data_rate * 8
2977
2978 opt_default(NULL, "b:a", "448000");
2979 parse_option(o, "ar", "48000", options);
2980
2981 } else if (!strncmp(arg, "dv", 2)) {
2982
2983 parse_option(o, "f", "dv", options);
2984
2985 parse_option(o, "s", norm == PAL ? "720x576" : "720x480", options);
2986 parse_option(o, "pix_fmt", !strncmp(arg, "dv50", 4) ? "yuv422p" :
2987 norm == PAL ? "yuv420p" : "yuv411p", options);
2988 parse_option(o, "r", frame_rates[norm], options);
2989
2990 parse_option(o, "ar", "48000", options);
2991 parse_option(o, "ac", "2", options);
2992
2993 } else {
2994 av_log(NULL, AV_LOG_ERROR, "Unknown target: %s\n", arg);
2995 return AVERROR(EINVAL);
2996 }
2997
2998 av_dict_copy(&o->g->codec_opts, codec_opts, AV_DICT_DONT_OVERWRITE);
2999 av_dict_copy(&o->g->format_opts, format_opts, AV_DICT_DONT_OVERWRITE);
3000
3001 return 0;
3002 }
3003
3004 static int opt_vstats_file(void *optctx, const char *opt, const char *arg)
3005 {
3006 av_free (vstats_filename);
3007 vstats_filename = av_strdup (arg);
3008 return 0;
3009 }
3010
3011 static int opt_vstats(void *optctx, const char *opt, const char *arg)
3012 {
3013 char filename[40];
3014 time_t today2 = time(NULL);
3015 struct tm *today = localtime(&today2);
3016
3017 if (!today) { // maybe tomorrow
3018 av_log(NULL, AV_LOG_FATAL, "Unable to get current time: %s\n", strerror(errno));
3019 exit_program(1);
3020 }
3021
3022 snprintf(filename, sizeof(filename), "vstats_%02d%02d%02d.log", today->tm_hour, today->tm_min,
3023 today->tm_sec);
3024 return opt_vstats_file(NULL, opt, filename);
3025 }
3026
3027 static int opt_video_frames(void *optctx, const char *opt, const char *arg)
3028 {
3029 OptionsContext *o = optctx;
3030 return parse_option(o, "frames:v", arg, options);
3031 }
3032
3033 static int opt_audio_frames(void *optctx, const char *opt, const char *arg)
3034 {
3035 OptionsContext *o = optctx;
3036 return parse_option(o, "frames:a", arg, options);
3037 }
3038
3039 static int opt_data_frames(void *optctx, const char *opt, const char *arg)
3040 {
3041 OptionsContext *o = optctx;
3042 return parse_option(o, "frames:d", arg, options);
3043 }
3044
3045 2 static int opt_default_new(OptionsContext *o, const char *opt, const char *arg)
3046 {
3047 int ret;
3048 2 AVDictionary *cbak = codec_opts;
3049 2 AVDictionary *fbak = format_opts;
3050 2 codec_opts = NULL;