FFmpeg
Data Structures | Macros | Enumerations | Functions | Variables
vf_fieldmatch.c File Reference
#include <inttypes.h>
#include "libavutil/avassert.h"
#include "libavutil/imgutils.h"
#include "libavutil/opt.h"
#include "libavutil/timestamp.h"
#include "avfilter.h"
#include "filters.h"
#include "internal.h"

Go to the source code of this file.

Data Structures

struct  FieldMatchContext
 

Macros

#define INPUT_MAIN   0
 
#define INPUT_CLEANSRC   1
 
#define OFFSET(x)   offsetof(FieldMatchContext, x)
 
#define FLAGS   AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
 
#define FILTER(xm2, xm1, xp1, xp2)
 
#define HAS_FF_AROUND(p, lz)
 
#define C_ARRAY_ADD(v)
 
#define VERTICAL_HALF(y_start, y_end)
 
#define LOAD_COMB(mid)
 
#define SLIDING_FRAME_WINDOW(prv, src, nxt)
 

Enumerations

enum  fieldmatch_parity { FM_PARITY_AUTO = -1, FM_PARITY_BOTTOM = 0, FM_PARITY_TOP = 1 }
 
enum  matching_mode {
  MODE_PC, MODE_PC_N, MODE_PC_U, MODE_PC_N_UB,
  MODE_PCN, MODE_PCN_UB, NB_MODE
}
 
enum  comb_matching_mode { COMBMATCH_NONE, COMBMATCH_SC, COMBMATCH_FULL, NB_COMBMATCH }
 
enum  comb_dbg { COMBDBG_NONE, COMBDBG_PCN, COMBDBG_PCNUB, NB_COMBDBG }
 
enum  {
  mP, mC, mN, mB,
  mU
}
 

Functions

 AVFILTER_DEFINE_CLASS (fieldmatch)
 
static int get_width (const FieldMatchContext *fm, const AVFrame *f, int plane)
 
static int get_height (const FieldMatchContext *fm, const AVFrame *f, int plane)
 
static int64_t luma_abs_diff (const AVFrame *f1, const AVFrame *f2)
 
static void fill_buf (uint8_t *data, int w, int h, int linesize, uint8_t v)
 
static int calc_combed_score (const FieldMatchContext *fm, const AVFrame *src)
 
static void build_abs_diff_mask (const uint8_t *prvp, int prv_linesize, const uint8_t *nxtp, int nxt_linesize, uint8_t *tbuffer, int tbuf_linesize, int width, int height)
 
static void build_diff_map (FieldMatchContext *fm, const uint8_t *prvp, int prv_linesize, const uint8_t *nxtp, int nxt_linesize, uint8_t *dstp, int dst_linesize, int height, int width, int plane)
 Build a map over which pixels differ a lot/a little. More...
 
static int get_field_base (int match, int field)
 
static AVFrameselect_frame (FieldMatchContext *fm, int match)
 
static int compare_fields (FieldMatchContext *fm, int match1, int match2, int field)
 
static void copy_fields (const FieldMatchContext *fm, AVFrame *dst, const AVFrame *src, int field)
 
static AVFramecreate_weave_frame (AVFilterContext *ctx, int match, int field, const AVFrame *prv, AVFrame *src, const AVFrame *nxt)
 
static int checkmm (AVFilterContext *ctx, int *combs, int m1, int m2, AVFrame **gen_frames, int field)
 
static int filter_frame (AVFilterLink *inlink, AVFrame *in)
 
static int activate (AVFilterContext *ctx)
 
static int query_formats (AVFilterContext *ctx)
 
static int config_input (AVFilterLink *inlink)
 
static av_cold int fieldmatch_init (AVFilterContext *ctx)
 
static av_cold void fieldmatch_uninit (AVFilterContext *ctx)
 
static int config_output (AVFilterLink *outlink)
 

Variables

static const AVOption fieldmatch_options []
 
static const int fxo0m [] = { mP, mC, mN, mB, mU }
 
static const int fxo1m [] = { mN, mC, mP, mU, mB }
 
static const AVFilterPad fieldmatch_outputs []
 
const AVFilter ff_vf_fieldmatch
 

Detailed Description

