FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/fftools/ffmpeg_opt.c
Date: 2022-07-07 01:21:54
Exec Total Coverage
Lines: 1183 2024 58.4%
Branches: 975 2528 38.6%

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