FFmpeg
Data Structures | Macros | Enumerations | Functions | Variables
vf_deflicker.c File Reference
#include "libavutil/imgutils.h"
#include "libavutil/mem.h"
#include "libavutil/opt.h"
#include "libavutil/pixdesc.h"
#include "libavutil/qsort.h"
#include "avfilter.h"
#include "bufferqueue.h"
#include "filters.h"
#include "video.h"

Go to the source code of this file.

Data Structures

struct  DeflickerContext
 

Macros

#define FF_BUFQUEUE_SIZE   129
 
#define SIZE   FF_BUFQUEUE_SIZE
 
#define OFFSET(x)   offsetof(DeflickerContext, x)
 
#define FLAGS   AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
 

Enumerations

enum  smooth_mode {
  ARITHMETIC_MEAN, GEOMETRIC_MEAN, HARMONIC_MEAN, QUADRATIC_MEAN,
  CUBIC_MEAN, POWER_MEAN, MEDIAN, NB_SMOOTH_MODE
}
 

Functions

 AVFILTER_DEFINE_CLASS (deflicker)
 
static int deflicker8 (AVFilterContext *ctx, const uint8_t *src, ptrdiff_t src_linesize, uint8_t *dst, ptrdiff_t dst_linesize, int w, int h, float f)
 
static int deflicker16 (AVFilterContext *ctx, const uint8_t *ssrc, ptrdiff_t src_linesize, uint8_t *ddst, ptrdiff_t dst_linesize, int w, int h, float f)
 
static float calc_avgy8 (AVFilterContext *ctx, AVFrame *in)
 
static float calc_avgy16 (AVFilterContext *ctx, AVFrame *in)
 
static void get_am_factor (AVFilterContext *ctx, float *f)
 
static void get_gm_factor (AVFilterContext *ctx, float *f)
 
static void get_hm_factor (AVFilterContext *ctx, float *f)
 
static void get_qm_factor (AVFilterContext *ctx, float *f)
 
static void get_cm_factor (AVFilterContext *ctx, float *f)
 
static void get_pm_factor (AVFilterContext *ctx, float *f)
 
static int comparef (const void *a, const void *b)
 
static void get_median_factor (AVFilterContext *ctx, float *f)
 
static int config_input (AVFilterLink *inlink)
 
static int filter_frame (AVFilterLink *inlink, AVFrame *buf)
 
static int request_frame (AVFilterLink *outlink)
 
static av_cold void uninit (AVFilterContext *ctx)
 

Variables

static const AVOption deflicker_options []
 
static enum AVPixelFormat pixel_fmts []
 
static const AVFilterPad inputs []
 
static const AVFilterPad outputs []
 
const AVFilter ff_vf_deflicker
 

Macro Definition Documentation

◆ FF_BUFQUEUE_SIZE

#define FF_BUFQUEUE_SIZE   129

Definition at line 28 of file vf_deflicker.c.

◆ SIZE

#define SIZE   FF_BUFQUEUE_SIZE

Definition at line 34 of file vf_deflicker.c.

◆ OFFSET

#define OFFSET (   x)    offsetof(DeflickerContext, x)

Definition at line 73 of file vf_deflicker.c.

◆ FLAGS

Definition at line 74 of file vf_deflicker.c.

Enumeration Type Documentation

◆ smooth_mode

Enumerator
ARITHMETIC_MEAN 
GEOMETRIC_MEAN 
HARMONIC_MEAN 
QUADRATIC_MEAN 
CUBIC_MEAN 
POWER_MEAN 
MEDIAN 
NB_SMOOTH_MODE 

Definition at line 36 of file vf_deflicker.c.

Function Documentation

◆ AVFILTER_DEFINE_CLASS()

AVFILTER_DEFINE_CLASS ( deflicker  )

◆ deflicker8()

static int deflicker8 ( AVFilterContext ctx,
const uint8_t *  src,
ptrdiff_t  src_linesize,
uint8_t *  dst,
ptrdiff_t  dst_linesize,
int  w,
int  h,
float  f 
)
static

