FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/fftools/ffmpeg_mux_init.c
Date: 2024-07-14 13:34:57
Exec Total Coverage
Lines: 1273 1940 65.6%
Functions: 41 48 85.4%
Branches: 1034 2397 43.1%

Line Branch Exec Source
1 /*
2 * Muxer/output file setup.
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 <string.h>
22
23 #include "cmdutils.h"
24 #include "ffmpeg.h"
25 #include "ffmpeg_mux.h"
26 #include "ffmpeg_sched.h"
27 #include "fopen_utf8.h"
28
29 #include "libavformat/avformat.h"
30 #include "libavformat/avio.h"
31
32 #include "libavcodec/avcodec.h"
33
34 #include "libavfilter/avfilter.h"
35
36 #include "libavutil/avassert.h"
37 #include "libavutil/avstring.h"
38 #include "libavutil/avutil.h"
39 #include "libavutil/bprint.h"
40 #include "libavutil/dict.h"
41 #include "libavutil/display.h"
42 #include "libavutil/getenv_utf8.h"
43 #include "libavutil/iamf.h"
44 #include "libavutil/intreadwrite.h"
45 #include "libavutil/log.h"
46 #include "libavutil/mem.h"
47 #include "libavutil/opt.h"
48 #include "libavutil/parseutils.h"
49 #include "libavutil/pixdesc.h"
50
51 #define DEFAULT_PASS_LOGFILENAME_PREFIX "ffmpeg2pass"
52
53 4978 static int check_opt_bitexact(void *ctx, const AVDictionary *opts,
54 const char *opt_name, int flag)
55 {
56 4978 const AVDictionaryEntry *e = av_dict_get(opts, opt_name, NULL, 0);
57
58
2/2
✓ Branch 0 taken 4006 times.
✓ Branch 1 taken 972 times.
4978 if (e) {
59 4006 const AVOption *o = av_opt_find(ctx, opt_name, NULL, 0, 0);
60 4006 int val = 0;
61
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4006 times.
4006 if (!o)
62 return 0;
63 4006 av_opt_eval_flags(ctx, o, e->value, &val);
64 4006 return !!(val & flag);
65 }
66 972 return 0;
67 }
68
69 7129 static int choose_encoder(const OptionsContext *o, AVFormatContext *s,
70 OutputStream *ost, const AVCodec **enc)
71 {
72 7129 enum AVMediaType type = ost->type;
73 7129 char *codec_name = NULL;
74
75 7129 *enc = NULL;
76
77
16/20
✓ Branch 1 taken 4302 times.
✓ Branch 2 taken 198 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 198 times.
✓ Branch 5 taken 4500 times.
✓ Branch 6 taken 7129 times.
✓ Branch 7 taken 62 times.
✓ Branch 8 taken 7067 times.
✓ Branch 9 taken 62 times.
✗ Branch 10 not taken.
✓ Branch 11 taken 62 times.
✗ Branch 12 not taken.
✓ Branch 13 taken 61 times.
✓ Branch 14 taken 1 times.
✓ Branch 15 taken 62 times.
✗ Branch 16 not taken.
✓ Branch 18 taken 310 times.
✓ Branch 19 taken 62 times.
✓ Branch 20 taken 61 times.
✓ Branch 21 taken 1 times.
11939 MATCH_PER_STREAM_OPT(codec_names, str, codec_name, s, ost->st);
78
79
4/4
✓ Branch 0 taken 1594 times.
✓ Branch 1 taken 5535 times.
✓ Branch 2 taken 82 times.
✓ Branch 3 taken 1512 times.
7129 if (type != AVMEDIA_TYPE_VIDEO &&
80
2/2
✓ Branch 0 taken 11 times.
✓ Branch 1 taken 71 times.
82 type != AVMEDIA_TYPE_AUDIO &&
81 type != AVMEDIA_TYPE_SUBTITLE) {
82
3/4
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 7 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 4 times.
11 if (codec_name && strcmp(codec_name, "copy")) {
83 const char *type_str = av_get_media_type_string(type);
84 av_log(ost, AV_LOG_FATAL,
85 "Encoder '%s' specified, but only '-codec copy' supported "
86 "for %s streams\n", codec_name, type_str);
87 return AVERROR(ENOSYS);
88 }
89 11 return 0;
90 }
91
92
2/2
✓ Branch 0 taken 2882 times.
✓ Branch 1 taken 4236 times.
7118 if (!codec_name) {
93 2882 ost->par_in->codec_id = av_guess_codec(s->oformat, NULL, s->url, NULL, ost->type);
94 2882 *enc = avcodec_find_encoder(ost->par_in->codec_id);
95
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2882 times.
2882 if (!*enc) {
96 av_log(ost, AV_LOG_FATAL, "Automatic encoder selection failed "
97 "Default encoder for format %s (codec %s) is "
98 "probably disabled. Please choose an encoder manually.\n",
99 s->oformat->name, avcodec_get_name(ost->par_in->codec_id));
100 return AVERROR_ENCODER_NOT_FOUND;
101 }
102
2/2
✓ Branch 0 taken 3603 times.
✓ Branch 1 taken 633 times.
4236 } else if (strcmp(codec_name, "copy")) {
103 3603 int ret = find_codec(ost, codec_name, ost->type, 1, enc);
104
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3603 times.
3603 if (ret < 0)
105 return ret;
106 3603 ost->par_in->codec_id = (*enc)->id;
107 }
108
109 7118 return 0;
110 }
111
112 static char *get_line(AVIOContext *s, AVBPrint *bprint)
113 {
114 char c;
115
116 while ((c = avio_r8(s)) && c != '\n')
117 av_bprint_chars(bprint, c, 1);
118
119 if (!av_bprint_is_complete(bprint))
120 return NULL;
121
122 return bprint->str;
123 }
124
125 static int get_preset_file_2(const char *preset_name, const char *codec_name, AVIOContext **s)
126 {
127 int i, ret = -1;
128 char filename[1000];
129 char *env_avconv_datadir = getenv_utf8("AVCONV_DATADIR");
130 char *env_home = getenv_utf8("HOME");
131 const char *base[3] = { env_avconv_datadir,
132 env_home,
133 AVCONV_DATADIR,
134 };
135
136 for (i = 0; i < FF_ARRAY_ELEMS(base) && ret < 0; i++) {
137 if (!base[i])
138 continue;
139 if (codec_name) {
140 snprintf(filename, sizeof(filename), "%s%s/%s-%s.avpreset", base[i],
141 i != 1 ? "" : "/.avconv", codec_name, preset_name);
142 ret = avio_open2(s, filename, AVIO_FLAG_READ, &int_cb, NULL);
143 }
144 if (ret < 0) {
145 snprintf(filename, sizeof(filename), "%s%s/%s.avpreset", base[i],
146 i != 1 ? "" : "/.avconv", preset_name);
147 ret = avio_open2(s, filename, AVIO_FLAG_READ, &int_cb, NULL);
148 }
149 }
150 freeenv_utf8(env_home);
151 freeenv_utf8(env_avconv_datadir);
152 return ret;
153 }
154
155 typedef struct EncStatsFile {
156 char *path;
157 AVIOContext *io;
158 } EncStatsFile;
159
160 static EncStatsFile *enc_stats_files;
161 static int nb_enc_stats_files;
162
163 static int enc_stats_get_file(AVIOContext **io, const char *path)
164 {
165 EncStatsFile *esf;
166 int ret;
167
168 for (int i = 0; i < nb_enc_stats_files; i++)
169 if (!strcmp(path, enc_stats_files[i].path)) {
170 *io = enc_stats_files[i].io;
171 return 0;
172 }
173
174 ret = GROW_ARRAY(enc_stats_files, nb_enc_stats_files);
175 if (ret < 0)
176 return ret;
177
178 esf = &enc_stats_files[nb_enc_stats_files - 1];
179
180 ret = avio_open2(&esf->io, path, AVIO_FLAG_WRITE, &int_cb, NULL);
181 if (ret < 0) {
182 av_log(NULL, AV_LOG_ERROR, "Error opening stats file '%s': %s\n",
183 path, av_err2str(ret));
184 return ret;
185 }
186
187 esf->path = av_strdup(path);
188 if (!esf->path)
189 return AVERROR(ENOMEM);
190
191 *io = esf->io;
192
193 return 0;
194 }
195
196 6775 void of_enc_stats_close(void)
197 {
198
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6775 times.
6775 for (int i = 0; i < nb_enc_stats_files; i++) {
199 av_freep(&enc_stats_files[i].path);
200 avio_closep(&enc_stats_files[i].io);
201 }
202 6775 av_freep(&enc_stats_files);
203 6775 nb_enc_stats_files = 0;
204 6775 }
205
206 static int unescape(char **pdst, size_t *dst_len,
207 const char **pstr, char delim)
208 {
209 const char *str = *pstr;
210 char *dst;
211 size_t len, idx;
212
213 *pdst = NULL;
214
215 len = strlen(str);
216 if (!len)
217 return 0;
218
219 dst = av_malloc(len + 1);
220 if (!dst)
221 return AVERROR(ENOMEM);
222
223 for (idx = 0; *str; idx++, str++) {
224 if (str[0] == '\\' && str[1])
225 str++;
226 else if (*str == delim)
227 break;
228
229 dst[idx] = *str;
230 }
231 if (!idx) {
232 av_freep(&dst);
233 return 0;
234 }
235
236 dst[idx] = 0;
237
238 *pdst = dst;
239 *dst_len = idx;
240 *pstr = str;
241
242 return 0;
243 }
244
245 static int enc_stats_init(OutputStream *ost, EncStats *es, int pre,
246 const char *path, const char *fmt_spec)
247 {
248 static const struct {
249 enum EncStatsType type;
250 const char *str;
251 unsigned pre_only:1;
252 unsigned post_only:1;
253 unsigned need_input_data:1;
254 } fmt_specs[] = {
255 { ENC_STATS_FILE_IDX, "fidx" },
256 { ENC_STATS_STREAM_IDX, "sidx" },
257 { ENC_STATS_FRAME_NUM, "n" },
258 { ENC_STATS_FRAME_NUM_IN, "ni", 0, 0, 1 },
259 { ENC_STATS_TIMEBASE, "tb" },
260 { ENC_STATS_TIMEBASE_IN, "tbi", 0, 0, 1 },
261 { ENC_STATS_PTS, "pts" },
262 { ENC_STATS_PTS_TIME, "t" },
263 { ENC_STATS_PTS_IN, "ptsi", 0, 0, 1 },
264 { ENC_STATS_PTS_TIME_IN, "ti", 0, 0, 1 },
265 { ENC_STATS_DTS, "dts", 0, 1 },
266 { ENC_STATS_DTS_TIME, "dt", 0, 1 },
267 { ENC_STATS_SAMPLE_NUM, "sn", 1 },
268 { ENC_STATS_NB_SAMPLES, "samp", 1 },
269 { ENC_STATS_PKT_SIZE, "size", 0, 1 },
270 { ENC_STATS_BITRATE, "br", 0, 1 },
271 { ENC_STATS_AVG_BITRATE, "abr", 0, 1 },
272 { ENC_STATS_KEYFRAME, "key", 0, 1 },
273 };
274 const char *next = fmt_spec;
275
276 int ret;
277
278 while (*next) {
279 EncStatsComponent *c;
280 char *val;
281 size_t val_len;
282
283 // get the sequence up until next opening brace
284 ret = unescape(&val, &val_len, &next, '{');
285 if (ret < 0)
286 return ret;
287
288 if (val) {
289 ret = GROW_ARRAY(es->components, es->nb_components);
290 if (ret < 0) {
291 av_freep(&val);
292 return ret;
293 }
294
295 c = &es->components[es->nb_components - 1];
296 c->type = ENC_STATS_LITERAL;
297 c->str = val;
298 c->str_len = val_len;
299 }
300
301 if (!*next)
302 break;
303 next++;
304
305 // get the part inside braces
306 ret = unescape(&val, &val_len, &next, '}');
307 if (ret < 0)
308 return ret;
309
310 if (!val) {
311 av_log(NULL, AV_LOG_ERROR,
312 "Empty formatting directive in: %s\n", fmt_spec);
313 return AVERROR(EINVAL);
314 }
315
316 if (!*next) {
317 av_log(NULL, AV_LOG_ERROR,
318 "Missing closing brace in: %s\n", fmt_spec);
319 ret = AVERROR(EINVAL);
320 goto fail;
321 }
322 next++;
323
324 ret = GROW_ARRAY(es->components, es->nb_components);
325 if (ret < 0)
326 goto fail;
327
328 c = &es->components[es->nb_components - 1];
329
330 for (size_t i = 0; i < FF_ARRAY_ELEMS(fmt_specs); i++) {
331 if (!strcmp(val, fmt_specs[i].str)) {
332 if ((pre && fmt_specs[i].post_only) || (!pre && fmt_specs[i].pre_only)) {
333 av_log(NULL, AV_LOG_ERROR,
334 "Format directive '%s' may only be used %s-encoding\n",
335 val, pre ? "post" : "pre");
336 ret = AVERROR(EINVAL);
337 goto fail;
338 }
339
340 c->type = fmt_specs[i].type;
341
342 if (fmt_specs[i].need_input_data && !ost->ist) {
343 av_log(ost, AV_LOG_WARNING,
344 "Format directive '%s' is unavailable, because "
345 "this output stream has no associated input stream\n",
346 val);
347 }
348
349 break;
350 }
351 }
352
353 if (!c->type) {
354 av_log(NULL, AV_LOG_ERROR, "Invalid format directive: %s\n", val);
355 ret = AVERROR(EINVAL);
356 goto fail;
357 }
358
359 fail:
360 av_freep(&val);
361 if (ret < 0)
362 return ret;
363 }
364
365 ret = pthread_mutex_init(&es->lock, NULL);
366 if (ret)
367 return AVERROR(ret);
368 es->lock_initialized = 1;
369
370 ret = enc_stats_get_file(&es->io, path);
371 if (ret < 0)
372 return ret;
373
374 return 0;
375 }
376
377 28 static const char *output_stream_item_name(void *obj)
378 {
379 28 const MuxStream *ms = obj;
380
381 28 return ms->log_name;
382 }
383
384 static const AVClass output_stream_class = {
385 .class_name = "OutputStream",
386 .version = LIBAVUTIL_VERSION_INT,
387 .item_name = output_stream_item_name,
388 .category = AV_CLASS_CATEGORY_MUXER,
389 };
390
391 7129 static MuxStream *mux_stream_alloc(Muxer *mux, enum AVMediaType type)
392 {
393 7129 const char *type_str = av_get_media_type_string(type);
394 MuxStream *ms;
395
396 7129 ms = allocate_array_elem(&mux->of.streams, sizeof(*ms), &mux->of.nb_streams);
397
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 7129 times.
7129 if (!ms)
398 return NULL;
399
400 7129 ms->ost.file = &mux->of;
401 7129 ms->ost.index = mux->of.nb_streams - 1;
402 7129 ms->ost.type = type;
403
404 7129 ms->ost.class = &output_stream_class;
405
406 7129 ms->sch_idx = -1;
407 7129 ms->sch_idx_enc = -1;
408
409
1/2
✓ Branch 0 taken 7129 times.
✗ Branch 1 not taken.
7129 snprintf(ms->log_name, sizeof(ms->log_name), "%cost#%d:%d",
410 7129 type_str ? *type_str : '?', mux->of.index, ms->ost.index);
411
412 7129 return ms;
413 }
414
415 7047 static int ost_get_filters(const OptionsContext *o, AVFormatContext *oc,
416 OutputStream *ost, char **dst)
417 {
418 7047 const char *filters = NULL;
419 #if FFMPEG_OPT_FILTER_SCRIPT
420 7047 const char *filters_script = NULL;
421
422
2/20
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✓ Branch 6 taken 7047 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 7047 times.
✗ Branch 9 not taken.
✗ 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 18 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
7047 MATCH_PER_STREAM_OPT(filter_scripts, str, filters_script, oc, ost->st);
423 #endif
424
6/20
✓ Branch 1 taken 3487 times.
✓ Branch 2 taken 91 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 91 times.
✓ Branch 5 taken 3578 times.
✓ Branch 6 taken 7047 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 7047 times.
✗ Branch 9 not taken.
✗ 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 18 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
10625 MATCH_PER_STREAM_OPT(filters, str, filters, oc, ost->st);
425
426
2/2
✓ Branch 0 taken 600 times.
✓ Branch 1 taken 6447 times.
7047 if (!ost->enc) {
427
1/2
✓ Branch 0 taken 600 times.
✗ Branch 1 not taken.
600 if (
428 #if FFMPEG_OPT_FILTER_SCRIPT
429
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 600 times.
600 filters_script ||
430 #endif
431 filters) {
432 av_log(ost, AV_LOG_ERROR,
433 "%s '%s' was specified, but codec copy was selected. "
434 "Filtering and streamcopy cannot be used together.\n",
435 #if FFMPEG_OPT_FILTER_SCRIPT
436 filters ? "Filtergraph" : "Filtergraph script",
437 filters ? filters : filters_script
438 #else
439 "Filtergraph", filters
440 #endif
441 );
442 return AVERROR(ENOSYS);
443 }
444 600 return 0;
445 }
446
447
2/2
✓ Branch 0 taken 168 times.
✓ Branch 1 taken 6279 times.
6447 if (!ost->ist) {
448
1/2
✓ Branch 0 taken 168 times.
✗ Branch 1 not taken.
168 if (
449 #if FFMPEG_OPT_FILTER_SCRIPT
450
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 168 times.
168 filters_script ||
451 #endif
452 filters) {
453 av_log(ost, AV_LOG_ERROR,
454 "%s '%s' was specified for a stream fed from a complex "
455 "filtergraph. Simple and complex filtering cannot be used "
456 "together for the same stream.\n",
457 #if FFMPEG_OPT_FILTER_SCRIPT
458 filters ? "Filtergraph" : "Filtergraph script",
459 filters ? filters : filters_script
460 #else
461 "Filtergraph", filters
462 #endif
463 );
464 return AVERROR(EINVAL);
465 }
466 168 return 0;
467 }
468
469 #if FFMPEG_OPT_FILTER_SCRIPT
470
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6279 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6279 if (filters_script && filters) {
471 av_log(ost, AV_LOG_ERROR, "Both -filter and -filter_script set\n");
472 return AVERROR(EINVAL);
473 }
474
475
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6279 times.
6279 if (filters_script)
476 *dst = file_read(filters_script);
477 else
478 #endif
479
2/2
✓ Branch 0 taken 3487 times.
✓ Branch 1 taken 2792 times.
6279 if (filters)
480 3487 *dst = av_strdup(filters);
481 else
482
2/2
✓ Branch 0 taken 2208 times.
✓ Branch 1 taken 584 times.
2792 *dst = av_strdup(ost->type == AVMEDIA_TYPE_VIDEO ? "null" : "anull");
483
1/2
✓ Branch 0 taken 6279 times.
✗ Branch 1 not taken.
6279 return *dst ? 0 : AVERROR(ENOMEM);
484 }
485
486 static int parse_matrix_coeffs(void *logctx, uint16_t *dest, const char *str)
487 {
488 const char *p = str;
489 for (int i = 0;; i++) {
490 dest[i] = atoi(p);
491 if (i == 63)
492 break;
493 p = strchr(p, ',');
494 if (!p) {
495 av_log(logctx, AV_LOG_FATAL,
496 "Syntax error in matrix \"%s\" at coeff %d\n", str, i);
497 return AVERROR(EINVAL);
498 }
499 p++;
500 }
501
502 return 0;
503 }
504
505 622 static int fmt_in_list(const int *formats, int format)
506 {
507
1/2
✓ Branch 0 taken 3374 times.
✗ Branch 1 not taken.
3374 for (; *formats != -1; formats++)
508
2/2
✓ Branch 0 taken 622 times.
✓ Branch 1 taken 2752 times.
3374 if (*formats == format)
509 622 return 1;
510 return 0;
511 }
512
513 static enum AVPixelFormat
514 choose_pixel_fmt(const AVCodec *codec, enum AVPixelFormat target)
515 {
516 const enum AVPixelFormat *p = codec->pix_fmts;
517 const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(target);
518 //FIXME: This should check for AV_PIX_FMT_FLAG_ALPHA after PAL8 pixel format without alpha is implemented
519 int has_alpha = desc ? desc->nb_components % 2 == 0 : 0;
520 enum AVPixelFormat best= AV_PIX_FMT_NONE;
521
522 for (; *p != AV_PIX_FMT_NONE; p++) {
523 best = av_find_best_pix_fmt_of_2(best, *p, target, has_alpha, NULL);
524 if (*p == target)
525 break;
526 }
527 if (*p == AV_PIX_FMT_NONE) {
528 if (target != AV_PIX_FMT_NONE)
529 av_log(NULL, AV_LOG_WARNING,
530 "Incompatible pixel format '%s' for codec '%s', auto-selecting format '%s'\n",
531 av_get_pix_fmt_name(target),
532 codec->name,
533 av_get_pix_fmt_name(best));
534 return best;
535 }
536 return target;
537 }
538
539 3740 static enum AVPixelFormat pix_fmt_parse(OutputStream *ost, const char *name)
540 {
541 3740 const enum AVPixelFormat *fmts = ost->enc_ctx->codec->pix_fmts;
542 enum AVPixelFormat fmt;
543
544 3740 fmt = av_get_pix_fmt(name);
545
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3740 times.
3740 if (fmt == AV_PIX_FMT_NONE) {
546 av_log(ost, AV_LOG_FATAL, "Unknown pixel format requested: %s.\n", name);
547 return AV_PIX_FMT_NONE;
548 }
549
550 /* when the user specified-format is an alias for an endianness-specific
551 * one (e.g. rgb48 -> rgb48be/le), it gets translated into the native
552 * endianness by av_get_pix_fmt();
553 * the following code handles the case when the native endianness is not
554 * supported by the encoder, but the other one is */
555
3/4
✓ Branch 0 taken 311 times.
✓ Branch 1 taken 3429 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 311 times.
3740 if (fmts && !fmt_in_list(fmts, fmt)) {
556 const char *name_canonical = av_get_pix_fmt_name(fmt);
557 int len = strlen(name_canonical);
558
559 if (strcmp(name, name_canonical) &&
560 (!strcmp(name_canonical + len - 2, "le") ||
561 !strcmp(name_canonical + len - 2, "be"))) {
562 char name_other[64];
563 enum AVPixelFormat fmt_other;
564
565 snprintf(name_other, sizeof(name_other), "%s%ce",
566 name, name_canonical[len - 2] == 'l' ? 'b' : 'l');
567 fmt_other = av_get_pix_fmt(name_other);
568 if (fmt_other != AV_PIX_FMT_NONE && fmt_in_list(fmts, fmt_other)) {
569 av_log(ost, AV_LOG_VERBOSE, "Mapping pixel format %s->%s\n",
570 name, name_other);
571 fmt = fmt_other;
572 }
573 }
574 }
575
576
3/4
✓ Branch 0 taken 311 times.
✓ Branch 1 taken 3429 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 311 times.
3740 if (fmts && !fmt_in_list(fmts, fmt))
577 fmt = choose_pixel_fmt(ost->enc_ctx->codec, fmt);
578
579 3740 return fmt;
580 }
581
582 5535 static int new_stream_video(Muxer *mux, const OptionsContext *o,
583 OutputStream *ost, int *keep_pix_fmt,
584 enum VideoSyncMethod *vsync_method)
585 {
586 5535 MuxStream *ms = ms_from_ost(ost);
587 5535 AVFormatContext *oc = mux->fc;
588 AVStream *st;
589 5535 char *frame_rate = NULL, *max_frame_rate = NULL, *frame_aspect_ratio = NULL;
590 5535 int ret = 0;
591
592 5535 st = ost->st;
593
594
4/20
✓ Branch 1 taken 22 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 22 times.
✓ Branch 6 taken 5535 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 5535 times.
✗ Branch 9 not taken.
✗ 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 18 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
5557 MATCH_PER_STREAM_OPT(frame_rates, str, frame_rate, oc, st);
595
3/4
✓ Branch 0 taken 22 times.
✓ Branch 1 taken 5513 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 22 times.
5535 if (frame_rate && av_parse_video_rate(&ost->frame_rate, frame_rate) < 0) {
596 av_log(ost, AV_LOG_FATAL, "Invalid framerate value: %s\n", frame_rate);
597 return AVERROR(EINVAL);
598 }
599
600
2/20
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✓ Branch 6 taken 5535 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 5535 times.
✗ Branch 9 not taken.
✗ 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 18 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
5535 MATCH_PER_STREAM_OPT(max_frame_rates, str, max_frame_rate, oc, st);
601
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 5535 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
5535 if (max_frame_rate && av_parse_video_rate(&ost->max_frame_rate, max_frame_rate) < 0) {
602 av_log(ost, AV_LOG_FATAL, "Invalid maximum framerate value: %s\n", max_frame_rate);
603 return AVERROR(EINVAL);
604 }
605
606
3/4
✓ Branch 0 taken 22 times.
✓ Branch 1 taken 5513 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 22 times.
5535 if (frame_rate && max_frame_rate) {
607 av_log(ost, AV_LOG_ERROR, "Only one of -fpsmax and -r can be set for a stream.\n");
608 return AVERROR(EINVAL);
609 }
610
611
2/20
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✓ Branch 6 taken 5535 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 5535 times.
✗ Branch 9 not taken.
✗ 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 18 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
5535 MATCH_PER_STREAM_OPT(frame_aspect_ratios, str, frame_aspect_ratio, oc, st);
612
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 5535 times.
5535 if (frame_aspect_ratio) {
613 AVRational q;
614 if (av_parse_ratio(&q, frame_aspect_ratio, 255, 0, NULL) < 0 ||
615 q.num <= 0 || q.den <= 0) {
616 av_log(ost, AV_LOG_FATAL, "Invalid aspect ratio: %s\n", frame_aspect_ratio);
617 return AVERROR(EINVAL);
618 }
619 ost->frame_aspect_ratio = q;
620 }
621
622
2/2
✓ Branch 0 taken 5200 times.
✓ Branch 1 taken 335 times.
5535 if (ost->enc_ctx) {
623 5200 AVCodecContext *video_enc = ost->enc_ctx;
624 5200 const char *p = NULL, *fps_mode = NULL;
625 5200 char *frame_size = NULL;
626 5200 char *frame_pix_fmt = NULL;
627 5200 char *intra_matrix = NULL, *inter_matrix = NULL;
628 5200 char *chroma_intra_matrix = NULL;
629 5200 int do_pass = 0;
630 int i;
631
632
4/20
✓ Branch 1 taken 231 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 231 times.
✓ Branch 6 taken 5200 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 5200 times.
✗ Branch 9 not taken.
✗ 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 18 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
5431 MATCH_PER_STREAM_OPT(frame_sizes, str, frame_size, oc, st);
633
2/2
✓ Branch 0 taken 231 times.
✓ Branch 1 taken 4969 times.
5200 if (frame_size) {
634 231 ret = av_parse_video_size(&video_enc->width, &video_enc->height, frame_size);
635
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 231 times.
231 if (ret < 0) {
636 av_log(ost, AV_LOG_FATAL, "Invalid frame size: %s.\n", frame_size);
637 return AVERROR(EINVAL);
638 }
639 }
640
641
4/20
✓ Branch 1 taken 3740 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 3740 times.
✓ Branch 6 taken 5200 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 5200 times.
✗ Branch 9 not taken.
✗ 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 18 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
8940 MATCH_PER_STREAM_OPT(frame_pix_fmts, str, frame_pix_fmt, oc, st);
642
3/4
✓ Branch 0 taken 3740 times.
✓ Branch 1 taken 1460 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 3740 times.
5200 if (frame_pix_fmt && *frame_pix_fmt == '+') {
643 *keep_pix_fmt = 1;
644 if (!*++frame_pix_fmt)
645 frame_pix_fmt = NULL;
646 }
647
2/2
✓ Branch 0 taken 3740 times.
✓ Branch 1 taken 1460 times.
5200 if (frame_pix_fmt) {
648 3740 video_enc->pix_fmt = pix_fmt_parse(ost, frame_pix_fmt);
649
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3740 times.
3740 if (video_enc->pix_fmt == AV_PIX_FMT_NONE)
650 return AVERROR(EINVAL);
651 }
652
653
2/20
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✓ Branch 6 taken 5200 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 5200 times.
✗ Branch 9 not taken.
✗ 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 18 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
5200 MATCH_PER_STREAM_OPT(intra_matrices, str, intra_matrix, oc, st);
654
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 5200 times.
5200 if (intra_matrix) {
655 if (!(video_enc->intra_matrix = av_mallocz(sizeof(*video_enc->intra_matrix) * 64)))
656 return AVERROR(ENOMEM);
657
658 ret = parse_matrix_coeffs(ost, video_enc->intra_matrix, intra_matrix);
659 if (ret < 0)
660 return ret;
661 }
662
2/20
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✓ Branch 6 taken 5200 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 5200 times.
✗ Branch 9 not taken.
✗ 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 18 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
5200 MATCH_PER_STREAM_OPT(chroma_intra_matrices, str, chroma_intra_matrix, oc, st);
663
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 5200 times.
5200 if (chroma_intra_matrix) {
664 uint16_t *p = av_mallocz(sizeof(*video_enc->chroma_intra_matrix) * 64);
665 if (!p)
666 return AVERROR(ENOMEM);
667 video_enc->chroma_intra_matrix = p;
668 ret = parse_matrix_coeffs(ost, p, chroma_intra_matrix);
669 if (ret < 0)
670 return ret;
671 }
672
2/20
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✓ Branch 6 taken 5200 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 5200 times.
✗ Branch 9 not taken.
✗ 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 18 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
5200 MATCH_PER_STREAM_OPT(inter_matrices, str, inter_matrix, oc, st);
673
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 5200 times.
5200 if (inter_matrix) {
674 if (!(video_enc->inter_matrix = av_mallocz(sizeof(*video_enc->inter_matrix) * 64)))
675 return AVERROR(ENOMEM);
676 ret = parse_matrix_coeffs(ost, video_enc->inter_matrix, inter_matrix);
677 if (ret < 0)
678 return ret;
679 }
680
681
2/20
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✓ Branch 6 taken 5200 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 5200 times.
✗ Branch 9 not taken.
✗ 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 18 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
5200 MATCH_PER_STREAM_OPT(rc_overrides, str, p, oc, st);
682
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 5200 times.
5200 for (i = 0; p; i++) {
683 int start, end, q;
684 int e = sscanf(p, "%d,%d,%d", &start, &end, &q);
685 if (e != 3) {
686 av_log(ost, AV_LOG_FATAL, "error parsing rc_override\n");
687 return AVERROR(EINVAL);
688 }
689 video_enc->rc_override =
690 av_realloc_array(video_enc->rc_override,
691 i + 1, sizeof(RcOverride));
692 if (!video_enc->rc_override) {
693 av_log(ost, AV_LOG_FATAL, "Could not (re)allocate memory for rc_override.\n");
694 return AVERROR(ENOMEM);
695 }
696 video_enc->rc_override[i].start_frame = start;
697 video_enc->rc_override[i].end_frame = end;
698 if (q > 0) {
699 video_enc->rc_override[i].qscale = q;
700 video_enc->rc_override[i].quality_factor = 1.0;
701 }
702 else {
703 video_enc->rc_override[i].qscale = 0;
704 video_enc->rc_override[i].quality_factor = -q/100.0;
705 }
706 p = strchr(p, '/');
707 if (p) p++;
708 }
709 5200 video_enc->rc_override_count = i;
710
711 /* two pass mode */
712
4/20
✓ Branch 1 taken 8 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 8 times.
✓ Branch 6 taken 5200 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 5200 times.
✗ Branch 9 not taken.
✗ 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 18 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
5208 MATCH_PER_STREAM_OPT(pass, i, do_pass, oc, st);
713
2/2
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 5192 times.
5200 if (do_pass) {
714
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 4 times.
8 if (do_pass & 1)
715 4 video_enc->flags |= AV_CODEC_FLAG_PASS1;
716
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 4 times.
8 if (do_pass & 2)
717 4 video_enc->flags |= AV_CODEC_FLAG_PASS2;
718 }
719
720
4/20
✓ Branch 1 taken 8 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 8 times.
✓ Branch 6 taken 5200 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 5200 times.
✗ Branch 9 not taken.
✗ 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 18 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
5208 MATCH_PER_STREAM_OPT(passlogfiles, str, ost->logfile_prefix, oc, st);
721
2/2
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 5192 times.
5200 if (ost->logfile_prefix &&
722
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 8 times.
8 !(ost->logfile_prefix = av_strdup(ost->logfile_prefix)))
723 return AVERROR(ENOMEM);
724
725
2/2
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 5192 times.
5200 if (do_pass) {
726 8 int ost_idx = -1;
727 char logfilename[1024];
728 FILE *f;
729
730 /* compute this stream's global index */
731
2/2
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 8 times.
16 for (int i = 0; i <= ost->file->index; i++)
732 8 ost_idx += output_files[i]->nb_streams;
733
734 8 snprintf(logfilename, sizeof(logfilename), "%s-%d.log",
735
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 ost->logfile_prefix ? ost->logfile_prefix :
736 DEFAULT_PASS_LOGFILENAME_PREFIX,
737 ost_idx);
738
2/4
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 8 times.
8 if (!strcmp(ost->enc_ctx->codec->name, "libx264") || !strcmp(ost->enc_ctx->codec->name, "libvvenc")) {
739 if (av_opt_is_set_to_default_by_name(ost->enc_ctx, "stats",
740 AV_OPT_SEARCH_CHILDREN) > 0)
741 av_opt_set(ost->enc_ctx, "stats", logfilename,
742 AV_OPT_SEARCH_CHILDREN);
743 } else {
744
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 4 times.
8 if (video_enc->flags & AV_CODEC_FLAG_PASS2) {
745 4 char *logbuffer = file_read(logfilename);
746
747
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
4 if (!logbuffer) {
748 av_log(ost, AV_LOG_FATAL, "Error reading log file '%s' for pass-2 encoding\n",
749 logfilename);
750 return AVERROR(EIO);
751 }
752 4 video_enc->stats_in = logbuffer;
753 }
754
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 4 times.
8 if (video_enc->flags & AV_CODEC_FLAG_PASS1) {
755 4 f = fopen_utf8(logfilename, "wb");
756
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
4 if (!f) {
757 av_log(ost, AV_LOG_FATAL,
758 "Cannot write log file '%s' for pass-1 encoding: %s\n",
759 logfilename, strerror(errno));
760 return AVERROR(errno);
761 }
762 4 ost->logfile = f;
763 }
764 }
765 }
766
767
4/20
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 1 times.
✓ Branch 6 taken 5200 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 5200 times.
✗ Branch 9 not taken.
✗ 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 18 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
5201 MATCH_PER_STREAM_OPT(force_fps, i, ost->force_fps, oc, st);
768
769 #if FFMPEG_OPT_TOP
770 5200 ost->top_field_first = -1;
771
2/20
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✓ Branch 6 taken 5200 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 5200 times.
✗ Branch 9 not taken.
✗ 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 18 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
5200 MATCH_PER_STREAM_OPT(top_field_first, i, ost->top_field_first, oc, st);
772
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 5200 times.
5200 if (ost->top_field_first >= 0)
773 av_log(ost, AV_LOG_WARNING, "-top is deprecated, use the setfield filter instead\n");
774 #endif
775
776 #if FFMPEG_OPT_VSYNC
777 5200 *vsync_method = video_sync_method;
778 #else
779 *vsync_method = VSYNC_AUTO;
780 #endif
781
4/20
✓ Branch 1 taken 514 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 514 times.
✓ Branch 6 taken 5200 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 5200 times.
✗ Branch 9 not taken.
✗ 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 18 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
5714 MATCH_PER_STREAM_OPT(fps_mode, str, fps_mode, oc, st);
782
2/2
✓ Branch 0 taken 514 times.
✓ Branch 1 taken 4686 times.
5200 if (fps_mode) {
783 514 ret = parse_and_set_vsync(fps_mode, vsync_method, ost->file->index, ost->index, 0);
784
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 514 times.
514 if (ret < 0)
785 return ret;
786 }
787
788
3/4
✓ Branch 0 taken 5179 times.
✓ Branch 1 taken 21 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 5179 times.
5200 if ((ost->frame_rate.num || ost->max_frame_rate.num) &&
789
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 20 times.
21 !(*vsync_method == VSYNC_AUTO ||
790
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
1 *vsync_method == VSYNC_CFR || *vsync_method == VSYNC_VSCFR)) {
791 av_log(ost, AV_LOG_FATAL, "One of -r/-fpsmax was specified "
792 "together a non-CFR -vsync/-fps_mode. This is contradictory.\n");
793 return AVERROR(EINVAL);
794 }
795
796
2/2
✓ Branch 0 taken 4686 times.
✓ Branch 1 taken 514 times.
5200 if (*vsync_method == VSYNC_AUTO) {
797
3/4
✓ Branch 0 taken 4666 times.
✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 4666 times.
4686 if (ost->frame_rate.num || ost->max_frame_rate.num) {
798 20 *vsync_method = VSYNC_CFR;
799
2/2
✓ Branch 0 taken 284 times.
✓ Branch 1 taken 4382 times.
4666 } else if (!strcmp(oc->oformat->name, "avi")) {
800 284 *vsync_method = VSYNC_VFR;
801 } else {
802 4382 *vsync_method = (oc->oformat->flags & AVFMT_VARIABLE_FPS) ?
803 4034 ((oc->oformat->flags & AVFMT_NOTIMESTAMPS) ?
804
4/4
✓ Branch 0 taken 4034 times.
✓ Branch 1 taken 348 times.
✓ Branch 2 taken 13 times.
✓ Branch 3 taken 4021 times.
4382 VSYNC_PASSTHROUGH : VSYNC_VFR) : VSYNC_CFR;
805 }
806
807
4/4
✓ Branch 0 taken 4597 times.
✓ Branch 1 taken 89 times.
✓ Branch 2 taken 368 times.
✓ Branch 3 taken 4229 times.
4686 if (ost->ist && *vsync_method == VSYNC_CFR) {
808 368 const InputFile *ifile = ost->ist->file;
809
810
3/4
✓ Branch 0 taken 323 times.
✓ Branch 1 taken 45 times.
✓ Branch 2 taken 323 times.
✗ Branch 3 not taken.
368 if (ifile->nb_streams == 1 && ifile->input_ts_offset == 0)
811 323 *vsync_method = VSYNC_VSCFR;
812 }
813
814
3/4
✓ Branch 0 taken 45 times.
✓ Branch 1 taken 4641 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 45 times.
4686 if (*vsync_method == VSYNC_CFR && copy_ts) {
815 *vsync_method = VSYNC_VSCFR;
816 }
817 }
818 #if FFMPEG_OPT_VSYNC_DROP
819
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 5200 times.
5200 if (*vsync_method == VSYNC_DROP)
820 ms->ts_drop = 1;
821 #endif
822 }
823
824 5535 return 0;
825 }
826
827 1512 static int new_stream_audio(Muxer *mux, const OptionsContext *o,
828 OutputStream *ost)
829 {
830 1512 MuxStream *ms = ms_from_ost(ost);
831 1512 AVFormatContext *oc = mux->fc;
832 1512 AVStream *st = ost->st;
833
834
2/2
✓ Branch 0 taken 1247 times.
✓ Branch 1 taken 265 times.
1512 if (ost->enc_ctx) {
835 1247 AVCodecContext *audio_enc = ost->enc_ctx;
836 1247 int channels = 0;
837 1247 char *layout = NULL;
838 1247 char *sample_fmt = NULL;
839
840
4/20
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 10 times.
✓ Branch 6 taken 1247 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 1247 times.
✗ Branch 9 not taken.
✗ 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 18 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
1257 MATCH_PER_STREAM_OPT(audio_channels, i, channels, oc, st);
841
2/2
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 1237 times.
1247 if (channels) {
842 10 audio_enc->ch_layout.order = AV_CHANNEL_ORDER_UNSPEC;
843 10 audio_enc->ch_layout.nb_channels = channels;
844 }
845
846
4/20
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 1 times.
✓ Branch 6 taken 1247 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 1247 times.
✗ Branch 9 not taken.
✗ 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 18 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
1248 MATCH_PER_STREAM_OPT(audio_ch_layouts, str, layout, oc, st);
847
3/4
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1246 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
1247 if (layout && av_channel_layout_from_string(&audio_enc->ch_layout, layout) < 0) {
848 av_log(ost, AV_LOG_FATAL, "Unknown channel layout: %s\n", layout);
849 return AVERROR(EINVAL);
850 }
851
852
2/20
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✓ Branch 6 taken 1247 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 1247 times.
✗ Branch 9 not taken.
✗ 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 18 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
1247 MATCH_PER_STREAM_OPT(sample_fmts, str, sample_fmt, oc, st);
853
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1247 times.
1247 if (sample_fmt &&
854 (audio_enc->sample_fmt = av_get_sample_fmt(sample_fmt)) == AV_SAMPLE_FMT_NONE) {
855 av_log(ost, AV_LOG_FATAL, "Invalid sample format '%s'\n", sample_fmt);
856 return AVERROR(EINVAL);
857 }
858
859
4/20
✓ Branch 1 taken 14 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 14 times.
✓ Branch 6 taken 1247 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 1247 times.
✗ Branch 9 not taken.
✗ 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 18 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
1261 MATCH_PER_STREAM_OPT(audio_sample_rate, i, audio_enc->sample_rate, oc, st);
860
861
2/20
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✓ Branch 6 taken 1247 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 1247 times.
✗ Branch 9 not taken.
✗ 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 18 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
1247 MATCH_PER_STREAM_OPT(apad, str, ms->apad, oc, st);
862 }
863
864 1512 return 0;
865 }
866
867 71 static int new_stream_subtitle(Muxer *mux, const OptionsContext *o,
868 OutputStream *ost)
869 {
870 AVStream *st;
871
872 71 st = ost->st;
873
874
2/2
✓ Branch 0 taken 38 times.
✓ Branch 1 taken 33 times.
71 if (ost->enc_ctx) {
875 38 AVCodecContext *subtitle_enc = ost->enc_ctx;
876
877 AVCodecDescriptor const *input_descriptor =
878 38 avcodec_descriptor_get(ost->ist->par->codec_id);
879 AVCodecDescriptor const *output_descriptor =
880 38 avcodec_descriptor_get(subtitle_enc->codec_id);
881 38 int input_props = 0, output_props = 0;
882
883 38 char *frame_size = NULL;
884
885
2/20
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✓ Branch 6 taken 38 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 38 times.
✗ Branch 9 not taken.
✗ 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 18 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
38 MATCH_PER_STREAM_OPT(frame_sizes, str, frame_size, mux->fc, st);
886
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 38 times.
38 if (frame_size) {
887 int ret = av_parse_video_size(&subtitle_enc->width, &subtitle_enc->height, frame_size);
888 if (ret < 0) {
889 av_log(ost, AV_LOG_FATAL, "Invalid frame size: %s.\n", frame_size);
890 return ret;
891 }
892 }
893
1/2
✓ Branch 0 taken 38 times.
✗ Branch 1 not taken.
38 if (input_descriptor)
894 38 input_props = input_descriptor->props & (AV_CODEC_PROP_TEXT_SUB | AV_CODEC_PROP_BITMAP_SUB);
895
1/2
✓ Branch 0 taken 38 times.
✗ Branch 1 not taken.
38 if (output_descriptor)
896 38 output_props = output_descriptor->props & (AV_CODEC_PROP_TEXT_SUB | AV_CODEC_PROP_BITMAP_SUB);
897
3/6
✓ Branch 0 taken 38 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 38 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 38 times.
38 if (input_props && output_props && input_props != output_props) {
898 av_log(ost, AV_LOG_ERROR,
899 "Subtitle encoding currently only possible from text to text "
900 "or bitmap to bitmap\n");
901 return AVERROR(EINVAL);
902 }
903 }
904
905 71 return 0;
906 }
907
908 643 static int streamcopy_init(const Muxer *mux, OutputStream *ost, AVDictionary **encoder_opts)
909 {
910 643 MuxStream *ms = ms_from_ost(ost);
911
912 643 const InputStream *ist = ost->ist;
913 643 const InputFile *ifile = ist->file;
914
915 643 AVCodecParameters *par = ost->par_in;
916 643 uint32_t codec_tag = par->codec_tag;
917
918 643 AVCodecContext *codec_ctx = NULL;
919 643 AVDictionary *codec_opts = NULL;
920
921 643 AVRational fr = ost->frame_rate;
922
923 643 int ret = 0;
924
925 643 codec_ctx = avcodec_alloc_context3(NULL);
926
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 643 times.
643 if (!codec_ctx)
927 return AVERROR(ENOMEM);
928
929 643 ret = avcodec_parameters_to_context(codec_ctx, ist->par);
930
1/2
✓ Branch 0 taken 643 times.
✗ Branch 1 not taken.
643 if (ret >= 0)
931 643 ret = av_opt_set_dict(codec_ctx, encoder_opts);
932
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 643 times.
643 if (ret < 0) {
933 av_log(ost, AV_LOG_FATAL,
934 "Error setting up codec context options.\n");
935 goto fail;
936 }
937
938 643 ret = avcodec_parameters_from_context(par, codec_ctx);
939
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 643 times.
643 if (ret < 0) {
940 av_log(ost, AV_LOG_FATAL,
941 "Error getting reference codec parameters.\n");
942 goto fail;
943 }
944
945
2/2
✓ Branch 0 taken 637 times.
✓ Branch 1 taken 6 times.
643 if (!codec_tag) {
946 637 const struct AVCodecTag * const *ct = mux->fc->oformat->codec_tag;
947 unsigned int codec_tag_tmp;
948
6/6
✓ Branch 0 taken 118 times.
✓ Branch 1 taken 519 times.
✓ Branch 3 taken 86 times.
✓ Branch 4 taken 32 times.
✓ Branch 5 taken 11 times.
✓ Branch 6 taken 75 times.
723 if (!ct || av_codec_get_id (ct, par->codec_tag) == par->codec_id ||
949 86 !av_codec_get_tag2(ct, par->codec_id, &codec_tag_tmp))
950 562 codec_tag = par->codec_tag;
951 }
952
953 643 par->codec_tag = codec_tag;
954
955
2/2
✓ Branch 0 taken 642 times.
✓ Branch 1 taken 1 times.
643 if (!fr.num)
956 642 fr = ist->framerate;
957
958
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 641 times.
643 if (fr.num)
959 2 ost->st->avg_frame_rate = fr;
960 else
961 641 ost->st->avg_frame_rate = ist->st->avg_frame_rate;
962
963 // copy timebase while removing common factors
964
3/4
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 641 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 2 times.
643 if (ost->st->time_base.num <= 0 || ost->st->time_base.den <= 0) {
965
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 640 times.
641 if (fr.num)
966 1 ost->st->time_base = av_inv_q(fr);
967 else
968 640 ost->st->time_base = av_add_q(ist->st->time_base, (AVRational){0, 1});
969 }
970
971
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 643 times.
643 if (!ms->copy_prior_start) {
972 ms->ts_copy_start = (mux->of.start_time == AV_NOPTS_VALUE) ?
973 0 : mux->of.start_time;
974 if (copy_ts && ifile->start_time != AV_NOPTS_VALUE) {
975 ms->ts_copy_start = FFMAX(ms->ts_copy_start,
976 ifile->start_time + ifile->ts_offset);
977 }
978 }
979
980
2/2
✓ Branch 0 taken 71 times.
✓ Branch 1 taken 643 times.
714 for (int i = 0; i < ist->st->codecpar->nb_coded_side_data; i++) {
981 71 const AVPacketSideData *sd_src = &ist->st->codecpar->coded_side_data[i];
982 AVPacketSideData *sd_dst;
983
984 71 sd_dst = av_packet_side_data_new(&ost->st->codecpar->coded_side_data,
985 71 &ost->st->codecpar->nb_coded_side_data,
986 71 sd_src->type, sd_src->size, 0);
987
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 71 times.
71 if (!sd_dst) {
988 ret = AVERROR(ENOMEM);
989 goto fail;
990 }
991 71 memcpy(sd_dst->data, sd_src->data, sd_src->size);
992 }
993
994
3/3
✓ Branch 0 taken 265 times.
✓ Branch 1 taken 335 times.
✓ Branch 2 taken 43 times.
643 switch (par->codec_type) {
995 265 case AVMEDIA_TYPE_AUDIO:
996
4/6
✓ Branch 0 taken 260 times.
✓ Branch 1 taken 5 times.
✓ Branch 2 taken 260 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 260 times.
265 if ((par->block_align == 1 || par->block_align == 1152 || par->block_align == 576) &&
997
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 5 times.
5 par->codec_id == AV_CODEC_ID_MP3)
998 par->block_align = 0;
999
2/2
✓ Branch 0 taken 13 times.
✓ Branch 1 taken 252 times.
265 if (par->codec_id == AV_CODEC_ID_AC3)
1000 13 par->block_align = 0;
1001 265 break;
1002 335 case AVMEDIA_TYPE_VIDEO: {
1003 AVRational sar;
1004
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 335 times.
335 if (ost->frame_aspect_ratio.num) { // overridden by the -aspect cli option
1005 sar =
1006 av_mul_q(ost->frame_aspect_ratio,
1007 (AVRational){ par->height, par->width });
1008 av_log(ost, AV_LOG_WARNING, "Overriding aspect ratio "
1009 "with stream copy may produce invalid files\n");
1010 }
1011
2/2
✓ Branch 0 taken 90 times.
✓ Branch 1 taken 245 times.
335 else if (ist->st->sample_aspect_ratio.num)
1012 90 sar = ist->st->sample_aspect_ratio;
1013 else
1014 245 sar = par->sample_aspect_ratio;
1015 335 ost->st->sample_aspect_ratio = par->sample_aspect_ratio = sar;
1016 335 ost->st->avg_frame_rate = ist->st->avg_frame_rate;
1017 335 ost->st->r_frame_rate = ist->st->r_frame_rate;
1018 335 break;
1019 }
1020 }
1021
1022 643 fail:
1023 643 avcodec_free_context(&codec_ctx);
1024 643 av_dict_free(&codec_opts);
1025 643 return ret;
1026 }
1027
1028 7129 static int ost_add(Muxer *mux, const OptionsContext *o, enum AVMediaType type,
1029 InputStream *ist, OutputFilter *ofilter,
1030 OutputStream **post)
1031 {
1032 7129 AVFormatContext *oc = mux->fc;
1033 MuxStream *ms;
1034 OutputStream *ost;
1035 const AVCodec *enc;
1036 AVStream *st;
1037 7129 AVDictionary *encoder_opts = NULL;
1038 7129 int ret = 0, keep_pix_fmt = 0, autoscale = 1;
1039 7129 int threads_manual = 0;
1040 7129 AVRational enc_tb = { 0, 0 };
1041 7129 enum VideoSyncMethod vsync_method = VSYNC_AUTO;
1042 7129 const char *bsfs = NULL, *time_base = NULL;
1043 7129 char *filters = NULL, *next, *codec_tag = NULL;
1044 7129 double qscale = -1;
1045
1046 7129 st = avformat_new_stream(oc, NULL);
1047
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 7129 times.
7129 if (!st)
1048 return AVERROR(ENOMEM);
1049
1050 7129 ms = mux_stream_alloc(mux, type);
1051
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 7129 times.
7129 if (!ms)
1052 return AVERROR(ENOMEM);
1053
1054 // only streams with sources (i.e. not attachments)
1055 // are handled by the scheduler
1056
4/4
✓ Branch 0 taken 169 times.
✓ Branch 1 taken 6960 times.
✓ Branch 2 taken 168 times.
✓ Branch 3 taken 1 times.
7129 if (ist || ofilter) {
1057 7128 ret = GROW_ARRAY(mux->sch_stream_idx, mux->nb_sch_stream_idx);
1058
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 7128 times.
7128 if (ret < 0)
1059 return ret;
1060
1061 7128 ret = sch_add_mux_stream(mux->sch, mux->sch_idx);
1062
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 7128 times.
7128 if (ret < 0)
1063 return ret;
1064
1065
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 7128 times.
7128 av_assert0(ret == mux->nb_sch_stream_idx - 1);
1066 7128 mux->sch_stream_idx[ret] = ms->ost.index;
1067 7128 ms->sch_idx = ret;
1068 }
1069
1070 7129 ost = &ms->ost;
1071
1072
2/2
✓ Branch 0 taken 40 times.
✓ Branch 1 taken 7089 times.
7129 if (o->streamid) {
1073 AVDictionaryEntry *e;
1074 char idx[16], *p;
1075 40 snprintf(idx, sizeof(idx), "%d", ost->index);
1076
1077 40 e = av_dict_get(o->streamid, idx, NULL, 0);
1078
1/2
✓ Branch 0 taken 40 times.
✗ Branch 1 not taken.
40 if (e) {
1079 40 st->id = strtol(e->value, &p, 0);
1080
2/4
✓ Branch 0 taken 40 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 40 times.
40 if (!e->value[0] || *p) {
1081 av_log(ost, AV_LOG_FATAL, "Invalid stream id: %s\n", e->value);
1082 return AVERROR(EINVAL);
1083 }
1084 }
1085 }
1086
1087 7129 ost->par_in = avcodec_parameters_alloc();
1088
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 7129 times.
7129 if (!ost->par_in)
1089 return AVERROR(ENOMEM);
1090
1091 7129 ms->last_mux_dts = AV_NOPTS_VALUE;
1092
1093 7129 ost->st = st;
1094 7129 ost->ist = ist;
1095 7129 ost->kf.ref_pts = AV_NOPTS_VALUE;
1096 7129 ost->par_in->codec_type = type;
1097 7129 st->codecpar->codec_type = type;
1098
1099 7129 ret = choose_encoder(o, oc, ost, &enc);
1100
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 7129 times.
7129 if (ret < 0) {
1101 av_log(ost, AV_LOG_FATAL, "Error selecting an encoder\n");
1102 return ret;
1103 }
1104
1105
2/2
✓ Branch 0 taken 6485 times.
✓ Branch 1 taken 644 times.
7129 if (enc) {
1106 6485 ost->enc_ctx = avcodec_alloc_context3(enc);
1107
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6485 times.
6485 if (!ost->enc_ctx)
1108 return AVERROR(ENOMEM);
1109
1110 6485 ret = sch_add_enc(mux->sch, encoder_thread, ost,
1111
2/2
✓ Branch 0 taken 6447 times.
✓ Branch 1 taken 38 times.
6485 ost->type == AVMEDIA_TYPE_SUBTITLE ? NULL : enc_open);
1112
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6485 times.
6485 if (ret < 0)
1113 return ret;
1114 6485 ms->sch_idx_enc = ret;
1115
1116 6485 ret = enc_alloc(&ost->enc, enc, mux->sch, ms->sch_idx_enc);
1117
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6485 times.
6485 if (ret < 0)
1118 return ret;
1119
1120 6485 av_strlcat(ms->log_name, "/", sizeof(ms->log_name));
1121 6485 av_strlcat(ms->log_name, enc->name, sizeof(ms->log_name));
1122 } else {
1123
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 644 times.
644 if (ofilter) {
1124 av_log(ost, AV_LOG_ERROR,
1125 "Streamcopy requested for output stream fed "
1126 "from a complex filtergraph. Filtering and streamcopy "
1127 "cannot be used together.\n");
1128 return AVERROR(EINVAL);
1129 }
1130
1131 644 av_strlcat(ms->log_name, "/copy", sizeof(ms->log_name));
1132 }
1133
1134 7129 av_log(ost, AV_LOG_VERBOSE, "Created %s stream from ",
1135 av_get_media_type_string(type));
1136
2/2
✓ Branch 0 taken 6960 times.
✓ Branch 1 taken 169 times.
7129 if (ist)
1137 6960 av_log(ost, AV_LOG_VERBOSE, "input stream %d:%d",
1138 6960 ist->file->index, ist->index);
1139
2/2
✓ Branch 0 taken 168 times.
✓ Branch 1 taken 1 times.
169 else if (ofilter)
1140 168 av_log(ost, AV_LOG_VERBOSE, "complex filtergraph %d:[%s]\n",
1141 168 ofilter->graph->index, ofilter->name);
1142
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 else if (type == AVMEDIA_TYPE_ATTACHMENT)
1143 1 av_log(ost, AV_LOG_VERBOSE, "attached file");
1144 else av_assert0(0);
1145 7129 av_log(ost, AV_LOG_VERBOSE, "\n");
1146
1147 7129 ms->pkt = av_packet_alloc();
1148
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 7129 times.
7129 if (!ms->pkt)
1149 return AVERROR(ENOMEM);
1150
1151
2/2
✓ Branch 0 taken 6485 times.
✓ Branch 1 taken 644 times.
7129 if (ost->enc_ctx) {
1152 6485 AVCodecContext *enc = ost->enc_ctx;
1153 6485 AVIOContext *s = NULL;
1154 6485 char *buf = NULL, *arg = NULL, *preset = NULL;
1155 6485 const char *enc_stats_pre = NULL, *enc_stats_post = NULL, *mux_stats = NULL;
1156 6485 const char *enc_time_base = NULL;
1157
1158 6485 ret = filter_codec_opts(o->g->codec_opts, enc->codec_id,
1159 6485 oc, st, enc->codec, &encoder_opts,
1160 &mux->enc_opts_used);
1161
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6485 times.
6485 if (ret < 0)
1162 goto fail;
1163
1164
2/20
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✓ Branch 6 taken 6485 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 6485 times.
✗ Branch 9 not taken.
✗ 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 18 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
6485 MATCH_PER_STREAM_OPT(presets, str, preset, oc, st);
1165
1166
2/20
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✓ Branch 6 taken 6485 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 6485 times.
✗ Branch 9 not taken.
✗ 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 18 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
6485 MATCH_PER_STREAM_OPT(autoscale, i, autoscale, oc, st);
1167
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6485 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
6485 if (preset && (!(ret = get_preset_file_2(preset, enc->codec->name, &s)))) {
1168 AVBPrint bprint;
1169 av_bprint_init(&bprint, 0, AV_BPRINT_SIZE_UNLIMITED);
1170 do {
1171 av_bprint_clear(&bprint);
1172 buf = get_line(s, &bprint);
1173 if (!buf) {
1174 ret = AVERROR(ENOMEM);
1175 break;
1176 }
1177
1178 if (!buf[0] || buf[0] == '#')
1179 continue;
1180 if (!(arg = strchr(buf, '='))) {
1181 av_log(ost, AV_LOG_FATAL, "Invalid line found in the preset file.\n");
1182 ret = AVERROR(EINVAL);
1183 break;
1184 }
1185 *arg++ = 0;
1186 av_dict_set(&encoder_opts, buf, arg, AV_DICT_DONT_OVERWRITE);
1187 } while (!s->eof_reached);
1188 av_bprint_finalize(&bprint, NULL);
1189 avio_closep(&s);
1190 }
1191
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6485 times.
6485 if (ret) {
1192 av_log(ost, AV_LOG_FATAL,
1193 "Preset %s specified, but could not be opened.\n", preset);
1194 goto fail;
1195 }
1196
1197
2/20
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✓ Branch 6 taken 6485 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 6485 times.
✗ Branch 9 not taken.
✗ 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 18 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
6485 MATCH_PER_STREAM_OPT(enc_stats_pre, str, enc_stats_pre, oc, st);
1198
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6485 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6485 if (enc_stats_pre &&
1199 (type == AVMEDIA_TYPE_VIDEO || type == AVMEDIA_TYPE_AUDIO)) {
1200 const char *format = "{fidx} {sidx} {n} {t}";
1201
1202 MATCH_PER_STREAM_OPT(enc_stats_pre_fmt, str, format, oc, st);
1203
1204 ret = enc_stats_init(ost, &ost->enc_stats_pre, 1, enc_stats_pre, format);
1205 if (ret < 0)
1206 goto fail;
1207 }
1208
1209
2/20
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✓ Branch 6 taken 6485 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 6485 times.
✗ Branch 9 not taken.
✗ 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 18 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
6485 MATCH_PER_STREAM_OPT(enc_stats_post, str, enc_stats_post, oc, st);
1210
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6485 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6485 if (enc_stats_post &&
1211 (type == AVMEDIA_TYPE_VIDEO || type == AVMEDIA_TYPE_AUDIO)) {
1212 const char *format = "{fidx} {sidx} {n} {t}";
1213
1214 MATCH_PER_STREAM_OPT(enc_stats_post_fmt, str, format, oc, st);
1215
1216 ret = enc_stats_init(ost, &ost->enc_stats_post, 0, enc_stats_post, format);
1217 if (ret < 0)
1218 goto fail;
1219 }
1220
1221
2/20
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✓ Branch 6 taken 6485 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 6485 times.
✗ Branch 9 not taken.
✗ 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 18 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
6485 MATCH_PER_STREAM_OPT(mux_stats, str, mux_stats, oc, st);
1222
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6485 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6485 if (mux_stats &&
1223 (type == AVMEDIA_TYPE_VIDEO || type == AVMEDIA_TYPE_AUDIO)) {
1224 const char *format = "{fidx} {sidx} {n} {t}";
1225
1226 MATCH_PER_STREAM_OPT(mux_stats_fmt, str, format, oc, st);
1227
1228 ret = enc_stats_init(ost, &ms->stats, 0, mux_stats, format);
1229 if (ret < 0)
1230 goto fail;
1231 }
1232
1233
4/20
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 1 times.
✓ Branch 6 taken 6485 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 6485 times.
✗ Branch 9 not taken.
✗ 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 18 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
6486 MATCH_PER_STREAM_OPT(enc_time_bases, str, enc_time_base, oc, st);
1234
3/4
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 6484 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
6485 if (enc_time_base && type == AVMEDIA_TYPE_SUBTITLE)
1235 av_log(ost, AV_LOG_WARNING,
1236 "-enc_time_base not supported for subtitles, ignoring\n");
1237
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 6484 times.
6485 else if (enc_time_base) {
1238 AVRational q;
1239
1240
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if (!strcmp(enc_time_base, "demux")) {
1241 1 q = (AVRational){ ENC_TIME_BASE_DEMUX, 0 };
1242 } else if (!strcmp(enc_time_base, "filter")) {
1243 q = (AVRational){ ENC_TIME_BASE_FILTER, 0 };
1244 } else {
1245 ret = av_parse_ratio(&q, enc_time_base, INT_MAX, 0, NULL);
1246 if (ret < 0 || q.den <= 0
1247 #if !FFMPEG_OPT_ENC_TIME_BASE_NUM
1248 || q.num < 0
1249 #endif
1250 ) {
1251 av_log(ost, AV_LOG_FATAL, "Invalid time base: %s\n", enc_time_base);
1252 ret = ret < 0 ? ret : AVERROR(EINVAL);
1253 goto fail;
1254 }
1255 #if FFMPEG_OPT_ENC_TIME_BASE_NUM
1256 if (q.num < 0)
1257 av_log(ost, AV_LOG_WARNING, "-enc_time_base -1 is deprecated,"
1258 " use -enc_timebase demux\n");
1259 #endif
1260 }
1261
1262 1 enc_tb = q;
1263 }
1264
1265 6485 threads_manual = !!av_dict_get(encoder_opts, "threads", NULL, 0);
1266
1267 6485 ret = av_opt_set_dict2(ost->enc_ctx, &encoder_opts, AV_OPT_SEARCH_CHILDREN);
1268
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6485 times.
6485 if (ret < 0) {
1269 av_log(ost, AV_LOG_ERROR, "Error applying encoder options: %s\n",
1270 av_err2str(ret));
1271 goto fail;
1272 }
1273
1274 6485 ret = check_avoptions(encoder_opts);
1275
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6485 times.
6485 if (ret < 0)
1276 goto fail;
1277
1278 // default to automatic thread count
1279
2/2
✓ Branch 0 taken 2651 times.
✓ Branch 1 taken 3834 times.
6485 if (!threads_manual)
1280 2651 ost->enc_ctx->thread_count = 0;
1281 } else {
1282 644 ret = filter_codec_opts(o->g->codec_opts, AV_CODEC_ID_NONE, oc, st,
1283 NULL, &encoder_opts,
1284 &mux->enc_opts_used);
1285
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 644 times.
644 if (ret < 0)
1286 goto fail;
1287 }
1288
1289
1290
2/2
✓ Branch 0 taken 1862 times.
✓ Branch 1 taken 5267 times.
7129 if (o->bitexact) {
1291 1862 ost->bitexact = 1;
1292
2/2
✓ Branch 0 taken 4731 times.
✓ Branch 1 taken 536 times.
5267 } else if (ost->enc_ctx) {
1293 4731 ost->bitexact = !!(ost->enc_ctx->flags & AV_CODEC_FLAG_BITEXACT);
1294 }
1295
1296
4/20
✓ Branch 1 taken 5 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 5 times.
✓ Branch 6 taken 7129 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 7129 times.
✗ Branch 9 not taken.
✗ 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 18 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
7134 MATCH_PER_STREAM_OPT(time_bases, str, time_base, oc, st);
1297
2/2
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 7124 times.
7129 if (time_base) {
1298 AVRational q;
1299
1/2
✓ Branch 1 taken 5 times.
✗ Branch 2 not taken.
5 if (av_parse_ratio(&q, time_base, INT_MAX, 0, NULL) < 0 ||
1300
2/4
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 5 times.
5 q.num <= 0 || q.den <= 0) {
1301 av_log(ost, AV_LOG_FATAL, "Invalid time base: %s\n", time_base);
1302 ret = AVERROR(EINVAL);
1303 goto fail;
1304 }
1305 5 st->time_base = q;
1306 }
1307
1308 7129 ms->max_frames = INT64_MAX;
1309
14/20
✓ Branch 1 taken 4819 times.
✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 4 times.
✓ Branch 5 taken 4823 times.
✓ Branch 6 taken 7129 times.
✓ Branch 7 taken 2141 times.
✓ Branch 8 taken 4988 times.
✓ Branch 9 taken 2141 times.
✗ Branch 10 not taken.
✓ Branch 11 taken 2141 times.
✗ Branch 12 not taken.
✓ Branch 13 taken 2141 times.
✗ Branch 14 not taken.
✓ Branch 15 taken 2141 times.
✗ Branch 16 not taken.
✓ Branch 18 taken 6423 times.
✓ Branch 19 taken 2141 times.
✓ Branch 20 taken 2141 times.
✗ Branch 21 not taken.
18375 MATCH_PER_STREAM_OPT(max_frames, i64, ms->max_frames, oc, st);
1310
2/2
✓ Branch 0 taken 4823 times.
✓ Branch 1 taken 7123 times.
11946 for (int i = 0; i < o->max_frames.nb_opt; i++) {
1311 4823 char *p = o->max_frames.opt[i].specifier;
1312
4/4
✓ Branch 0 taken 169 times.
✓ Branch 1 taken 4654 times.
✓ Branch 2 taken 6 times.
✓ Branch 3 taken 163 times.
4823 if (!*p && type != AVMEDIA_TYPE_VIDEO) {
1313 6 av_log(ost, AV_LOG_WARNING, "Applying unspecific -frames to non video streams, maybe you meant -vframes ?\n");
1314 6 break;
1315 }
1316 }
1317
1318 7129 ms->copy_prior_start = -1;
1319
2/20
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✓ Branch 6 taken 7129 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 7129 times.
✗ Branch 9 not taken.
✗ 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 18 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
7129 MATCH_PER_STREAM_OPT(copy_prior_start, i, ms->copy_prior_start, oc ,st);
1320
1321
6/20
✓ Branch 1 taken 132 times.
✓ Branch 2 taken 10 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 10 times.
✓ Branch 5 taken 142 times.
✓ Branch 6 taken 7129 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 7129 times.
✗ Branch 9 not taken.
✗ 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 18 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
7271 MATCH_PER_STREAM_OPT(bitstream_filters, str, bsfs, oc, st);
1322
3/4
✓ Branch 0 taken 132 times.
✓ Branch 1 taken 6997 times.
✓ Branch 2 taken 132 times.
✗ Branch 3 not taken.
7129 if (bsfs && *bsfs) {
1323 132 ret = av_bsf_list_parse_str(bsfs, &ms->bsf_ctx);
1324
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 132 times.
132 if (ret < 0) {
1325 av_log(ost, AV_LOG_ERROR, "Error parsing bitstream filter sequence '%s': %s\n", bsfs, av_err2str(ret));
1326 goto fail;
1327 }
1328 }
1329
1330
4/20
✓ Branch 1 taken 7 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 7 times.
✓ Branch 6 taken 7129 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 7129 times.
✗ Branch 9 not taken.
✗ 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 18 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
7136 MATCH_PER_STREAM_OPT(codec_tags, str, codec_tag, oc, st);
1331
2/2
✓ Branch 0 taken 7 times.
✓ Branch 1 taken 7122 times.
7129 if (codec_tag) {
1332 7 uint32_t tag = strtol(codec_tag, &next, 0);
1333
1/2
✓ Branch 0 taken 7 times.
✗ Branch 1 not taken.
7 if (*next) {
1334 7 uint8_t buf[4] = { 0 };
1335
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 7 times.
7 memcpy(buf, codec_tag, FFMIN(sizeof(buf), strlen(codec_tag)));
1336 7 tag = AV_RL32(buf);
1337 }
1338 7 ost->st->codecpar->codec_tag = tag;
1339 7 ost->par_in->codec_tag = tag;
1340
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 6 times.
7 if (ost->enc_ctx)
1341 1 ost->enc_ctx->codec_tag = tag;
1342 }
1343
1344
14/20
✓ Branch 1 taken 267 times.
✓ Branch 2 taken 56 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 56 times.
✓ Branch 5 taken 323 times.
✓ Branch 6 taken 7129 times.
✓ Branch 7 taken 1 times.
✓ Branch 8 taken 7128 times.
✓ Branch 9 taken 1 times.
✗ Branch 10 not taken.
✓ Branch 11 taken 1 times.
✗ Branch 12 not taken.
✓ Branch 13 taken 1 times.
✗ Branch 14 not taken.
✓ Branch 15 taken 1 times.
✗ Branch 16 not taken.
✓ Branch 18 taken 1 times.
✓ Branch 19 taken 1 times.
✓ Branch 20 taken 1 times.
✗ Branch 21 not taken.
7453 MATCH_PER_STREAM_OPT(qscale, dbl, qscale, oc, st);
1345
4/4
✓ Branch 0 taken 6485 times.
✓ Branch 1 taken 644 times.
✓ Branch 2 taken 266 times.
✓ Branch 3 taken 6219 times.
7129 if (ost->enc_ctx && qscale >= 0) {
1346 266 ost->enc_ctx->flags |= AV_CODEC_FLAG_QSCALE;
1347 266 ost->enc_ctx->global_quality = FF_QP2LAMBDA * qscale;
1348 }
1349
1350
2/2
✓ Branch 0 taken 7128 times.
✓ Branch 1 taken 1 times.
7129 if (ms->sch_idx >= 0) {
1351 7128 int max_muxing_queue_size = 128;
1352 7128 int muxing_queue_data_threshold = 50 * 1024 * 1024;
1353
1354
4/20
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 2 times.
✓ Branch 6 taken 7128 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 7128 times.
✗ Branch 9 not taken.
✗ 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 18 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
7130 MATCH_PER_STREAM_OPT(max_muxing_queue_size, i, max_muxing_queue_size, oc, st);
1355
2/20
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✓ Branch 6 taken 7128 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 7128 times.
✗ Branch 9 not taken.
✗ 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 18 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
7128 MATCH_PER_STREAM_OPT(muxing_queue_data_threshold, i, muxing_queue_data_threshold, oc, st);
1356
1357 7128 sch_mux_stream_buffering(mux->sch, mux->sch_idx, ms->sch_idx,
1358 max_muxing_queue_size, muxing_queue_data_threshold);
1359 }
1360
1361
4/20
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 1 times.
✓ Branch 6 taken 7129 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 7129 times.
✗ Branch 9 not taken.
✗ 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 18 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
7130 MATCH_PER_STREAM_OPT(bits_per_raw_sample, i, ost->bits_per_raw_sample,
1362 oc, st);
1363
1364
6/20
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✓ Branch 5 taken 2 times.
✓ Branch 6 taken 7129 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 7129 times.
✗ Branch 9 not taken.
✗ 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 18 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
7131 MATCH_PER_STREAM_OPT(fix_sub_duration_heartbeat, i, ost->fix_sub_duration_heartbeat,
1365 oc, st);
1366
1367
4/4
✓ Branch 0 taken 2756 times.
✓ Branch 1 taken 4373 times.
✓ Branch 2 taken 2654 times.
✓ Branch 3 taken 102 times.
7129 if (oc->oformat->flags & AVFMT_GLOBALHEADER && ost->enc_ctx)
1368 2654 ost->enc_ctx->flags |= AV_CODEC_FLAG_GLOBAL_HEADER;
1369
1370
2/20
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✓ Branch 6 taken 7129 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 7129 times.
✗ Branch 9 not taken.
✗ 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 18 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
7129 MATCH_PER_STREAM_OPT(copy_initial_nonkeyframes, i,
1371 ms->copy_initial_nonkeyframes, oc, st);
1372
1373
4/4
✓ Branch 0 taken 5535 times.
✓ Branch 1 taken 1512 times.
✓ Branch 2 taken 71 times.
✓ Branch 3 taken 11 times.
7129 switch (type) {
1374 5535 case AVMEDIA_TYPE_VIDEO: ret = new_stream_video (mux, o, ost, &keep_pix_fmt, &vsync_method); break;
1375 1512 case AVMEDIA_TYPE_AUDIO: ret = new_stream_audio (mux, o, ost); break;
1376 71 case AVMEDIA_TYPE_SUBTITLE: ret = new_stream_subtitle (mux, o, ost); break;
1377 }
1378
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 7129 times.
7129 if (ret < 0)
1379 goto fail;
1380
1381
4/4
✓ Branch 0 taken 1594 times.
✓ Branch 1 taken 5535 times.
✓ Branch 2 taken 1512 times.
✓ Branch 3 taken 82 times.
7129 if (type == AVMEDIA_TYPE_VIDEO || type == AVMEDIA_TYPE_AUDIO) {
1382 7047 ret = ost_get_filters(o, oc, ost, &filters);
1383
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 7047 times.
7047 if (ret < 0)
1384 goto fail;
1385 }
1386
1387
4/4
✓ Branch 0 taken 6485 times.
✓ Branch 1 taken 644 times.
✓ Branch 2 taken 1285 times.
✓ Branch 3 taken 5200 times.
7129 if (ost->enc &&
1388
2/2
✓ Branch 0 taken 1247 times.
✓ Branch 1 taken 38 times.
7732 (type == AVMEDIA_TYPE_VIDEO || type == AVMEDIA_TYPE_AUDIO)) {
1389 char name[16];
1390 25788 OutputFilterOptions opts = {
1391 .enc = enc,
1392 .name = name,
1393 .format = (type == AVMEDIA_TYPE_VIDEO) ?
1394 6447 ost->enc_ctx->pix_fmt : ost->enc_ctx->sample_fmt,
1395 6447 .width = ost->enc_ctx->width,
1396 6447 .height = ost->enc_ctx->height,
1397 .vsync_method = vsync_method,
1398 6447 .sample_rate = ost->enc_ctx->sample_rate,
1399 6447 .ch_layout = ost->enc_ctx->ch_layout,
1400 6447 .sws_opts = o->g->sws_dict,
1401 6447 .swr_opts = o->g->swr_opts,
1402 .output_tb = enc_tb,
1403 6447 .trim_start_us = mux->of.start_time,
1404 6447 .trim_duration_us = mux->of.recording_time,
1405 6447 .ts_offset = mux->of.start_time == AV_NOPTS_VALUE ?
1406
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 6446 times.
6447 0 : mux->of.start_time,
1407 12894 .flags = OFILTER_FLAG_DISABLE_CONVERT * !!keep_pix_fmt |
1408
3/4
✓ Branch 0 taken 6447 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5200 times.
✓ Branch 3 taken 1247 times.
12894 OFILTER_FLAG_AUTOSCALE * !!autoscale |
1409
2/2
✓ Branch 1 taken 59 times.
✓ Branch 2 taken 6388 times.
6447 OFILTER_FLAG_AUDIO_24BIT * !!(av_get_exact_bits_per_sample(ost->enc_ctx->codec_id) == 24),
1410 };
1411
1412 6447 snprintf(name, sizeof(name), "#%d:%d", mux->of.index, ost->index);
1413
1414 // MJPEG encoder exports a full list of supported pixel formats,
1415 // but the full-range ones are experimental-only.
1416 // Restrict the auto-conversion list unless -strict experimental
1417 // has been specified.
1418
2/2
✓ Branch 0 taken 27 times.
✓ Branch 1 taken 6420 times.
6447 if (!strcmp(enc->name, "mjpeg")) {
1419 // FIXME: YUV420P etc. are actually supported with full color range,
1420 // yet the latter information isn't available here.
1421 static const enum AVPixelFormat mjpeg_formats[] =
1422 { AV_PIX_FMT_YUVJ420P, AV_PIX_FMT_YUVJ422P, AV_PIX_FMT_YUVJ444P,
1423 AV_PIX_FMT_NONE };
1424
1425
1/2
✓ Branch 0 taken 27 times.
✗ Branch 1 not taken.
27 if (ost->enc_ctx->strict_std_compliance > FF_COMPLIANCE_UNOFFICIAL)
1426 27 opts.pix_fmts = mjpeg_formats;
1427 }
1428
1429
2/2
✓ Branch 0 taken 3834 times.
✓ Branch 1 taken 2613 times.
6447 if (threads_manual) {
1430 3834 ret = av_opt_get(ost->enc_ctx, "threads", 0, (uint8_t**)&opts.nb_threads);
1431
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3834 times.
3834 if (ret < 0)
1432 goto fail;
1433 }
1434
1435
2/2
✓ Branch 0 taken 168 times.
✓ Branch 1 taken 6279 times.
6447 if (ofilter) {
1436 168 ost->filter = ofilter;
1437 168 ret = ofilter_bind_ost(ofilter, ost, ms->sch_idx_enc, &opts);
1438 } else {
1439 6279 ret = init_simple_filtergraph(ost->ist, ost, filters,
1440 6279 mux->sch, ms->sch_idx_enc, &opts);
1441 }
1442 6447 av_freep(&opts.nb_threads);
1443
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6447 times.
6447 if (ret < 0)
1444 goto fail;
1445
1446 6447 ret = sch_connect(mux->sch, SCH_ENC(ms->sch_idx_enc),
1447 6447 SCH_MSTREAM(mux->sch_idx, ms->sch_idx));
1448
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6447 times.
6447 if (ret < 0)
1449 goto fail;
1450
2/2
✓ Branch 0 taken 681 times.
✓ Branch 1 taken 1 times.
682 } else if (ost->ist) {
1451 681 int sched_idx = ist_output_add(ost->ist, ost);
1452
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 681 times.
681 if (sched_idx < 0) {
1453 av_log(ost, AV_LOG_ERROR,
1454 "Error binding an input stream\n");
1455 ret = sched_idx;
1456 goto fail;
1457 }
1458 681 ms->sch_idx_src = sched_idx;
1459
1460
2/2
✓ Branch 0 taken 38 times.
✓ Branch 1 taken 643 times.
681 if (ost->enc) {
1461 38 ret = sch_connect(mux->sch, SCH_DEC(sched_idx),
1462 38 SCH_ENC(ms->sch_idx_enc));
1463
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 38 times.
38 if (ret < 0)
1464 goto fail;
1465
1466 38 ret = sch_connect(mux->sch, SCH_ENC(ms->sch_idx_enc),
1467 38 SCH_MSTREAM(mux->sch_idx, ms->sch_idx));
1468
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 38 times.
38 if (ret < 0)
1469 goto fail;
1470 } else {
1471 643 ret = sch_connect(mux->sch, SCH_DSTREAM(ost->ist->file->index, sched_idx),
1472 643 SCH_MSTREAM(ost->file->index, ms->sch_idx));
1473
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 643 times.
643 if (ret < 0)
1474 goto fail;
1475 }
1476 }
1477
1478
4/4
✓ Branch 0 taken 6960 times.
✓ Branch 1 taken 169 times.
✓ Branch 2 taken 643 times.
✓ Branch 3 taken 6317 times.
7129 if (ost->ist && !ost->enc) {
1479 643 ret = streamcopy_init(mux, ost, &encoder_opts);
1480
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 643 times.
643 if (ret < 0)
1481 goto fail;
1482 }
1483
1484 // copy estimated duration as a hint to the muxer
1485
4/4
✓ Branch 0 taken 6960 times.
✓ Branch 1 taken 169 times.
✓ Branch 2 taken 5444 times.
✓ Branch 3 taken 1516 times.
7129 if (ost->ist && ost->ist->st->duration > 0) {
1486 5444 ms->stream_duration = ist->st->duration;
1487 5444 ms->stream_duration_tb = ist->st->time_base;
1488 }
1489
1490
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 7128 times.
7129 if (post)
1491 1 *post = ost;
1492
1493 7129 ret = 0;
1494
1495 7129 fail:
1496 7129 av_dict_free(&encoder_opts);
1497
1498 7129 return ret;
1499 }
1500
1501 6376 static int map_auto_video(Muxer *mux, const OptionsContext *o)
1502 {
1503 6376 AVFormatContext *oc = mux->fc;
1504 6376 InputStream *best_ist = NULL;
1505 6376 int best_score = 0;
1506 int qcr;
1507
1508 /* video: highest resolution */
1509
2/2
✓ Branch 1 taken 732 times.
✓ Branch 2 taken 5644 times.
6376 if (av_guess_codec(oc->oformat, NULL, oc->url, NULL, AVMEDIA_TYPE_VIDEO) == AV_CODEC_ID_NONE)
1510 732 return 0;
1511
1512 5644 qcr = avformat_query_codec(oc->oformat, oc->oformat->video_codec, 0);
1513
2/2
✓ Branch 0 taken 5685 times.
✓ Branch 1 taken 5644 times.
11329 for (int j = 0; j < nb_input_files; j++) {
1514 5685 InputFile *ifile = input_files[j];
1515 5685 InputStream *file_best_ist = NULL;
1516 5685 int file_best_score = 0;
1517
2/2
✓ Branch 0 taken 5963 times.
✓ Branch 1 taken 5685 times.
11648 for (int i = 0; i < ifile->nb_streams; i++) {
1518 5963 InputStream *ist = ifile->streams[i];
1519 int score;
1520
1521
2/2
✓ Branch 0 taken 5962 times.
✓ Branch 1 taken 1 times.
5963 if (ist->user_set_discard == AVDISCARD_ALL ||
1522
2/2
✓ Branch 0 taken 632 times.
✓ Branch 1 taken 5330 times.
5962 ist->st->codecpar->codec_type != AVMEDIA_TYPE_VIDEO)
1523 633 continue;
1524
1525 10660 score = ist->st->codecpar->width * ist->st->codecpar->height
1526
2/2
✓ Branch 0 taken 5328 times.
✓ Branch 1 taken 2 times.
5330 + 100000000 * !!(ist->st->event_flags & AVSTREAM_EVENT_FLAG_NEW_PACKETS)
1527
2/2
✓ Branch 0 taken 512 times.
✓ Branch 1 taken 4818 times.
5330 + 5000000*!!(ist->st->disposition & AV_DISPOSITION_DEFAULT);
1528
3/4
✓ Branch 0 taken 5330 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✓ Branch 3 taken 5321 times.
5330 if((qcr!=MKTAG('A', 'P', 'I', 'C')) && (ist->st->disposition & AV_DISPOSITION_ATTACHED_PIC))
1529 9 score = 1;
1530
1531
2/2
✓ Branch 0 taken 5329 times.
✓ Branch 1 taken 1 times.
5330 if (score > file_best_score) {
1532
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 5329 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
5329 if((qcr==MKTAG('A', 'P', 'I', 'C')) && !(ist->st->disposition & AV_DISPOSITION_ATTACHED_PIC))
1533 continue;
1534 5329 file_best_score = score;
1535 5329 file_best_ist = ist;
1536 }
1537 }
1538
2/2
✓ Branch 0 taken 5329 times.
✓ Branch 1 taken 356 times.
5685 if (file_best_ist) {
1539
1/2
✓ Branch 0 taken 5329 times.
✗ Branch 1 not taken.
5329 if((qcr == MKTAG('A', 'P', 'I', 'C')) ||
1540
2/2
✓ Branch 0 taken 5321 times.
✓ Branch 1 taken 8 times.
5329 !(file_best_ist->st->disposition & AV_DISPOSITION_ATTACHED_PIC))
1541
2/2
✓ Branch 0 taken 512 times.
✓ Branch 1 taken 4809 times.
5321 file_best_score -= 5000000*!!(file_best_ist->st->disposition & AV_DISPOSITION_DEFAULT);
1542
1/2
✓ Branch 0 taken 5329 times.
✗ Branch 1 not taken.
5329 if (file_best_score > best_score) {
1543 5329 best_score = file_best_score;
1544 5329 best_ist = file_best_ist;
1545 }
1546 }
1547 }
1548
2/2
✓ Branch 0 taken 5329 times.
✓ Branch 1 taken 315 times.
5644 if (best_ist)
1549 5329 return ost_add(mux, o, AVMEDIA_TYPE_VIDEO, best_ist, NULL, NULL);
1550
1551 315 return 0;
1552 }
1553
1554 6469 static int map_auto_audio(Muxer *mux, const OptionsContext *o)
1555 {
1556 6469 AVFormatContext *oc = mux->fc;
1557 6469 InputStream *best_ist = NULL;
1558 6469 int best_score = 0;
1559
1560 /* audio: most channels */
1561
2/2
✓ Branch 1 taken 842 times.
✓ Branch 2 taken 5627 times.
6469 if (av_guess_codec(oc->oformat, NULL, oc->url, NULL, AVMEDIA_TYPE_AUDIO) == AV_CODEC_ID_NONE)
1562 842 return 0;
1563
1564
2/2
✓ Branch 0 taken 5626 times.
✓ Branch 1 taken 5627 times.
11253 for (int j = 0; j < nb_input_files; j++) {
1565 5626 InputFile *ifile = input_files[j];
1566 5626 InputStream *file_best_ist = NULL;
1567 5626 int file_best_score = 0;
1568
2/2
✓ Branch 0 taken 5830 times.
✓ Branch 1 taken 5626 times.
11456 for (int i = 0; i < ifile->nb_streams; i++) {
1569 5830 InputStream *ist = ifile->streams[i];
1570 int score;
1571
1572
2/2
✓ Branch 0 taken 5829 times.
✓ Branch 1 taken 1 times.
5830 if (ist->user_set_discard == AVDISCARD_ALL ||
1573
2/2
✓ Branch 0 taken 4533 times.
✓ Branch 1 taken 1296 times.
5829 ist->st->codecpar->codec_type != AVMEDIA_TYPE_AUDIO)
1574 4534 continue;
1575
1576 2592 score = ist->st->codecpar->ch_layout.nb_channels
1577
2/2
✓ Branch 0 taken 1295 times.
✓ Branch 1 taken 1 times.
1296 + 100000000 * !!(ist->st->event_flags & AVSTREAM_EVENT_FLAG_NEW_PACKETS)
1578
2/2
✓ Branch 0 taken 174 times.
✓ Branch 1 taken 1122 times.
1296 + 5000000*!!(ist->st->disposition & AV_DISPOSITION_DEFAULT);
1579
2/2
✓ Branch 0 taken 1286 times.
✓ Branch 1 taken 10 times.
1296 if (score > file_best_score) {
1580 1286 file_best_score = score;
1581 1286 file_best_ist = ist;
1582 }
1583 }
1584
2/2
✓ Branch 0 taken 1286 times.
✓ Branch 1 taken 4340 times.
5626 if (file_best_ist) {
1585
2/2
✓ Branch 0 taken 174 times.
✓ Branch 1 taken 1112 times.
1286 file_best_score -= 5000000*!!(file_best_ist->st->disposition & AV_DISPOSITION_DEFAULT);
1586
1/2
✓ Branch 0 taken 1286 times.
✗ Branch 1 not taken.
1286 if (file_best_score > best_score) {
1587 1286 best_score = file_best_score;
1588 1286 best_ist = file_best_ist;
1589 }
1590 }
1591 }
1592
2/2
✓ Branch 0 taken 1286 times.
✓ Branch 1 taken 4341 times.
5627 if (best_ist)
1593 1286 return ost_add(mux, o, AVMEDIA_TYPE_AUDIO, best_ist, NULL, NULL);
1594
1595 4341 return 0;
1596 }
1597
1598 6626 static int map_auto_subtitle(Muxer *mux, const OptionsContext *o)
1599 {
1600 6626 AVFormatContext *oc = mux->fc;
1601 6626 const char *subtitle_codec_name = NULL;
1602
1603 /* subtitles: pick first */
1604 6626 subtitle_codec_name = opt_match_per_type_str(&o->codec_names, 's');
1605
4/4
✓ Branch 1 taken 6566 times.
✓ Branch 2 taken 60 times.
✓ Branch 3 taken 6559 times.
✓ Branch 4 taken 7 times.
6626 if (!avcodec_find_encoder(oc->oformat->subtitle_codec) && !subtitle_codec_name)
1606 6559 return 0;
1607
1608
2/2
✓ Branch 2 taken 81 times.
✓ Branch 3 taken 19 times.
100 for (InputStream *ist = ist_iter(NULL); ist; ist = ist_iter(ist))
1609
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 33 times.
81 if (ist->st->codecpar->codec_type == AVMEDIA_TYPE_SUBTITLE) {
1610 AVCodecDescriptor const *input_descriptor =
1611 48 avcodec_descriptor_get(ist->st->codecpar->codec_id);
1612 48 AVCodecDescriptor const *output_descriptor = NULL;
1613 AVCodec const *output_codec =
1614 48 avcodec_find_encoder(oc->oformat->subtitle_codec);
1615 48 int input_props = 0, output_props = 0;
1616
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 48 times.
48 if (ist->user_set_discard == AVDISCARD_ALL)
1617 continue;
1618
2/2
✓ Branch 0 taken 41 times.
✓ Branch 1 taken 7 times.
48 if (output_codec)
1619 41 output_descriptor = avcodec_descriptor_get(output_codec->id);
1620
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if (input_descriptor)
1621 48 input_props = input_descriptor->props & (AV_CODEC_PROP_TEXT_SUB | AV_CODEC_PROP_BITMAP_SUB);
1622
2/2
✓ Branch 0 taken 41 times.
✓ Branch 1 taken 7 times.
48 if (output_descriptor)
1623 41 output_props = output_descriptor->props & (AV_CODEC_PROP_TEXT_SUB | AV_CODEC_PROP_BITMAP_SUB);
1624
2/2
✓ Branch 0 taken 32 times.
✓ Branch 1 taken 16 times.
48 if (subtitle_codec_name ||
1625
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 32 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
32 input_props & output_props ||
1626 // Map dvb teletext which has neither property to any output subtitle encoder
1627 input_descriptor && output_descriptor &&
1628 (!input_descriptor->props ||
1629 !output_descriptor->props)) {
1630 48 return ost_add(mux, o, AVMEDIA_TYPE_SUBTITLE, ist, NULL, NULL);
1631 }
1632 }
1633
1634 19 return 0;
1635 }
1636
1637 6627 static int map_auto_data(Muxer *mux, const OptionsContext *o)
1638 {
1639 6627 AVFormatContext *oc = mux->fc;
1640 /* Data only if codec id match */
1641 6627 enum AVCodecID codec_id = av_guess_codec(oc->oformat, NULL, oc->url, NULL, AVMEDIA_TYPE_DATA);
1642
1643
1/2
✓ Branch 0 taken 6627 times.
✗ Branch 1 not taken.
6627 if (codec_id == AV_CODEC_ID_NONE)
1644 6627 return 0;
1645
1646 for (InputStream *ist = ist_iter(NULL); ist; ist = ist_iter(ist)) {
1647 if (ist->user_set_discard == AVDISCARD_ALL)
1648 continue;
1649 if (ist->st->codecpar->codec_type == AVMEDIA_TYPE_DATA &&
1650 ist->st->codecpar->codec_id == codec_id) {
1651 int ret = ost_add(mux, o, AVMEDIA_TYPE_DATA, ist, NULL, NULL);
1652 if (ret < 0)
1653 return ret;
1654 }
1655 }
1656
1657 return 0;
1658 }
1659
1660 351 static int map_manual(Muxer *mux, const OptionsContext *o, const StreamMap *map)
1661 {
1662 InputStream *ist;
1663 int ret;
1664
1665
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 351 times.
351 if (map->disabled)
1666 return 0;
1667
1668
2/2
✓ Branch 0 taken 54 times.
✓ Branch 1 taken 297 times.
351 if (map->linklabel) {
1669 FilterGraph *fg;
1670 54 OutputFilter *ofilter = NULL;
1671 int j, k;
1672
1673
1/2
✓ Branch 0 taken 54 times.
✗ Branch 1 not taken.
54 for (j = 0; j < nb_filtergraphs; j++) {
1674 54 fg = filtergraphs[j];
1675
1/2
✓ Branch 0 taken 176 times.
✗ Branch 1 not taken.
176 for (k = 0; k < fg->nb_outputs; k++) {
1676 176 const char *linklabel = fg->outputs[k]->linklabel;
1677
3/4
✓ Branch 0 taken 54 times.
✓ Branch 1 taken 122 times.
✓ Branch 2 taken 54 times.
✗ Branch 3 not taken.
176 if (linklabel && !strcmp(linklabel, map->linklabel)) {
1678 54 ofilter = fg->outputs[k];
1679 54 goto loop_end;
1680 }
1681 }
1682 }
1683 loop_end:
1684
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 54 times.
54 if (!ofilter) {
1685 av_log(mux, AV_LOG_FATAL, "Output with label '%s' does not exist "
1686 "in any defined filter graph, or was already used elsewhere.\n", map->linklabel);
1687 return AVERROR(EINVAL);
1688 }
1689
1690 54 av_log(mux, AV_LOG_VERBOSE, "Creating output stream from an explicitly "
1691 54 "mapped complex filtergraph %d, output [%s]\n", fg->index, map->linklabel);
1692
1693 54 ret = ost_add(mux, o, ofilter->type, NULL, ofilter, NULL);
1694
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 54 times.
54 if (ret < 0)
1695 return ret;
1696 } else {
1697 297 ist = input_files[map->file_index]->streams[map->stream_index];
1698
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 297 times.
297 if (ist->user_set_discard == AVDISCARD_ALL) {
1699 av_log(mux, AV_LOG_FATAL, "Stream #%d:%d is disabled and cannot be mapped.\n",
1700 map->file_index, map->stream_index);
1701 return AVERROR(EINVAL);
1702 }
1703
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 297 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
297 if(o->subtitle_disable && ist->st->codecpar->codec_type == AVMEDIA_TYPE_SUBTITLE)
1704 return 0;
1705
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 297 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
297 if(o-> audio_disable && ist->st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO)
1706 return 0;
1707
3/4
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 296 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
297 if(o-> video_disable && ist->st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO)
1708 return 0;
1709
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 297 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
297 if(o-> data_disable && ist->st->codecpar->codec_type == AVMEDIA_TYPE_DATA)
1710 return 0;
1711
1712
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 297 times.
297 if (ist->st->codecpar->codec_type == AVMEDIA_TYPE_UNKNOWN &&
1713 !copy_unknown_streams) {
1714 av_log(mux, ignore_unknown_streams ? AV_LOG_WARNING : AV_LOG_FATAL,
1715 "Cannot map stream #%d:%d - unsupported type.\n",
1716 map->file_index, map->stream_index);
1717 if (!ignore_unknown_streams) {
1718 av_log(mux, AV_LOG_FATAL,
1719 "If you want unsupported types ignored instead "
1720 "of failing, please use the -ignore_unknown option\n"
1721 "If you want them copied, please use -copy_unknown\n");
1722 return AVERROR(EINVAL);
1723 }
1724 return 0;
1725 }
1726
1727 297 ret = ost_add(mux, o, ist->st->codecpar->codec_type, ist, NULL, NULL);
1728
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 297 times.
297 if (ret < 0)
1729 return ret;
1730 }
1731
1732 351 return 0;
1733 }
1734
1735 6776 static int of_add_attachments(Muxer *mux, const OptionsContext *o)
1736 {
1737 OutputStream *ost;
1738 int err;
1739
1740
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 6776 times.
6777 for (int i = 0; i < o->nb_attachments; i++) {
1741 AVIOContext *pb;
1742 uint8_t *attachment;
1743 char *attachment_filename;
1744 const char *p;
1745 int64_t len;
1746
1747
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) {
1748 av_log(mux, AV_LOG_FATAL, "Could not open attachment file %s.\n",
1749 o->attachments[i]);
1750 return err;
1751 }
1752
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 if ((len = avio_size(pb)) <= 0) {
1753 av_log(mux, AV_LOG_FATAL, "Could not get size of the attachment %s.\n",
1754 o->attachments[i]);
1755 err = len ? len : AVERROR_INVALIDDATA;
1756 goto read_fail;
1757 }
1758
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 if (len > INT_MAX - AV_INPUT_BUFFER_PADDING_SIZE) {
1759 av_log(mux, AV_LOG_FATAL, "Attachment %s too large.\n",
1760 o->attachments[i]);
1761 err = AVERROR(ERANGE);
1762 goto read_fail;
1763 }
1764
1765 1 attachment = av_malloc(len + AV_INPUT_BUFFER_PADDING_SIZE);
1766
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 if (!attachment) {
1767 err = AVERROR(ENOMEM);
1768 goto read_fail;
1769 }
1770
1771 1 err = avio_read(pb, attachment, len);
1772
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 if (err < 0)
1773 av_log(mux, AV_LOG_FATAL, "Error reading attachment file %s: %s\n",
1774 o->attachments[i], av_err2str(err));
1775
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 else if (err != len) {
1776 av_log(mux, AV_LOG_FATAL, "Could not read all %"PRId64" bytes for "
1777 "attachment file %s\n", len, o->attachments[i]);
1778 err = AVERROR(EIO);
1779 }
1780
1781 1 read_fail:
1782 1 avio_closep(&pb);
1783
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 if (err < 0)
1784 return err;
1785
1786 1 memset(attachment + len, 0, AV_INPUT_BUFFER_PADDING_SIZE);
1787
1788 1 av_log(mux, AV_LOG_VERBOSE, "Creating attachment stream from file %s\n",
1789 1 o->attachments[i]);
1790
1791 1 attachment_filename = av_strdup(o->attachments[i]);
1792
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 if (!attachment_filename) {
1793 av_free(attachment);
1794 return AVERROR(ENOMEM);
1795 }
1796
1797 1 err = ost_add(mux, o, AVMEDIA_TYPE_ATTACHMENT, NULL, NULL, &ost);
1798
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 if (err < 0) {
1799 av_free(attachment_filename);
1800 av_freep(&attachment);
1801 return err;
1802 }
1803
1804 1 ost->attachment_filename = attachment_filename;
1805 1 ost->par_in->extradata = attachment;
1806 1 ost->par_in->extradata_size = len;
1807
1808 1 p = strrchr(o->attachments[i], '/');
1809
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);
1810 }
1811
1812 6776 return 0;
1813 }
1814
1815 6776 static int create_streams(Muxer *mux, const OptionsContext *o)
1816 {
1817 static int (* const map_func[])(Muxer *mux, const OptionsContext *o) = {
1818 [AVMEDIA_TYPE_VIDEO] = map_auto_video,
1819 [AVMEDIA_TYPE_AUDIO] = map_auto_audio,
1820 [AVMEDIA_TYPE_SUBTITLE] = map_auto_subtitle,
1821 [AVMEDIA_TYPE_DATA] = map_auto_data,
1822 };
1823
1824 6776 AVFormatContext *oc = mux->fc;
1825
1826 6776 int auto_disable =
1827 6776 o->video_disable * (1 << AVMEDIA_TYPE_VIDEO) |
1828 6776 o->audio_disable * (1 << AVMEDIA_TYPE_AUDIO) |
1829 6776 o->subtitle_disable * (1 << AVMEDIA_TYPE_SUBTITLE) |
1830 6776 o->data_disable * (1 << AVMEDIA_TYPE_DATA);
1831
1832 int ret;
1833
1834 /* create streams for all unlabeled output pads */
1835
2/2
✓ Branch 0 taken 119 times.
✓ Branch 1 taken 6776 times.
6895 for (int i = 0; i < nb_filtergraphs; i++) {
1836 119 FilterGraph *fg = filtergraphs[i];
1837
2/2
✓ Branch 0 taken 169 times.
✓ Branch 1 taken 119 times.
288 for (int j = 0; j < fg->nb_outputs; j++) {
1838 169 OutputFilter *ofilter = fg->outputs[j];
1839
1840
3/4
✓ Branch 0 taken 114 times.
✓ Branch 1 taken 55 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 114 times.
169 if (ofilter->linklabel || ofilter->bound)
1841 55 continue;
1842
1843 114 auto_disable |= 1 << ofilter->type;
1844
1845 114 av_log(mux, AV_LOG_VERBOSE, "Creating output stream from unlabeled "
1846 "output of complex filtergraph %d.", fg->index);
1847
1/2
✓ Branch 0 taken 114 times.
✗ Branch 1 not taken.
114 if (!o->nb_stream_maps)
1848 114 av_log(mux, AV_LOG_VERBOSE, " This overrides automatic %s mapping.",
1849 av_get_media_type_string(ofilter->type));
1850 114 av_log(mux, AV_LOG_VERBOSE, "\n");
1851
1852 114 ret = ost_add(mux, o, ofilter->type, NULL, ofilter, NULL);
1853
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 114 times.
114 if (ret < 0)
1854 return ret;
1855 }
1856 }
1857
1858
2/2
✓ Branch 0 taken 6627 times.
✓ Branch 1 taken 149 times.
6776 if (!o->nb_stream_maps) {
1859 6627 av_log(mux, AV_LOG_VERBOSE, "No explicit maps, mapping streams automatically...\n");
1860
1861 /* pick the "best" stream of each type */
1862
2/2
✓ Branch 0 taken 26508 times.
✓ Branch 1 taken 6627 times.
33135 for (int i = 0; i < FF_ARRAY_ELEMS(map_func); i++) {
1863
3/4
✓ Branch 0 taken 26508 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 410 times.
✓ Branch 3 taken 26098 times.
26508 if (!map_func[i] || auto_disable & (1 << i))
1864 410 continue;
1865 26098 ret = map_func[i](mux, o);
1866
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 26098 times.
26098 if (ret < 0)
1867 return ret;
1868 }
1869 } else {
1870 149 av_log(mux, AV_LOG_VERBOSE, "Adding streams from explicit maps...\n");
1871
1872
2/2
✓ Branch 0 taken 351 times.
✓ Branch 1 taken 149 times.
500 for (int i = 0; i < o->nb_stream_maps; i++) {
1873 351 ret = map_manual(mux, o, &o->stream_maps[i]);
1874
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 351 times.
351 if (ret < 0)
1875 return ret;
1876 }
1877 }
1878
1879 6776 ret = of_add_attachments(mux, o);
1880
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6776 times.
6776 if (ret < 0)
1881 return ret;
1882
1883 // setup fix_sub_duration_heartbeat mappings
1884
2/2
✓ Branch 0 taken 7129 times.
✓ Branch 1 taken 6776 times.
13905 for (unsigned i = 0; i < oc->nb_streams; i++) {
1885 7129 MuxStream *src = ms_from_ost(mux->of.streams[i]);
1886
1887
2/2
✓ Branch 0 taken 7128 times.
✓ Branch 1 taken 1 times.
7129 if (!src->ost.fix_sub_duration_heartbeat)
1888 7128 continue;
1889
1890
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 1 times.
3 for (unsigned j = 0; j < oc->nb_streams; j++) {
1891 2 MuxStream *dst = ms_from_ost(mux->of.streams[j]);
1892
1893
3/4
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
2 if (src == dst || dst->ost.type != AVMEDIA_TYPE_SUBTITLE ||
1894
3/6
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 1 times.
1 !dst->ost.enc || !dst->ost.ist || !dst->ost.ist->fix_sub_duration)
1895 1 continue;
1896
1897 1 ret = sch_mux_sub_heartbeat_add(mux->sch, mux->sch_idx, src->sch_idx,
1898 1 dst->sch_idx_src);
1899
1900 }
1901 }
1902
1903 // handle -apad
1904
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 6772 times.
6776 if (o->shortest) {
1905 4 int have_video = 0;
1906
1907
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 for (unsigned i = 0; i < mux->of.nb_streams; i++)
1908
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 if (mux->of.streams[i]->type == AVMEDIA_TYPE_VIDEO) {
1909 4 have_video = 1;
1910 4 break;
1911 }
1912
1913
3/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 8 times.
✓ Branch 3 taken 4 times.
12 for (unsigned i = 0; have_video && i < mux->of.nb_streams; i++) {
1914 8 MuxStream *ms = ms_from_ost(mux->of.streams[i]);
1915 8 OutputFilter *ofilter = ms->ost.filter;
1916
1917
3/6
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 5 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 3 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
8 if (ms->ost.type != AVMEDIA_TYPE_AUDIO || !ms->apad || !ofilter)
1918 8 continue;
1919
1920 ofilter->apad = av_strdup(ms->apad);
1921 if (!ofilter->apad)
1922 return AVERROR(ENOMEM);
1923 }
1924 }
1925
2/2
✓ Branch 0 taken 7129 times.
✓ Branch 1 taken 6776 times.
13905 for (unsigned i = 0; i < mux->of.nb_streams; i++) {
1926 7129 MuxStream *ms = ms_from_ost(mux->of.streams[i]);
1927 7129 ms->apad = NULL;
1928 }
1929
1930
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6776 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6776 if (!oc->nb_streams && !(oc->oformat->flags & AVFMT_NOSTREAMS)) {
1931 av_dump_format(oc, nb_output_files - 1, oc->url, 1);
1932 av_log(mux, AV_LOG_ERROR, "Output file does not contain any stream\n");
1933 return AVERROR(EINVAL);
1934 }
1935
1936 6776 return 0;
1937 }
1938
1939 6776 static int setup_sync_queues(Muxer *mux, AVFormatContext *oc,
1940 int64_t buf_size_us, int shortest)
1941 {
1942 6776 OutputFile *of = &mux->of;
1943 6776 int