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
288288 goto finish;
289289 }
290290 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+
291299 dst = &sol->opt[sol->nb_opt - 1].u;
292300 }
293301
fftools/cmdutils.h+5−1
@@ -159,7 +159,11 @@ unsigned stream_specifier_match(const StreamSpecifier *ss, · 158 unmodified lines
159159 void stream_specifier_uninit(StreamSpecifier *ss);
160160
161161 typedef 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+
163167 union {
164168 uint8_t *str;
165169 int i;
fftools/ffmpeg.h+8−8
@@ -859,14 +859,14 @@ void update_benchmark(const char *fmt, ...); · 858 unmodified lines
859859
860860 const char *opt_match_per_type_str(const SpecifierOptList *sol,
861861 char mediatype);
862−int opt_match_per_stream_str(void *logctx, const SpecifierOptList *sol,
863− AVFormatContext *fc, AVStream *st, const char **out);
864−int opt_match_per_stream_int(void *logctx, const SpecifierOptList *sol,
865− AVFormatContext *fc, AVStream *st, int *out);
866−int opt_match_per_stream_int64(void *logctx, const SpecifierOptList *sol,
867− AVFormatContext *fc, AVStream *st, int64_t *out);
868−int opt_match_per_stream_dbl(void *logctx, const SpecifierOptList *sol,
869− AVFormatContext *fc, AVStream *st, double *out);
862+void opt_match_per_stream_str(void *logctx, const SpecifierOptList *sol,
863+ AVFormatContext *fc, AVStream *st, const char **out);
864+void opt_match_per_stream_int(void *logctx, const SpecifierOptList *sol,
865+ AVFormatContext *fc, AVStream *st, int *out);
866+void opt_match_per_stream_int64(void *logctx, const SpecifierOptList *sol,
867+ AVFormatContext *fc, AVStream *st, int64_t *out);
868+void opt_match_per_stream_dbl(void *logctx, const SpecifierOptList *sol,
869+ AVFormatContext *fc, AVStream *st, double *out);
870870
871871 int muxer_thread(void *arg);
872872 int 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
10841084
10851085 {
10861086 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;
10921087
1088+ opt_match_per_stream_str(logctx, &o->codec_names, s, st, &codec_name);
10931089 if (codec_name) {
10941090 int ret = find_codec(NULL, codec_name, st->codecpar->codec_type, 0, pcodec);
10951091 if (ret < 0)
@@ -1153,18 +1149,11 @@ static int add_display_matrix_to_stream(const OptionsContext *o, · 57 unmodified lines
11531149 double rotation = DBL_MAX;
11541150 int hflip = -1, vflip = -1;
11551151 int hflip_set = 0, vflip_set = 0, rotation_set = 0;
1156− int ret;
11571152 int32_t *buf;
11581153
1159− ret = opt_match_per_stream_dbl(ist, &o->display_rotations, ctx, st, &rotation);
1160− if (ret < 0)
1161− return ret;
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;
1154+ opt_match_per_stream_dbl(ist, &o->display_rotations, ctx, st, &rotation);
1155+ opt_match_per_stream_int(ist, &o->display_hflips, ctx, st, &hflip);
1156+ opt_match_per_stream_int(ist, &o->display_vflips, ctx, st, &vflip);
11681157
11691158 rotation_set = rotation != DBL_MAX;
11701159 hflip_set = hflip != -1;
@@ -1262,19 +1251,13 @@ static int ist_add(const OptionsContext *o, Demuxer *d, AVStream *st, AVDictiona · 91 unmodified lines
12621251 ds->dec_opts.time_base = st->time_base;
12631252
12641253 ds->ts_scale = 1.0;
1265− ret = opt_match_per_stream_dbl(ist, &o->ts_scale, ic, st, &ds->ts_scale);
1266− if (ret < 0)
1267− return ret;
1254+ opt_match_per_stream_dbl(ist, &o->ts_scale, ic, st, &ds->ts_scale);
12681255
12691256 ds->autorotate = 1;
1270− ret = opt_match_per_stream_int(ist, &o->autorotate, ic, st, &ds->autorotate);
1271− if (ret < 0)
1272− return ret;
1257+ opt_match_per_stream_int(ist, &o->autorotate, ic, st, &ds->autorotate);
12731258
12741259 ds->apply_cropping = CROP_ALL;
1275− ret = opt_match_per_stream_str(ist, &o->apply_cropping, ic, st, &apply_cropping);
1276− if (ret < 0)
1277− return ret;
1260+ opt_match_per_stream_str(ist, &o->apply_cropping, ic, st, &apply_cropping);
12781261 if (apply_cropping) {
12791262 const AVOption opts[] = {
12801263 { "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
13001283 }
13011284 }
13021285
1303− ret = opt_match_per_stream_str(ist, &o->codec_tags, ic, st, &codec_tag);
1304− if (ret < 0)
1305− return ret;
1286+ opt_match_per_stream_str(ist, &o->codec_tags, ic, st, &codec_tag);
13061287 if (codec_tag) {
13071288 uint32_t tag = strtol(codec_tag, &next, 0);
13081289 if (*next) {
@@ -1319,15 +1300,9 @@ static int ist_add(const OptionsContext *o, Demuxer *d, AVStream *st, AVDictiona · 10 unmodified lines
13191300 if (ret < 0)
13201301 return ret;
13211302
1322− ret = opt_match_per_stream_str(ist, &o->hwaccels, ic, st, &hwaccel);
1323− if (ret < 0)
1324− return ret;
1325−
1326− ret = opt_match_per_stream_str(ist, &o->hwaccel_output_formats, ic, st,
1303+ opt_match_per_stream_str(ist, &o->hwaccels, ic, st, &hwaccel);
1304+ opt_match_per_stream_str(ist, &o->hwaccel_output_formats, ic, st,
13271305 &hwaccel_output_format);
1328− if (ret < 0)
1329− return ret;
1330−
13311306 if (!hwaccel_output_format && hwaccel && !strcmp(hwaccel, "cuvid")) {
13321307 av_log(ist, AV_LOG_WARNING,
13331308 "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
13851360 }
13861361 }
13871362
1388− ret = opt_match_per_stream_str(ist, &o->hwaccel_devices, ic, st, &hwaccel_device);
1389− if (ret < 0)
1390− return ret;
1363+ opt_match_per_stream_str(ist, &o->hwaccel_devices, ic, st, &hwaccel_device);
13911364 if (hwaccel_device) {
13921365 ds->dec_opts.hwaccel_device = av_strdup(hwaccel_device);
13931366 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
14081381 }
14091382
14101383 ds->reinit_filters = -1;
1411− ret = opt_match_per_stream_int(ist, &o->reinit_filters, ic, st, &ds->reinit_filters);
1412− if (ret < 0)
1413− return ret;
1384+ opt_match_per_stream_int(ist, &o->reinit_filters, ic, st, &ds->reinit_filters);
14141385
14151386 ist->user_set_discard = AVDISCARD_NONE;
14161387
@@ -1420,9 +1391,7 @@ static int ist_add(const OptionsContext *o, Demuxer *d, AVStream *st, AVDictiona · 3 unmodified lines
14201391 (o->data_disable && ist->st->codecpar->codec_type == AVMEDIA_TYPE_DATA))
14211392 ist->user_set_discard = AVDISCARD_ALL;
14221393
1423− ret = opt_match_per_stream_str(ist, &o->discard, ic, st, &discard_str);
1424− if (ret < 0)
1425− return ret;
1394+ opt_match_per_stream_str(ist, &o->discard, ic, st, &discard_str);
14261395 if (discard_str) {
14271396 ret = av_opt_set(ist->st, "discard", discard_str, 0);
14281397 if (ret < 0) {
@@ -1444,9 +1413,7 @@ static int ist_add(const OptionsContext *o, Demuxer *d, AVStream *st, AVDictiona · 15 unmodified lines
14441413
14451414 switch (par->codec_type) {
14461415 case AVMEDIA_TYPE_VIDEO:
1447− ret = opt_match_per_stream_str(ist, &o->frame_rates, ic, st, &framerate);
1448− if (ret < 0)
1449− return ret;
1416+ opt_match_per_stream_str(ist, &o->frame_rates, ic, st, &framerate);
14501417 if (framerate) {
14511418 ret = av_parse_video_rate(&ist->framerate, framerate);
14521419 if (ret < 0) {
@@ -1458,18 +1425,14 @@ static int ist_add(const OptionsContext *o, Demuxer *d, AVStream *st, AVDictiona · 5 unmodified lines
14581425
14591426 #if FFMPEG_OPT_TOP
14601427 ist->top_field_first = -1;
1461− ret = opt_match_per_stream_int(ist, &o->top_field_first, ic, st, &ist->top_field_first);
1462− if (ret < 0)
1463− return ret;
1428+ opt_match_per_stream_int(ist, &o->top_field_first, ic, st, &ist->top_field_first);
14641429 #endif
14651430
14661431 break;
14671432 case AVMEDIA_TYPE_AUDIO: {
14681433 const char *ch_layout_str = NULL;
14691434
1470− ret = opt_match_per_stream_str(ist, &o->audio_ch_layouts, ic, st, &ch_layout_str);
1471− if (ret < 0)
1472− return ret;
1435+ opt_match_per_stream_str(ist, &o->audio_ch_layouts, ic, st, &ch_layout_str);
14731436 if (ch_layout_str) {
14741437 AVChannelLayout ch_layout;
14751438 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
14891452 }
14901453 } else {
14911454 int guess_layout_max = INT_MAX;
1492− ret = opt_match_per_stream_int(ist, &o->guess_layout_max, ic, st, &guess_layout_max);
1493− if (ret < 0)
1494− return ret;
1495−
1455+ opt_match_per_stream_int(ist, &o->guess_layout_max, ic, st, &guess_layout_max);
14961456 guess_input_channel_layout(ist, par, guess_layout_max);
14971457 }
14981458 break;
@@ -1501,13 +1461,8 @@ static int ist_add(const OptionsContext *o, Demuxer *d, AVStream *st, AVDictiona · 2 unmodified lines
15011461 case AVMEDIA_TYPE_SUBTITLE: {
15021462 const char *canvas_size = NULL;
15031463
1504− ret = opt_match_per_stream_int(ist, &o->fix_sub_duration, ic, st, &ist->fix_sub_duration);
1505− if (ret < 0)
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;
1464+ opt_match_per_stream_int(ist, &o->fix_sub_duration, ic, st, &ist->fix_sub_duration);
1465+ opt_match_per_stream_str(ist, &o->canvas_sizes, ic, st, &canvas_size);
15111466 if (canvas_size) {
15121467 ret = av_parse_video_size(&par->width, &par->height,
15131468 canvas_size);
@@ -1537,9 +1492,7 @@ static int ist_add(const OptionsContext *o, Demuxer *d, AVStream *st, AVDictiona · 23 unmodified lines
15371492 if (ist->st->sample_aspect_ratio.num)
15381493 ist->par->sample_aspect_ratio = ist->st->sample_aspect_ratio;
15391494
1540− ret = opt_match_per_stream_str(ist, &o->bitstream_filters, ic, st, &bsfs);
1541− if (ret < 0)
1542− return ret;
1495+ opt_match_per_stream_str(ist, &o->bitstream_filters, ic, st, &bsfs);
15431496 if (bsfs) {
15441497 ret = av_bsf_list_parse_str(bsfs, &ds->bsf);
15451498 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
7171 {
7272 enum AVMediaType type = ost->type;
7373 const char *codec_name = NULL;
74− int ret;
7574
7675 *enc = NULL;
7776
78− ret = opt_match_per_stream_str(ost, &o->codec_names, s, ost->st, &codec_name);
79− if (ret < 0)
80− return ret;
77+ opt_match_per_stream_str(ost, &o->codec_names, s, ost->st, &codec_name);
8178
8279 if (type != AVMEDIA_TYPE_VIDEO &&
8380 type != AVMEDIA_TYPE_AUDIO &&
@@ -419,17 +416,12 @@ static int ost_get_filters(const OptionsContext *o, AVFormatContext *oc, · 335 unmodified lines
419416 OutputStream *ost, char **dst)
420417 {
421418 const char *filters = NULL;
422− int ret;
423419 #if FFMPEG_OPT_FILTER_SCRIPT
424420 const char *filters_script = NULL;
425421
426− ret = opt_match_per_stream_str(ost, &o->filter_scripts, oc, ost->st, &filters_script);
427− if (ret < 0)
428− return ret;
422+ opt_match_per_stream_str(ost, &o->filter_scripts, oc, ost->st, &filters_script);
429423 #endif
430− ret = opt_match_per_stream_str(ost, &o->filters, oc, ost->st, &filters);
431− if (ret < 0)
432− return ret;
424+ opt_match_per_stream_str(ost, &o->filters, oc, ost->st, &filters);
433425
434426 if (!ost->enc) {
435427 if (
@@ -599,17 +591,13 @@ static int new_stream_video(Muxer *mux, const OptionsContext *o, · 163 unmodified lines
599591
600592 st = ost->st;
601593
602− ret = opt_match_per_stream_str(ost, &o->frame_rates, oc, st, &frame_rate);
603− if (ret < 0)
604− return ret;
594+ opt_match_per_stream_str(ost, &o->frame_rates, oc, st, &frame_rate);
605595 if (frame_rate && av_parse_video_rate(&ost->frame_rate, frame_rate) < 0) {
606596 av_log(ost, AV_LOG_FATAL, "Invalid framerate value: %s\n", frame_rate);
607597 return AVERROR(EINVAL);
608598 }
609599
610− ret = opt_match_per_stream_str(ost, &o->max_frame_rates, oc, st, &max_frame_rate);
611− if (ret < 0)
612− return ret;
600+ opt_match_per_stream_str(ost, &o->max_frame_rates, oc, st, &max_frame_rate);
613601 if (max_frame_rate && av_parse_video_rate(&ost->max_frame_rate, max_frame_rate) < 0) {
614602 av_log(ost, AV_LOG_FATAL, "Invalid maximum framerate value: %s\n", max_frame_rate);
615603 return AVERROR(EINVAL);
@@ -620,9 +608,7 @@ static int new_stream_video(Muxer *mux, const OptionsContext *o, · 4 unmodified lines
620608 return AVERROR(EINVAL);
621609 }
622610
623− ret = opt_match_per_stream_str(ost, &o->frame_aspect_ratios, oc, st, &frame_aspect_ratio);
624− if (ret < 0)
625− return ret;
611+ opt_match_per_stream_str(ost, &o->frame_aspect_ratios, oc, st, &frame_aspect_ratio);
626612 if (frame_aspect_ratio) {
627613 AVRational q;
628614 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
643629 int do_pass = 0;
644630 int i;
645631
646− ret = opt_match_per_stream_str(ost, &o->frame_sizes, oc, st, &frame_size);
647− if (ret < 0)
648− return ret;
632+ opt_match_per_stream_str(ost, &o->frame_sizes, oc, st, &frame_size);
649633 if (frame_size) {
650634 ret = av_parse_video_size(&video_enc->width, &video_enc->height, frame_size);
651635 if (ret < 0) {
@@ -654,9 +638,7 @@ static int new_stream_video(Muxer *mux, const OptionsContext *o, · 2 unmodified lines
654638 }
655639 }
656640
657− ret = opt_match_per_stream_str(ost, &o->frame_pix_fmts, oc, st, &frame_pix_fmt);
658− if (ret < 0)
659− return ret;
641+ opt_match_per_stream_str(ost, &o->frame_pix_fmts, oc, st, &frame_pix_fmt);
660642 if (frame_pix_fmt && *frame_pix_fmt == '+') {
661643 *keep_pix_fmt = 1;
662644 if (!*++frame_pix_fmt)
@@ -668,9 +650,7 @@ static int new_stream_video(Muxer *mux, const OptionsContext *o, · 5 unmodified lines
668650 return AVERROR(EINVAL);
669651 }
670652
671− ret = opt_match_per_stream_str(ost, &o->intra_matrices, oc, st, &intra_matrix);
672− if (ret < 0)
673− return ret;
653+ opt_match_per_stream_str(ost, &o->intra_matrices, oc, st, &intra_matrix);
674654 if (intra_matrix) {
675655 if (!(video_enc->intra_matrix = av_mallocz(sizeof(*video_enc->intra_matrix) * 64)))
676656 return AVERROR(ENOMEM);
@@ -679,9 +659,7 @@ static int new_stream_video(Muxer *mux, const OptionsContext *o, · 2 unmodified lines
679659 if (ret < 0)
680660 return ret;
681661 }
682− ret = opt_match_per_stream_str(ost, &o->chroma_intra_matrices, oc, st, &chroma_intra_matrix);
683− if (ret < 0)
684− return ret;
662+ opt_match_per_stream_str(ost, &o->chroma_intra_matrices, oc, st, &chroma_intra_matrix);
685663 if (chroma_intra_matrix) {
686664 uint16_t *p = av_mallocz(sizeof(*video_enc->chroma_intra_matrix) * 64);
687665 if (!p)
@@ -691,9 +669,7 @@ static int new_stream_video(Muxer *mux, const OptionsContext *o, · 3 unmodified lines
691669 if (ret < 0)
692670 return ret;
693671 }
694− ret = opt_match_per_stream_str(ost, &o->inter_matrices, oc, st, &inter_matrix);
695− if (ret < 0)
696− return ret;
672+ opt_match_per_stream_str(ost, &o->inter_matrices, oc, st, &inter_matrix);
697673 if (inter_matrix) {
698674 if (!(video_enc->inter_matrix = av_mallocz(sizeof(*video_enc->inter_matrix) * 64)))
699675 return AVERROR(ENOMEM);
@@ -702,9 +678,7 @@ static int new_stream_video(Muxer *mux, const OptionsContext *o, · 2 unmodified lines
702678 return ret;
703679 }
704680
705− ret = opt_match_per_stream_str(ost, &o->rc_overrides, oc, st, &p);
706− if (ret < 0)
707− return ret;
681+ opt_match_per_stream_str(ost, &o->rc_overrides, oc, st, &p);
708682 for (i = 0; p; i++) {
709683 int start, end, q;
710684 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
735709 video_enc->rc_override_count = i;
736710
737711 /* two pass mode */
738− ret = opt_match_per_stream_int(ost, &o->pass, oc, st, &do_pass);
739− if (ret < 0)
740− return ret;
712+ opt_match_per_stream_int(ost, &o->pass, oc, st, &do_pass);
741713 if (do_pass) {
742714 if (do_pass & 1)
743715 video_enc->flags |= AV_CODEC_FLAG_PASS1;
@@ -745,9 +717,7 @@ static int new_stream_video(Muxer *mux, const OptionsContext *o, · 1 unmodified line
745717 video_enc->flags |= AV_CODEC_FLAG_PASS2;
746718 }
747719
748− ret = opt_match_per_stream_str(ost, &o->passlogfiles, oc, st, &ost->logfile_prefix);
749− if (ret < 0)
750− return ret;
720+ opt_match_per_stream_str(ost, &o->passlogfiles, oc, st, &ost->logfile_prefix);
751721 if (ost->logfile_prefix &&
752722 !(ost->logfile_prefix = av_strdup(ost->logfile_prefix)))
753723 return AVERROR(ENOMEM);
@@ -794,15 +764,11 @@ static int new_stream_video(Muxer *mux, const OptionsContext *o, · 40 unmodified lines
794764 }
795765 }
796766
797− ret = opt_match_per_stream_int(ost, &o->force_fps, oc, st, &ost->force_fps);
798− if (ret < 0)
799− return ret;
767+ opt_match_per_stream_int(ost, &o->force_fps, oc, st, &ost->force_fps);
800768
801769 #if FFMPEG_OPT_TOP
802770 ost->top_field_first = -1;
803− ret = opt_match_per_stream_int(ost, &o->top_field_first, oc, st, &ost->top_field_first);
804− if (ret < 0)
805− return ret;
771+ opt_match_per_stream_int(ost, &o->top_field_first, oc, st, &ost->top_field_first);
806772 if (ost->top_field_first >= 0)
807773 av_log(ost, AV_LOG_WARNING, "-top is deprecated, use the setfield filter instead\n");
808774 #endif
@@ -812,9 +778,7 @@ static int new_stream_video(Muxer *mux, const OptionsContext *o, · 3 unmodified lines
812778 #else
813779 *vsync_method = VSYNC_AUTO;
814780 #endif
815− ret = opt_match_per_stream_str(ost, &o->fps_mode, oc, st, &fps_mode);
816− if (ret < 0)
817− return ret;
781+ opt_match_per_stream_str(ost, &o->fps_mode, oc, st, &fps_mode);
818782 if (fps_mode) {
819783 ret = parse_and_set_vsync(fps_mode, vsync_method, ost->file->index, ost->index, 0);
820784 if (ret < 0)
@@ -872,40 +836,28 @@ static int new_stream_audio(Muxer *mux, const OptionsContext *o, · 51 unmodified lines
872836 int channels = 0;
873837 const char *layout = NULL;
874838 const char *sample_fmt = NULL;
875− int ret;
876839
877− ret = opt_match_per_stream_int(ost, &o->audio_channels, oc, st, &channels);
878− if (ret < 0)
879− return ret;
840+ opt_match_per_stream_int(ost, &o->audio_channels, oc, st, &channels);
880841 if (channels) {
881842 audio_enc->ch_layout.order = AV_CHANNEL_ORDER_UNSPEC;
882843 audio_enc->ch_layout.nb_channels = channels;
883844 }
884845
885− ret = opt_match_per_stream_str(ost, &o->audio_ch_layouts, oc, st, &layout);
886− if (ret < 0)
887− return ret;
846+ opt_match_per_stream_str(ost, &o->audio_ch_layouts, oc, st, &layout);
888847 if (layout && av_channel_layout_from_string(&audio_enc->ch_layout, layout) < 0) {
889848 av_log(ost, AV_LOG_FATAL, "Unknown channel layout: %s\n", layout);
890849 return AVERROR(EINVAL);
891850 }
892851
893− ret = opt_match_per_stream_str(ost, &o->sample_fmts, oc, st, &sample_fmt);
894− if (ret < 0)
895− return ret;
852+ opt_match_per_stream_str(ost, &o->sample_fmts, oc, st, &sample_fmt);
896853 if (sample_fmt &&
897854 (audio_enc->sample_fmt = av_get_sample_fmt(sample_fmt)) == AV_SAMPLE_FMT_NONE) {
898855 av_log(ost, AV_LOG_FATAL, "Invalid sample format '%s'\n", sample_fmt);
899856 return AVERROR(EINVAL);
900857 }
901858
902− ret = opt_match_per_stream_int(ost, &o->audio_sample_rate, oc, st, &audio_enc->sample_rate);
903− if (ret < 0)
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;
859+ opt_match_per_stream_int(ost, &o->audio_sample_rate, oc, st, &audio_enc->sample_rate);
860+ opt_match_per_stream_str(ost, &o->apad, oc, st, &ms->apad);
909861 }
910862
911863 return 0;
@@ -928,11 +880,8 @@ static int new_stream_subtitle(Muxer *mux, const OptionsContext *o, · 16 unmodified lines
928880 int input_props = 0, output_props = 0;
929881
930882 const char *frame_size = NULL;
931− int ret;
932883
933− ret = opt_match_per_stream_str(ost, &o->frame_sizes, mux->fc, st, &frame_size);
934− if (ret < 0)
935− return ret;
884+ opt_match_per_stream_str(ost, &o->frame_sizes, mux->fc, st, &frame_size);
936885 if (frame_size) {
937886 int ret = av_parse_video_size(&subtitle_enc->width, &subtitle_enc->height, frame_size);
938887 if (ret < 0) {
@@ -1211,13 +1160,8 @@ static int ost_add(Muxer *mux, const OptionsContext *o, enum AVMediaType type, · 272 unmodified lines
12111160 if (ret < 0)
12121161 goto fail;
12131162
1214− ret = opt_match_per_stream_str(ost, &o->presets, oc, st, &preset);
1215− if (ret < 0)
1216− goto fail;
1217−
1218− ret = opt_match_per_stream_int(ost, &o->autoscale, oc, st, &autoscale);
1219− if (ret < 0)
1220− goto fail;
1163+ opt_match_per_stream_str(ost, &o->presets, oc, st, &preset);
1164+ opt_match_per_stream_int(ost, &o->autoscale, oc, st, &autoscale);
12211165 if (preset && (!(ret = get_preset_file_2(preset, enc->codec->name, &s)))) {
12221166 AVBPrint bprint;
12231167 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
12481192 goto fail;
12491193 }
12501194
1251− ret = opt_match_per_stream_str(ost, &o->enc_stats_pre, oc, st, &enc_stats_pre);
1252− if (ret < 0)
1253− goto fail;
1195+ opt_match_per_stream_str(ost, &o->enc_stats_pre, oc, st, &enc_stats_pre);
12541196 if (enc_stats_pre &&
12551197 (type == AVMEDIA_TYPE_VIDEO || type == AVMEDIA_TYPE_AUDIO)) {
12561198 const char *format = "{fidx} {sidx} {n} {t}";
12571199
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);
12591201 if (ret < 0)
12601202 goto fail;
12611203
@@ -1264,41 +1206,31 @@ static int ost_add(Muxer *mux, const OptionsContext *o, enum AVMediaType type, · 2 unmodified lines
12641206 goto fail;
12651207 }
12661208
1267− ret = opt_match_per_stream_str(ost, &o->enc_stats_post, oc, st, &enc_stats_post);
1268− if (ret < 0)
1269− goto fail;
1209+ opt_match_per_stream_str(ost, &o->enc_stats_post, oc, st, &enc_stats_post);
12701210 if (enc_stats_post &&
12711211 (type == AVMEDIA_TYPE_VIDEO || type == AVMEDIA_TYPE_AUDIO)) {
12721212 const char *format = "{fidx} {sidx} {n} {t}";
12731213
1274− ret = opt_match_per_stream_str(ost, &o->enc_stats_post_fmt, oc, st, &format);
1275− if (ret < 0)
1276− goto fail;
1214+ opt_match_per_stream_str(ost, &o->enc_stats_post_fmt, oc, st, &format);
12771215
12781216 ret = enc_stats_init(ost, &ost->enc_stats_post, 0, enc_stats_post, format);
12791217 if (ret < 0)
12801218 goto fail;
12811219 }
12821220
1283− ret = opt_match_per_stream_str(ost, &o->mux_stats, oc, st, &mux_stats);
1284− if (ret < 0)
1285− goto fail;
1221+ opt_match_per_stream_str(ost, &o->mux_stats, oc, st, &mux_stats);
12861222 if (mux_stats &&
12871223 (type == AVMEDIA_TYPE_VIDEO || type == AVMEDIA_TYPE_AUDIO)) {
12881224 const char *format = "{fidx} {sidx} {n} {t}";
12891225
1290− ret = opt_match_per_stream_str(ost, &o->mux_stats_fmt, oc, st, &format);
1291− if (ret < 0)
1292− goto fail;
1226+ opt_match_per_stream_str(ost, &o->mux_stats_fmt, oc, st, &format);
12931227
12941228 ret = enc_stats_init(ost, &ms->stats, 0, mux_stats, format);
12951229 if (ret < 0)
12961230 goto fail;
12971231 }
12981232
1299− ret = opt_match_per_stream_str(ost, &o->enc_time_bases, oc, st, &enc_time_base);
1300− if (ret < 0)
1301− goto fail;
1233+ opt_match_per_stream_str(ost, &o->enc_time_bases, oc, st, &enc_time_base);
13021234 if (enc_time_base && type == AVMEDIA_TYPE_SUBTITLE)
13031235 av_log(ost, AV_LOG_WARNING,
13041236 "-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
13611293 ost->bitexact = !!(ost->enc_ctx->flags & AV_CODEC_FLAG_BITEXACT);
13621294 }
13631295
1364− ret = opt_match_per_stream_str(ost, &o->time_bases, oc, st, &time_base);
1365− if (ret < 0)
1366− goto fail;
1296+ opt_match_per_stream_str(ost, &o->time_bases, oc, st, &time_base);
13671297 if (time_base) {
13681298 AVRational q;
13691299 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
13761306 }
13771307
13781308 ms->max_frames = INT64_MAX;
1379− ret = opt_match_per_stream_int64(ost, &o->max_frames, oc, st, &ms->max_frames);
1380− if (ret < 0)
1381− return ret;
1309+ opt_match_per_stream_int64(ost, &o->max_frames, oc, st, &ms->max_frames);
13821310 for (int i = 0; i < o->max_frames.nb_opt; i++) {
13831311 char *p = o->max_frames.opt[i].specifier;
13841312 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
13881316 }
13891317
13901318 ms->copy_prior_start = -1;
1391− ret = opt_match_per_stream_int(ost, &o->copy_prior_start, oc, st, &ms->copy_prior_start);
1392− if (ret < 0)
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;
1319+ opt_match_per_stream_int(ost, &o->copy_prior_start, oc, st, &ms->copy_prior_start);
1320+ opt_match_per_stream_str(ost, &o->bitstream_filters, oc, st, &bsfs);
13981321 if (bsfs && *bsfs) {
13991322 ret = av_bsf_list_parse_str(bsfs, &ms->bsf_ctx);
14001323 if (ret < 0) {
@@ -1403,9 +1326,7 @@ static int ost_add(Muxer *mux, const OptionsContext *o, enum AVMediaType type, · 2 unmodified lines
14031326 }
14041327 }
14051328
1406− ret = opt_match_per_stream_str(ost, &o->codec_tags, oc, st, &codec_tag);
1407− if (ret < 0)
1408− goto fail;
1329+ opt_match_per_stream_str(ost, &o->codec_tags, oc, st, &codec_tag);
14091330 if (codec_tag) {
14101331 uint32_t tag = strtol(codec_tag, &next, 0);
14111332 if (*next) {
@@ -1419,9 +1340,7 @@ static int ost_add(Muxer *mux, const OptionsContext *o, enum AVMediaType type, · 7 unmodified lines
14191340 ost->enc_ctx->codec_tag = tag;
14201341 }
14211342
1422− ret = opt_match_per_stream_dbl(ost, &o->qscale, oc, st, &qscale);
1423− if (ret < 0)
1424− return ret;
1343+ opt_match_per_stream_dbl(ost, &o->qscale, oc, st, &qscale);
14251344 if (ost->enc_ctx && qscale >= 0) {
14261345 ost->enc_ctx->flags |= AV_CODEC_FLAG_QSCALE;
14271346 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
14311350 int max_muxing_queue_size = 128;
14321351 int muxing_queue_data_threshold = 50 * 1024 * 1024;
14331352
1434− ret = opt_match_per_stream_int(ost, &o->max_muxing_queue_size, oc, st,
1435− &max_muxing_queue_size);
1436− if (ret < 0)
1437− goto fail;
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;
1353+ opt_match_per_stream_int(ost, &o->max_muxing_queue_size, oc, st,
1354+ &max_muxing_queue_size);
1355+ opt_match_per_stream_int(ost, &o->muxing_queue_data_threshold,
1356+ oc, st, &muxing_queue_data_threshold);
14431357
14441358 sch_mux_stream_buffering(mux->sch, mux->sch_idx, ms->sch_idx,
14451359 max_muxing_queue_size, muxing_queue_data_threshold);
14461360 }
14471361
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,
14491363 &ost->bits_per_raw_sample);
1450− if (ret < 0)
1451− goto fail;
14521364
1453− ret = opt_match_per_stream_int(ost, &o->fix_sub_duration_heartbeat,
1454− oc, st, &ost->fix_sub_duration_heartbeat);
1455− if (ret < 0)
1456− goto fail;
1365+ opt_match_per_stream_int(ost, &o->fix_sub_duration_heartbeat,
1366+ oc, st, &ost->fix_sub_duration_heartbeat);
14571367
14581368 if (oc->oformat->flags & AVFMT_GLOBALHEADER && ost->enc_ctx)
14591369 ost->enc_ctx->flags |= AV_CODEC_FLAG_GLOBAL_HEADER;
14601370
1461− ret = opt_match_per_stream_int(ost, &o->copy_initial_nonkeyframes,
1462− oc, st, &ms->copy_initial_nonkeyframes);
1463− if (ret < 0)
1464− goto fail;
1465−
1371+ opt_match_per_stream_int(ost, &o->copy_initial_nonkeyframes,
1372+ oc, st, &ms->copy_initial_nonkeyframes);
14661373 switch (type) {
14671374 case AVMEDIA_TYPE_VIDEO: ret = new_stream_video (mux, o, ost, &keep_pix_fmt, &vsync_method); break;
14681375 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
30362943
30372944 nb_streams[ost->type + 1]++;
30382945
3039− ret = opt_match_per_stream_str(ost, &o->disposition, ctx, ost->st, &dispositions[i]);
3040− if (ret < 0)
3041− goto finish;
2946+ opt_match_per_stream_str(ost, &o->disposition, ctx, ost->st, &dispositions[i]);
30422947
30432948 have_manual |= !!dispositions[i];
30442949
@@ -3183,12 +3088,9 @@ static int process_forced_keyframes(Muxer *mux, const OptionsContext *o) · 138 unmodified lines
31833088 for (int i = 0; i < mux->of.nb_streams; i++) {
31843089 OutputStream *ost = mux->of.streams[i];
31853090 const char *forced_keyframes = NULL;
3186− int ret;
31873091
3188− ret = opt_match_per_stream_str(ost, &o->forced_key_frames,
3189− mux->fc, ost->st, &forced_keyframes);
3190− if (ret < 0)
3191− return ret;
3092+ opt_match_per_stream_str(ost, &o->forced_key_frames,
3093+ mux->fc, ost->st, &forced_keyframes);
31923094
31933095 if (!(ost->type == AVMEDIA_TYPE_VIDEO &&
31943096 ost->enc_ctx && forced_keyframes))
fftools/ffmpeg_opt.c+14−18
@@ -101,6 +101,8 @@ static void uninit_options(OptionsContext *o) · 100 unmodified lines
101101 SpecifierOptList *so = dst;
102102 for (int i = 0; i < so->nb_opt; i++) {
103103 av_freep(&so->opt[i].specifier);
104+ if (po->flags & OPT_FLAG_PERSTREAM)
105+ stream_specifier_uninit(&so->opt[i].stream_spec);
104106 if (po->type == OPT_TYPE_STRING)
105107 av_freep(&so->opt[i].u.str);
106108 }
@@ -164,22 +166,21 @@ const char *opt_match_per_type_str(const SpecifierOptList *sol, · 57 unmodified lines
164166 return NULL;
165167 }
166168
167−static int opt_match_per_stream(void *logctx, enum OptionType type,
168− const SpecifierOptList *sol,
169− AVFormatContext *fc, AVStream *st)
169+static unsigned opt_match_per_stream(void *logctx, enum OptionType type,
170+ const SpecifierOptList *sol,
171+ AVFormatContext *fc, AVStream *st)
170172 {
171173 int matches = 0, match_idx = -1;
172174
173175 av_assert0((type == sol->type) || !sol->nb_opt);
174176
175177 for (int i = 0; i < sol->nb_opt; i++) {
176− const char *spec = sol->opt[i].specifier;
177− int ret = check_stream_specifier(fc, st, spec);
178− if (ret > 0) {
178+ const StreamSpecifier *ss = &sol->opt[i].stream_spec;
179+
180+ if (stream_specifier_match(ss, fc, st, logctx)) {
179181 match_idx = i;
180182 matches++;
181− } else if (ret < 0)
182− return ret;
183+ }
183184 }
184185
185186 if (matches > 1 && sol->opt_canon) {
@@ -216,17 +217,12 @@ static int opt_match_per_stream(void *logctx, enum OptionType type, · 30 unmodified lines
216217 }
217218
218219 #define OPT_MATCH_PER_STREAM(name, type, opt_type, m) \
219−int opt_match_per_stream_ ## name(void *logctx, const SpecifierOptList *sol, \
220− AVFormatContext *fc, AVStream *st, type *out) \
220+void opt_match_per_stream_ ## name(void *logctx, const SpecifierOptList *sol, \
221+ AVFormatContext *fc, AVStream *st, type *out) \
221222 { \
222− int ret = opt_match_per_stream(logctx, opt_type, sol, fc, st); \
223− \
224− if (ret <= 0) \
225− return ret; \
226− \
227− *out = sol->opt[ret - 1].u.m; \
228− \
229− return 0; \
223+ unsigned ret = opt_match_per_stream(logctx, opt_type, sol, fc, st); \
224+ if (ret > 0) \
225+ *out = sol->opt[ret - 1].u.m; \
230226 }
231227
232228 OPT_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