Fieldmatching filter, ported from VFM filter (VapourSynth) by Clément. Fredrik Mellbin is the author of the VIVTC/VFM filter, which is itself a light clone of the TIVTC/TFM (AviSynth) filter written by Kevin Stone (tritical), the original author.

See also
http://bengal.missouri.edu/~kes25c/
http://www.vapoursynth.com/about/

Definition in file vf_fieldmatch.c.

Macro Definition Documentation

◆ INPUT_MAIN

#define INPUT_MAIN   0

Definition at line 43 of file vf_fieldmatch.c.

◆ INPUT_CLEANSRC

#define INPUT_CLEANSRC   1

Definition at line 44 of file vf_fieldmatch.c.

◆ OFFSET

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

Definition at line 114 of file vf_fieldmatch.c.

◆ FLAGS

Definition at line 115 of file vf_fieldmatch.c.

◆ FILTER

#define FILTER (   xm2,
  xm1,
  xp1,
  xp2 
)
Value:
abs( 4 * srcp[x] \
-3 * (srcp[x + (xm1)*src_linesize] + srcp[x + (xp1)*src_linesize]) \
+ (srcp[x + (xm2)*src_linesize] + srcp[x + (xp2)*src_linesize])) > cthresh6

◆ HAS_FF_AROUND

#define HAS_FF_AROUND (   p,
  lz 
)
Value:
(p[(x)-1 - (lz)] == 0xff || p[(x) - (lz)] == 0xff || p[(x)+1 - (lz)] == 0xff || \
p[(x)-1 ] == 0xff || p[(x)+1 ] == 0xff || \
p[(x)-1 + (lz)] == 0xff || p[(x) + (lz)] == 0xff || p[(x)+1 + (lz)] == 0xff)

◆ C_ARRAY_ADD

#define C_ARRAY_ADD (   v)
Value:
do { \
const int box1 = (x / blockx) * 4; \
const int box2 = ((x + xhalf) / blockx) * 4; \
c_array[temp1 + box1 ] += v; \
c_array[temp1 + box2 + 1] += v; \
c_array[temp2 + box1 + 2] += v; \
c_array[temp2 + box2 + 3] += v; \
} while (0)

◆ VERTICAL_HALF

#define VERTICAL_HALF (   y_start,
  y_end 
)
Value:
do { \
for (y = y_start; y < y_end; y++) { \
const int temp1 = (y / blocky) * xblocks4; \
const int temp2 = ((y + yhalf) / blocky) * xblocks4; \
for (x = 0; x < width; x++) \
if (cmkp[x - cmk_linesize] == 0xff && \
cmkp[x ] == 0xff && \
cmkp[x + cmk_linesize] == 0xff) \
C_ARRAY_ADD(1); \
cmkp += cmk_linesize; \
} \
} while (0)

◆ LOAD_COMB

#define LOAD_COMB (   mid)
Value:
do { \
if (combs[mid] < 0) { \
if (!gen_frames[mid]) \
gen_frames[mid] = create_weave_frame(ctx, mid, field, \
fm->prv, fm->src, fm->nxt); \
combs[mid] = calc_combed_score(fm, gen_frames[mid]); \
} \
} while (0)

◆ SLIDING_FRAME_WINDOW

#define SLIDING_FRAME_WINDOW (   prv,
  src,
  nxt 
)
Value:
do { \
if (prv != src) /* 2nd loop exception (1st has prv==src and we don't want to loose src) */ \
av_frame_free(&prv); \
prv = src; \
src = nxt; \
if (in) \
nxt = in; \
if (!prv) \
prv = src; \
if (!prv) /* received only one frame at that point */ \
return 0; \
av_assert0(prv && src && nxt); \
} while (0)

Enumeration Type Documentation

◆ fieldmatch_parity

Enumerator
FM_PARITY_AUTO 
FM_PARITY_BOTTOM 
FM_PARITY_TOP 

Definition at line 46 of file vf_fieldmatch.c.

◆ matching_mode

Enumerator
MODE_PC 
MODE_PC_N 
MODE_PC_U 
MODE_PC_N_UB 
MODE_PCN 
MODE_PCN_UB 
NB_MODE 

Definition at line 52 of file vf_fieldmatch.c.

◆ comb_matching_mode

Enumerator
COMBMATCH_NONE 
COMBMATCH_SC 
COMBMATCH_FULL 
NB_COMBMATCH 