Definition at line 117 of file vf_deflicker.c.

Referenced by config_input().

◆ deflicker16()

static int deflicker16 ( AVFilterContext ctx,
const uint8_t *  ssrc,
ptrdiff_t  src_linesize,
uint8_t *  ddst,
ptrdiff_t  dst_linesize,
int  w,
int  h,
float  f 
)
static

Definition at line 136 of file vf_deflicker.c.

Referenced by config_input().

◆ calc_avgy8()

static float calc_avgy8 ( AVFilterContext ctx,
AVFrame in 
)
static

Definition at line 159 of file vf_deflicker.c.

Referenced by config_input().

◆ calc_avgy16()

static float calc_avgy16 ( AVFilterContext ctx,
AVFrame in 
)
static

Definition at line 182 of file vf_deflicker.c.

Referenced by config_input().

◆ get_am_factor()

static void get_am_factor ( AVFilterContext ctx,
float f 
)
static

Definition at line 205 of file vf_deflicker.c.

Referenced by config_input().

◆ get_gm_factor()

static void get_gm_factor ( AVFilterContext ctx,
float f 
)
static

Definition at line 220 of file vf_deflicker.c.

Referenced by config_input().

◆ get_hm_factor()

static void get_hm_factor ( AVFilterContext ctx,
float f 
)
static

Definition at line 235 of file vf_deflicker.c.

Referenced by config_input().

◆ get_qm_factor()

static void get_qm_factor ( AVFilterContext ctx,
float f 
)
static

Definition at line 250 of file vf_deflicker.c.

Referenced by config_input().

◆ get_cm_factor()

static void get_cm_factor ( AVFilterContext ctx,
float f 
)
static

Definition at line 266 of file vf_deflicker.c.

Referenced by config_input().

◆ get_pm_factor()

static void get_pm_factor ( AVFilterContext ctx,
float f 
)
static

Definition at line 282 of file vf_deflicker.c.

Referenced by config_input().

◆ comparef()

static int comparef ( const void *  a,
const void *  b 
)
static

Definition at line 298 of file vf_deflicker.c.

Referenced by get_median_factor().

◆ get_median_factor()

static void get_median_factor ( AVFilterContext ctx,
float f 
)
static

Definition at line 304 of file vf_deflicker.c.

Referenced by config_input().

◆ config_input()

static int config_input ( AVFilterLink inlink)
static

Definition at line 314 of file vf_deflicker.c.

◆ filter_frame()

static int filter_frame ( AVFilterLink inlink,
AVFrame buf 
)
static

Definition at line 353 of file vf_deflicker.c.

Referenced by request_frame().

◆ request_frame()

static int request_frame ( AVFilterLink outlink)
static

Definition at line 412 of file vf_deflicker.c.

◆ uninit()

static av_cold void uninit ( AVFilterContext ctx)
static

Definition at line 435 of file vf_deflicker.c.

Variable Documentation

◆ deflicker_options

const AVOption deflicker_options[]
static
Initial value:
= {
{ "size", "set how many frames to use", OFFSET(size), AV_OPT_TYPE_INT, {.i64=5}, 2, SIZE, FLAGS },
{ "s", "set how many frames to use", OFFSET(size), AV_OPT_TYPE_INT, {.i64=5}, 2, SIZE, FLAGS },
{ "mode", "set how to smooth luminance", OFFSET(mode), AV_OPT_TYPE_INT, {.i64=0}, 0, NB_SMOOTH_MODE-1, FLAGS, .unit = "mode" },
{ "m", "set how to smooth luminance", OFFSET(mode), AV_OPT_TYPE_INT, {.i64=0}, 0, NB_SMOOTH_MODE-1, FLAGS, .unit = "mode" },
{ "am", "arithmetic mean", 0, AV_OPT_TYPE_CONST, {.i64=ARITHMETIC_MEAN}, 0, 0, FLAGS, .unit = "mode" },
{ "gm", "geometric mean", 0, AV_OPT_TYPE_CONST, {.i64=GEOMETRIC_MEAN}, 0, 0, FLAGS, .unit = "mode" },
{ "hm", "harmonic mean", 0, AV_OPT_TYPE_CONST, {.i64=HARMONIC_MEAN}, 0, 0, FLAGS, .unit = "mode" },
{ "qm", "quadratic mean", 0, AV_OPT_TYPE_CONST, {.i64=QUADRATIC_MEAN}, 0, 0, FLAGS, .unit = "mode" },
{ "cm", "cubic mean", 0, AV_OPT_TYPE_CONST, {.i64=CUBIC_MEAN}, 0, 0, FLAGS, .unit = "mode" },
{ "pm", "power mean", 0, AV_OPT_TYPE_CONST, {.i64=POWER_MEAN}, 0, 0, FLAGS, .unit = "mode" },
{ "median", "median", 0, AV_OPT_TYPE_CONST, {.i64=MEDIAN}, 0, 0, FLAGS, .unit = "mode" },
{ "bypass", "leave frames unchanged", OFFSET(bypass), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS },
{ NULL }
}

