History

avfilter/vf_colorspace: use colorspace negotiation API

Fixes a regression due to the fact that the colorspace filter does not use the new API introduced by 8c7934f73ab6c568acaa. The scale filter uses it since 45e09a30419cc2a7251e, and the setparams filter since 3bf80df3ccd32aed23f0. Example: ffprobe -f lavfi yuvtestsrc,setparams=color_primaries=bt470bg:color_trc= bt470bg:colorspace=bt470bg,colorspace=bt709:range=tv,scale,showinfo Before: color_range:unknown color_space:bt470bg ... After: color_range:tv color_space:bt709 ...

Nicolas Gaullier committed 2 years ago

Commit 376b3d51 parent 38c32261 file · +36 −26Browse files

Showing the changes to libavfilter (1 of 1 file). Show all

Unified · Split

libavfilter/vf_colorspace.c+36−26
@@ -433,8 +433,7 @@ static int create_filtergraph(AVFilterContext *ctx, · 432 unmodified lines
433433 if (out->color_trc != s->out_trc) s->out_txchr = NULL;
434434 if (in->colorspace != s->in_csp ||
435435 in->color_range != s->in_rng) s->in_lumacoef = NULL;
436− if (out->colorspace != s->out_csp ||
437− out->color_range != s->out_rng) s->out_lumacoef = NULL;
436+ if (out->color_range != s->out_rng) s->rgb2yuv = NULL;
438437
439438 if (!s->out_primaries || !s->in_primaries) {
440439 s->in_prm = in->color_primaries;
@@ -563,26 +562,8 @@ static int create_filtergraph(AVFilterContext *ctx, · 122 unmodified lines
563562 redo_yuv2rgb = 1;
564563 }
565564
566− if (!s->out_lumacoef) {
567− s->out_csp = out->colorspace;
565+ if (!s->rgb2yuv) {
568566 s->out_rng = out->color_range;
569− s->out_lumacoef = av_csp_luma_coeffs_from_avcsp(s->out_csp);
570− if (!s->out_lumacoef) {
571− if (s->out_csp == AVCOL_SPC_UNSPECIFIED) {
572− if (s->user_all == CS_UNSPECIFIED) {
573− av_log(ctx, AV_LOG_ERROR,
574− "Please specify output colorspace\n");
575− } else {
576− av_log(ctx, AV_LOG_ERROR,
577− "Unsupported output color property %d\n", s->user_all);
578− }
579− } else {
580− av_log(ctx, AV_LOG_ERROR,
581− "Unsupported output colorspace %d (%s)\n", s->out_csp,
582− av_color_space_name(s->out_csp));
583− }
584− return AVERROR(EINVAL);
585− }
586567 redo_rgb2yuv = 1;
587568 }
588569
@@ -687,6 +668,26 @@ static av_cold int init(AVFilterContext *ctx) · 98 unmodified lines
687668 {
688669 ColorSpaceContext *s = ctx->priv;
689670
671+ s->out_csp = s->user_csp == AVCOL_SPC_UNSPECIFIED ?
672+ default_csp[FFMIN(s->user_all, CS_NB)] : s->user_csp;
673+ s->out_lumacoef = av_csp_luma_coeffs_from_avcsp(s->out_csp);
674+ if (!s->out_lumacoef) {
675+ if (s->out_csp == AVCOL_SPC_UNSPECIFIED) {
676+ if (s->user_all == CS_UNSPECIFIED) {
677+ av_log(ctx, AV_LOG_ERROR,
678+ "Please specify output colorspace\n");
679+ } else {
680+ av_log(ctx, AV_LOG_ERROR,
681+ "Unsupported output color property %d\n", s->user_all);
682+ }
683+ } else {
684+ av_log(ctx, AV_LOG_ERROR,
685+ "Unsupported output colorspace %d (%s)\n", s->out_csp,
686+ av_color_space_name(s->out_csp));
687+ }
688+ return AVERROR(EINVAL);
689+ }
690+
690691 ff_colorspacedsp_init(&s->dsp);
691692
692693 return 0;
@@ -735,6 +736,9 @@ static int filter_frame(AVFilterLink *link, AVFrame *in) · 42 unmodified lines
735736 return res;
736737 }
737738
739+ out->colorspace = s->out_csp;
740+ out->color_range = s->user_rng == AVCOL_RANGE_UNSPECIFIED ?
741+ in->color_range : s->user_rng;
738742 out->color_primaries = s->user_prm == AVCOL_PRI_UNSPECIFIED ?
739743 default_prm[FFMIN(s->user_all, CS_NB)] : s->user_prm;
740744 if (s->user_trc == AVCOL_TRC_UNSPECIFIED) {
@@ -746,10 +750,6 @@ static int filter_frame(AVFilterLink *link, AVFrame *in) · 5 unmodified lines
746750 } else {
747751 out->color_trc = s->user_trc;
748752 }
749− out->colorspace = s->user_csp == AVCOL_SPC_UNSPECIFIED ?
750− default_csp[FFMIN(s->user_all, CS_NB)] : s->user_csp;
751− out->color_range = s->user_rng == AVCOL_RANGE_UNSPECIFIED ?
752− in->color_range : s->user_rng;
753753 if (rgb_sz != s->rgb_sz) {
754754 const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(out->format);
755755 int uvw = in->width >> desc->log2_chroma_w;
@@ -841,8 +841,18 @@ static int query_formats(AVFilterContext *ctx) · 85 unmodified lines
841841 };
842842 int res;
843843 ColorSpaceContext *s = ctx->priv;
844+ AVFilterLink *outlink = ctx->outputs[0];
844845 AVFilterFormats *formats = ff_make_format_list(pix_fmts);
845846
847+ res = ff_formats_ref(ff_make_formats_list_singleton(s->out_csp), &outlink->incfg.color_spaces);
848+ if (res < 0)
849+ return res;
850+ if (s->user_rng != AVCOL_RANGE_UNSPECIFIED) {
851+ res = ff_formats_ref(ff_make_formats_list_singleton(s->user_rng), &outlink->incfg.color_ranges);
852+ if (res < 0)
853+ return res;
854+ }
855+
846856 if (!formats)
847857 return AVERROR(ENOMEM);
848858 if (s->user_format == AV_PIX_FMT_NONE)
@@ -855,7 +865,7 @@ static int query_formats(AVFilterContext *ctx) · 6 unmodified lines
855865 if (res < 0)
856866 return res;
857867
858− return ff_formats_ref(formats, &ctx->outputs[0]->incfg.formats);
868+ return ff_formats_ref(formats, &outlink->incfg.formats);
859869 }
860870
861871 static int config_props(AVFilterLink *outlink)

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