1 /*
2 * Copyright (c) 2010 Brandon Mintern
3 * Copyright (c) 2007 Bobby Bingham
4 *
5 * This file is part of FFmpeg.
6 *
7 * FFmpeg is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * FFmpeg is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with FFmpeg; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
22 /**
23 * @file
24 * video fade filter
25 * based heavily on vf_negate.c by Bobby Bingham
26 */
27
39
44
48
51
67
69 {
71
74
76 // If duration (seconds) is non-zero, assume that we are not fading based on frames
77 s->
nb_frames = 0;
// Mostly to clean up logging
78 }
79
80 // Choose what to log. If both time-based and frame-based options, both lines will be in the log
83 "type:%s start_frame:%d nb_frames:%d alpha:%d\n",
86 }
89 "type:%s start_time:%f duration:%f alpha:%d\n",
92 }
93
95 return 0;
96 }
97
99 {
111 };
117 };
123 };
128 };
130
134 else
136 } else {
139 else
141 }
142 if (!fmts_list)
145 }
146
152 };
153
155 {
158
161
163 1 :
167
168 /* use CCIR601/709 black level for studio-level pixel non-alpha components */
171 /* 32768 = 1 << 15, it is an integer representation
172 * of 0.5 and is for rounding. */
174 return 0;
175 }
176
179 int do_alpha, int step)
180 {
181 int i, j;
187
188 for (i = slice_start; i <
slice_end; i++) {
190 for (j = 0; j < frame->
width; j++) {
191 #define INTERP(c_name, c_idx) av_clip_uint8(((c[c_idx]<<16) + ((int)p[c_name] - (int)c[c_idx]) * s->factor + (1<<15)) >> 16)
192 p[r_idx] =
INTERP(r_idx, 0);
193 p[g_idx] =
INTERP(g_idx, 1);
194 p[b_idx] =
INTERP(b_idx, 2);
195 if (do_alpha)
196 p[a_idx] =
INTERP(a_idx, 3);
197 p += step;
198 }
199 }
200 }
201
203 int nb_jobs)
204 {
207 int slice_start = (frame->
height * jobnr ) / nb_jobs;
209
211 else if (s->
bpp == 3)
filter_rgb(s, frame, slice_start, slice_end, 0, 3);
212 else if (s->
bpp == 4)
filter_rgb(s, frame, slice_start, slice_end, 0, 4);
214
215 return 0;
216 }
217
219 int nb_jobs)
220 {
223 int slice_start = (frame->
height * jobnr ) / nb_jobs;
225 int i, j;
226
227 for (i = slice_start; i <
slice_end; i++) {
229 for (j = 0; j < frame->
width * s->
bpp; j++) {
230 /* s->factor is using 16 lower-order bits for decimal
231 * places. 32768 = 1 << 15, it is an integer representation
232 * of 0.5 and is for rounding. */
234 p++;
235 }
236 }
237
238 return 0;
239 }
240
242 int nb_jobs)
243 {
249 int slice_start = (height * jobnr ) / nb_jobs;
251
252 for (plane = 1; plane < 3; plane++) {
253 for (i = slice_start; i <
slice_end; i++) {
255 for (j = 0; j <
width; j++) {
256 /* 8421367 = ((128 << 1) + 1) << 15. It is an integer
257 * representation of 128.5. The .5 is for rounding
258 * purposes. */
259 *p = ((*p - 128) * s->
factor + 8421367) >> 16;
260 p++;
261 }
262 }
263 }
264
265 return 0;
266 }
267
269 int nb_jobs)
270 {
274 int slice_start = (frame->
height * jobnr ) / nb_jobs;
276 int i, j;
277
278 for (i = slice_start; i <
slice_end; i++) {
281 for (j = 0; j < frame->
width; j++) {
282 /* s->factor is using 16 lower-order bits for decimal
283 * places. 32768 = 1 << 15, it is an integer representation
284 * of 0.5 and is for rounding. */
286 p += step;
287 }
288 }
289
290 return 0;
291 }
292
294 {
298
299 // Calculate Fade assuming this is a Fade In
304 // Time to start fading
306
307 // Save start time in case we are starting based on frames and fading based on time
310 }
311
312 // Save start frame in case we are starting based on time and fading based on frames
315 }
316 }
317 }
320 // Fading based on frame count
324 }
325
326 } else {
327 // Fading based on duration
333 }
334 }
335 }
338 }
339
341
342 // Invert fade_factor if Fading Out
345 }
346
347 if (s->
factor < UINT16_MAX) {
354 } else {
355 /* luma, or rgb plane in case of black */
358
359 if (frame->
data[1] && frame->
data[2]) {
360 /* chroma planes */
363 }
364 }
365 }
366
368 }
369
370
371 #define OFFSET(x) offsetof(FadeContext, x)
372 #define FLAGS AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
373
379 { "start_frame", "Number of the first frame to which to apply the effect.",
381 { "s", "Number of the first frame to which to apply the effect.",
383 { "nb_frames", "Number of frames to which the effect should be applied.",
385 { "n", "Number of frames to which the effect should be applied.",
388 { "start_time", "Number of seconds of the beginning of the effect.",
390 { "st", "Number of seconds of the beginning of the effect.",
392 { "duration", "Duration of the effect in seconds.",
394 { "d", "Duration of the effect in seconds.",
399 };
400
402
404 {
409 .needs_writable = 1,
410 },
412 };
413
415 {
418 },
420 };
421
427 .priv_class = &fade_class,
429 .
inputs = avfilter_vf_fade_inputs,
430 .
outputs = avfilter_vf_fade_outputs,
432 };
static float alpha(float a)
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
This structure describes decoded (raw) audio or video data.
static const AVFilterPad avfilter_vf_fade_outputs[]
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
Main libavfilter public API header.
packed RGB 8:8:8, 24bpp, RGBRGB...
int av_get_bits_per_pixel(const AVPixFmtDescriptor *pixdesc)
Return the number of bits per pixel used by the pixel format described by pixdesc.
static int config_props(AVFilterLink *inlink)
static const AVOption fade_options[]
uint8_t log2_chroma_w
Amount to shift the luma width right to find the chroma width.
const char * name
Pad name.
#define av_assert0(cond)
assert() equivalent, that is always enabled.
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
planar YUV 4:2:0, 20bpp, (1 Cr & Cb sample per 2x2 Y & A samples)
static int64_t start_time
#define AV_PIX_FMT_FLAG_ALPHA
The pixel format has an alpha channel.
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
#define INTERP(c_name, c_idx)
packed ABGR 8:8:8:8, 32bpp, ABGRABGR...
int black_fade
if color_rgba is black
static double av_q2d(AVRational a)
Convert an AVRational to a double.
planar YUV 4:4:0 full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV440P and setting color_range...
planar YUV 4:2:2, 16bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV422P and setting col...
#define AV_LOG_VERBOSE
Detailed information.
static av_always_inline void filter_rgb(FadeContext *s, const AVFrame *frame, int slice_start, int slice_end, int do_alpha, int step)
A filter pad used for either input or output.
A link between two filters.
static int query_formats(AVFilterContext *ctx)
planar YUV 4:2:2 24bpp, (1 Cr & Cb sample per 2x1 Y & A samples)
uint8_t log2_chroma_h
Amount to shift the luma height right to find the chroma height.
static void fade(uint8_t *dst, ptrdiff_t dst_linesize, const uint8_t *src, ptrdiff_t src_linesize, int width, int height, int alpha, int beta)
static av_cold int init(AVFilterContext *ctx)
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
packed BGRA 8:8:8:8, 32bpp, BGRABGRA...
void * priv
private data for use by the filter
#define AVFILTER_FLAG_SLICE_THREADS
The filter supports multithreading by splitting frames into multiple parts and processing them concur...
AVRational time_base
Define the time base used by the PTS of the frames/samples which will pass through this link...
simple assert() macros that are a bit more flexible than ISO C assert().
enum FadeContext::@190 fade_state
static int filter_frame(AVFilterLink *inlink, AVFrame *frame)
packed ARGB 8:8:8:8, 32bpp, ARGBARGB...
packed RGBA 8:8:8:8, 32bpp, RGBARGBA...
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
uint64_t flags
Combination of AV_PIX_FMT_FLAG_...
int ff_filter_get_nb_threads(AVFilterContext *ctx)
Get number of threads for current filter instance.
#define AV_TIME_BASE
Internal time base represented as integer.
static int filter_slice_rgb(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
planar YUV 4:2:0, 12bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV420P and setting col...
static int filter_slice_chroma(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
packed RGB 8:8:8, 24bpp, BGRBGR...
static const AVFilterPad avfilter_vf_fade_inputs[]
static const AVFilterPad inputs[]
static const AVFilterPad outputs[]
int format
agreed upon media format
int ff_fill_rgba_map(uint8_t *rgba_map, enum AVPixelFormat pix_fmt)
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
planar YUV 4:4:4 32bpp, (1 Cr & Cb sample per 1x1 Y & A samples)
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
planar YUV 4:1:0, 9bpp, (1 Cr & Cb sample per 4x4 Y samples)
Describe the class of an AVClass context structure.
static int filter_slice_luma(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
const char * name
Filter name.
AVFilterLink ** outputs
array of pointers to output links
static enum AVPixelFormat pix_fmts[]
AVFilterInternal * internal
An opaque struct for libavfilter internal use.
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
uint8_t color_rgba[4]
fade color
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
common internal and external API header
planar YUV 4:4:4, 24bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV444P and setting col...
planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples)
avfilter_execute_func * execute
static int slice_end(AVCodecContext *avctx, AVFrame *pict)
Handle slice ends.
AVFilterContext * dst
dest filter
unsigned int black_level_scaled
static int filter_slice_alpha(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
planar YUV 4:4:0 (1 Cr & Cb sample per 1x2 Y samples)
static const enum AVPixelFormat studio_level_pix_fmts[]
AVPixelFormat
Pixel format.
#define AV_PIX_FMT_FLAG_PLANAR
At least one pixel component is not in the first data plane.
#define AV_NOPTS_VALUE
Undefined timestamp value.
simple arithmetic expression evaluator
#define AV_CEIL_RSHIFT(a, b)
AVFILTER_DEFINE_CLASS(fade)