Go to the documentation of this file.
77 s->fade_per_frame = (1 << 16) /
s->nb_frames;
78 s->fade_state = VF_FADE_WAITING;
80 if (
s->duration != 0) {
86 if (
s->start_frame ||
s->nb_frames) {
88 "type:%s start_frame:%d nb_frames:%d alpha:%d\n",
89 s->type ==
FADE_IN ?
"in" :
"out",
s->start_frame,
90 s->nb_frames,
s->alpha);
92 if (
s->start_time ||
s->duration) {
94 "type:%s start_time:%f duration:%f alpha:%d\n",
99 s->black_fade = !memcmp(
s->color_rgba,
"\x00\x00\x00\xff", 4);
187 int do_alpha,
int step)
198 for (j = 0; j <
frame->width; j++) {
199 #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)
200 p[r_idx] =
INTERP(r_idx, 0);
201 p[g_idx] =
INTERP(g_idx, 1);
202 p[b_idx] =
INTERP(b_idx, 2);
204 p[a_idx] =
INTERP(a_idx, 3);
222 for (j = 0; j <
frame->width; j++) {
223 #define INTERPP(c_name, c_idx) av_clip_uint8(((c[c_idx]<<16) + ((int)c_name - (int)c[c_idx]) * s->factor + (1<<15)) >> 16)
238 int slice_start = (
frame->height * jobnr ) / nb_jobs;
241 if (
s->is_planar &&
s->alpha)
243 else if (
s->is_planar)
258 int slice_start = (
frame->height * jobnr ) / nb_jobs;
262 for (
int k = 0; k < 1 + 2 * (
s->is_planar &&
s->is_rgb); k++) {
265 for (j = 0; j <
frame->width *
s->bpp; j++) {
269 *p = ((*p -
s->black_level) *
s->factor +
s->black_level_scaled) >> 16;
283 int slice_start = (
frame->height * jobnr ) / nb_jobs;
287 for (
int k = 0; k < 1 + 2 * (
s->is_planar &&
s->is_rgb); k++) {
289 uint16_t *p = (uint16_t *)(
frame->data[k] +
i *
frame->linesize[k]);
290 for (j = 0; j <
frame->width *
s->bpp; j++) {
294 *p = ((*p -
s->black_level) *
s->factor +
s->black_level_scaled) >> 16;
311 int slice_start = (
height * jobnr ) / nb_jobs;
314 for (plane = 1; plane < 3; plane++) {
317 for (j = 0; j <
width; j++) {
321 *p = ((*p - 128) *
s->factor + 8421367) >> 16;
338 const int mid = 1 << (
s->depth - 1);
339 const int add = ((mid << 1) + 1) << 15;
340 int slice_start = (
height * jobnr ) / nb_jobs;
343 for (plane = 1; plane < 3; plane++) {
345 uint16_t *p = (uint16_t *)(
frame->data[plane] +
i *
frame->linesize[plane]);
346 for (j = 0; j <
width; j++) {
347 *p = ((*p - mid) *
s->factor + add) >> 16;
361 int plane =
s->is_packed_rgb ? 0 :
A;
362 int slice_start = (
frame->height * jobnr ) / nb_jobs;
368 int step =
s->is_packed_rgb ? 4 : 1;
369 for (j = 0; j <
frame->width; j++) {
373 *p = ((*p -
s->black_level) *
s->factor +
s->black_level_scaled) >> 16;
386 int plane =
s->is_packed_rgb ? 0 :
A;
387 int slice_start = (
frame->height * jobnr ) / nb_jobs;
392 uint16_t *p = (uint16_t *)(
frame->data[plane] +
i *
frame->linesize[plane]) +
s->is_packed_rgb*
s->rgba_map[
A];
393 int step =
s->is_packed_rgb ? 4 : 1;
394 for (j = 0; j <
frame->width; j++) {
398 *p = ((*p -
s->black_level) *
s->factor +
s->black_level_scaled) >> 16;
423 s->is_packed_rgb = !
s->is_planar &&
s->is_rgb;
430 s->black_level_scaled = (
s->black_level << 16) + 32768;
446 if (
s->fade_state == VF_FADE_WAITING) {
449 &&
inlink->frame_count_out >=
s->start_frame) {
451 s->fade_state = VF_FADE_FADING;
454 if (
s->start_time == 0 &&
s->start_frame != 0) {
459 if (
s->start_time != 0 &&
s->start_frame == 0) {
460 s->start_frame =
inlink->frame_count_out;
464 if (
s->fade_state == VF_FADE_FADING) {
465 if (
s->duration == 0) {
467 s->factor = (
inlink->frame_count_out -
s->start_frame) *
s->fade_per_frame;
468 if (
inlink->frame_count_out >
s->start_frame +
s->nb_frames) {
469 s->fade_state = VF_FADE_DONE;
474 s->factor = (frame_timestamp -
s->start_time/(double)
AV_TIME_BASE)
478 s->fade_state = VF_FADE_DONE;
482 if (
s->fade_state == VF_FADE_DONE) {
483 s->factor=UINT16_MAX;
486 s->factor = av_clip_uint16(
s->factor);
490 s->factor=UINT16_MAX-
s->factor;
493 if (
s->factor < UINT16_MAX) {
497 }
else if (
s->is_rgb && !
s->black_fade) {
505 if (
frame->data[1] &&
frame->data[2] && !
s->is_rgb) {
517 #define OFFSET(x) offsetof(FadeContext, x)
518 #define FLAGS AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
525 {
"start_frame",
"Number of the first frame to which to apply the effect.",
527 {
"s",
"Number of the first frame to which to apply the effect.",
529 {
"nb_frames",
"Number of frames to which the effect should be applied.",
531 {
"n",
"Number of frames to which the effect should be applied.",
534 {
"start_time",
"Number of seconds of the beginning of the effect.",
536 {
"st",
"Number of seconds of the beginning of the effect.",
538 {
"duration",
"Duration of the effect in seconds.",
540 {
"d",
"Duration of the effect in seconds.",
573 .priv_class = &fade_class,
#define AV_PIX_FMT_YUVA422P16
AVPixelFormat
Pixel format.
static enum AVPixelFormat pix_fmts_rgb[3]
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
static int filter_slice_rgb(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
static int filter_slice_alpha16(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
static av_cold int init(AVFilterContext *ctx)
int(* filter_slice_luma)(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
The exact code depends on how similar the blocks are and how related they are to the and needs to apply these operations to the correct inlink or outlink if there are several Macros are available to factor that when no extra processing is inlink
static int query_formats(AVFilterContext *ctx)
#define AV_PIX_FMT_YUVA422P9
This structure describes decoded (raw) audio or video data.
trying all byte sequences megabyte in length and selecting the best looking sequence will yield cases to try But a word about which is also called distortion Distortion can be quantified by almost any quality measurement one chooses the sum of squared differences is used but more complex methods that consider psychovisual effects can be used as well It makes no difference in this discussion First step
#define AV_PIX_FMT_YUVA420P16
int depth
Number of bits in the component.
#define AV_PIX_FMT_YUVA420P10
const static enum AVPixelFormat studio_level_pix_fmts[]
#define AV_PIX_FMT_YUV420P10
#define AV_LOG_VERBOSE
Detailed information.
@ AV_PIX_FMT_BGR24
packed RGB 8:8:8, 24bpp, BGRBGR...
@ AV_PIX_FMT_BGRA
packed BGRA 8:8:8:8, 32bpp, BGRABGRA...
int av_get_bits_per_pixel(const AVPixFmtDescriptor *pixdesc)
Return the number of bits per pixel used by the pixel format described by pixdesc.
@ AV_PIX_FMT_YUV440P
planar YUV 4:4:0 (1 Cr & Cb sample per 1x2 Y samples)
const char * name
Filter name.
static int filter_slice_alpha(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
AVFormatInternal * internal
An opaque field for libavformat internal usage.
A link between two filters.
#define AV_PIX_FMT_YUVA422P10
#define AV_PIX_FMT_YUVA420P9
@ AV_PIX_FMT_GBRAP
planar GBRA 4:4:4:4 32bpp
static int filter_slice_luma16(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
#define AV_PIX_FMT_YUVA444P16
#define AV_PIX_FMT_YUV422P9
static const AVFilterPad avfilter_vf_fade_inputs[]
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf type
static int filter_slice_chroma(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
A filter pad used for either input or output.
#define AV_PIX_FMT_YUV444P10
static const AVOption fade_options[]
#define AV_PIX_FMT_YUV422P16
@ AV_PIX_FMT_YUVJ422P
planar YUV 4:2:2, 16bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV422P and setting col...
@ AV_PIX_FMT_YUVA420P
planar YUV 4:2:0, 20bpp, (1 Cr & Cb sample per 2x2 Y & A samples)
#define AV_PIX_FMT_YUV444P16
#define AV_CEIL_RSHIFT(a, b)
static int slice_end(AVCodecContext *avctx, AVFrame *pict)
Handle slice ends.
static double av_q2d(AVRational a)
Convert an AVRational to a double.
#define av_assert0(cond)
assert() equivalent, that is always enabled.
unsigned int black_level_scaled
static const AVFilterPad outputs[]
static enum AVPixelFormat pix_fmts[]
#define AV_PIX_FMT_YUVA444P12
#define AV_PIX_FMT_YUV420P9
#define AV_PIX_FMT_YUV420P16
#define AV_PIX_FMT_FLAG_ALPHA
The pixel format has an alpha channel.
uint8_t log2_chroma_w
Amount to shift the luma width right to find the chroma width.
@ AV_PIX_FMT_YUV420P
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
@ AV_PIX_FMT_RGBA
packed RGBA 8:8:8:8, 32bpp, RGBARGBA...
@ AV_PIX_FMT_YUVJ444P
planar YUV 4:4:4, 24bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV444P and setting col...
Describe the class of an AVClass context structure.
@ AV_PIX_FMT_YUVJ420P
planar YUV 4:2:0, 12bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV420P and setting col...
static int filter_slice_chroma16(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
int(* filter_slice_chroma)(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
#define AV_PIX_FMT_YUV422P10
these buffered frames must be flushed immediately if a new input produces new the filter must not call request_frame to get more It must just process the frame or queue it The task of requesting more frames is left to the filter s request_frame method or the application If a filter has several inputs
uint64_t flags
Combination of AV_PIX_FMT_FLAG_...
@ AV_PIX_FMT_ABGR
packed ABGR 8:8:8:8, 32bpp, ABGRABGR...
Undefined Behavior In the C some operations are like signed integer dereferencing freed accessing outside allocated Undefined Behavior must not occur in a C it is not safe even if the output of undefined operations is unused The unsafety may seem nit picking but Optimizing compilers have in fact optimized code on the assumption that no undefined Behavior occurs Optimizing code based on wrong assumptions can and has in some cases lead to effects beyond the output of computations The signed integer overflow problem in speed critical code Code which is highly optimized and works with signed integers sometimes has the problem that often the output of the computation does not c
@ AV_PIX_FMT_RGB24
packed RGB 8:8:8, 24bpp, RGBRGB...
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
#define AV_PIX_FMT_FLAG_RGB
The pixel format contains RGB-like data (as opposed to YUV/grayscale).
static int64_t start_time
#define AV_PIX_FMT_YUV422P12
#define AV_NOPTS_VALUE
Undefined timestamp value.
static av_always_inline void filter_rgb(FadeContext *s, const AVFrame *frame, int slice_start, int slice_end, int do_alpha, int step)
#define AV_PIX_FMT_YUV444P12
@ AV_PIX_FMT_YUVA444P
planar YUV 4:4:4 32bpp, (1 Cr & Cb sample per 1x1 Y & A samples)
#define AV_PIX_FMT_YUVA444P10
#define INTERP(c_name, c_idx)
int black_fade
if color_rgba is black
enum FadeContext::@221 fade_state
@ AV_PIX_FMT_ARGB
packed ARGB 8:8:8:8, 32bpp, ARGBARGB...
static av_always_inline void filter_rgb_planar(FadeContext *s, const AVFrame *frame, int slice_start, int slice_end, int do_alpha)
#define i(width, name, range_min, range_max)
static int filter_slice_luma(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
int(* filter_slice_alpha)(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
#define AV_TIME_BASE
Internal time base represented as integer.
int ff_filter_get_nb_threads(AVFilterContext *ctx)
Get number of threads for current filter instance.
@ AV_PIX_FMT_YUVJ440P
planar YUV 4:4:0 full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV440P and setting color_range
const char * name
Pad name.
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)
#define AV_PIX_FMT_YUV444P9
these buffered frames must be flushed immediately if a new input produces new the filter must not call request_frame to get more It must just process the frame or queue it The task of requesting more frames is left to the filter s request_frame method or the application If a filter has several the filter must be ready for frames arriving randomly on any input any filter with several inputs will most likely require some kind of queuing mechanism It is perfectly acceptable to have a limited queue and to drop frames when the inputs are too unbalanced request_frame For filters that do not use the this method is called when a frame is wanted on an output For a it should directly call filter_frame on the corresponding output For a if there are queued frames already one of these frames should be pushed If the filter should request a frame on one of its repeatedly until at least one frame has been pushed Return or at least make progress towards producing a frame
#define AV_PIX_FMT_YUVA444P9
#define AV_PIX_FMT_YUV420P12
#define AV_PIX_FMT_YUV422P14
static int config_props(AVFilterLink *inlink)
AVFILTER_DEFINE_CLASS(fade)
#define AV_PIX_FMT_YUVA422P12
AVComponentDescriptor comp[4]
Parameters that describe how pixels are packed.
#define AV_PIX_FMT_FLAG_PLANAR
At least one pixel component is not in the first data plane.
@ AV_PIX_FMT_YUV444P
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
uint8_t color_rgba[4]
fade color
@ AV_PIX_FMT_GBRP
planar GBR 4:4:4 24bpp
#define AVFILTER_FLAG_SLICE_THREADS
The filter supports multithreading by splitting frames into multiple parts and processing them concur...
@ AV_PIX_FMT_YUV422P
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
static const int16_t alpha[]
#define INTERPP(c_name, c_idx)
@ AV_PIX_FMT_YUV411P
planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples)
int ff_fill_rgba_map(uint8_t *rgba_map, enum AVPixelFormat pix_fmt)
#define flags(name, subs,...)
@ AV_PIX_FMT_YUV410P
planar YUV 4:1:0, 9bpp, (1 Cr & Cb sample per 4x4 Y samples)
#define AV_PIX_FMT_YUV440P12
#define AV_PIX_FMT_YUV444P14
static const AVFilterPad avfilter_vf_fade_outputs[]
static int filter_frame(AVFilterLink *inlink, AVFrame *frame)
uint8_t log2_chroma_h
Amount to shift the luma height right to find the chroma height.
@ AV_PIX_FMT_YUVA422P
planar YUV 4:2:2 24bpp, (1 Cr & Cb sample per 2x1 Y & A samples)
#define AV_PIX_FMT_YUV420P14