History

lavfi: add untile filter.

Nicolas George committed 6 years ago

Commit 88567a21 parent 2a52f198 files · +252 −1Browse files

Unified · Split

8 files
  1. Changelog +1 −0
  2. doc/filters.texi +34 −0
  3. libavfilter/Makefile +1 −0
  4. libavfilter/allfilters.c +1 −0
  5. libavfilter/version.h +1 −1
  6. libavfilter/vf_untile.c +198 −0
  7. tests/fate/filter-video.mak +3 −0
  8. tests/ref/fate/filter-untile +13 −0
Changelog+1−0
@@ -70,6 +70,7 @@ version <next>: · 69 unmodified lines
70- NotchLC decoder70- NotchLC decoder
71- gradients source video filter71- gradients source video filter
72- MediaFoundation encoder wrapper72- MediaFoundation encoder wrapper
73- untile filter
73 74
74 75
75version 4.2:76version 4.2:
doc/filters.texi+34−0
@@ -18197,10 +18197,13 @@ ffmpeg -i in.avi -vf thumbnail,scale=300:200 -frames:v 1 out.png · 18196 unmodified lines
18197@end example18197@end example
18198@end itemize18198@end itemize
18199 18199
18200@anchor{tile}
18200@section tile18201@section tile
18201 18202
18202Tile several successive frames together.18203Tile several successive frames together.
18203 18204
18205The @ref{untile} filter can do the reverse.
18206
18204The filter accepts the following options:18207The filter accepts the following options:
18205 18208
18206@table @option18209@table @option
@@ -18984,6 +18987,37 @@ unsharp=7:7:-2:7:7:-2 · 777 unmodified lines
18984@end example18987@end example
18985@end itemize18988@end itemize
18986 18989
18990@anchor{untile}
18991@section untile
18992
18993Decompose a video made of tiled images into the individual images.
18994
18995The frame rate of the output video is the frame rate of the input video
18996multiplied by the number of tiles.
18997
18998This filter does the reverse of @ref{tile}.
18999
19000The filter accepts the following options:
19001
19002@table @option
19003
19004@item layout
19005Set the grid size (i.e. the number of lines and columns). For the syntax of
19006this option, check the
19007@ref{video size syntax,,"Video size" section in the ffmpeg-utils manual,ffmpeg-utils}.
19008@end table
19009
19010@subsection Examples
19011
19012@itemize
19013@item
19014Produce a 1-second video from a still image file made of 25 frames stacked
19015vertically, like an analogic film reel:
19016@example
19017ffmpeg -r 1 -i image.jpg -vf untile=1x25 movie.mkv
19018@end example
19019@end itemize
19020
18987@section uspp19021@section uspp
18988 19022
18989Apply ultra slow/simple postprocessing filter that compresses and decompresses19023Apply ultra slow/simple postprocessing filter that compresses and decompresses
libavfilter/Makefile+1−0
@@ -436,6 +436,7 @@ OBJS-$(CONFIG_UNPREMULTIPLY_FILTER) += vf_premultiply.o framesync.o · 435 unmodified lines
436OBJS-$(CONFIG_UNSHARP_FILTER) += vf_unsharp.o436OBJS-$(CONFIG_UNSHARP_FILTER) += vf_unsharp.o
437OBJS-$(CONFIG_UNSHARP_OPENCL_FILTER) += vf_unsharp_opencl.o opencl.o \437OBJS-$(CONFIG_UNSHARP_OPENCL_FILTER) += vf_unsharp_opencl.o opencl.o \
438 opencl/unsharp.o438 opencl/unsharp.o
439OBJS-$(CONFIG_UNTILE_FILTER) += vf_untile.o
439OBJS-$(CONFIG_USPP_FILTER) += vf_uspp.o440OBJS-$(CONFIG_USPP_FILTER) += vf_uspp.o
440OBJS-$(CONFIG_V360_FILTER) += vf_v360.o441OBJS-$(CONFIG_V360_FILTER) += vf_v360.o
441OBJS-$(CONFIG_VAGUEDENOISER_FILTER) += vf_vaguedenoiser.o442OBJS-$(CONFIG_VAGUEDENOISER_FILTER) += vf_vaguedenoiser.o
libavfilter/allfilters.c+1−0
@@ -415,6 +415,7 @@ extern AVFilter ff_vf_trim; · 414 unmodified lines
415extern AVFilter ff_vf_unpremultiply;415extern AVFilter ff_vf_unpremultiply;
416extern AVFilter ff_vf_unsharp;416extern AVFilter ff_vf_unsharp;
417extern AVFilter ff_vf_unsharp_opencl;417extern AVFilter ff_vf_unsharp_opencl;
418extern AVFilter ff_vf_untile;
418extern AVFilter ff_vf_uspp;419extern AVFilter ff_vf_uspp;
419extern AVFilter ff_vf_v360;420extern AVFilter ff_vf_v360;
420extern AVFilter ff_vf_vaguedenoiser;421extern AVFilter ff_vf_vaguedenoiser;
libavfilter/version.h+1−1
@@ -30,7 +30,7 @@ · 29 unmodified lines
30#include "libavutil/version.h"30#include "libavutil/version.h"
31 31
32#define LIBAVFILTER_VERSION_MAJOR 732#define LIBAVFILTER_VERSION_MAJOR 7
33#define LIBAVFILTER_VERSION_MINOR 8233#define LIBAVFILTER_VERSION_MINOR 83
34#define LIBAVFILTER_VERSION_MICRO 10034#define LIBAVFILTER_VERSION_MICRO 100
35 35
36 36
libavfilter/vf_untile.c+198−0
@@ -0,0 +1,198 @@
1/*
2 * Copyright (c) 2020 Nicolas George
3 *
4 * This file is part of FFmpeg.
5 *
6 * FFmpeg is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * FFmpeg is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with FFmpeg; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21#include "libavutil/imgutils.h"
22#include "libavutil/opt.h"
23#include "libavutil/pixdesc.h"
24#include "avfilter.h"
25#include "formats.h"
26#include "filters.h"
27
28typedef struct UntileContext {
29 const AVClass *class;
30 unsigned w, h;
31 unsigned current;
32 unsigned nb_frames;
33 AVFrame *frame;
34 const AVPixFmtDescriptor *desc;
35 int64_t dpts, pts;
36 int max_step[4];
37} UntileContext;
38
39#define OFFSET(x) offsetof(UntileContext, x)
40#define FLAGS AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
41
42static const AVOption untile_options[] = {
43 { "layout", "set grid size", OFFSET(w), AV_OPT_TYPE_IMAGE_SIZE,
44 {.str = "6x5"}, 0, 0, FLAGS },
45 { NULL }
46};
47
48AVFILTER_DEFINE_CLASS(untile);
49
50static av_cold int init(AVFilterContext *ctx)
51{
52 UntileContext *s = ctx->priv;
53
54 if (s->w > UINT_MAX / s->h) {
55 av_log(ctx, AV_LOG_ERROR, "Tile size %ux%u is insane.\n",
56 s->w, s->h);
57 return AVERROR(EINVAL);
58 }
59 s->nb_frames = s->w * s->h;
60 return 0;
61}
62
63static int query_formats(AVFilterContext *ctx)
64{
65 AVFilterFormats *formats = NULL;
66 int ret;
67
68 ret = ff_formats_pixdesc_filter(&formats, 0,
69 AV_PIX_FMT_FLAG_HWACCEL |
70 AV_PIX_FMT_FLAG_BITSTREAM |
71 FF_PIX_FMT_FLAG_SW_FLAT_SUB);
72 if (ret < 0)
73 return ret;
74 return ff_set_common_formats(ctx, formats);
75}
76
77static int config_output(AVFilterLink *outlink)
78{
79 AVFilterContext *ctx = outlink->src;
80 UntileContext *s = ctx->priv;
81 AVFilterLink *inlink = ctx->inputs[0];
82 AVRational dt;
83
84 s->desc = av_pix_fmt_desc_get(outlink->format);
85 if (inlink->w % (s->w << s->desc->log2_chroma_w) ||
86 inlink->h % (s->h << s->desc->log2_chroma_h)) {
87 av_log(ctx, AV_LOG_ERROR,
88 "Input resolution %ux%u not multiple of layout %ux%u.\n",
89 inlink->w, inlink->h, s->w, s->h);
90 return AVERROR(EINVAL);
91 }
92 outlink->w = inlink->w / s->w;
93 outlink->h = inlink->h / s->h;
94 outlink->sample_aspect_ratio = inlink->sample_aspect_ratio;
95 outlink->frame_rate = av_mul_q(inlink->frame_rate, av_make_q(s->nb_frames, 1));
96 if (outlink->frame_rate.num)
97 dt = av_inv_q(outlink->frame_rate);
98 else
99 dt = av_mul_q(inlink->time_base, av_make_q(1, s->nb_frames));
100 outlink->time_base = av_gcd_q(inlink->time_base, dt, AV_TIME_BASE / 2, AV_TIME_BASE_Q);
101 s->dpts = av_rescale_q(1, dt, outlink->time_base);
102 av_log(ctx, AV_LOG_VERBOSE, "frame interval: %"PRId64"*%d/%d\n",
103 s->dpts, dt.num, dt.den);
104 av_image_fill_max_pixsteps(s->max_step, NULL, s->desc);
105 return 0;
106}
107
108static int activate(AVFilterContext *ctx)
109{
110 UntileContext *s = ctx->priv;
111 AVFilterLink *inlink = ctx->inputs[0];
112 AVFilterLink *outlink = ctx->outputs[0];
113 AVFrame *out;
114 int i, x, y, ret;
115
116 FF_FILTER_FORWARD_STATUS_BACK(outlink, inlink);
117 if (!s->frame) {
118 ret = ff_inlink_consume_frame(inlink, &s->frame);
119 if (ret < 0)
120 return ret;
121 if (ret)
122 s->pts = av_rescale_q(s->frame->pts, inlink->time_base, outlink->time_base);
123 }
124 if (s->frame) {
125 if (s->current == s->nb_frames - 1) {
126 out = s->frame;
127 s->frame = NULL;
128 } else {
129 out = av_frame_clone(s->frame);
130 if (!out)
131 return AVERROR(ENOMEM);
132 }
133 x = outlink->w * (s->current % s->w);
134 y = outlink->h * (s->current / s->w);
135 out->width = outlink->w;
136 out->height = outlink->h;
137 out->data[0] += y * out->linesize[0];
138 out->data[0] += x * s->max_step[0];
139 if (!(s->desc->flags & AV_PIX_FMT_FLAG_PAL || s->desc->flags & FF_PSEUDOPAL)) {
140 for (i = 1; i < 3; i ++) {
141 if (out->data[i]) {
142 out->data[i] += (y >> s->desc->log2_chroma_w) * out->linesize[i];
143 out->data[i] += (x >> s->desc->log2_chroma_h) * s->max_step[i];
144 }
145 }
146 }
147 if (out->data[3]) {
148 out->data[3] += y * out->linesize[3];
149 out->data[3] += x * s->max_step[3];
150 }
151 out->pts = s->pts;
152 s->pts += s->dpts;
153 if (++s->current == s->nb_frames)
154 s->current = 0;
155 return ff_filter_frame(outlink, out);
156 }
157 FF_FILTER_FORWARD_STATUS(inlink, outlink);
158 FF_FILTER_FORWARD_WANTED(outlink, inlink);
159 return FFERROR_NOT_READY;
160
161}
162
163static av_cold void uninit(AVFilterContext *ctx)
164{
165 UntileContext *s = ctx->priv;
166
167 av_frame_free(&s->frame);
168}
169
170static const AVFilterPad untile_inputs[] = {
171 {
172 .name = "default",
173 .type = AVMEDIA_TYPE_VIDEO,
174 },
175 { NULL }
176};
177
178static const AVFilterPad untile_outputs[] = {
179 {
180 .name = "default",
181 .type = AVMEDIA_TYPE_VIDEO,
182 .config_props = config_output,
183 },
184 { NULL }
185};
186
187AVFilter ff_vf_untile = {
188 .name = "untile",
189 .description = NULL_IF_CONFIG_SMALL("Untile a frame into a sequence of frames."),
190 .init = init,
191 .uninit = uninit,
192 .query_formats = query_formats,
193 .activate = activate,
194 .priv_size = sizeof(UntileContext),
195 .inputs = untile_inputs,
196 .outputs = untile_outputs,
197 .priv_class = &untile_class,
198};
tests/fate/filter-video.mak+3−0
@@ -396,6 +396,9 @@ fate-filter-trim-time: CMD = framecrc -i $(SRC) -vf trim=0:0.09 · 395 unmodified lines
396 396
397FATE_FILTER_VSYNTH-$(CONFIG_TRIM_FILTER) += $(FATE_TRIM)397FATE_FILTER_VSYNTH-$(CONFIG_TRIM_FILTER) += $(FATE_TRIM)
398 398
399FATE_FILTER-$(call ALLYES, TESTSRC2_FILTER UNTILE_FILTER) += fate-filter-untile
400fate-filter-untile: CMD = framecrc -lavfi testsrc2=d=1:r=2,untile=2x2
401
399FATE_FILTER_VSYNTH-$(CONFIG_UNSHARP_FILTER) += fate-filter-unsharp402FATE_FILTER_VSYNTH-$(CONFIG_UNSHARP_FILTER) += fate-filter-unsharp
400fate-filter-unsharp: CMD = framecrc -c:v pgmyuv -i $(SRC) -vf unsharp=11:11:-1.5:11:11:-1.5403fate-filter-unsharp: CMD = framecrc -c:v pgmyuv -i $(SRC) -vf unsharp=11:11:-1.5:11:11:-1.5
401 404
tests/ref/fate/filter-untile+13−0
@@ -0,0 +1,13 @@
1#tb 0: 1/8
2#media_type 0: video
3#codec_id 0: rawvideo
4#dimensions 0: 160x120
5#sar 0: 1/1
60, 0, 0, 1, 28800, 0xb3725302
70, 1, 1, 1, 28800, 0xf9612057
80, 2, 2, 1, 28800, 0x9b207db0
90, 3, 3, 1, 28800, 0x1331c2d5
100, 4, 4, 1, 28800, 0x2edf3ee4
110, 5, 5, 1, 28800, 0x84105711
120, 6, 6, 1, 28800, 0xa7a35f25
130, 7, 7, 1, 28800, 0xa9c49677

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t