Definition at line 62 of file vf_fieldmatch.c.

◆ comb_dbg

enum comb_dbg
Enumerator
COMBDBG_NONE 
COMBDBG_PCN 
COMBDBG_PCNUB 
NB_COMBDBG 

Definition at line 69 of file vf_fieldmatch.c.

◆ anonymous enum

anonymous enum
Enumerator
mP 
mC 
mN 
mB 
mU 

Definition at line 473 of file vf_fieldmatch.c.

Function Documentation

◆ AVFILTER_DEFINE_CLASS()

AVFILTER_DEFINE_CLASS ( fieldmatch  )

◆ get_width()

static int get_width ( const FieldMatchContext fm,
const AVFrame f,
int  plane 
)
static

Definition at line 156 of file vf_fieldmatch.c.

Referenced by calc_combed_score(), compare_fields(), and copy_fields().

◆ get_height()

static int get_height ( const FieldMatchContext fm,
const AVFrame f,
int  plane 
)
static

Definition at line 161 of file vf_fieldmatch.c.

Referenced by calc_combed_score(), compare_fields(), copy_fields(), and ff_sauce_read().

◆ luma_abs_diff()

static int64_t luma_abs_diff ( const AVFrame f1,
const AVFrame f2 
)
static

Definition at line 166 of file vf_fieldmatch.c.

Referenced by filter_frame().

◆ fill_buf()

static void fill_buf ( uint8_t *  data,
int  w,
int  h,
int  linesize,
uint8_t  v 
)
static

Definition at line 186 of file vf_fieldmatch.c.

Referenced by calc_combed_score(), compare_fields(), and intercept_id3().

◆ calc_combed_score()

static int calc_combed_score ( const FieldMatchContext fm,
const AVFrame src 
)
static

Definition at line 196 of file vf_fieldmatch.c.

Referenced by filter_frame().

◆ build_abs_diff_mask()

static void build_abs_diff_mask ( const uint8_t *  prvp,
int  prv_linesize,
const uint8_t *  nxtp,
int  nxt_linesize,
uint8_t *  tbuffer,
int  tbuf_linesize,
int  width,
int  height 
)
static

Definition at line 394 of file vf_fieldmatch.c.

Referenced by build_diff_map().

◆ build_diff_map()

static void build_diff_map ( FieldMatchContext fm,
const uint8_t *  prvp,
int  prv_linesize,
const uint8_t *  nxtp,
int  nxt_linesize,
uint8_t *  dstp,
int  dst_linesize,
int  height,
int  width,
int  plane 
)
static

Build a map over which pixels differ a lot/a little.

Definition at line 415 of file vf_fieldmatch.c.

Referenced by compare_fields().

◆ get_field_base()

static int get_field_base ( int  match,
int  field 
)
static

Definition at line 475 of file vf_fieldmatch.c.

Referenced by compare_fields().

◆ select_frame()

static AVFrame* select_frame ( FieldMatchContext fm,
int  match 
)
static

Definition at line 480 of file vf_fieldmatch.c.

Referenced by compare_fields().

◆ compare_fields()

static int compare_fields ( FieldMatchContext fm,
int  match1,
int  match2,
int  field 
)
static

Definition at line 487 of file vf_fieldmatch.c.

Referenced by filter_frame().

◆ copy_fields()

static void copy_fields ( const FieldMatchContext fm,
AVFrame dst,
const AVFrame src,
int  field 
)
static

Definition at line 609 of file vf_fieldmatch.c.

Referenced by create_weave_frame().

◆ create_weave_frame()

static AVFrame* create_weave_frame ( AVFilterContext ctx,
int  match,
int  field,
const AVFrame prv,
AVFrame src,
const AVFrame nxt 
)
static

Definition at line 622 of file vf_fieldmatch.c.

Referenced by filter_frame().

◆ checkmm()

static int checkmm ( AVFilterContext ctx,
int combs,
int  m1,
int  m2,
AVFrame **  gen_frames,
int  field 
)
static

Definition at line 649 of file vf_fieldmatch.c.

Referenced by filter_frame().

◆ filter_frame()

static int filter_frame ( AVFilterLink inlink,
AVFrame in 
)
static

Definition at line 676 of file vf_fieldmatch.c.

Referenced by activate().

◆ activate()

