[FFmpeg-devel] [PATCH] avfilter/vf_scale: allow overriding in/out yuv colorspace type
Stefano Sabatini
stefasab at gmail.com
Fri Jul 12 09:16:23 CEST 2013
On date Friday 2013-07-12 00:52:08 +0200, Michael Niedermayer encoded:
> Signed-off-by: Michael Niedermayer <michaelni at gmx.at>
> ---
> doc/filters.texi | 15 +++++++++++++++
> libavfilter/vf_scale.c | 44 ++++++++++++++++++++++++++++++++++++++++++++
> 2 files changed, 59 insertions(+)
>
> diff --git a/doc/filters.texi b/doc/filters.texi
> index 92f8612..5f6e11b 100644
> --- a/doc/filters.texi
> +++ b/doc/filters.texi
> @@ -6201,6 +6201,21 @@ 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
> +In/Output YCbCr colorspace type
Set in/output ...
> + at table @option
@table @samp
> + at item jpeg
> +Full 0-255 jpeg style
> +
> + at item 709
> +ITU Rec BT709
> +
> + at item 601
> +ITU Rec BT601
> + at end table
> +
> @end table
Which is the default value?
> 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..481eb85 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;
Did you consider to use named constants instead?
> } ScaleContext;
>
> static av_cold int init(AVFilterContext *ctx)
> @@ -182,6 +185,21 @@ static int query_formats(AVFilterContext *ctx)
> return 0;
> }
>
> +static const int *parse_yuv_type(const char *s, int *full)
> +{
> + const static int32_t yuv2rgb_coeffs[2][4] = {
> + { 117504, 138453, 13954, 34903 }, /* ITU-R Rec. 709 (1990) */
> + { 104597, 132201, 25675, 53279 }, /* ITU-R Rec. 624-4 System B, G */
> + };
> +
> + if (s && (strstr(s, "full") || strstr(s, "jpeg")))
> + *full = 1;
> + if (s && strstr(s, "709")) {
> + return yuv2rgb_coeffs[0];
> + } /*else if (s && strstr(s, "601"))*/
> + return yuv2rgb_coeffs[1];
> +}
> +
> static int config_props(AVFilterLink *outlink)
> {
> AVFilterContext *ctx = outlink->src;
> @@ -279,6 +297,30 @@ static int config_props(AVFilterLink *outlink)
> scale->flags, NULL, NULL, NULL);
> if (!scale->sws || !scale->isws[0] || !scale->isws[1])
> return AVERROR(EINVAL);
> +
> + 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);
> +
> + if (scale->inyuvtype)
> + inv_table = parse_yuv_type(scale->inyuvtype, &in_full);
> + if (scale->outyuvtype)
> + table = parse_yuv_type(scale->outyuvtype, &out_full);
> +
> + 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);
> + }
> }
>
> if (inlink->sample_aspect_ratio.num){
> @@ -398,6 +440,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", "Input YCbCr type", OFFSET(inyuvtype), AV_OPT_TYPE_STRING, { .str = NULL }, .flags = FLAGS },
> + { "outyuvtype", "Output YCbCr type", OFFSET(outyuvtype), AV_OPT_TYPE_STRING, { .str = NULL }, .flags = FLAGS },
set input ...
set output ...
[...]
--
FFmpeg = Frightening & Fantastic Magic Peaceless Erotic Gymnast
More information about the ffmpeg-devel
mailing list