[FFmpeg-soc] [soc]: r5819 - in libavfilter: Makefile allfilters.c vf_fade.c

Stefano Sabatini stefano.sabatini-lala at poste.it
Thu Jun 3 00:27:02 CEST 2010


On date Wednesday 2010-06-02 23:43:50 +0200, bcoudurier encoded:
> Author: bcoudurier
> Date: Wed Jun  2 23:43:50 2010
> New Revision: 5819
> 
> Log:
> Fade filter by Brandon Mintern, rgb support and direct rendering by me
> 
> Added:
>    libavfilter/vf_fade.c
> Modified:
>    libavfilter/Makefile
>    libavfilter/allfilters.c
> 
> Modified: libavfilter/Makefile
> ==============================================================================
> --- libavfilter/Makefile	Wed May 26 00:54:24 2010	(r5818)
> +++ libavfilter/Makefile	Wed Jun  2 23:43:50 2010	(r5819)
> @@ -19,6 +19,7 @@ OBJS-$(CONFIG_ASPECT_FILTER)            
>  OBJS-$(CONFIG_CROP_FILTER)                   += vf_crop.o
>  OBJS-$(CONFIG_DRAWBOX_FILTER)                += vf_drawbox.o
>  OBJS-$(CONFIG_DRAWTEXT_FILTER)               += vf_drawtext.o
> +OBJS-$(CONFIG_FADE_FILTER)                   += vf_fade.o
>  OBJS-$(CONFIG_FIFO_FILTER)                   += vf_fifo.o
>  OBJS-$(CONFIG_FORMAT_FILTER)                 += vf_format.o
>  OBJS-$(CONFIG_FPS_FILTER)                    += vf_fps.o
> 
> Modified: libavfilter/allfilters.c
> ==============================================================================
> --- libavfilter/allfilters.c	Wed May 26 00:54:24 2010	(r5818)
> +++ libavfilter/allfilters.c	Wed Jun  2 23:43:50 2010	(r5819)
> @@ -38,6 +38,7 @@ void avfilter_register_all(void)
>      REGISTER_FILTER (CROP,        crop,        vf);
>      REGISTER_FILTER (DRAWBOX,     drawbox,     vf);
>      REGISTER_FILTER (DRAWTEXT,    drawtext,    vf);
> +    REGISTER_FILTER (FADE,        fade,        vf);
>      REGISTER_FILTER (FIFO,        fifo,        vf);
>      REGISTER_FILTER (FORMAT,      format,      vf);
>      REGISTER_FILTER (FPS,         fps,         vf);
> 
> Added: libavfilter/vf_fade.c
> ==============================================================================
> --- /dev/null	00:00:00 1970	(empty, because file is newly added)
> +++ libavfilter/vf_fade.c	Wed Jun  2 23:43:50 2010	(r5819)
> @@ -0,0 +1,195 @@
> +/*
> + * video fade filter
> + * copyright (c) 2010 Brandon Mintern
> + * based heavily on vf_negate.c which is copyright (c) 2007 Bobby Bingham
> + *
> + * 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
> + */
> +
> +/*
> + # A few usage examples follow, usable too as test scenarios.
> +
> + # Fade in first 30 frames of video
> + ffmpeg -i input.avi -vfilters fade=in:0:30 output.avi
> +
> + # Fade out last 45 frames of a 200-frame video
> + ffmpeg -i input.avi -vfilters fade=out:155:45 output.avi
> +
> + # Fade in first 25 frames and fade out last 25 frames of a 1000-frame video
> + ffmpeg -i input.avi -vfilters "fade=in:0:25, fade=out:975:25" output.avi
> +
> + # Make first 5 frames black, then fade in from frame 5-24
> + ffmpeg -i input.avi -vfilters "fade=in:5:20" output.avi
> +*/

This goes to user docs, with explanation of all the params.

> +
> +#include "avfilter.h"
> +
> +typedef struct
> +{
> +    int factor, fade_per_frame;
> +    unsigned int frame_index, start_frame, stop_frame;
> +    int hsub, vsub, bpp;
> +} FadeContext;

missing doxies (at least it is required for factor).

> +static av_cold int init(AVFilterContext *ctx, const char *args, void *opaque)
> +{
> +    FadeContext *fade = ctx->priv;
> +    unsigned int frames;
> +    char in_out[4];
> +
> +    if(args && sscanf(args, " %3[^:]:%u:%u", in_out,
> +                   &fade->start_frame, &frames) == 3) {
> +        frames = frames ? frames : 1;
> +        fade->fade_per_frame = (1 << 16) / frames;
> +        if (!strcmp(in_out, "in"))
> +            fade->factor = 0;
> +        else if (!strcmp(in_out, "out")) {
> +            fade->fade_per_frame = -fade->fade_per_frame;
> +            fade->factor = (1 << 16);
> +        }

> +        else {
> +            av_log(ctx, AV_LOG_ERROR,
> +                "init() 1st arg must be 'in' or 'out':'%s'\n", in_out);

Such messages are supposed to be exposed to the UI, here it is why I
consider poor practice to use the name of the function (and
inconsistent with the rest of the filters).

> +            return -1;
> +        }
> +        fade->stop_frame = fade->start_frame + frames;
> +        return 0;
> +    }
> +    av_log(ctx, AV_LOG_ERROR,
> +           "init() expected 3 arguments '(in|out):#:#':'%s'\n", args);
> +    return -1;

return meaningful error codes.

> +}
> +
> +static int query_formats(AVFilterContext *ctx)
> +{
> +    enum PixelFormat pix_fmts[] = {
> +        PIX_FMT_YUV444P,  PIX_FMT_YUV422P,  PIX_FMT_YUV420P,
> +        PIX_FMT_YUV411P,  PIX_FMT_YUV410P,
> +        PIX_FMT_YUVJ444P, PIX_FMT_YUVJ422P, PIX_FMT_YUVJ420P,
> +        PIX_FMT_YUV440P,  PIX_FMT_YUVJ440P,
> +        PIX_FMT_RGB24,    PIX_FMT_BGR24,
> +        PIX_FMT_NONE
> +    };
> +
> +    avfilter_set_common_formats(ctx, avfilter_make_format_list(pix_fmts));
> +    return 0;
> +}
> +
> +static int config_props(AVFilterLink *link)
> +{
> +    FadeContext *fade = link->dst->priv;
> +    avcodec_get_chroma_sub_sample(link->format, &fade->hsub, &fade->vsub);

add a dependency on lavc, use pixdesc.c instead.

> +    if (link->format == PIX_FMT_RGB24 || link->format == PIX_FMT_BGR24)
> +        fade->bpp = 3;
> +    else
> +        fade->bpp = 1;

this also can be made more robust using pixdescs, I assume bpp here
means bytes per pixel, and not something else as is in the overlay
filter.

[...]

Anyway nice stuff, thanks.

Regards.


More information about the FFmpeg-soc mailing list