static int activate ( AVFilterContext ctx)
static

Definition at line 835 of file vf_fieldmatch.c.

◆ query_formats()

static int query_formats ( AVFilterContext ctx)
static

Definition at line 886 of file vf_fieldmatch.c.

◆ config_input()

static int config_input ( AVFilterLink inlink)
static

Definition at line 932 of file vf_fieldmatch.c.

Referenced by fieldmatch_init().

◆ fieldmatch_init()

static av_cold int fieldmatch_init ( AVFilterContext ctx)
static

Definition at line 963 of file vf_fieldmatch.c.

◆ fieldmatch_uninit()

static av_cold void fieldmatch_uninit ( AVFilterContext ctx)
static

Definition at line 997 of file vf_fieldmatch.c.

◆ config_output()

static int config_output ( AVFilterLink outlink)
static

Definition at line 1017 of file vf_fieldmatch.c.

Variable Documentation

◆ fieldmatch_options

const AVOption fieldmatch_options[]
static

Definition at line 117 of file vf_fieldmatch.c.

◆ fxo0m

const int fxo0m[] = { mP, mC, mN, mB, mU }
static

Definition at line 673 of file vf_fieldmatch.c.

Referenced by filter_frame().

◆ fxo1m

const int fxo1m[] = { mN, mC, mP, mU, mB }
static

Definition at line 674 of file vf_fieldmatch.c.

Referenced by filter_frame().

◆ fieldmatch_outputs

const AVFilterPad fieldmatch_outputs[]
static
Initial value:
= {
{
.name = "default",
.config_props = config_output,
},
{ NULL }
}

Definition at line 1034 of file vf_fieldmatch.c.

◆ ff_vf_fieldmatch

const AVFilter ff_vf_fieldmatch
Initial value:
= {
.name = "fieldmatch",
.description = NULL_IF_CONFIG_SMALL("Field matching for inverse telecine."),
.query_formats = query_formats,
.priv_size = sizeof(FieldMatchContext),
.priv_class = &fieldmatch_class,
}

Definition at line 1043 of file vf_fieldmatch.c.

create_weave_frame
static AVFrame * create_weave_frame(AVFilterContext *ctx, int match, int field, const AVFrame *prv, AVFrame *src, const AVFrame *nxt)
Definition: vf_fieldmatch.c:622
init
static av_cold int init(AVCodecContext *avctx)
Definition: avrndec.c:31
activate
static int activate(AVFilterContext *ctx)
Definition: vf_fieldmatch.c:835
AVFILTER_FLAG_DYNAMIC_INPUTS
#define AVFILTER_FLAG_DYNAMIC_INPUTS
The number of the filter inputs is not determined just by AVFilter.inputs.
Definition: avfilter.h:106
inputs
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
Definition: filter_design.txt:243
width
#define width
config_output
static int config_output(AVFilterLink *outlink)
Definition: vf_fieldmatch.c:1017
fieldmatch_outputs
static const AVFilterPad fieldmatch_outputs[]
Definition: vf_fieldmatch.c:1034
outputs
static const AVFilterPad outputs[]
Definition: af_acontrast.c:203
ctx
AVFormatContext * ctx
Definition: movenc.c:48
field
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 field
Definition: writing_filters.txt:78
NULL
#define NULL
Definition: coverity.c:32
src
#define src
Definition: vp8dsp.c:255
abs
#define abs(x)
Definition: cuda_runtime.h:35
FieldMatchContext
Definition: vf_fieldmatch.c:76
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:117
query_formats
static int query_formats(AVFilterContext *ctx)
Definition: vf_fieldmatch.c:886
AVMEDIA_TYPE_VIDEO
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:201
fieldmatch_uninit
static av_cold void fieldmatch_uninit(AVFilterContext *ctx)
Definition: vf_fieldmatch.c:997
fieldmatch_init
static av_cold int fieldmatch_init(AVFilterContext *ctx)
Definition: vf_fieldmatch.c:963
flags
#define flags(name, subs,...)
Definition: cbs_av1.c:561
uninit
static av_cold int uninit(AVCodecContext *avctx)
Definition: crystalhd.c:279
calc_combed_score
static int calc_combed_score(const FieldMatchContext *fm, const AVFrame *src)
Definition: vf_fieldmatch.c:196