FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/fftools/ffmpeg_opt.c
Date: 2022-01-18 10:05:52
Exec Total Coverage
Lines: 1183 2013 58.8%
Branches: 959 2488 38.5%

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