[FFmpeg-devel] [PATCH] api-example for libavfilter

Stefano Sabatini stefano.sabatini-lala
Wed Dec 8 19:37:40 CET 2010


On date Wednesday 2010-12-08 12:40:23 +0100, Nicolas George encoded:
> Hi.
> 
> The attached patch adds an api-example.c file to libavfilter, to help
> application programmers get a quick start on how to use the new library.
> 
> This file imitates what is done inside ffmpeg.c itself; I would like
> confirmation that everything is done the preferred way though.
> 
> Regards,
> 
> -- 
>   Nicolas George

>  libavfilter/Makefile      |    4 +
>  libavfilter/api-example.c |  227 +++++++++++++++++++++++++++++++++++++++++++++
>  2 files changed, 231 insertions(+), 0 deletions(-)
> 
> diff --git a/libavfilter/Makefile b/libavfilter/Makefile
> index aece3ab..3c804cb 100644
> --- a/libavfilter/Makefile
> +++ b/libavfilter/Makefile
> @@ -56,4 +56,8 @@ OBJS-$(CONFIG_NULLSINK_FILTER)               += vsink_nullsink.o
>  
>  DIRS = x86
>  
> +EXAMPLES  = api
> +
>  include $(SUBDIR)../subdir.mak
> +
> +$(SUBDIR)api-example$(EXESUF): ELIBS = -lavformat -lavcodec -lavcore -lavutil $(FFEXTRALIBS)
> diff --git a/libavfilter/api-example.c b/libavfilter/api-example.c
> new file mode 100644
> index 0000000..878d7cb
> --- /dev/null
> +++ b/libavfilter/api-example.c
> @@ -0,0 +1,227 @@
> +/*
> + * API example for libavfilter
> + * Copyright (c) 2010 Nicolas George
> + *
> + * 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
> + */
> +
> +#define _XOPEN_SOURCE 600 /* for usleep */

> +#include <stdio.h>
> +#include <stdlib.h>
> +#include <string.h>
> +#include <unistd.h>

These headers shouldn't be required.

> +#include <libavformat/avformat.h>
> +#include <libavcodec/avcodec.h>

I'd prefer to avoid to rely on other FFmpeg libraries, currently lavfi
only depends on libavutil, libavcore and libswscale, and API example
should be minimal so should be as strict as possible in terms of
requirements.

Also consider that it is possible to install and compile libavfilter
without lavc/lavf, so I'd like to make the API example working even in
that case.

Also the code could be simpler if you implement it this
way... implement a video sink for printing to console a textual
representation of the image (which could be useful even in
libavfilter), and let the user specify the input for the input source
in the filtergraph description.

> +#include <libavfilter/avfiltergraph.h>
> +#include <libavfilter/vsrc_buffer.h>
> +
> +const char *filter_descr = "scale=78:24,format=gray";
> +
> +static AVFormatContext *avf;
> +static AVCodecContext *video_dec;
> +AVFilterContext *video_in_filter;
> +AVFilterContext *video_out_filter;
> +AVFilterGraph *filter_graph;
> +static int video_stream = -1;
> +static int64_t last_pts = AV_NOPTS_VALUE;
> +
> +static void fatal_libav_error(const char *tag, int r)
> +{
> +    char buf[1024];
> +
> +    av_strerror(r, buf, sizeof(buf));
> +    fprintf(stderr, "%s: %s\n", tag, buf);
> +    exit(1);
> +}

you can use the log system (with the fancy coloring support).

[...]
-- 
FFmpeg = Funny & Fostering Multimedia Purposeless Ecumenical Glue



More information about the ffmpeg-devel mailing list