... | ... |
@@ -2682,6 +2682,22 @@ Complete example of a thumbnail creation with @command{ffmpeg}: |
2682 | 2682 |
ffmpeg -i in.avi -vf thumbnail,scale=300:200 -frames:v 1 out.png |
2683 | 2683 |
@end example |
2684 | 2684 |
|
2685 |
+@section tile |
|
2686 |
+ |
|
2687 |
+Tile several successive frames together. |
|
2688 |
+ |
|
2689 |
+It accepts as argument the tile size (i.e. the number of lines and columns) |
|
2690 |
+in the form "@var{w}x@var{h}". |
|
2691 |
+ |
|
2692 |
+For example, produce 8×8 PNG tiles of all keyframes (@option{-skip_frame |
|
2693 |
+nokey}) in a movie: |
|
2694 |
+@example |
|
2695 |
+ffmpeg -skip_frame nokey -i file.avi -vf 'scale=128:72,tile=8x8' -an -vsync 0 keyframes%03d.png |
|
2696 |
+@end example |
|
2697 |
+The @option{-vsync 0} is necessary to prevent @command{ffmpeg} from |
|
2698 |
+duplicating each output frame to accomodate the originally detected frame |
|
2699 |
+rate. |
|
2700 |
+ |
|
2685 | 2701 |
@section tinterlace |
2686 | 2702 |
|
2687 | 2703 |
Perform various types of temporal field interlacing. |
... | ... |
@@ -90,6 +90,7 @@ OBJS-$(CONFIG_SLICIFY_FILTER) += vf_slicify.o |
90 | 90 |
OBJS-$(CONFIG_SPLIT_FILTER) += vf_split.o |
91 | 91 |
OBJS-$(CONFIG_SWAPUV_FILTER) += vf_swapuv.o |
92 | 92 |
OBJS-$(CONFIG_THUMBNAIL_FILTER) += vf_thumbnail.o |
93 |
+OBJS-$(CONFIG_TILE_FILTER) += vf_tile.o |
|
93 | 94 |
OBJS-$(CONFIG_TINTERLACE_FILTER) += vf_tinterlace.o |
94 | 95 |
OBJS-$(CONFIG_TRANSPOSE_FILTER) += vf_transpose.o |
95 | 96 |
OBJS-$(CONFIG_UNSHARP_FILTER) += vf_unsharp.o |
... | ... |
@@ -98,6 +98,7 @@ void avfilter_register_all(void) |
98 | 98 |
REGISTER_FILTER (SPLIT, split, vf); |
99 | 99 |
REGISTER_FILTER (SWAPUV, swapuv, vf); |
100 | 100 |
REGISTER_FILTER (THUMBNAIL, thumbnail, vf); |
101 |
+ REGISTER_FILTER (TILE, tile, vf); |
|
101 | 102 |
REGISTER_FILTER (TINTERLACE, tinterlace, vf); |
102 | 103 |
REGISTER_FILTER (TRANSPOSE, transpose, vf); |
103 | 104 |
REGISTER_FILTER (UNSHARP, unsharp, vf); |
104 | 105 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,206 @@ |
0 |
+/* |
|
1 |
+ * Copyright (c) 2012 Nicolas George |
|
2 |
+ * |
|
3 |
+ * This file is part of FFmpeg. |
|
4 |
+ * |
|
5 |
+ * FFmpeg is free software; you can redistribute it and/or |
|
6 |
+ * modify it under the terms of the GNU Lesser General Public |
|
7 |
+ * License as published by the Free Software Foundation; either |
|
8 |
+ * version 2.1 of the License, or (at your option) any later version. |
|
9 |
+ * |
|
10 |
+ * FFmpeg is distributed in the hope that it will be useful, |
|
11 |
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 |
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
13 |
+ * Lesser General Public License for more details. |
|
14 |
+ * |
|
15 |
+ * You should have received a copy of the GNU Lesser General Public |
|
16 |
+ * License along with FFmpeg; if not, write to the Free Software |
|
17 |
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
|
18 |
+ */ |
|
19 |
+ |
|
20 |
+/** |
|
21 |
+ * @file |
|
22 |
+ * tile video filter |
|
23 |
+ */ |
|
24 |
+ |
|
25 |
+#include "libavutil/pixdesc.h" |
|
26 |
+#include "avfilter.h" |
|
27 |
+#include "drawutils.h" |
|
28 |
+ |
|
29 |
+typedef struct { |
|
30 |
+ unsigned w, h; |
|
31 |
+ unsigned current; |
|
32 |
+ FFDrawContext draw; |
|
33 |
+ FFDrawColor blank; |
|
34 |
+} TileContext; |
|
35 |
+ |
|
36 |
+#define REASONABLE_SIZE 1024 |
|
37 |
+ |
|
38 |
+static av_cold int init(AVFilterContext *ctx, const char *args, void *opaque) |
|
39 |
+{ |
|
40 |
+ TileContext *tile = ctx->priv; |
|
41 |
+ int r; |
|
42 |
+ char dummy; |
|
43 |
+ |
|
44 |
+ if (!args) |
|
45 |
+ args = "6x5"; |
|
46 |
+ r = sscanf(args, "%ux%u%c", &tile->w, &tile->h, &dummy); |
|
47 |
+ if (r != 2 || !tile->w || !tile->h) |
|
48 |
+ return AVERROR(EINVAL); |
|
49 |
+ if (tile->w > REASONABLE_SIZE || tile->h > REASONABLE_SIZE) { |
|
50 |
+ av_log(ctx, AV_LOG_ERROR, "Tile size %ux%u is insane.\n", |
|
51 |
+ tile->w, tile->h); |
|
52 |
+ return AVERROR(EINVAL); |
|
53 |
+ } |
|
54 |
+ return 0; |
|
55 |
+} |
|
56 |
+ |
|
57 |
+static int query_formats(AVFilterContext *ctx) |
|
58 |
+{ |
|
59 |
+ avfilter_set_common_pixel_formats(ctx, ff_draw_supported_pixel_formats(0)); |
|
60 |
+ return 0; |
|
61 |
+} |
|
62 |
+ |
|
63 |
+static int config_props(AVFilterLink *outlink) |
|
64 |
+{ |
|
65 |
+ AVFilterContext *ctx = outlink->src; |
|
66 |
+ TileContext *tile = ctx->priv; |
|
67 |
+ AVFilterLink *inlink = ctx->inputs[0]; |
|
68 |
+ |
|
69 |
+ if (inlink->w > INT_MAX / tile->w) { |
|
70 |
+ av_log(ctx, AV_LOG_ERROR, "Total width %ux%u is too much.\n", |
|
71 |
+ tile->w, inlink->w); |
|
72 |
+ return AVERROR(EINVAL); |
|
73 |
+ } |
|
74 |
+ if (inlink->h > INT_MAX / tile->h) { |
|
75 |
+ av_log(ctx, AV_LOG_ERROR, "Total height %ux%u is too much.\n", |
|
76 |
+ tile->h, inlink->h); |
|
77 |
+ return AVERROR(EINVAL); |
|
78 |
+ } |
|
79 |
+ outlink->w = tile->w * inlink->w; |
|
80 |
+ outlink->h = tile->h * inlink->h; |
|
81 |
+ outlink->sample_aspect_ratio = inlink->sample_aspect_ratio; |
|
82 |
+ ff_draw_init(&tile->draw, inlink->format, 0); |
|
83 |
+ /* TODO make the color an option, or find an unified way of choosing it */ |
|
84 |
+ ff_draw_color(&tile->draw, &tile->blank, (uint8_t[]){ 0, 0, 0, -1 }); |
|
85 |
+ |
|
86 |
+ return 0; |
|
87 |
+} |
|
88 |
+ |
|
89 |
+/* Note: direct rendering is not possible since there is no guarantee that |
|
90 |
+ * buffers are fed to start_frame in the order they were obtained from |
|
91 |
+ * get_buffer (think B-frames). */ |
|
92 |
+ |
|
93 |
+static void start_frame(AVFilterLink *inlink, AVFilterBufferRef *picref) |
|
94 |
+{ |
|
95 |
+ AVFilterContext *ctx = inlink->dst; |
|
96 |
+ TileContext *tile = ctx->priv; |
|
97 |
+ AVFilterLink *outlink = ctx->outputs[0]; |
|
98 |
+ |
|
99 |
+ if (tile->current) |
|
100 |
+ return; |
|
101 |
+ outlink->out_buf = avfilter_get_video_buffer(outlink, AV_PERM_WRITE, |
|
102 |
+ outlink->w, outlink->h); |
|
103 |
+ avfilter_copy_buffer_ref_props(outlink->out_buf, picref); |
|
104 |
+ outlink->out_buf->video->w = outlink->w; |
|
105 |
+ outlink->out_buf->video->h = outlink->h; |
|
106 |
+ avfilter_start_frame(outlink, outlink->out_buf); |
|
107 |
+} |
|
108 |
+ |
|
109 |
+static void draw_slice(AVFilterLink *inlink, int y, int h, int slice_dir) |
|
110 |
+{ |
|
111 |
+ AVFilterContext *ctx = inlink->dst; |
|
112 |
+ TileContext *tile = ctx->priv; |
|
113 |
+ AVFilterLink *outlink = ctx->outputs[0]; |
|
114 |
+ unsigned x0 = inlink->w * (tile->current % tile->w); |
|
115 |
+ unsigned y0 = inlink->h * (tile->current / tile->w); |
|
116 |
+ |
|
117 |
+ ff_copy_rectangle2(&tile->draw, |
|
118 |
+ outlink->out_buf->data, outlink->out_buf->linesize, |
|
119 |
+ inlink ->cur_buf->data, inlink ->cur_buf->linesize, |
|
120 |
+ x0, y0 + y, 0, y, inlink->cur_buf->video->w, h); |
|
121 |
+ /* TODO if tile->w == 1 && slice_dir is always 1, we could draw_slice |
|
122 |
+ * immediately. */ |
|
123 |
+} |
|
124 |
+ |
|
125 |
+static void draw_blank_frame(AVFilterContext *ctx) |
|
126 |
+{ |
|
127 |
+ TileContext *tile = ctx->priv; |
|
128 |
+ AVFilterLink *inlink = ctx->inputs[0]; |
|
129 |
+ AVFilterLink *outlink = ctx->outputs[0]; |
|
130 |
+ unsigned x0 = inlink->w * (tile->current % tile->w); |
|
131 |
+ unsigned y0 = inlink->h * (tile->current / tile->w); |
|
132 |
+ |
|
133 |
+ ff_fill_rectangle(&tile->draw, &tile->blank, |
|
134 |
+ outlink->out_buf->data, outlink->out_buf->linesize, |
|
135 |
+ x0, y0, inlink->w, inlink->h); |
|
136 |
+ tile->current++; |
|
137 |
+} |
|
138 |
+static void end_last_frame(AVFilterContext *ctx) |
|
139 |
+{ |
|
140 |
+ TileContext *tile = ctx->priv; |
|
141 |
+ AVFilterLink *outlink = ctx->outputs[0]; |
|
142 |
+ |
|
143 |
+ while (tile->current < tile->w * tile->h) |
|
144 |
+ draw_blank_frame(ctx); |
|
145 |
+ avfilter_draw_slice(outlink, 0, outlink->out_buf->video->h, 1); |
|
146 |
+ avfilter_end_frame(outlink); |
|
147 |
+ tile->current = 0; |
|
148 |
+} |
|
149 |
+ |
|
150 |
+static void end_frame(AVFilterLink *inlink) |
|
151 |
+{ |
|
152 |
+ AVFilterContext *ctx = inlink->dst; |
|
153 |
+ TileContext *tile = ctx->priv; |
|
154 |
+ |
|
155 |
+ avfilter_unref_buffer(inlink->cur_buf); |
|
156 |
+ if (++tile->current == tile->w * tile->h) |
|
157 |
+ end_last_frame(ctx); |
|
158 |
+} |
|
159 |
+ |
|
160 |
+static int request_frame(AVFilterLink *outlink) |
|
161 |
+{ |
|
162 |
+ AVFilterContext *ctx = outlink->src; |
|
163 |
+ TileContext *tile = ctx->priv; |
|
164 |
+ AVFilterLink *inlink = ctx->inputs[0]; |
|
165 |
+ int r; |
|
166 |
+ |
|
167 |
+ while (1) { |
|
168 |
+ r = avfilter_request_frame(inlink); |
|
169 |
+ if (r < 0) { |
|
170 |
+ if (r == AVERROR_EOF && tile->current) |
|
171 |
+ end_last_frame(ctx); |
|
172 |
+ else |
|
173 |
+ return r; |
|
174 |
+ break; |
|
175 |
+ } |
|
176 |
+ if (!tile->current) /* done */ |
|
177 |
+ break; |
|
178 |
+ } |
|
179 |
+ return 0; |
|
180 |
+} |
|
181 |
+ |
|
182 |
+ |
|
183 |
+AVFilter avfilter_vf_tile = { |
|
184 |
+ .name = "tile", |
|
185 |
+ .description = NULL_IF_CONFIG_SMALL("Tile several successive frames together."), |
|
186 |
+ .init = init, |
|
187 |
+ .query_formats = query_formats, |
|
188 |
+ .priv_size = sizeof(TileContext), |
|
189 |
+ .inputs = (const AVFilterPad[]) { |
|
190 |
+ { .name = "default", |
|
191 |
+ .type = AVMEDIA_TYPE_VIDEO, |
|
192 |
+ .start_frame = start_frame, |
|
193 |
+ .draw_slice = draw_slice, |
|
194 |
+ .end_frame = end_frame, |
|
195 |
+ .min_perms = AV_PERM_READ, }, |
|
196 |
+ { .name = NULL } |
|
197 |
+ }, |
|
198 |
+ .outputs = (const AVFilterPad[]) { |
|
199 |
+ { .name = "default", |
|
200 |
+ .type = AVMEDIA_TYPE_VIDEO, |
|
201 |
+ .config_props = config_props, |
|
202 |
+ .request_frame = request_frame }, |
|
203 |
+ { .name = NULL } |
|
204 |
+ }, |
|
205 |
+}; |