FFmpeg
Loading...
Searching...
No Matches
vf_colordetect.c File Reference

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

#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_colordetectdsp.h"

Go to the source code of this file.

Data Structures

struct  ColorDetectContext
 

Macros

#define OFFSET(x)
 
#define FLAGS   AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
 

Enumerations

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 report_detected_props (AVFilterContext *ctx)
 
static int activate (AVFilterContext *ctx)
 

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)
Value:

Definition at line 71 of file vf_colordetect.c.

◆ FLAGS

Definition at line 72 of file vf_colordetect.c.

Enumeration Type Documentation

◆ ColorDetectMode

Enumerator
COLOR_DETECT_COLOR_RANGE 
COLOR_DETECT_ALPHA_MODE 

Definition at line 42 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 87 of file vf_colordetect.c.

◆ config_input()

static int config_input ( AVFilterLink * inlink)
static

Alpha mode detection:

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 + threshold

This simplifies to: (x - mpeg_min - threshold) * pixel_max > (mpeg_max - mpeg_min) * a = range * x - offset > mpeg_range * a in the below formula.

We subtract an additional offset of (1 << (depth - 1)) to account for rounding errors in the value of x.

For full range input this degenerates to x > a + threshold, so the threshold is passed through directly, without the range scaling.

Definition at line 106 of file vf_colordetect.c.

◆ detect_range()

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

Definition at line 170 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

Definition at line 188 of file vf_colordetect.c.

Referenced by filter_frame().

◆ filter_frame()

static int filter_frame ( AVFilterLink * inlink,
AVFrame * in )
static

Definition at line 217 of file vf_colordetect.c.

Referenced by activate().

◆ report_detected_props()

static av_cold void report_detected_props ( AVFilterContext * ctx)
static

Definition at line 235 of file vf_colordetect.c.

Referenced by activate().

◆ activate()

static int activate ( AVFilterContext * ctx)
static

Definition at line 261 of file vf_colordetect.c.

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" },
{ "threshold", "Detection threshold, as a fraction of the full range", OFFSET(threshold), AV_OPT_TYPE_FLOAT, {.dbl = 0.001}, 0.0, 0.05, FLAGS },
{ NULL }
}
#define FLAGS
Definition cmdutils.c:596
#define NULL
Definition coverity.c:32
#define OFFSET(x)
@ AV_OPT_TYPE_CONST
Special option type for declaring named constants.
Definition opt.h:298
@ AV_OPT_TYPE_FLAGS
Underlying C type is unsigned int.
Definition opt.h:254
@ AV_OPT_TYPE_FLOAT
Underlying C type is float.
Definition opt.h:270
@ COLOR_DETECT_COLOR_RANGE
@ COLOR_DETECT_ALPHA_MODE
Definition swscale.c:85

Definition at line 74 of file vf_colordetect.c.

◆ colordetect_inputs

const AVFilterPad colordetect_inputs[]
static
Initial value:
= {
{
.name = "default",
.config_props = config_input,
},
}
static int config_input(AVFilterLink *inlink)
@ AVMEDIA_TYPE_VIDEO
Definition avutil.h:200

Definition at line 293 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),
.activate = activate,
}
#define AVFILTER_FLAG_SLICE_THREADS
The filter supports multithreading by splitting frames into multiple parts and processing them concur...
Definition avfilter.h:172
#define AVFILTER_FLAG_METADATA_ONLY
The filter is a "metadata" filter - it does not modify the frame data in any way.
Definition avfilter.h:188
static int activate(AVBitStreamFilterContext *ctx)
#define FILTER_INPUTS(array)
Definition filters.h:279
#define FILTER_OUTPUTS(array)
Definition filters.h:280
#define FF_FILTER_FLAG_DYNAMIC_FRAME_SIZE
The filter handles input frames whose size differs from the one its input link was configured with.
Definition filters.h:214
#define FILTER_QUERY_FUNC2(func)
Definition filters.h:256
static int query_format(const AVFilterContext *ctx, AVFilterFormatsConfig **cfg_in, AVFilterFormatsConfig **cfg_out)
static const AVFilterPad colordetect_inputs[]
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
Definition internal.h:97
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

Definition at line 301 of file vf_colordetect.c.