History

fftools/ffmpeg: use new stream specifier API in opt_match_per_stream*()

Removes a lot of error checking code, as matching cannot fail.

Anton Khirnov committed 2 years ago

Commit d1bdd891 parent 46cbe4a6 files · +105 −242Browse files

Unified · Split

6 files
  1. fftools/cmdutils.c +8 −0
  2. fftools/cmdutils.h +5 −1
  3. fftools/ffmpeg.h +8 −8
  4. fftools/ffmpeg_demux.c +20 −67
  5. fftools/ffmpeg_mux_init.c +50 −148
  6. fftools/ffmpeg_opt.c +14 −18
fftools/cmdutils.c+8−0
@@ -288,6 +288,14 @@ static int write_option(void *optctx, const OptionDef *po, const char *opt, · 287 unmodified lines
288 goto finish;288 goto finish;
289 }289 }
290 sol->opt[sol->nb_opt - 1].specifier = str;290 sol->opt[sol->nb_opt - 1].specifier = str;
291
292 if (po->flags & OPT_FLAG_PERSTREAM) {
293 ret = stream_specifier_parse(&sol->opt[sol->nb_opt - 1].stream_spec,
294 str, 0, NULL);
295 if (ret < 0)
296 goto finish;
297 }
298
291 dst = &sol->opt[sol->nb_opt - 1].u;299 dst = &sol->opt[sol->nb_opt - 1].u;
292 }300 }
293 301
fftools/cmdutils.h+5−1
@@ -159,7 +159,11 @@ unsigned stream_specifier_match(const StreamSpecifier *ss, · 158 unmodified lines
159void stream_specifier_uninit(StreamSpecifier *ss);159void stream_specifier_uninit(StreamSpecifier *ss);
160 160
161typedef struct SpecifierOpt {161typedef struct SpecifierOpt {
162 char *specifier; /**< stream/chapter/program/... specifier */162 // original specifier or empty string
163 char *specifier;
164 // parsed specifier for OPT_FLAG_PERSTREAM options
165 StreamSpecifier stream_spec;
166
163 union {167 union {
164 uint8_t *str;168 uint8_t *str;
165 int i;169 int i;
fftools/ffmpeg.h+8−8
@@ -859,14 +859,14 @@ void update_benchmark(const char *fmt, ...); · 858 unmodified lines
859 859
860const char *opt_match_per_type_str(const SpecifierOptList *sol,860const char *opt_match_per_type_str(const SpecifierOptList *sol,
861 char mediatype);861 char mediatype);
862int opt_match_per_stream_str(void *logctx, const SpecifierOptList *sol,862void opt_match_per_stream_str(void *logctx, const SpecifierOptList *sol,
863 AVFormatContext *fc, AVStream *st, const char **out);863 AVFormatContext *fc, AVStream *st, const char **out);
864int opt_match_per_stream_int(void *logctx, const SpecifierOptList *sol,864void opt_match_per_stream_int(void *logctx, const SpecifierOptList *sol,
865 AVFormatContext *fc, AVStream *st, int *out);865 AVFormatContext *fc, AVStream *st, int *out);
866int opt_match_per_stream_int64(void *logctx, const SpecifierOptList *sol,866void opt_match_per_stream_int64(void *logctx, const SpecifierOptList *sol,
867 AVFormatContext *fc, AVStream *st, int64_t *out);867 AVFormatContext *fc, AVStream *st, int64_t *out);
868int opt_match_per_stream_dbl(void *logctx, const SpecifierOptList *sol,868void opt_match_per_stream_dbl(void *logctx, const SpecifierOptList *sol,
869 AVFormatContext *fc, AVStream *st, double *out);869 AVFormatContext *fc, AVStream *st, double *out);
870 870
871int muxer_thread(void *arg);871int muxer_thread(void *arg);
872int encoder_thread(void *arg);872int encoder_thread(void *arg);
fftools/ffmpeg_demux.c+20−67
@@ -1084,12 +1084,8 @@ static int choose_decoder(const OptionsContext *o, void *logctx, · 1083 unmodified lines
1084 1084
1085{1085{
1086 const char *codec_name = NULL;1086 const char *codec_name = NULL;
1087 int ret;
1088
1089 ret = opt_match_per_stream_str(logctx, &o->codec_names, s, st, &codec_name);
1090 if (ret < 0)
1091 return ret;
1092 1087
1088 opt_match_per_stream_str(logctx, &o->codec_names, s, st, &codec_name);
1093 if (codec_name) {1089 if (codec_name) {
1094 int ret = find_codec(NULL, codec_name, st->codecpar->codec_type, 0, pcodec);1090 int ret = find_codec(NULL, codec_name, st->codecpar->codec_type, 0, pcodec);
1095 if (ret < 0)1091 if (ret < 0)
@@ -1153,18 +1149,11 @@ static int add_display_matrix_to_stream(const OptionsContext *o, · 57 unmodified lines
1153 double rotation = DBL_MAX;1149 double rotation = DBL_MAX;
1154 int hflip = -1, vflip = -1;1150 int hflip = -1, vflip = -1;
1155 int hflip_set = 0, vflip_set = 0, rotation_set = 0;1151 int hflip_set = 0, vflip_set = 0, rotation_set = 0;
1156 int ret;
1157 int32_t *buf;1152 int32_t *buf;
1158 1153
1159 ret = opt_match_per_stream_dbl(ist, &o->display_rotations, ctx, st, &rotation);1154 opt_match_per_stream_dbl(ist, &o->display_rotations, ctx, st, &rotation);
1160 if (ret < 0)1155 opt_match_per_stream_int(ist, &o->display_hflips, ctx, st, &hflip);
1161 return ret;1156 opt_match_per_stream_int(ist, &o->display_vflips, ctx, st, &vflip);
1162 ret = opt_match_per_stream_int(ist, &o->display_hflips, ctx, st, &hflip);
1163 if (ret < 0)
1164 return ret;
1165 ret = opt_match_per_stream_int(ist, &o->display_vflips, ctx, st, &vflip);
1166 if (ret < 0)
1167 return ret;
1168 1157
1169 rotation_set = rotation != DBL_MAX;1158 rotation_set = rotation != DBL_MAX;
1170 hflip_set = hflip != -1;1159 hflip_set = hflip != -1;
@@ -1262,19 +1251,13 @@ static int ist_add(const OptionsContext *o, Demuxer *d, AVStream *st, AVDictiona · 91 unmodified lines
1262 ds->dec_opts.time_base = st->time_base;1251 ds->dec_opts.time_base = st->time_base;
1263 1252
1264 ds->ts_scale = 1.0;1253 ds->ts_scale = 1.0;
1265 ret = opt_match_per_stream_dbl(ist, &o->ts_scale, ic, st, &ds->ts_scale);1254 opt_match_per_stream_dbl(ist, &o->ts_scale, ic, st, &ds->ts_scale);
1266 if (ret < 0)
1267 return ret;
1268 1255
1269 ds->autorotate = 1;1256 ds->autorotate = 1;
1270 ret = opt_match_per_stream_int(ist, &o->autorotate, ic, st, &ds->autorotate);1257 opt_match_per_stream_int(ist, &o->autorotate, ic, st, &ds->autorotate);
1271 if (ret < 0)
1272 return ret;
1273 1258
1274 ds->apply_cropping = CROP_ALL;1259 ds->apply_cropping = CROP_ALL;
1275 ret = opt_match_per_stream_str(ist, &o->apply_cropping, ic, st, &apply_cropping);1260 opt_match_per_stream_str(ist, &o->apply_cropping, ic, st, &apply_cropping);
1276 if (ret < 0)
1277 return ret;
1278 if (apply_cropping) {1261 if (apply_cropping) {
1279 const AVOption opts[] = {1262 const AVOption opts[] = {
1280 { "apply_cropping", NULL, 0, AV_OPT_TYPE_INT,1263 { "apply_cropping", NULL, 0, AV_OPT_TYPE_INT,
@@ -1300,9 +1283,7 @@ static int ist_add(const OptionsContext *o, Demuxer *d, AVStream *st, AVDictiona · 19 unmodified lines
1300 }1283 }
1301 }1284 }
1302 1285
1303 ret = opt_match_per_stream_str(ist, &o->codec_tags, ic, st, &codec_tag);1286 opt_match_per_stream_str(ist, &o->codec_tags, ic, st, &codec_tag);
1304 if (ret < 0)
1305 return ret;
1306 if (codec_tag) {1287 if (codec_tag) {
1307 uint32_t tag = strtol(codec_tag, &next, 0);1288 uint32_t tag = strtol(codec_tag, &next, 0);
1308 if (*next) {1289 if (*next) {
@@ -1319,15 +1300,9 @@ static int ist_add(const OptionsContext *o, Demuxer *d, AVStream *st, AVDictiona · 10 unmodified lines
1319 if (ret < 0)1300 if (ret < 0)
1320 return ret;1301 return ret;
1321 1302
1322 ret = opt_match_per_stream_str(ist, &o->hwaccels, ic, st, &hwaccel);1303 opt_match_per_stream_str(ist, &o->hwaccels, ic, st, &hwaccel);
1323 if (ret < 0)1304 opt_match_per_stream_str(ist, &o->hwaccel_output_formats, ic, st,
1324 return ret;
1325
1326 ret = opt_match_per_stream_str(ist, &o->hwaccel_output_formats, ic, st,
1327 &hwaccel_output_format);1305 &hwaccel_output_format);
1328 if (ret < 0)
1329 return ret;
1330
1331 if (!hwaccel_output_format && hwaccel && !strcmp(hwaccel, "cuvid")) {1306 if (!hwaccel_output_format && hwaccel && !strcmp(hwaccel, "cuvid")) {
1332 av_log(ist, AV_LOG_WARNING,1307 av_log(ist, AV_LOG_WARNING,
1333 "WARNING: defaulting hwaccel_output_format to cuda for compatibility "1308 "WARNING: defaulting hwaccel_output_format to cuda for compatibility "
@@ -1385,9 +1360,7 @@ static int ist_add(const OptionsContext *o, Demuxer *d, AVStream *st, AVDictiona · 51 unmodified lines
1385 }1360 }
1386 }1361 }
1387 1362
1388 ret = opt_match_per_stream_str(ist, &o->hwaccel_devices, ic, st, &hwaccel_device);1363 opt_match_per_stream_str(ist, &o->hwaccel_devices, ic, st, &hwaccel_device);
1389 if (ret < 0)
1390 return ret;
1391 if (hwaccel_device) {1364 if (hwaccel_device) {
1392 ds->dec_opts.hwaccel_device = av_strdup(hwaccel_device);1365 ds->dec_opts.hwaccel_device = av_strdup(hwaccel_device);
1393 if (!ds->dec_opts.hwaccel_device)1366 if (!ds->dec_opts.hwaccel_device)
@@ -1408,9 +1381,7 @@ static int ist_add(const OptionsContext *o, Demuxer *d, AVStream *st, AVDictiona · 14 unmodified lines
1408 }1381 }
1409 1382
1410 ds->reinit_filters = -1;1383 ds->reinit_filters = -1;
1411 ret = opt_match_per_stream_int(ist, &o->reinit_filters, ic, st, &ds->reinit_filters);1384 opt_match_per_stream_int(ist, &o->reinit_filters, ic, st, &ds->reinit_filters);
1412 if (ret < 0)
1413 return ret;
1414 1385
1415 ist->user_set_discard = AVDISCARD_NONE;1386 ist->user_set_discard = AVDISCARD_NONE;
1416 1387
@@ -1420,9 +1391,7 @@ static int ist_add(const OptionsContext *o, Demuxer *d, AVStream *st, AVDictiona · 3 unmodified lines
1420 (o->data_disable && ist->st->codecpar->codec_type == AVMEDIA_TYPE_DATA))1391 (o->data_disable && ist->st->codecpar->codec_type == AVMEDIA_TYPE_DATA))
1421 ist->user_set_discard = AVDISCARD_ALL;1392 ist->user_set_discard = AVDISCARD_ALL;
1422 1393
1423 ret = opt_match_per_stream_str(ist, &o->discard, ic, st, &discard_str);1394 opt_match_per_stream_str(ist, &o->discard, ic, st, &discard_str);
1424 if (ret < 0)
1425 return ret;
1426 if (discard_str) {1395 if (discard_str) {
1427 ret = av_opt_set(ist->st, "discard", discard_str, 0);1396 ret = av_opt_set(ist->st, "discard", discard_str, 0);
1428 if (ret < 0) {1397 if (ret < 0) {
@@ -1444,9 +1413,7 @@ static int ist_add(const OptionsContext *o, Demuxer *d, AVStream *st, AVDictiona · 15 unmodified lines
1444 1413
1445 switch (par->codec_type) {1414 switch (par->codec_type) {
1446 case AVMEDIA_TYPE_VIDEO:1415 case AVMEDIA_TYPE_VIDEO:
1447 ret = opt_match_per_stream_str(ist, &o->frame_rates, ic, st, &framerate);1416 opt_match_per_stream_str(ist, &o->frame_rates, ic, st, &framerate);
1448 if (ret < 0)
1449 return ret;
1450 if (framerate) {1417 if (framerate) {
1451 ret = av_parse_video_rate(&ist->framerate, framerate);1418 ret = av_parse_video_rate(&ist->framerate, framerate);
1452 if (ret < 0) {1419 if (ret < 0) {
@@ -1458,18 +1425,14 @@ static int ist_add(const OptionsContext *o, Demuxer *d, AVStream *st, AVDictiona · 5 unmodified lines
1458 1425
1459#if FFMPEG_OPT_TOP1426#if FFMPEG_OPT_TOP
1460 ist->top_field_first = -1;1427 ist->top_field_first = -1;
1461 ret = opt_match_per_stream_int(ist, &o->top_field_first, ic, st, &ist->top_field_first);1428 opt_match_per_stream_int(ist, &o->top_field_first, ic, st, &ist->top_field_first);
1462 if (ret < 0)
1463 return ret;
1464#endif1429#endif
1465 1430
1466 break;1431 break;
1467 case AVMEDIA_TYPE_AUDIO: {1432 case AVMEDIA_TYPE_AUDIO: {
1468 const char *ch_layout_str = NULL;1433 const char *ch_layout_str = NULL;
1469 1434
1470 ret = opt_match_per_stream_str(ist, &o->audio_ch_layouts, ic, st, &ch_layout_str);1435 opt_match_per_stream_str(ist, &o->audio_ch_layouts, ic, st, &ch_layout_str);
1471 if (ret < 0)
1472 return ret;
1473 if (ch_layout_str) {1436 if (ch_layout_str) {
1474 AVChannelLayout ch_layout;1437 AVChannelLayout ch_layout;
1475 ret = av_channel_layout_from_string(&ch_layout, ch_layout_str);1438 ret = av_channel_layout_from_string(&ch_layout, ch_layout_str);
@@ -1489,10 +1452,7 @@ static int ist_add(const OptionsContext *o, Demuxer *d, AVStream *st, AVDictiona · 13 unmodified lines
1489 }1452 }
1490 } else {1453 } else {
1491 int guess_layout_max = INT_MAX;1454 int guess_layout_max = INT_MAX;
1492 ret = opt_match_per_stream_int(ist, &o->guess_layout_max, ic, st, &guess_layout_max);1455 opt_match_per_stream_int(ist, &o->guess_layout_max, ic, st, &guess_layout_max);
1493 if (ret < 0)
1494 return ret;
1495
1496 guess_input_channel_layout(ist, par, guess_layout_max);1456 guess_input_channel_layout(ist, par, guess_layout_max);
1497 }1457 }
1498 break;1458 break;
@@ -1501,13 +1461,8 @@ static int ist_add(const OptionsContext *o, Demuxer *d, AVStream *st, AVDictiona · 2 unmodified lines
1501 case AVMEDIA_TYPE_SUBTITLE: {1461 case AVMEDIA_TYPE_SUBTITLE: {
1502 const char *canvas_size = NULL;1462 const char *canvas_size = NULL;
1503 1463
1504 ret = opt_match_per_stream_int(ist, &o->fix_sub_duration, ic, st, &ist->fix_sub_duration);1464 opt_match_per_stream_int(ist, &o->fix_sub_duration, ic, st, &ist->fix_sub_duration);
1505 if (ret < 0)1465 opt_match_per_stream_str(ist, &o->canvas_sizes, ic, st, &canvas_size);
1506 return ret;
1507
1508 ret = opt_match_per_stream_str(ist, &o->canvas_sizes, ic, st, &canvas_size);
1509 if (ret < 0)
1510 return ret;
1511 if (canvas_size) {1466 if (canvas_size) {
1512 ret = av_parse_video_size(&par->width, &par->height,1467 ret = av_parse_video_size(&par->width, &par->height,
1513 canvas_size);1468 canvas_size);
@@ -1537,9 +1492,7 @@ static int ist_add(const OptionsContext *o, Demuxer *d, AVStream *st, AVDictiona · 23 unmodified lines
1537 if (ist->st->sample_aspect_ratio.num)1492 if (ist->st->sample_aspect_ratio.num)
1538 ist->par->sample_aspect_ratio = ist->st->sample_aspect_ratio;1493 ist->par->sample_aspect_ratio = ist->st->sample_aspect_ratio;
1539 1494
1540 ret = opt_match_per_stream_str(ist, &o->bitstream_filters, ic, st, &bsfs);1495 opt_match_per_stream_str(ist, &o->bitstream_filters, ic, st, &bsfs);
1541 if (ret < 0)
1542 return ret;
1543 if (bsfs) {1496 if (bsfs) {
1544 ret = av_bsf_list_parse_str(bsfs, &ds->bsf);1497 ret = av_bsf_list_parse_str(bsfs, &ds->bsf);
1545 if (ret < 0) {1498 if (ret < 0) {
fftools/ffmpeg_mux_init.c+50−148
@@ -71,13 +71,10 @@ static int choose_encoder(const OptionsContext *o, AVFormatContext *s, · 70 unmodified lines
71{71{
72 enum AVMediaType type = ost->type;72 enum AVMediaType type = ost->type;
73 const char *codec_name = NULL;73 const char *codec_name = NULL;
74 int ret;
75 74
76 *enc = NULL;75 *enc = NULL;
77 76
78 ret = opt_match_per_stream_str(ost, &o->codec_names, s, ost->st, &codec_name);77 opt_match_per_stream_str(ost, &o->codec_names, s, ost->st, &codec_name);
79 if (ret < 0)
80 return ret;
81 78
82 if (type != AVMEDIA_TYPE_VIDEO &&79 if (type != AVMEDIA_TYPE_VIDEO &&
83 type != AVMEDIA_TYPE_AUDIO &&80 type != AVMEDIA_TYPE_AUDIO &&
@@ -419,17 +416,12 @@ static int ost_get_filters(const OptionsContext *o, AVFormatContext *oc, · 335 unmodified lines
419 OutputStream *ost, char **dst)416 OutputStream *ost, char **dst)
420{417{
421 const char *filters = NULL;418 const char *filters = NULL;
422 int ret;
423#if FFMPEG_OPT_FILTER_SCRIPT419#if FFMPEG_OPT_FILTER_SCRIPT
424 const char *filters_script = NULL;420 const char *filters_script = NULL;
425 421
426 ret = opt_match_per_stream_str(ost, &o->filter_scripts, oc, ost->st, &filters_script);422 opt_match_per_stream_str(ost, &o->filter_scripts, oc, ost->st, &filters_script);
427 if (ret < 0)
428 return ret;
429#endif423#endif
430 ret = opt_match_per_stream_str(ost, &o->filters, oc, ost->st, &filters);424 opt_match_per_stream_str(ost, &o->filters, oc, ost->st, &filters);
431 if (ret < 0)
432 return ret;
433 425
434 if (!ost->enc) {426 if (!ost->enc) {
435 if (427 if (
@@ -599,17 +591,13 @@ static int new_stream_video(Muxer *mux, const OptionsContext *o, · 163 unmodified lines
599 591
600 st = ost->st;592 st = ost->st;
601 593
602 ret = opt_match_per_stream_str(ost, &o->frame_rates, oc, st, &frame_rate);594 opt_match_per_stream_str(ost, &o->frame_rates, oc, st, &frame_rate);
603 if (ret < 0)
604 return ret;
605 if (frame_rate && av_parse_video_rate(&ost->frame_rate, frame_rate) < 0) {595 if (frame_rate && av_parse_video_rate(&ost->frame_rate, frame_rate) < 0) {
606 av_log(ost, AV_LOG_FATAL, "Invalid framerate value: %s\n", frame_rate);596 av_log(ost, AV_LOG_FATAL, "Invalid framerate value: %s\n", frame_rate);
607 return AVERROR(EINVAL);597 return AVERROR(EINVAL);
608 }598 }
609 599
610 ret = opt_match_per_stream_str(ost, &o->max_frame_rates, oc, st, &max_frame_rate);600 opt_match_per_stream_str(ost, &o->max_frame_rates, oc, st, &max_frame_rate);
611 if (ret < 0)
612 return ret;
613 if (max_frame_rate && av_parse_video_rate(&ost->max_frame_rate, max_frame_rate) < 0) {601 if (max_frame_rate && av_parse_video_rate(&ost->max_frame_rate, max_frame_rate) < 0) {
614 av_log(ost, AV_LOG_FATAL, "Invalid maximum framerate value: %s\n", max_frame_rate);602 av_log(ost, AV_LOG_FATAL, "Invalid maximum framerate value: %s\n", max_frame_rate);
615 return AVERROR(EINVAL);603 return AVERROR(EINVAL);
@@ -620,9 +608,7 @@ static int new_stream_video(Muxer *mux, const OptionsContext *o, · 4 unmodified lines
620 return AVERROR(EINVAL);608 return AVERROR(EINVAL);
621 }609 }
622 610
623 ret = opt_match_per_stream_str(ost, &o->frame_aspect_ratios, oc, st, &frame_aspect_ratio);611 opt_match_per_stream_str(ost, &o->frame_aspect_ratios, oc, st, &frame_aspect_ratio);
624 if (ret < 0)
625 return ret;
626 if (frame_aspect_ratio) {612 if (frame_aspect_ratio) {
627 AVRational q;613 AVRational q;
628 if (av_parse_ratio(&q, frame_aspect_ratio, 255, 0, NULL) < 0 ||614 if (av_parse_ratio(&q, frame_aspect_ratio, 255, 0, NULL) < 0 ||
@@ -643,9 +629,7 @@ static int new_stream_video(Muxer *mux, const OptionsContext *o, · 14 unmodified lines
643 int do_pass = 0;629 int do_pass = 0;
644 int i;630 int i;
645 631
646 ret = opt_match_per_stream_str(ost, &o->frame_sizes, oc, st, &frame_size);632 opt_match_per_stream_str(ost, &o->frame_sizes, oc, st, &frame_size);
647 if (ret < 0)
648 return ret;
649 if (frame_size) {633 if (frame_size) {
650 ret = av_parse_video_size(&video_enc->width, &video_enc->height, frame_size);634 ret = av_parse_video_size(&video_enc->width, &video_enc->height, frame_size);
651 if (ret < 0) {635 if (ret < 0) {
@@ -654,9 +638,7 @@ static int new_stream_video(Muxer *mux, const OptionsContext *o, · 2 unmodified lines
654 }638 }
655 }639 }
656 640
657 ret = opt_match_per_stream_str(ost, &o->frame_pix_fmts, oc, st, &frame_pix_fmt);641 opt_match_per_stream_str(ost, &o->frame_pix_fmts, oc, st, &frame_pix_fmt);
658 if (ret < 0)
659 return ret;
660 if (frame_pix_fmt && *frame_pix_fmt == '+') {642 if (frame_pix_fmt && *frame_pix_fmt == '+') {
661 *keep_pix_fmt = 1;643 *keep_pix_fmt = 1;
662 if (!*++frame_pix_fmt)644 if (!*++frame_pix_fmt)
@@ -668,9 +650,7 @@ static int new_stream_video(Muxer *mux, const OptionsContext *o, · 5 unmodified lines
668 return AVERROR(EINVAL);650 return AVERROR(EINVAL);
669 }651 }
670 652
671 ret = opt_match_per_stream_str(ost, &o->intra_matrices, oc, st, &intra_matrix);653 opt_match_per_stream_str(ost, &o->intra_matrices, oc, st, &intra_matrix);
672 if (ret < 0)
673 return ret;
674 if (intra_matrix) {654 if (intra_matrix) {
675 if (!(video_enc->intra_matrix = av_mallocz(sizeof(*video_enc->intra_matrix) * 64)))655 if (!(video_enc->intra_matrix = av_mallocz(sizeof(*video_enc->intra_matrix) * 64)))
676 return AVERROR(ENOMEM);656 return AVERROR(ENOMEM);
@@ -679,9 +659,7 @@ static int new_stream_video(Muxer *mux, const OptionsContext *o, · 2 unmodified lines
679 if (ret < 0)659 if (ret < 0)
680 return ret;660 return ret;
681 }661 }
682 ret = opt_match_per_stream_str(ost, &o->chroma_intra_matrices, oc, st, &chroma_intra_matrix);662 opt_match_per_stream_str(ost, &o->chroma_intra_matrices, oc, st, &chroma_intra_matrix);
683 if (ret < 0)
684 return ret;
685 if (chroma_intra_matrix) {663 if (chroma_intra_matrix) {
686 uint16_t *p = av_mallocz(sizeof(*video_enc->chroma_intra_matrix) * 64);664 uint16_t *p = av_mallocz(sizeof(*video_enc->chroma_intra_matrix) * 64);
687 if (!p)665 if (!p)
@@ -691,9 +669,7 @@ static int new_stream_video(Muxer *mux, const OptionsContext *o, · 3 unmodified lines
691 if (ret < 0)669 if (ret < 0)
692 return ret;670 return ret;
693 }671 }
694 ret = opt_match_per_stream_str(ost, &o->inter_matrices, oc, st, &inter_matrix);672 opt_match_per_stream_str(ost, &o->inter_matrices, oc, st, &inter_matrix);
695 if (ret < 0)
696 return ret;
697 if (inter_matrix) {673 if (inter_matrix) {
698 if (!(video_enc->inter_matrix = av_mallocz(sizeof(*video_enc->inter_matrix) * 64)))674 if (!(video_enc->inter_matrix = av_mallocz(sizeof(*video_enc->inter_matrix) * 64)))
699 return AVERROR(ENOMEM);675 return AVERROR(ENOMEM);
@@ -702,9 +678,7 @@ static int new_stream_video(Muxer *mux, const OptionsContext *o, · 2 unmodified lines
702 return ret;678 return ret;
703 }679 }
704 680
705 ret = opt_match_per_stream_str(ost, &o->rc_overrides, oc, st, &p);681 opt_match_per_stream_str(ost, &o->rc_overrides, oc, st, &p);
706 if (ret < 0)
707 return ret;
708 for (i = 0; p; i++) {682 for (i = 0; p; i++) {
709 int start, end, q;683 int start, end, q;
710 int e = sscanf(p, "%d,%d,%d", &start, &end, &q);684 int e = sscanf(p, "%d,%d,%d", &start, &end, &q);
@@ -735,9 +709,7 @@ static int new_stream_video(Muxer *mux, const OptionsContext *o, · 24 unmodified lines
735 video_enc->rc_override_count = i;709 video_enc->rc_override_count = i;
736 710
737 /* two pass mode */711 /* two pass mode */
738 ret = opt_match_per_stream_int(ost, &o->pass, oc, st, &do_pass);712 opt_match_per_stream_int(ost, &o->pass, oc, st, &do_pass);
739 if (ret < 0)
740 return ret;
741 if (do_pass) {713 if (do_pass) {
742 if (do_pass & 1)714 if (do_pass & 1)
743 video_enc->flags |= AV_CODEC_FLAG_PASS1;715 video_enc->flags |= AV_CODEC_FLAG_PASS1;
@@ -745,9 +717,7 @@ static int new_stream_video(Muxer *mux, const OptionsContext *o, · 1 unmodified line
745 video_enc->flags |= AV_CODEC_FLAG_PASS2;717 video_enc->flags |= AV_CODEC_FLAG_PASS2;
746 }718 }
747 719
748 ret = opt_match_per_stream_str(ost, &o->passlogfiles, oc, st, &ost->logfile_prefix);720 opt_match_per_stream_str(ost, &o->passlogfiles, oc, st, &ost->logfile_prefix);
749 if (ret < 0)
750 return ret;
751 if (ost->logfile_prefix &&721 if (ost->logfile_prefix &&
752 !(ost->logfile_prefix = av_strdup(ost->logfile_prefix)))722 !(ost->logfile_prefix = av_strdup(ost->logfile_prefix)))
753 return AVERROR(ENOMEM);723 return AVERROR(ENOMEM);
@@ -794,15 +764,11 @@ static int new_stream_video(Muxer *mux, const OptionsContext *o, · 40 unmodified lines
794 }764 }
795 }765 }
796 766
797 ret = opt_match_per_stream_int(ost, &o->force_fps, oc, st, &ost->force_fps);767 opt_match_per_stream_int(ost, &o->force_fps, oc, st, &ost->force_fps);
798 if (ret < 0)
799 return ret;
800 768
801#if FFMPEG_OPT_TOP769#if FFMPEG_OPT_TOP
802 ost->top_field_first = -1;770 ost->top_field_first = -1;
803 ret = opt_match_per_stream_int(ost, &o->top_field_first, oc, st, &ost->top_field_first);771 opt_match_per_stream_int(ost, &o->top_field_first, oc, st, &ost->top_field_first);
804 if (ret < 0)
805 return ret;
806 if (ost->top_field_first >= 0)772 if (ost->top_field_first >= 0)
807 av_log(ost, AV_LOG_WARNING, "-top is deprecated, use the setfield filter instead\n");773 av_log(ost, AV_LOG_WARNING, "-top is deprecated, use the setfield filter instead\n");
808#endif774#endif
@@ -812,9 +778,7 @@ static int new_stream_video(Muxer *mux, const OptionsContext *o, · 3 unmodified lines
812#else778#else
813 *vsync_method = VSYNC_AUTO;779 *vsync_method = VSYNC_AUTO;
814#endif780#endif
815 ret = opt_match_per_stream_str(ost, &o->fps_mode, oc, st, &fps_mode);781 opt_match_per_stream_str(ost, &o->fps_mode, oc, st, &fps_mode);
816 if (ret < 0)
817 return ret;
818 if (fps_mode) {782 if (fps_mode) {
819 ret = parse_and_set_vsync(fps_mode, vsync_method, ost->file->index, ost->index, 0);783 ret = parse_and_set_vsync(fps_mode, vsync_method, ost->file->index, ost->index, 0);
820 if (ret < 0)784 if (ret < 0)
@@ -872,40 +836,28 @@ static int new_stream_audio(Muxer *mux, const OptionsContext *o, · 51 unmodified lines
872 int channels = 0;836 int channels = 0;
873 const char *layout = NULL;837 const char *layout = NULL;
874 const char *sample_fmt = NULL;838 const char *sample_fmt = NULL;
875 int ret;
876 839
877 ret = opt_match_per_stream_int(ost, &o->audio_channels, oc, st, &channels);840 opt_match_per_stream_int(ost, &o->audio_channels, oc, st, &channels);
878 if (ret < 0)
879 return ret;
880 if (channels) {841 if (channels) {
881 audio_enc->ch_layout.order = AV_CHANNEL_ORDER_UNSPEC;842 audio_enc->ch_layout.order = AV_CHANNEL_ORDER_UNSPEC;
882 audio_enc->ch_layout.nb_channels = channels;843 audio_enc->ch_layout.nb_channels = channels;
883 }844 }
884 845
885 ret = opt_match_per_stream_str(ost, &o->audio_ch_layouts, oc, st, &layout);846 opt_match_per_stream_str(ost, &o->audio_ch_layouts, oc, st, &layout);
886 if (ret < 0)
887 return ret;
888 if (layout && av_channel_layout_from_string(&audio_enc->ch_layout, layout) < 0) {847 if (layout && av_channel_layout_from_string(&audio_enc->ch_layout, layout) < 0) {
889 av_log(ost, AV_LOG_FATAL, "Unknown channel layout: %s\n", layout);848 av_log(ost, AV_LOG_FATAL, "Unknown channel layout: %s\n", layout);
890 return AVERROR(EINVAL);849 return AVERROR(EINVAL);
891 }850 }
892 851
893 ret = opt_match_per_stream_str(ost, &o->sample_fmts, oc, st, &sample_fmt);852 opt_match_per_stream_str(ost, &o->sample_fmts, oc, st, &sample_fmt);
894 if (ret < 0)
895 return ret;
896 if (sample_fmt &&853 if (sample_fmt &&
897 (audio_enc->sample_fmt = av_get_sample_fmt(sample_fmt)) == AV_SAMPLE_FMT_NONE) {854 (audio_enc->sample_fmt = av_get_sample_fmt(sample_fmt)) == AV_SAMPLE_FMT_NONE) {
898 av_log(ost, AV_LOG_FATAL, "Invalid sample format '%s'\n", sample_fmt);855 av_log(ost, AV_LOG_FATAL, "Invalid sample format '%s'\n", sample_fmt);
899 return AVERROR(EINVAL);856 return AVERROR(EINVAL);
900 }857 }
901 858
902 ret = opt_match_per_stream_int(ost, &o->audio_sample_rate, oc, st, &audio_enc->sample_rate);859 opt_match_per_stream_int(ost, &o->audio_sample_rate, oc, st, &audio_enc->sample_rate);
903 if (ret < 0)860 opt_match_per_stream_str(ost, &o->apad, oc, st, &ms->apad);
904 return ret;
905
906 ret = opt_match_per_stream_str(ost, &o->apad, oc, st, &ms->apad);
907 if (ret < 0)
908 return ret;
909 }861 }
910 862
911 return 0;863 return 0;
@@ -928,11 +880,8 @@ static int new_stream_subtitle(Muxer *mux, const OptionsContext *o, · 16 unmodified lines
928 int input_props = 0, output_props = 0;880 int input_props = 0, output_props = 0;
929 881
930 const char *frame_size = NULL;882 const char *frame_size = NULL;
931 int ret;
932 883
933 ret = opt_match_per_stream_str(ost, &o->frame_sizes, mux->fc, st, &frame_size);884 opt_match_per_stream_str(ost, &o->frame_sizes, mux->fc, st, &frame_size);
934 if (ret < 0)
935 return ret;
936 if (frame_size) {885 if (frame_size) {
937 int ret = av_parse_video_size(&subtitle_enc->width, &subtitle_enc->height, frame_size);886 int ret = av_parse_video_size(&subtitle_enc->width, &subtitle_enc->height, frame_size);
938 if (ret < 0) {887 if (ret < 0) {
@@ -1211,13 +1160,8 @@ static int ost_add(Muxer *mux, const OptionsContext *o, enum AVMediaType type, · 272 unmodified lines
1211 if (ret < 0)1160 if (ret < 0)
1212 goto fail;1161 goto fail;
1213 1162
1214 ret = opt_match_per_stream_str(ost, &o->presets, oc, st, &preset);1163 opt_match_per_stream_str(ost, &o->presets, oc, st, &preset);
1215 if (ret < 0)1164 opt_match_per_stream_int(ost, &o->autoscale, oc, st, &autoscale);
1216 goto fail;
1217
1218 ret = opt_match_per_stream_int(ost, &o->autoscale, oc, st, &autoscale);
1219 if (ret < 0)
1220 goto fail;
1221 if (preset && (!(ret = get_preset_file_2(preset, enc->codec->name, &s)))) {1165 if (preset && (!(ret = get_preset_file_2(preset, enc->codec->name, &s)))) {
1222 AVBPrint bprint;1166 AVBPrint bprint;
1223 av_bprint_init(&bprint, 0, AV_BPRINT_SIZE_UNLIMITED);1167 av_bprint_init(&bprint, 0, AV_BPRINT_SIZE_UNLIMITED);
@@ -1248,14 +1192,12 @@ static int ost_add(Muxer *mux, const OptionsContext *o, enum AVMediaType type, · 24 unmodified lines
1248 goto fail;1192 goto fail;
1249 }1193 }
1250 1194
1251 ret = opt_match_per_stream_str(ost, &o->enc_stats_pre, oc, st, &enc_stats_pre);1195 opt_match_per_stream_str(ost, &o->enc_stats_pre, oc, st, &enc_stats_pre);
1252 if (ret < 0)
1253 goto fail;
1254 if (enc_stats_pre &&1196 if (enc_stats_pre &&
1255 (type == AVMEDIA_TYPE_VIDEO || type == AVMEDIA_TYPE_AUDIO)) {1197 (type == AVMEDIA_TYPE_VIDEO || type == AVMEDIA_TYPE_AUDIO)) {
1256 const char *format = "{fidx} {sidx} {n} {t}";1198 const char *format = "{fidx} {sidx} {n} {t}";
1257 1199
1258 ret = opt_match_per_stream_str(ost, &o->enc_stats_pre_fmt, oc, st, &format);1200 opt_match_per_stream_str(ost, &o->enc_stats_pre_fmt, oc, st, &format);
1259 if (ret < 0)1201 if (ret < 0)
1260 goto fail;1202 goto fail;
1261 1203
@@ -1264,41 +1206,31 @@ static int ost_add(Muxer *mux, const OptionsContext *o, enum AVMediaType type, · 2 unmodified lines
1264 goto fail;1206 goto fail;
1265 }1207 }
1266 1208
1267 ret = opt_match_per_stream_str(ost, &o->enc_stats_post, oc, st, &enc_stats_post);1209 opt_match_per_stream_str(ost, &o->enc_stats_post, oc, st, &enc_stats_post);
1268 if (ret < 0)
1269 goto fail;
1270 if (enc_stats_post &&1210 if (enc_stats_post &&
1271 (type == AVMEDIA_TYPE_VIDEO || type == AVMEDIA_TYPE_AUDIO)) {1211 (type == AVMEDIA_TYPE_VIDEO || type == AVMEDIA_TYPE_AUDIO)) {
1272 const char *format = "{fidx} {sidx} {n} {t}";1212 const char *format = "{fidx} {sidx} {n} {t}";
1273 1213
1274 ret = opt_match_per_stream_str(ost, &o->enc_stats_post_fmt, oc, st, &format);1214 opt_match_per_stream_str(ost, &o->enc_stats_post_fmt, oc, st, &format);
1275 if (ret < 0)
1276 goto fail;
1277 1215
1278 ret = enc_stats_init(ost, &ost->enc_stats_post, 0, enc_stats_post, format);1216 ret = enc_stats_init(ost, &ost->enc_stats_post, 0, enc_stats_post, format);
1279 if (ret < 0)1217 if (ret < 0)
1280 goto fail;1218 goto fail;
1281 }1219 }
1282 1220
1283 ret = opt_match_per_stream_str(ost, &o->mux_stats, oc, st, &mux_stats);1221 opt_match_per_stream_str(ost, &o->mux_stats, oc, st, &mux_stats);
1284 if (ret < 0)
1285 goto fail;
1286 if (mux_stats &&1222 if (mux_stats &&
1287 (type == AVMEDIA_TYPE_VIDEO || type == AVMEDIA_TYPE_AUDIO)) {1223 (type == AVMEDIA_TYPE_VIDEO || type == AVMEDIA_TYPE_AUDIO)) {
1288 const char *format = "{fidx} {sidx} {n} {t}";1224 const char *format = "{fidx} {sidx} {n} {t}";
1289 1225
1290 ret = opt_match_per_stream_str(ost, &o->mux_stats_fmt, oc, st, &format);1226 opt_match_per_stream_str(ost, &o->mux_stats_fmt, oc, st, &format);
1291 if (ret < 0)
1292 goto fail;
1293 1227
1294 ret = enc_stats_init(ost, &ms->stats, 0, mux_stats, format);1228 ret = enc_stats_init(ost, &ms->stats, 0, mux_stats, format);
1295 if (ret < 0)1229 if (ret < 0)
1296 goto fail;1230 goto fail;
1297 }1231 }
1298 1232
1299 ret = opt_match_per_stream_str(ost, &o->enc_time_bases, oc, st, &enc_time_base);1233 opt_match_per_stream_str(ost, &o->enc_time_bases, oc, st, &enc_time_base);
1300 if (ret < 0)
1301 goto fail;
1302 if (enc_time_base && type == AVMEDIA_TYPE_SUBTITLE)1234 if (enc_time_base && type == AVMEDIA_TYPE_SUBTITLE)
1303 av_log(ost, AV_LOG_WARNING,1235 av_log(ost, AV_LOG_WARNING,
1304 "-enc_time_base not supported for subtitles, ignoring\n");1236 "-enc_time_base not supported for subtitles, ignoring\n");
@@ -1361,9 +1293,7 @@ static int ost_add(Muxer *mux, const OptionsContext *o, enum AVMediaType type, · 56 unmodified lines
1361 ost->bitexact = !!(ost->enc_ctx->flags & AV_CODEC_FLAG_BITEXACT);1293 ost->bitexact = !!(ost->enc_ctx->flags & AV_CODEC_FLAG_BITEXACT);
1362 }1294 }
1363 1295
1364 ret = opt_match_per_stream_str(ost, &o->time_bases, oc, st, &time_base);1296 opt_match_per_stream_str(ost, &o->time_bases, oc, st, &time_base);
1365 if (ret < 0)
1366 goto fail;
1367 if (time_base) {1297 if (time_base) {
1368 AVRational q;1298 AVRational q;
1369 if (av_parse_ratio(&q, time_base, INT_MAX, 0, NULL) < 0 ||1299 if (av_parse_ratio(&q, time_base, INT_MAX, 0, NULL) < 0 ||
@@ -1376,9 +1306,7 @@ static int ost_add(Muxer *mux, const OptionsContext *o, enum AVMediaType type, · 6 unmodified lines
1376 }1306 }
1377 1307
1378 ms->max_frames = INT64_MAX;1308 ms->max_frames = INT64_MAX;
1379 ret = opt_match_per_stream_int64(ost, &o->max_frames, oc, st, &ms->max_frames);1309 opt_match_per_stream_int64(ost, &o->max_frames, oc, st, &ms->max_frames);
1380 if (ret < 0)
1381 return ret;
1382 for (int i = 0; i < o->max_frames.nb_opt; i++) {1310 for (int i = 0; i < o->max_frames.nb_opt; i++) {
1383 char *p = o->max_frames.opt[i].specifier;1311 char *p = o->max_frames.opt[i].specifier;
1384 if (!*p && type != AVMEDIA_TYPE_VIDEO) {1312 if (!*p && type != AVMEDIA_TYPE_VIDEO) {
@@ -1388,13 +1316,8 @@ static int ost_add(Muxer *mux, const OptionsContext *o, enum AVMediaType type, · 3 unmodified lines
1388 }1316 }
1389 1317
1390 ms->copy_prior_start = -1;1318 ms->copy_prior_start = -1;
1391 ret = opt_match_per_stream_int(ost, &o->copy_prior_start, oc, st, &ms->copy_prior_start);1319 opt_match_per_stream_int(ost, &o->copy_prior_start, oc, st, &ms->copy_prior_start);
1392 if (ret < 0)1320 opt_match_per_stream_str(ost, &o->bitstream_filters, oc, st, &bsfs);
1393 goto fail;
1394
1395 ret = opt_match_per_stream_str(ost, &o->bitstream_filters, oc, st, &bsfs);
1396 if (ret < 0)
1397 goto fail;
1398 if (bsfs && *bsfs) {1321 if (bsfs && *bsfs) {
1399 ret = av_bsf_list_parse_str(bsfs, &ms->bsf_ctx);1322 ret = av_bsf_list_parse_str(bsfs, &ms->bsf_ctx);
1400 if (ret < 0) {1323 if (ret < 0) {
@@ -1403,9 +1326,7 @@ static int ost_add(Muxer *mux, const OptionsContext *o, enum AVMediaType type, · 2 unmodified lines
1403 }1326 }
1404 }1327 }
1405 1328
1406 ret = opt_match_per_stream_str(ost, &o->codec_tags, oc, st, &codec_tag);1329 opt_match_per_stream_str(ost, &o->codec_tags, oc, st, &codec_tag);
1407 if (ret < 0)
1408 goto fail;
1409 if (codec_tag) {1330 if (codec_tag) {
1410 uint32_t tag = strtol(codec_tag, &next, 0);1331 uint32_t tag = strtol(codec_tag, &next, 0);
1411 if (*next) {1332 if (*next) {
@@ -1419,9 +1340,7 @@ static int ost_add(Muxer *mux, const OptionsContext *o, enum AVMediaType type, · 7 unmodified lines
1419 ost->enc_ctx->codec_tag = tag;1340 ost->enc_ctx->codec_tag = tag;
1420 }1341 }
1421 1342
1422 ret = opt_match_per_stream_dbl(ost, &o->qscale, oc, st, &qscale);1343 opt_match_per_stream_dbl(ost, &o->qscale, oc, st, &qscale);
1423 if (ret < 0)
1424 return ret;
1425 if (ost->enc_ctx && qscale >= 0) {1344 if (ost->enc_ctx && qscale >= 0) {
1426 ost->enc_ctx->flags |= AV_CODEC_FLAG_QSCALE;1345 ost->enc_ctx->flags |= AV_CODEC_FLAG_QSCALE;
1427 ost->enc_ctx->global_quality = FF_QP2LAMBDA * qscale;1346 ost->enc_ctx->global_quality = FF_QP2LAMBDA * qscale;
@@ -1431,38 +1350,26 @@ static int ost_add(Muxer *mux, const OptionsContext *o, enum AVMediaType type, · 3 unmodified lines
1431 int max_muxing_queue_size = 128;1350 int max_muxing_queue_size = 128;
1432 int muxing_queue_data_threshold = 50 * 1024 * 1024;1351 int muxing_queue_data_threshold = 50 * 1024 * 1024;
1433 1352
1434 ret = opt_match_per_stream_int(ost, &o->max_muxing_queue_size, oc, st,1353 opt_match_per_stream_int(ost, &o->max_muxing_queue_size, oc, st,
1435 &max_muxing_queue_size);1354 &max_muxing_queue_size);
1436 if (ret < 0)1355 opt_match_per_stream_int(ost, &o->muxing_queue_data_threshold,
1437 goto fail;1356 oc, st, &muxing_queue_data_threshold);
1438
1439 ret = opt_match_per_stream_int(ost, &o->muxing_queue_data_threshold,
1440 oc, st, &muxing_queue_data_threshold);
1441 if (ret < 0)
1442 goto fail;
1443 1357
1444 sch_mux_stream_buffering(mux->sch, mux->sch_idx, ms->sch_idx,1358 sch_mux_stream_buffering(mux->sch, mux->sch_idx, ms->sch_idx,
1445 max_muxing_queue_size, muxing_queue_data_threshold);1359 max_muxing_queue_size, muxing_queue_data_threshold);
1446 }1360 }
1447 1361
1448 ret = opt_match_per_stream_int(ost, &o->bits_per_raw_sample, oc, st,1362 opt_match_per_stream_int(ost, &o->bits_per_raw_sample, oc, st,
1449 &ost->bits_per_raw_sample);1363 &ost->bits_per_raw_sample);
1450 if (ret < 0)
1451 goto fail;
1452 1364
1453 ret = opt_match_per_stream_int(ost, &o->fix_sub_duration_heartbeat,1365 opt_match_per_stream_int(ost, &o->fix_sub_duration_heartbeat,
1454 oc, st, &ost->fix_sub_duration_heartbeat);1366 oc, st, &ost->fix_sub_duration_heartbeat);
1455 if (ret < 0)
1456 goto fail;
1457 1367
1458 if (oc->oformat->flags & AVFMT_GLOBALHEADER && ost->enc_ctx)1368 if (oc->oformat->flags & AVFMT_GLOBALHEADER && ost->enc_ctx)
1459 ost->enc_ctx->flags |= AV_CODEC_FLAG_GLOBAL_HEADER;1369 ost->enc_ctx->flags |= AV_CODEC_FLAG_GLOBAL_HEADER;
1460 1370
1461 ret = opt_match_per_stream_int(ost, &o->copy_initial_nonkeyframes,1371 opt_match_per_stream_int(ost, &o->copy_initial_nonkeyframes,
1462 oc, st, &ms->copy_initial_nonkeyframes);1372 oc, st, &ms->copy_initial_nonkeyframes);
1463 if (ret < 0)
1464 goto fail;
1465
1466 switch (type) {1373 switch (type) {
1467 case AVMEDIA_TYPE_VIDEO: ret = new_stream_video (mux, o, ost, &keep_pix_fmt, &vsync_method); break;1374 case AVMEDIA_TYPE_VIDEO: ret = new_stream_video (mux, o, ost, &keep_pix_fmt, &vsync_method); break;
1468 case AVMEDIA_TYPE_AUDIO: ret = new_stream_audio (mux, o, ost); break;1375 case AVMEDIA_TYPE_AUDIO: ret = new_stream_audio (mux, o, ost); break;
@@ -3036,9 +2943,7 @@ static int set_dispositions(Muxer *mux, const OptionsContext *o) · 1567 unmodified lines
3036 2943
3037 nb_streams[ost->type + 1]++;2944 nb_streams[ost->type + 1]++;
3038 2945
3039 ret = opt_match_per_stream_str(ost, &o->disposition, ctx, ost->st, &dispositions[i]);2946 opt_match_per_stream_str(ost, &o->disposition, ctx, ost->st, &dispositions[i]);
3040 if (ret < 0)
3041 goto finish;
3042 2947
3043 have_manual |= !!dispositions[i];2948 have_manual |= !!dispositions[i];
3044 2949
@@ -3183,12 +3088,9 @@ static int process_forced_keyframes(Muxer *mux, const OptionsContext *o) · 138 unmodified lines
3183 for (int i = 0; i < mux->of.nb_streams; i++) {3088 for (int i = 0; i < mux->of.nb_streams; i++) {
3184 OutputStream *ost = mux->of.streams[i];3089 OutputStream *ost = mux->of.streams[i];
3185 const char *forced_keyframes = NULL;3090 const char *forced_keyframes = NULL;
3186 int ret;
3187 3091
3188 ret = opt_match_per_stream_str(ost, &o->forced_key_frames,3092 opt_match_per_stream_str(ost, &o->forced_key_frames,
3189 mux->fc, ost->st, &forced_keyframes);3093 mux->fc, ost->st, &forced_keyframes);
3190 if (ret < 0)
3191 return ret;
3192 3094
3193 if (!(ost->type == AVMEDIA_TYPE_VIDEO &&3095 if (!(ost->type == AVMEDIA_TYPE_VIDEO &&
3194 ost->enc_ctx && forced_keyframes))3096 ost->enc_ctx && forced_keyframes))
fftools/ffmpeg_opt.c+14−18
@@ -101,6 +101,8 @@ static void uninit_options(OptionsContext *o) · 100 unmodified lines
101 SpecifierOptList *so = dst;101 SpecifierOptList *so = dst;
102 for (int i = 0; i < so->nb_opt; i++) {102 for (int i = 0; i < so->nb_opt; i++) {
103 av_freep(&so->opt[i].specifier);103 av_freep(&so->opt[i].specifier);
104 if (po->flags & OPT_FLAG_PERSTREAM)
105 stream_specifier_uninit(&so->opt[i].stream_spec);
104 if (po->type == OPT_TYPE_STRING)106 if (po->type == OPT_TYPE_STRING)
105 av_freep(&so->opt[i].u.str);107 av_freep(&so->opt[i].u.str);
106 }108 }
@@ -164,22 +166,21 @@ const char *opt_match_per_type_str(const SpecifierOptList *sol, · 57 unmodified lines
164 return NULL;166 return NULL;
165}167}
166 168
167static int opt_match_per_stream(void *logctx, enum OptionType type,169static unsigned opt_match_per_stream(void *logctx, enum OptionType type,
168 const SpecifierOptList *sol,170 const SpecifierOptList *sol,
169 AVFormatContext *fc, AVStream *st)171 AVFormatContext *fc, AVStream *st)
170{172{
171 int matches = 0, match_idx = -1;173 int matches = 0, match_idx = -1;
172 174
173 av_assert0((type == sol->type) || !sol->nb_opt);175 av_assert0((type == sol->type) || !sol->nb_opt);
174 176
175 for (int i = 0; i < sol->nb_opt; i++) {177 for (int i = 0; i < sol->nb_opt; i++) {
176 const char *spec = sol->opt[i].specifier;178 const StreamSpecifier *ss = &sol->opt[i].stream_spec;
177 int ret = check_stream_specifier(fc, st, spec);179
178 if (ret > 0) {180 if (stream_specifier_match(ss, fc, st, logctx)) {
179 match_idx = i;181 match_idx = i;
180 matches++;182 matches++;
181 } else if (ret < 0)183 }
182 return ret;
183 }184 }
184 185
185 if (matches > 1 && sol->opt_canon) {186 if (matches > 1 && sol->opt_canon) {
@@ -216,17 +217,12 @@ static int opt_match_per_stream(void *logctx, enum OptionType type, · 30 unmodified lines
216}217}
217 218
218#define OPT_MATCH_PER_STREAM(name, type, opt_type, m) \219#define OPT_MATCH_PER_STREAM(name, type, opt_type, m) \
219int opt_match_per_stream_ ## name(void *logctx, const SpecifierOptList *sol, \220void opt_match_per_stream_ ## name(void *logctx, const SpecifierOptList *sol, \
220 AVFormatContext *fc, AVStream *st, type *out) \221 AVFormatContext *fc, AVStream *st, type *out) \
221{ \222{ \
222 int ret = opt_match_per_stream(logctx, opt_type, sol, fc, st); \223 unsigned ret = opt_match_per_stream(logctx, opt_type, sol, fc, st); \
223 \224 if (ret > 0) \
224 if (ret <= 0) \225 *out = sol->opt[ret - 1].u.m; \
225 return ret; \
226 \
227 *out = sol->opt[ret - 1].u.m; \
228 \
229 return 0; \
230}226}
231 227
232OPT_MATCH_PER_STREAM(str, const char *, OPT_TYPE_STRING, str);228OPT_MATCH_PER_STREAM(str, const char *, OPT_TYPE_STRING, str);

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t