[FFmpeg-soc] libavfilter: port of Imlib2 vhook

Vitor vitor1001 at gmail.com
Wed Dec 19 18:50:32 CET 2007


Hi

Víctor Paesa wrote:
> Hi,
> 
> Here I attach a port of the Imlib2 vhook to the libavfilter API for
> your kind review/testing.

Nice work!

> 
> I have not ported the -C option, as I favour the RGBA options.
> The vf_imlib2.c source is diff'ed from /dev/null, as diff'ing from vf_negate.c
> produces a less legible diff, IMHO.
> 
> The source contains a few usage examples, usable too as test scenarios.

Maybe add a TODO to say that it should one day be in FFmpeg doc...

[...]

> --- /dev/null	2006-12-01 01:00:00.000000000 +0100
> +++ vf_imlib2.c	2007-12-19 00:00:00.327862700 +0100
> @@ -0,0 +1,413 @@
> +/*
> + * Video Imlib2 filter (a port of the imlib2 vhook to the avfilter API)
> + * copyright (c) 2007 Victor Paesa
> + *
> + * This file is part of FFmpeg.
> + *

[...]

> +
> +#include "avfilter.h"
> +
> +#include <stdio.h>
> +#include <stdlib.h>
> +#include <fcntl.h>
> +#include <unistd.h>
> +
> +#include <Imlib2.h>
> +#include "eval.h"
> +
> +const char *const_names[]={
> +    "PI",
> +    "E",
> +    "N",  // frame number (starting at zero)
> +    "H",  // frame height
> +    "W",  // frame width
> +    "h",  // image height
> +    "w",  // image width
> +    "X",  // previous x
> +    "Y",  // previous y
> +    NULL
> +};

This can be a Doxygen comment...

> +
> +#define MAX_IMLIB2_CMD 256
> +typedef struct
> +{
> +    char        cmd;
> +    union
> +    {
> +        char      *str;
> +        AVEvalExpr *exp;
> +        Imlib_Image img;
> +        Imlib_Font  fnt;
> +    } data;
> +} Imlib2Command;
> +
> +typedef struct
> +{
> +    int r, g, b, a;
> +    int x, y;
> +    int w, h, h_a, v_a;
> +    int frame_number, num_cmd;
> +    Imlib_Image image;
> +    Imlib2Command cmd[MAX_IMLIB2_CMD];
> +} Imlib2Context;
> +
> +static int init(AVFilterContext *ctx, const char *args, void *opaque)
> +{
> +    int chars_read;
> +    char str[256], cmd[2], *argss, *error, *p, *fp;
> +    Imlib2Context *imlib2 = ctx->priv;
> +
> +    imlib2->r = imlib2->g = imlib2->b = 0;
> +    imlib2->a = 255;
> +    imlib2->x = imlib2->y = imlib2->w = imlib2->h = 0;
> +    imlib2->h_a = imlib2->v_a = 0;
> +    imlib2->frame_number = 0;
> +    imlib2->num_cmd = 0;

I think that opaque is alloc'ed with mallocz, so no need to zero it...

> +
> +    fp = getenv("FONTPATH");
> +    /* Use ':' to split FONTPATH */
> +    if (fp)
> +        while (p = strchr(fp, ':')) {
> +            *p = 0;
> +            imlib_add_path_to_font_path(fp);
> +            fp = p + 1;
> +        }
> +    if ((fp) && (*fp))
> +        imlib_add_path_to_font_path(fp);
> +
> +    argss = args;
> +    if(argss) {
> +        while (2 == sscanf(argss, "%1[FtfxyiRGBA]:%255[^:]%n",
> +                                    cmd, str, &chars_read)) {
> +            //av_log(NULL, AV_LOG_INFO, "init() cmd:%d args:'%c:%s'\n", 
> +            //                           imlib2->num_cmd, cmd[0], str);
> +
> +            if (imlib2->num_cmd>=MAX_IMLIB2_CMD) {
> +                av_log(NULL, AV_LOG_ERROR, 
> +                    "imlib2 init() cannot handle more than %d arguments\n",
> +                    MAX_IMLIB2_CMD);
> +                return -1;
> +            }
> +            imlib2->cmd[imlib2->num_cmd].cmd = cmd[0];
> +            switch(cmd[0]) {
> +            case 'F':
> +                if (!(imlib2->cmd[imlib2->num_cmd].data.fnt = 
> +                        imlib_load_font(str))) {
> +                    av_log(NULL, AV_LOG_ERROR, 
> +                           "imlib2 init() cannot load font '%s'\n", str);
> +                    return -1;

I think you can use av_log(ctx, ...) to give a better error message.

[...]

> +
> +static int *query_formats(AVFilterLink *link)
> +{
> +    return avfilter_make_format_list(1, PIX_FMT_RGB32);
> +}

That's the sad part of this filter, the likely YUV->RGB->YUV 
conversion... Maybe a libavyuvimlib as a SoC 2010 project? :-)

Also, if you don't get any other feedback in two/three days, just commit 
it. No policy has been decided for when to commit to SoC trees...

-Vitor




More information about the FFmpeg-soc mailing list