[FFmpeg-devel] [PATCH 2/2] avfilter/vf_scale: allow overriding in/out yuv colorspace type

Paul B Mahol onemda at gmail.com
Sun Jul 14 19:20:57 CEST 2013


On 7/14/13, Michael Niedermayer <michaelni at gmx.at> wrote:
> This also uses the decoders yuy type if "auto" is specified
>
> Signed-off-by: Michael Niedermayer <michaelni at gmx.at>
> ---
>  doc/filters.texi       |   30 ++++++++++++++++++++++++
>  libavfilter/vf_scale.c |   61
> ++++++++++++++++++++++++++++++++++++++++++++++++
>  2 files changed, 91 insertions(+)
>
> diff --git a/doc/filters.texi b/doc/filters.texi
> index 6f3994a..579f28b 100644
> --- a/doc/filters.texi
> +++ b/doc/filters.texi
> @@ -6210,6 +6210,36 @@ applies a bilinear scaling algorithm.
>  @item size, s
>  Set the video size, the value must be a valid abbreviation or in the
>  form @var{width}x at var{height}.
> +
> + at item inyuvtype
> + at item outyuvtype
> +Set in/output YCbCr colorspace type.
> +This allows the autodetected value to be overridden as well as allows
> forcing
> +a specific value used for the output and encoder.
> +If not specified, the colorspace type depends on the pixel format.
> + at table @samp
> + at item auto
> +Choose automatically
> +
> + at item jpeg
> +Full 0-255 jpeg style
> +
> + at item bt709
> +ITU Rec BT709
> +
> + at item fcc
> +United States Federal Communications Commission Title 47 Code of
> +Federal Regulations (2003) 73.682 (a)
> +
> + at item bt601
> +ITU Rec BT601
> +ITU-R Rec. BT.470-6 System B, G
> +Society of Motion Picture and Television Engineers 170M (2004)
> +
> + at item smpte240m
> +Society of Motion Picture and Television Engineers 240M
> + at end table
> +
>  @end table
>
>  The values of the @var{w} and @var{h} options are expressions
> diff --git a/libavfilter/vf_scale.c b/libavfilter/vf_scale.c
> index b1246fe..4625167 100644
> --- a/libavfilter/vf_scale.c
> +++ b/libavfilter/vf_scale.c
> @@ -90,6 +90,9 @@ typedef struct {
>      char *w_expr;               ///< width  expression string
>      char *h_expr;               ///< height expression string
>      char *flags_str;
> +
> +    char *inyuvtype;
> +    char *outyuvtype;
>  } ScaleContext;
>
>  static av_cold int init(AVFilterContext *ctx)
> @@ -182,6 +185,40 @@ static int query_formats(AVFilterContext *ctx)
>      return 0;
>  }
>
> +static const int *parse_yuv_type(const char *s, int *full, enum
> AVColorSpace colorspace)
> +{
> +    const static int32_t yuv2rgb_coeffs[8][4] = {
> +        {},
> +        { 117504, 138453, 13954, 34903 }, /* ITU-R Rec. 709 (1990) */
> +        { 104597, 132201, 25675, 53279 }, /* unspecified */
> +        { 104597, 132201, 25675, 53279 }, /* reserved */
> +        { 104448, 132798, 24759, 53109 }, /* FCC */
> +        { 104597, 132201, 25675, 53279 }, /* ITU-R Rec. 624-4 System B, G
> */
> +        { 104597, 132201, 25675, 53279 }, /* SMPTE 170M */
> +        { 117579, 136230, 16907, 35559 }  /* SMPTE 240M (1987) */
> +    };
> +    if (!s)
> +        s = "bt601";
> +
> +    if (s && (strstr(s, "full") || strstr(s, "jpeg")))
> +        *full = 1;
> +    if (s && strstr(s, "bt709")) {
> +        colorspace = AVCOL_SPC_BT709;
> +    } else if (s && strstr(s, "fcc")) {
> +        colorspace = AVCOL_SPC_FCC;
> +    } else if (s && strstr(s, "smpte240m")) {
> +        colorspace = AVCOL_SPC_SMPTE240M;
> +    } else if (s && (strstr(s, "bt601") || strstr(s, "bt470") || strstr(s,
> "smpte170m"))) {
> +        colorspace = AVCOL_SPC_BT470BG;
> +    }
> +
> +    if (colorspace < 1 || colorspace > 7) {
> +        colorspace = AVCOL_SPC_BT470BG;
> +    }
> +
> +    return yuv2rgb_coeffs[colorspace];
> +}
> +
>  static int config_props(AVFilterLink *outlink)
>  {
>      AVFilterContext *ctx = outlink->src;
> @@ -370,6 +407,28 @@ static int filter_frame(AVFilterLink *link, AVFrame
> *in)
>      if(scale->output_is_pal)
>          avpriv_set_systematic_pal2((uint32_t*)out->data[1], outlink->format
> == AV_PIX_FMT_PAL8 ? AV_PIX_FMT_BGR8 : outlink->format);
>
> +    if (scale->inyuvtype || scale->outyuvtype) {
> +        int in_full, out_full, brightness, contrast, saturation;
> +        const int *inv_table, *table;
> +
> +        sws_getColorspaceDetails(scale->sws, (int **)&inv_table, &in_full,
> +                                 (int **)&table, &out_full,
> +                                 &brightness, &contrast, &saturation);
> +
> +        inv_table = parse_yuv_type(scale->inyuvtype, &in_full,
> av_frame_get_colorspace(in));
> +        table     = parse_yuv_type(scale->outyuvtype, &out_full,
> AVCOL_SPC_UNSPECIFIED);
> +
> +        sws_setColorspaceDetails(scale->sws, inv_table, in_full,
> +                                 table, out_full,
> +                                 brightness, contrast, saturation);
> +        sws_setColorspaceDetails(scale->isws[0], inv_table, in_full,
> +                                 table, out_full,
> +                                 brightness, contrast, saturation);
> +        sws_setColorspaceDetails(scale->isws[1], inv_table, in_full,
> +                                 table, out_full,
> +                                 brightness, contrast, saturation);
> +    }
> +
>      av_reduce(&out->sample_aspect_ratio.num,
> &out->sample_aspect_ratio.den,
>                (int64_t)in->sample_aspect_ratio.num * outlink->h * link->w,
>                (int64_t)in->sample_aspect_ratio.den * outlink->w * link->h,
> @@ -398,6 +457,8 @@ static const AVOption scale_options[] = {
>      { "interl", "set interlacing", OFFSET(interlaced), AV_OPT_TYPE_INT,
> {.i64 = 0 }, -1, 1, FLAGS },
>      { "size",   "set video size",          OFFSET(size_str),
> AV_OPT_TYPE_STRING, {.str = NULL}, 0, FLAGS },
>      { "s",      "set video size",          OFFSET(size_str),
> AV_OPT_TYPE_STRING, {.str = NULL}, 0, FLAGS },
> +    {  "inyuvtype", "set input YCbCr type",   OFFSET(inyuvtype),
> AV_OPT_TYPE_STRING, { .str = NULL }, .flags = FLAGS },
> +    { "outyuvtype", "set output YCbCr type",  OFFSET(outyuvtype),
> AV_OPT_TYPE_STRING, { .str = NULL }, .flags = FLAGS },

As stefano already pointed out use named constans so user can see what can be
set for in/out yuv type.

As colorspaces are already ints, you avoid useless use of strstr in code.

>      { NULL },
>  };
>
> --
> 1.7.9.5
>
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel at ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>


More information about the ffmpeg-devel mailing list