Definition at line 76 of file vf_deflicker.c.

◆ pixel_fmts

enum AVPixelFormat pixel_fmts[]
static

◆ inputs

const AVFilterPad inputs[]
static
Initial value:
= {
{
.name = "default",
.filter_frame = filter_frame,
.config_props = config_input,
},
}

Definition at line 443 of file vf_deflicker.c.

◆ outputs

const AVFilterPad outputs[]
static
Initial value:
= {
{
.name = "default",
.request_frame = request_frame,
},
}

Definition at line 452 of file vf_deflicker.c.

◆ ff_vf_deflicker

const AVFilter ff_vf_deflicker
Initial value:
= {
.name = "deflicker",
.description = NULL_IF_CONFIG_SMALL("Remove temporal frame luminance variations."),
.priv_size = sizeof(DeflickerContext),
.priv_class = &deflicker_class,
}

Definition at line 460 of file vf_deflicker.c.

GEOMETRIC_MEAN
@ GEOMETRIC_MEAN
Definition: vf_deflicker.c:38
AV_PIX_FMT_YUVA422P16
#define AV_PIX_FMT_YUVA422P16
Definition: pixfmt.h:546
FILTER_PIXFMTS_ARRAY
#define FILTER_PIXFMTS_ARRAY(array)
Definition: filters.h:242
AV_PIX_FMT_YUVA422P9
#define AV_PIX_FMT_YUVA422P9
Definition: pixfmt.h:538
FILTER_INPUTS
#define FILTER_INPUTS(array)
Definition: filters.h:262
mode
Definition: swscale.c:52
AV_PIX_FMT_YUVA420P16
#define AV_PIX_FMT_YUVA420P16
Definition: pixfmt.h:545
AV_PIX_FMT_YUVA420P10
#define AV_PIX_FMT_YUVA420P10
Definition: pixfmt.h:540
AV_PIX_FMT_YUV420P10
#define AV_PIX_FMT_YUV420P10
Definition: pixfmt.h:502
AV_PIX_FMT_YUV440P
@ AV_PIX_FMT_YUV440P
planar YUV 4:4:0 (1 Cr & Cb sample per 1x2 Y samples)
Definition: pixfmt.h:106
AV_PIX_FMT_YUVA422P10
#define AV_PIX_FMT_YUVA422P10
Definition: pixfmt.h:541
AV_PIX_FMT_GRAY9
#define AV_PIX_FMT_GRAY9
Definition: pixfmt.h:482
AV_PIX_FMT_YUVA420P9
#define AV_PIX_FMT_YUVA420P9
Definition: pixfmt.h:537
OFFSET
#define OFFSET(x)
Definition: vf_deflicker.c:73
FLAGS
#define FLAGS
Definition: vf_deflicker.c:74
AV_PIX_FMT_YUVA444P16
#define AV_PIX_FMT_YUVA444P16
Definition: pixfmt.h:547
AV_PIX_FMT_YUV422P9
#define AV_PIX_FMT_YUV422P9
Definition: pixfmt.h:500
NB_SMOOTH_MODE
@ NB_SMOOTH_MODE
Definition: vf_deflicker.c:44
AV_PIX_FMT_GRAY16
#define AV_PIX_FMT_GRAY16
Definition: pixfmt.h:486
ARITHMETIC_MEAN
@ ARITHMETIC_MEAN
Definition: vf_deflicker.c:37
AV_PIX_FMT_YUV444P10
#define AV_PIX_FMT_YUV444P10
Definition: pixfmt.h:505
AV_PIX_FMT_YUVJ411P
@ AV_PIX_FMT_YUVJ411P
planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples) full scale (JPEG), deprecated in favor ...
Definition: pixfmt.h:283
AV_PIX_FMT_YUV422P16
#define AV_PIX_FMT_YUV422P16
Definition: pixfmt.h:514
AV_PIX_FMT_YUVJ422P
@ AV_PIX_FMT_YUVJ422P
planar YUV 4:2:2, 16bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV422P and setting col...
Definition: pixfmt.h:86
AV_PIX_FMT_YUVA420P
@ AV_PIX_FMT_YUVA420P
planar YUV 4:2:0, 20bpp, (1 Cr & Cb sample per 2x2 Y & A samples)
Definition: pixfmt.h:108
AV_PIX_FMT_YUV444P16
#define AV_PIX_FMT_YUV444P16
Definition: pixfmt.h:515
CUBIC_MEAN
@ CUBIC_MEAN
Definition: vf_deflicker.c:41
AV_PIX_FMT_YUVA444P12
#define AV_PIX_FMT_YUVA444P12
Definition: pixfmt.h:544
AV_PIX_FMT_YUV420P9
#define AV_PIX_FMT_YUV420P9
Definition: pixfmt.h:499
AV_PIX_FMT_YUV420P16
#define AV_PIX_FMT_YUV420P16
Definition: pixfmt.h:513
AV_PIX_FMT_GRAY14
#define AV_PIX_FMT_GRAY14
Definition: pixfmt.h:485
AV_PIX_FMT_YUV420P
@ AV_PIX_FMT_YUV420P
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
Definition: pixfmt.h:73
FILTER_OUTPUTS
#define FILTER_OUTPUTS(array)
Definition: filters.h:263
AV_PIX_FMT_YUVJ444P
@ AV_PIX_FMT_YUVJ444P
planar YUV 4:4:4, 24bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV444P and setting col...
Definition: pixfmt.h:87
AV_PIX_FMT_GRAY10
#define AV_PIX_FMT_GRAY10
Definition: pixfmt.h:483
DeflickerContext
Definition: vf_deflicker.c:47
NULL
#define NULL
Definition: coverity.c:32
AV_PIX_FMT_YUVJ420P
@ AV_PIX_FMT_YUVJ420P
planar YUV 4:2:0, 12bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV420P and setting col...
Definition: pixfmt.h:85
AV_PIX_FMT_YUV440P10
#define AV_PIX_FMT_YUV440P10
Definition: pixfmt.h:504
MEDIAN
@ MEDIAN
Definition: vf_deflicker.c:43
AV_PIX_FMT_YUV422P10
#define AV_PIX_FMT_YUV422P10
Definition: pixfmt.h:503
AV_PIX_FMT_GRAY8
@ AV_PIX_FMT_GRAY8
Y , 8bpp.
Definition: pixfmt.h:81
outputs
static const AVFilterPad outputs[]
Definition: vf_deflicker.c:452
request_frame
static int request_frame(AVFilterLink *outlink)
Definition: vf_deflicker.c:412
SIZE
#define SIZE
Definition: vf_deflicker.c:34
NULL_IF_CONFIG_SMALL
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
Definition: internal.h:94
AV_PIX_FMT_YUV422P12
#define AV_PIX_FMT_YUV422P12
Definition: pixfmt.h:507
size
int size
Definition: twinvq_data.h:10344
inputs
static const AVFilterPad inputs[]
Definition: vf_deflicker.c:443
AV_PIX_FMT_YUV444P12
#define AV_PIX_FMT_YUV444P12
Definition: pixfmt.h:509
uninit
static av_cold void uninit(AVFilterContext *ctx)
Definition: vf_deflicker.c:435
AV_PIX_FMT_YUVA444P
@ AV_PIX_FMT_YUVA444P
planar YUV 4:4:4 32bpp, (1 Cr & Cb sample per 1x1 Y & A samples)
Definition: pixfmt.h:174
AV_PIX_FMT_YUVA444P10
#define AV_PIX_FMT_YUVA444P10
Definition: pixfmt.h:542
filter_frame
static int filter_frame(AVFilterLink *inlink, AVFrame *buf)
Definition: vf_deflicker.c:353
QUADRATIC_MEAN
@ QUADRATIC_MEAN
Definition: vf_deflicker.c:40
POWER_MEAN
@ POWER_MEAN
Definition: vf_deflicker.c:42
AV_PIX_FMT_YUVJ440P
@ AV_PIX_FMT_YUVJ440P
planar YUV 4:4:0 full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV440P and setting color_range
Definition: pixfmt.h:107
AV_PIX_FMT_YUV444P9
#define AV_PIX_FMT_YUV444P9
Definition: pixfmt.h:501
pixel_fmts
static enum AVPixelFormat pixel_fmts[]
Definition: vf_deflicker.c:94
AV_PIX_FMT_YUVA444P9
#define AV_PIX_FMT_YUVA444P9
Definition: pixfmt.h:539
AV_PIX_FMT_YUV420P12
#define AV_PIX_FMT_YUV420P12
Definition: pixfmt.h:506
AV_PIX_FMT_YUV422P14
#define AV_PIX_FMT_YUV422P14
Definition: pixfmt.h:511
AV_PIX_FMT_NONE
@ AV_PIX_FMT_NONE
Definition: pixfmt.h:72
AV_PIX_FMT_YUVA422P12
#define AV_PIX_FMT_YUVA422P12
Definition: pixfmt.h:543
AV_OPT_TYPE_INT
@ AV_OPT_TYPE_INT
Underlying C type is int.
Definition: opt.h:259
AV_PIX_FMT_YUV444P
@ AV_PIX_FMT_YUV444P
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
Definition: pixfmt.h:78
AVMEDIA_TYPE_VIDEO
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:201
AV_PIX_FMT_YUV422P
@ AV_PIX_FMT_YUV422P
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
Definition: pixfmt.h:77
AV_OPT_TYPE_BOOL
@ AV_OPT_TYPE_BOOL
Underlying C type is int.
Definition: opt.h:327
AV_PIX_FMT_YUV411P
@ AV_PIX_FMT_YUV411P
planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples)
Definition: pixfmt.h:80
config_input
static int config_input(AVFilterLink *inlink)
Definition: vf_deflicker.c:314
AV_PIX_FMT_YUV410P
@ AV_PIX_FMT_YUV410P
planar YUV 4:1:0, 9bpp, (1 Cr & Cb sample per 4x4 Y samples)
Definition: pixfmt.h:79
AV_PIX_FMT_YUV440P12
#define AV_PIX_FMT_YUV440P12
Definition: pixfmt.h:508
AV_PIX_FMT_YUV444P14
#define AV_PIX_FMT_YUV444P14
Definition: pixfmt.h:512
HARMONIC_MEAN
@ HARMONIC_MEAN
Definition: vf_deflicker.c:39
AV_PIX_FMT_GRAY12
#define AV_PIX_FMT_GRAY12
Definition: pixfmt.h:484
AV_OPT_TYPE_CONST
@ AV_OPT_TYPE_CONST
Special option type for declaring named constants.
Definition: opt.h:299
AV_PIX_FMT_YUVA422P
@ AV_PIX_FMT_YUVA422P
planar YUV 4:2:2 24bpp, (1 Cr & Cb sample per 2x1 Y & A samples)
Definition: pixfmt.h:173
AV_PIX_FMT_YUV420P14
#define AV_PIX_FMT_YUV420P14
Definition: pixfmt.h:510