[FFmpeg-devel] [PATCH] lavfi: add untile filter.
Paul B Mahol
onemda at gmail.com
Fri Apr 17 12:20:02 EEST 2020
On 4/16/20, Nicolas George <george at nsup.org> wrote:
> Signed-off-by: Nicolas George <george at nsup.org>
> ---
> doc/filters.texi | 34 ++++++
> libavfilter/Makefile | 1 +
> libavfilter/allfilters.c | 1 +
> libavfilter/vf_untile.c | 198 +++++++++++++++++++++++++++++++++++
> tests/fate/filter-video.mak | 3 +
> tests/ref/fate/filter-untile | 13 +++
> 6 files changed, 250 insertions(+)
> create mode 100644 libavfilter/vf_untile.c
> create mode 100644 tests/ref/fate/filter-untile
>
> diff --git a/doc/filters.texi b/doc/filters.texi
> index a4f99ef376..3f08b8805c 100644
> --- a/doc/filters.texi
> +++ b/doc/filters.texi
> @@ -18071,10 +18071,13 @@ ffmpeg -i in.avi -vf thumbnail,scale=300:200
> -frames:v 1 out.png
> @end example
> @end itemize
>
> + at anchor{tile}
> @section tile
>
> Tile several successive frames together.
>
> +The @ref{untile} filter can do the reverse.
> +
> The filter accepts the following options:
>
> @table @option
> @@ -18839,6 +18842,37 @@ unsharp=7:7:-2:7:7:-2
> @end example
> @end itemize
>
> + at anchor{untile}
> + at section untile
> +
> +Decompose a video made of tiled images into the individual images.
> +
> +The frame rate of the output video is the frame rate of the input video
> +multiplied by the number of tiles.
> +
> +This filter does the reverse of @ref{tile}.
> +
> +The filter accepts the following options:
> +
> + at table @option
> +
> + at item layout
> +Set the grid size (i.e. the number of lines and columns). For the syntax of
> +this option, check the
> + at ref{video size syntax,,"Video size" section in the ffmpeg-utils
> manual,ffmpeg-utils}.
> + at end table
> +
> + at subsection Examples
> +
> + at itemize
> + at item
> +Produce a 1-second video from a still image file made of 25 frames stacked
> +vertically, like an analogic film reel:
> + at example
> +ffmpeg -r 1 -i image.jpg -vf untile=1x25 movie.mkv
> + at end example
> + at end itemize
> +
> @section uspp
>
> Apply ultra slow/simple postprocessing filter that compresses and
> decompresses
> diff --git a/libavfilter/Makefile b/libavfilter/Makefile
> index ecbc628868..82e2991f7a 100644
> --- a/libavfilter/Makefile
> +++ b/libavfilter/Makefile
> @@ -432,6 +432,7 @@ OBJS-$(CONFIG_UNPREMULTIPLY_FILTER) +=
> vf_premultiply.o framesync.o
> OBJS-$(CONFIG_UNSHARP_FILTER) += vf_unsharp.o
> OBJS-$(CONFIG_UNSHARP_OPENCL_FILTER) += vf_unsharp_opencl.o
> opencl.o \
> opencl/unsharp.o
> +OBJS-$(CONFIG_UNTILE_FILTER) += vf_untile.o
> OBJS-$(CONFIG_USPP_FILTER) += vf_uspp.o
> OBJS-$(CONFIG_V360_FILTER) += vf_v360.o
> OBJS-$(CONFIG_VAGUEDENOISER_FILTER) += vf_vaguedenoiser.o
> diff --git a/libavfilter/allfilters.c b/libavfilter/allfilters.c
> index fb32bef788..31711d35c7 100644
> --- a/libavfilter/allfilters.c
> +++ b/libavfilter/allfilters.c
> @@ -411,6 +411,7 @@ extern AVFilter ff_vf_trim;
> extern AVFilter ff_vf_unpremultiply;
> extern AVFilter ff_vf_unsharp;
> extern AVFilter ff_vf_unsharp_opencl;
> +extern AVFilter ff_vf_untile;
> extern AVFilter ff_vf_uspp;
> extern AVFilter ff_vf_v360;
> extern AVFilter ff_vf_vaguedenoiser;
> diff --git a/libavfilter/vf_untile.c b/libavfilter/vf_untile.c
> new file mode 100644
> index 0000000000..9a2eb24901
> --- /dev/null
> +++ b/libavfilter/vf_untile.c
> @@ -0,0 +1,198 @@
> +/*
> + * Copyright (c) 2020 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
> + */
> +
> +#include "libavutil/imgutils.h"
> +#include "libavutil/opt.h"
> +#include "libavutil/pixdesc.h"
> +#include "avfilter.h"
> +#include "formats.h"
> +#include "filters.h"
> +
> +typedef struct UntileContext {
> + const AVClass *class;
> + unsigned w, h;
> + unsigned current;
> + unsigned nb_frames;
> + AVFrame *frame;
> + const AVPixFmtDescriptor *desc;
> + int64_t dpts, pts;
> + int max_step[4];
> +} UntileContext;
> +
> +#define OFFSET(x) offsetof(UntileContext, x)
> +#define FLAGS AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
> +
> +static const AVOption untile_options[] = {
> + { "layout", "set grid size", OFFSET(w), AV_OPT_TYPE_IMAGE_SIZE,
> + {.str = "6x5"}, 0, 0, FLAGS },
> + { NULL }
> +};
> +
> +AVFILTER_DEFINE_CLASS(untile);
> +
> +static av_cold int init(AVFilterContext *ctx)
> +{
> + UntileContext *s = ctx->priv;
> +
> + if (s->w > UINT_MAX / s->h) {
> + av_log(ctx, AV_LOG_ERROR, "Tile size %ux%u is insane.\n",
> + s->w, s->h);
> + return AVERROR(EINVAL);
> + }
> + s->nb_frames = s->w * s->h;
Can't nb_frames be int64 ?
More information about the ffmpeg-devel
mailing list