FFmpeg
Data Structures | Macros | Enumerations | Functions | Variables
vf_colordetect.c File Reference
#include <stdbool.h>
#include <stdatomic.h>
#include "config.h"
#include "libavutil/mem.h"
#include "libavutil/opt.h"
#include "libavutil/pixdesc.h"
#include "avfilter.h"
#include "filters.h"
#include "formats.h"
#include "video.h"
#include "vf_colordetect.h"

Go to the source code of this file.

Data Structures

struct  ColorDetectContext
 

Macros

#define OFFSET(x)   offsetof(ColorDetectContext, x)
 
#define FLAGS   AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
 

Enumerations

enum  AlphaMode { ALPHA_NONE = -1, ALPHA_UNDETERMINED = 0, ALPHA_STRAIGHT }
 
enum  ColorDetectMode { COLOR_DETECT_COLOR_RANGE = 1 << 0, COLOR_DETECT_ALPHA_MODE = 1 << 1 }
 

Functions

 AVFILTER_DEFINE_CLASS (colordetect)
 
static int query_format (const AVFilterContext *ctx, AVFilterFormatsConfig **cfg_in, AVFilterFormatsConfig **cfg_out)
 
static int config_input (AVFilterLink *inlink)
 
static int detect_range (AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
 
static int detect_alpha (AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
 
static int filter_frame (AVFilterLink *inlink, AVFrame *in)
 
static av_cold void uninit (AVFilterContext *ctx)
 
av_cold void ff_color_detect_dsp_init (FFColorDetectDSPContext *dsp, int depth, enum AVColorRange color_range)
 

Variables

static const AVOption colordetect_options []
 
static const AVFilterPad colordetect_inputs []
 
const FFFilter ff_vf_colordetect
 

Detailed Description

Video color space detector, tries to auto-detect YUV range and alpha mode.

Definition in file vf_colordetect.c.

Macro Definition Documentation

◆ OFFSET

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

Definition at line 70 of file vf_colordetect.c.

◆ FLAGS

Definition at line 71 of file vf_colordetect.c.

Enumeration Type Documentation

◆ AlphaMode

enum AlphaMode
Enumerator
ALPHA_NONE 
ALPHA_UNDETERMINED 
ALPHA_STRAIGHT 

Definition at line 42 of file vf_colordetect.c.

◆ ColorDetectMode

Enumerator
COLOR_DETECT_COLOR_RANGE 
COLOR_DETECT_ALPHA_MODE 

Definition at line 49 of file vf_colordetect.c.

Function Documentation

◆ AVFILTER_DEFINE_CLASS()

AVFILTER_DEFINE_CLASS ( colordetect  )

◆ query_format()

static int query_format ( const AVFilterContext ctx,
AVFilterFormatsConfig **  cfg_in,
AVFilterFormatsConfig **  cfg_out 
)
static

Definition at line 83 of file vf_colordetect.c.

◆ config_input()

static int config_input ( AVFilterLink inlink)
static

Definition at line 102 of file vf_colordetect.c.

◆ detect_range()

static int detect_range ( AVFilterContext ctx,
void *  arg,
int  jobnr,
int  nb_jobs 
)
static

Definition at line 136 of file vf_colordetect.c.

Referenced by filter_frame().

◆ detect_alpha()

static int detect_alpha ( AVFilterContext ctx,
void *  arg,
int  jobnr,
int  nb_jobs 
)
static

To check if a value is out of range, we need to compare the color value against the maximum possible color for a given alpha value. x > ((mpeg_max - mpeg_min) / pixel_max) * a + mpeg_min

This simplifies to: (x - mpeg_min) * pixel_max > (mpeg_max - mpeg_min) * a = P * x - K > Q * a in the below formula.

We subtract an additional offset of (1 << (depth - 1)) to account for rounding errors in the value of x, and an extra safety margin of Q because vf_premultiply.c et al. add an offset of (a >> 1) & 1.

Definition at line 153 of file vf_colordetect.c.

Referenced by filter_frame().

◆ filter_frame()

static int filter_frame ( AVFilterLink inlink,
AVFrame in 
)
static

Definition at line 197 of file vf_colordetect.c.

◆ uninit()

static av_cold void uninit ( AVFilterContext ctx)
static

Definition at line 211 of file vf_colordetect.c.

◆ ff_color_detect_dsp_init()

av_cold void ff_color_detect_dsp_init ( FFColorDetectDSPContext dsp,
int  depth,
enum AVColorRange  color_range 
)

Definition at line 232 of file vf_colordetect.c.

Referenced by check_alpha_detect(), check_range_detect(), and config_input().

Variable Documentation

◆ colordetect_options

const AVOption colordetect_options[]
static
Initial value:
= {
{ "mode", "Image properties to detect", OFFSET(mode), AV_OPT_TYPE_FLAGS, {.i64 = -1}, 0, UINT_MAX, FLAGS, .unit = "mode" },
{ "color_range", "Detect (YUV) color range", 0, AV_OPT_TYPE_CONST, {.i64 = COLOR_DETECT_COLOR_RANGE}, 0, 0, FLAGS, .unit = "mode" },
{ "alpha_mode", "Detect alpha mode", 0, AV_OPT_TYPE_CONST, {.i64 = COLOR_DETECT_ALPHA_MODE }, 0, 0, FLAGS, .unit = "mode" },
{ "all", "Detect all supported properties", 0, AV_OPT_TYPE_CONST, {.i64 = -1}, 0, 0, FLAGS, .unit = "mode" },
{ NULL }
}

Definition at line 73 of file vf_colordetect.c.

◆ colordetect_inputs

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

Definition at line 250 of file vf_colordetect.c.

◆ ff_vf_colordetect

const FFFilter ff_vf_colordetect
Initial value:
= {
.p.name = "colordetect",
.p.description = NULL_IF_CONFIG_SMALL("Detect video color properties."),
.p.priv_class = &colordetect_class,
.priv_size = sizeof(ColorDetectContext),
.uninit = uninit,
}

Definition at line 259 of file vf_colordetect.c.

uninit
static av_cold void uninit(AVFilterContext *ctx)
Definition: vf_colordetect.c:211
FILTER_INPUTS
#define FILTER_INPUTS(array)
Definition: filters.h:263
mode
Definition: swscale.c:56
config_input
static int config_input(AVFilterLink *inlink)
Definition: vf_colordetect.c:102
colordetect_inputs
static const AVFilterPad colordetect_inputs[]
Definition: vf_colordetect.c:250
ff_video_default_filterpad
const AVFilterPad ff_video_default_filterpad[1]
An AVFilterPad array whose only entry has name "default" and is of type AVMEDIA_TYPE_VIDEO.
Definition: video.c:37
COLOR_DETECT_COLOR_RANGE
@ COLOR_DETECT_COLOR_RANGE
Definition: vf_colordetect.c:50
FILTER_OUTPUTS
#define FILTER_OUTPUTS(array)
Definition: filters.h:264
NULL
#define NULL
Definition: coverity.c:32
ColorDetectContext
Definition: vf_colordetect.c:54
OFFSET
#define OFFSET(x)
Definition: vf_colordetect.c:70
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
query_format
static int query_format(const AVFilterContext *ctx, AVFilterFormatsConfig **cfg_in, AVFilterFormatsConfig **cfg_out)
Definition: vf_colordetect.c:83
FILTER_QUERY_FUNC2
#define FILTER_QUERY_FUNC2(func)
Definition: filters.h:240
filter_frame
static int filter_frame(AVFilterLink *inlink, AVFrame *in)
Definition: vf_colordetect.c:197
AVFILTER_FLAG_METADATA_ONLY
#define AVFILTER_FLAG_METADATA_ONLY
The filter is a "metadata" filter - it does not modify the frame data in any way.
Definition: avfilter.h:178
AVFILTER_FLAG_SLICE_THREADS
#define AVFILTER_FLAG_SLICE_THREADS
The filter supports multithreading by splitting frames into multiple parts and processing them concur...
Definition: avfilter.h:162
AVMEDIA_TYPE_VIDEO
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:200
COLOR_DETECT_ALPHA_MODE
@ COLOR_DETECT_ALPHA_MODE
Definition: vf_colordetect.c:51
AV_OPT_TYPE_FLAGS
@ AV_OPT_TYPE_FLAGS
Underlying C type is unsigned int.
Definition: opt.h:255
AV_OPT_TYPE_CONST
@ AV_OPT_TYPE_CONST
Special option type for declaring named constants.
Definition: opt.h:299
FLAGS
#define FLAGS
Definition: vf_colordetect.c:71