1 /*
2 * Copyright (c) 2012 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 /**
22 * @file
23 * tile video filter
24 */
25
33
46
47 #define REASONABLE_SIZE 1024
48
49 #define OFFSET(x) offsetof(TileContext, x)
50 #define FLAGS AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
51
54 {.str =
"6x5"}, 0, 0,
FLAGS },
55 {
"nb_frames",
"set maximum number of frame to render",
OFFSET(nb_frames),
57 {
"margin",
"set outer border margin in pixels",
OFFSET(margin),
59 {
"padding",
"set inner border thickness in pixels",
OFFSET(padding),
63 };
64
66
68 {
70
75 }
76
81 tile->
w, tile->
h, tile->
w * tile->
h);
83 }
84
85 return 0;
86 }
87
89 {
91 }
92
94 {
98 const unsigned total_margin_w = (tile->
w - 1) * tile->
padding + 2*tile->
margin;
99 const unsigned total_margin_h = (tile->
h - 1) * tile->
padding + 2*tile->
margin;
100
101 if (inlink->
w > (INT_MAX - total_margin_w) / tile->
w) {
105 }
106 if (inlink->
h > (INT_MAX - total_margin_h) / tile->
h) {
110 }
111 outlink->
w = tile->
w * inlink->
w + total_margin_w;
112 outlink->
h = tile->
h * inlink->
h + total_margin_h;
118
119 return 0;
120 }
121
123 {
126 const unsigned tx = tile->
current % tile->
w;
127 const unsigned ty = tile->
current / tile->
w;
128
131 }
132
134 {
137 unsigned x0, y0;
138
142 x0, y0, inlink->
w, inlink->
h);
144 }
146 {
150 int ret;
151
156 return ret;
157 }
158
159 /* Note: direct rendering is not possible since there is no guarantee that
160 * buffers are fed to filter_frame in the order they were obtained from
161 * get_buffer (think B-frames). */
162
164 {
168 unsigned x0, y0;
169
175 }
179
180 /* fill surface once for margin/padding */
185 0, 0, outlink->
w, outlink->
h);
186 }
187
192 x0, y0, 0, 0, inlink->
w, inlink->
h);
193
197
198 return 0;
199 }
200
202 {
207
212 }
213
215 {
219 },
221 };
222
224 {
229 },
231 };
232
241 .priv_class = &tile_class,
242 };
AVFilterFormats * ff_draw_supported_pixel_formats(unsigned flags)
Return the list of pixel formats supported by the draw functions.
This structure describes decoded (raw) audio or video data.
void ff_copy_rectangle2(FFDrawContext *draw, uint8_t *dst[], int dst_linesize[], uint8_t *src[], int src_linesize[], int dst_x, int dst_y, int src_x, int src_y, int w, int h)
Copy a rectangle from an image to another.
static int request_frame(AVFilterLink *outlink)
Main libavfilter public API header.
int h
agreed upon image height
AVFrame * ff_get_video_buffer(AVFilterLink *link, int w, int h)
Request a picture buffer with a specific set of permissions.
static int filter_frame(AVFilterLink *inlink, AVFrame *picref)
const char * name
Pad name.
AVFilterLink ** inputs
array of pointers to input links
static int end_last_frame(AVFilterContext *ctx)
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
static int config_props(AVFilterLink *outlink)
#define AVERROR_EOF
End of file.
static void get_current_tile_pos(AVFilterContext *ctx, unsigned *x, unsigned *y)
static const AVFilterPad tile_inputs[]
A filter pad used for either input or output.
A link between two filters.
int width
width and height of the video frame
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
AVRational frame_rate
Frame rate of the stream on the link, or 1/0 if unknown or variable; if left to 0/0, will be automatically copied from the first input of the source filter if it exists.
static void draw_blank_frame(AVFilterContext *ctx, AVFrame *out_buf)
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
AVFILTER_DEFINE_CLASS(tile)
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
void * priv
private data for use by the filter
void ff_draw_color(FFDrawContext *draw, FFDrawColor *color, const uint8_t rgba[4])
Prepare a color.
int w
agreed upon image width
static int query_formats(AVFilterContext *ctx)
AVFilterContext * src
source filter
static const AVFilterPad outputs[]
static const AVFilterPad tile_outputs[]
static av_cold int init(AVFilterContext *ctx)
int format
agreed upon media format
static const AVFilterPad inputs[]
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
static AVRational av_make_q(int num, int den)
Create an AVRational.
Describe the class of an AVClass context structure.
const char * name
Filter name.
int ff_draw_init(FFDrawContext *draw, enum AVPixelFormat format, unsigned flags)
Init a draw context.
AVRational sample_aspect_ratio
agreed upon sample aspect ratio
offset must point to two consecutive integers
AVFilterLink ** outputs
array of pointers to output links
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
AVFilterContext * dst
dest filter
static const AVOption tile_options[]
void ff_fill_rectangle(FFDrawContext *draw, FFDrawColor *color, uint8_t *dst[], int dst_linesize[], int dst_x, int dst_y, int w, int h)
Fill a rectangle with an uniform color.
AVRational av_mul_q(AVRational b, AVRational c)
Multiply two rationals.
int ff_request_frame(AVFilterLink *link)
Request an input frame from the filter at the other end of the link.
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.