[FFmpeg-devel] [PATCH] Implement color source

Stefano Sabatini stefano.sabatini-lala
Tue Dec 8 21:33:09 CET 2009


On date Tuesday 2009-12-08 21:08:10 +0100, Stefano Sabatini encoded:
> Hi,
> 
> in attachment a simple color source, much code is based on the pad
> filter, so I wonder how that could be factorized.
> 
> In order to test it the only way I can found is to use the overlay
> filter, for example with:
> 
> ffplay  in.avi -loglevel info -vfilters "color=100x100:25:tomato, format=yuva420p [wm]; [in][wm] overlay=main_w - over_w - 10:10 [out]"
> 
> which is not very nice.
> 
> Maybe we should also start to think about some syntax for specifying a
> libavfilter source to ffmpeg/ffplay, something of the kind, ideas are
> welcome.
> 
> Regards.
> -- 
> FFmpeg = Foolish & Furious Murdering Portable Ecstatic God

> Index: ffmpeg/doc/libavfilter.texi
> ===================================================================
> --- ffmpeg.orig/doc/libavfilter.texi	2009-12-08 21:07:24.000000000 +0100
> +++ ffmpeg/doc/libavfilter.texi	2009-12-08 21:07:26.000000000 +0100
> @@ -231,4 +231,47 @@
>  ./ffmpeg -i in.avi -vfilters "vflip" out.avi
>  @end example
>  
> + at chapter Available video sources
> +
> + at section color
> +
> +Generates a video with the specified color.
> +
> +It accepts the following parameters: frame_size:frame_rate:color.
> +
> +Follows the description of the accepted parameters.
> +
> + at table @option
> + at item size
> +
> + at example
> +"color=qcif:25:red"
> + at end example
> +
> + at table @option
> +
> + at item frame_size
> +
> +Specify the size of the output image. The size has to be a string in
> +the format WIDTHxHEIGHT or a valid video frame size abbreviation.
> +
> +The default value of ``size'' is 320x240.
> +
> + at item frame_rate
> +
> +Specify the frame rate of the output video. The frame rate has to be a
> +string in the format NUM/DEN, a float number or a valid video frame
> +rate abbreviation.
> +
> +The default value of ``size'' is 25/1.
> +
> + at item color
> +
> +Specify the color of the padded area, it can be the name of a color
> +(case insensitive match) or a 0xRRGGBB[AA] sequence.
> +
> +The default value of ``color'' is ``black''.
> +
> + at end table
> +
>  @bye
> Index: ffmpeg/libavfilter/Makefile
> ===================================================================
> --- ffmpeg.orig/libavfilter/Makefile	2009-12-08 20:48:15.000000000 +0100
> +++ ffmpeg/libavfilter/Makefile	2009-12-08 20:50:51.000000000 +0100
> @@ -21,4 +21,6 @@
>  OBJS-$(CONFIG_SLICIFY_FILTER)                += vf_slicify.o
>  OBJS-$(CONFIG_VFLIP_FILTER)                  += vf_vflip.o
>  
> +OBJS-$(CONFIG_COLOR_FILTER)                  += vsrc_color.o
> +
>  include $(SUBDIR)../subdir.mak
> Index: ffmpeg/libavfilter/allfilters.c
> ===================================================================
> --- ffmpeg.orig/libavfilter/allfilters.c	2009-12-08 20:48:07.000000000 +0100
> +++ ffmpeg/libavfilter/allfilters.c	2009-12-08 20:50:29.000000000 +0100
> @@ -42,4 +42,6 @@
>      REGISTER_FILTER (SCALE, scale, vf);
>      REGISTER_FILTER (SLICIFY, slicify, vf);
>      REGISTER_FILTER (VFLIP, vflip, vf);
> +
> +    REGISTER_FILTER (COLOR, color, vsrc);
>  }
> Index: ffmpeg/libavfilter/vsrc_color.c
> ===================================================================
> --- /dev/null	1970-01-01 00:00:00.000000000 +0000
> +++ ffmpeg/libavfilter/vsrc_color.c	2009-12-08 20:48:35.000000000 +0100
> @@ -0,0 +1,219 @@
> +/*
> + * copyright (c) 2009 Stefano Sabatini
> + *
> + * This file is part of FFmpeg.
> + *
> + * FFmpeg is free software; you can redistribute it and/or
> + * modify it under the terms of the GNU Lesser General Public
> + * License as published by the Free Software Foundation; either
> + * version 2.1 of the License, or (at your option) any later version.
> + *
> + * FFmpeg is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
> + * Lesser General Public License for more details.
> + *
> + * You should have received a copy of the GNU Lesser General Public
> + * License along with FFmpeg; if not, write to the Free Software
> + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
> + */
> +
> +/**
> + * @file libavfilter/vsrc_color.c
> + * color source
> + */
> +
> +#include "avfilter.h"
> +#include "parseutils.h"
> +#include "libavcodec/colorspace.h"
> +#include "libavcodec/avcodec.h"
> +#include "libavutil/pixdesc.h"
> +
> +typedef struct {
> +    int w, h;
> +    uint8_t color[4];
> +    AVRational time_base;
> +    uint8_t *line[4];
> +    int      line_step[4];
> +    int hsub, vsub;         ///< chroma subsampling values
> +    uint64_t pts;
> +} ColorContext;
> +
> +enum { RED = 0, GREEN, BLUE, ALPHA };
> +
> +static int init(AVFilterContext *ctx, const char *args, void *opaque)
> +{
> +    ColorContext *priv = ctx->priv;
> +    char frame_size  [128] = "320x240";
> +    char frame_rate  [128] = "25";
> +    char color_string[128] = "black";
> +    AVRational frame_rate_q;
> +
> +    if (args)
> +        sscanf(args, "%128[^:]:%128[^:]:%128s", frame_size, frame_rate, color_string);
> +
> +    if (av_parse_video_frame_size(&priv->w, &priv->h, frame_size) < 0) {
> +        av_log(ctx, AV_LOG_ERROR, "Invalid frame size: %s\n", frame_size);
> +        return -1;
> +    }
> +    priv->w &= ~((1 << priv->hsub) - 1);
> +    priv->h &= ~((1 << priv->vsub) - 1);
> +    if (avcodec_check_dimensions(ctx, priv->w, priv->h) < 0)
> +        return -1;

Ugh, hsub and vsub still not accessible here, fixed.

Regards.
-- 
FFmpeg = Fiendish and Frenzy Most Perennial Ecstatic Gangster
-------------- next part --------------
A non-text attachment was scrubbed...
Name: implement-color-source.patch
Type: text/x-diff
Size: 10009 bytes
Desc: not available
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20091208/83da388b/attachment.patch>



More information about the ffmpeg-devel mailing list