FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Data Structures | Macros | Enumerations | Functions | Variables
vf_fieldmatch.c File Reference

Fieldmatching filter, ported from VFM filter (VapourSynth) by Clément. More...

#include <inttypes.h>
#include "libavutil/avassert.h"
#include "libavutil/imgutils.h"
#include "libavutil/opt.h"
#include "libavutil/timestamp.h"
#include "avfilter.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 request_inlink (AVFilterContext *ctx, int lid)
 
static int request_frame (AVFilterLink *outlink)
 
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 []
 
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

#define INPUT_MAIN   0

Definition at line 42 of file vf_fieldmatch.c.

Referenced by config_output(), fieldmatch_init(), filter_frame(), and request_frame().

#define INPUT_CLEANSRC   1

Definition at line 43 of file vf_fieldmatch.c.

Referenced by config_output(), fieldmatch_init(), filter_frame(), and request_frame().

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

Definition at line 112 of file vf_fieldmatch.c.

Definition at line 113 of file vf_fieldmatch.c.

#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
BYTE int const BYTE * srcp
Definition: avisynth_c.h:813

Referenced by calc_combed_score().

#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)

Referenced by calc_combed_score().

#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)

Referenced by calc_combed_score().

#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) \
cmkp += cmk_linesize; \
} \
} while (0)
uint16_t width
Definition: gdv.c:47
#define C_ARRAY_ADD(v)
for(j=16;j >0;--j)

Referenced by calc_combed_score().

#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)
static AVFrame * create_weave_frame(AVFilterContext *ctx, int match, int field, const AVFrame *prv, AVFrame *src, const AVFrame *nxt)
AVFormatContext * ctx
Definition: movenc.c:48
if(ret< 0)
Definition: vf_mcdeint.c:279
static int calc_combed_score(const FieldMatchContext *fm, const AVFrame *src)

Referenced by checkmm().

#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) */ \
prv = src; \
src = nxt; \
if (in) \
nxt = in; \
if (!prv) \
prv = src; \
if (!prv) /* received only one frame at that point */ \
av_assert0(prv && src && nxt); \
} while (0)
#define src
Definition: vp8dsp.c:254
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:37
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition: frame.c:202
return
uint8_t pi<< 24) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0f/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16, int16_t,(*(constint16_t *) pi >>8)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32, int32_t,(*(constint32_t *) pi >>24)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, float, av_clip_uint8(lrintf(*(constfloat *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, float, av_clip_int16(lrintf(*(constfloat *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, float, av_clipl_int32(llrintf(*(constfloat *) pi *(1U<< 31)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, double, av_clip_uint8(lrint(*(constdouble *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, double, av_clip_int16(lrint(*(constdouble *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, double, av_clipl_int32(llrint(*(constdouble *) pi *(1U<< 31))))#defineSET_CONV_FUNC_GROUP(ofmt, ifmt) staticvoidset_generic_function(AudioConvert *ac){}voidff_audio_convert_free(AudioConvert **ac){if(!*ac) return;ff_dither_free(&(*ac) ->dc);av_freep(ac);}AudioConvert *ff_audio_convert_alloc(AVAudioResampleContext *avr, enumAVSampleFormatout_fmt, enumAVSampleFormatin_fmt, intchannels, intsample_rate, intapply_map){AudioConvert *ac;intin_planar, out_planar;ac=av_mallocz(sizeof(*ac));if(!ac) returnNULL;ac->avr=avr;ac->out_fmt=out_fmt;ac->in_fmt=in_fmt;ac->channels=channels;ac->apply_map=apply_map;if(avr->dither_method!=AV_RESAMPLE_DITHER_NONE &&av_get_packed_sample_fmt(out_fmt)==AV_SAMPLE_FMT_S16 &&av_get_bytes_per_sample(in_fmt)>2){ac->dc=ff_dither_alloc(avr, out_fmt, in_fmt, channels, sample_rate, apply_map);if(!ac->dc){av_free(ac);returnNULL;}returnac;}in_planar=ff_sample_fmt_is_planar(in_fmt, channels);out_planar=ff_sample_fmt_is_planar(out_fmt, channels);if(in_planar==out_planar){ac->func_type=CONV_FUNC_TYPE_FLAT;ac->planes=in_planar?ac->channels:1;}elseif(in_planar) ac->func_type=CONV_FUNC_TYPE_INTERLEAVE;elseac->func_type=CONV_FUNC_TYPE_DEINTERLEAVE;set_generic_function(ac);if(ARCH_AARCH64) ff_audio_convert_init_aarch64(ac);if(ARCH_ARM) ff_audio_convert_init_arm(ac);if(ARCH_X86) ff_audio_convert_init_x86(ac);returnac;}intff_audio_convert(AudioConvert *ac, AudioData *out, AudioData *in){intuse_generic=1;intlen=in->nb_samples;intp;if(ac->dc){av_log(ac->avr, AV_LOG_TRACE,"%dsamples-audio_convert:%sto%s(dithered)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt));returnff_convert_dither(ac-> in
if(ret< 0)
Definition: vf_mcdeint.c:279

Referenced by filter_frame().

Enumeration Type Documentation

Enumerator
FM_PARITY_AUTO 
FM_PARITY_BOTTOM 
FM_PARITY_TOP 

Definition at line 45 of file vf_fieldmatch.c.

Enumerator
MODE_PC 
MODE_PC_N 
MODE_PC_U 
MODE_PC_N_UB 
MODE_PCN 
MODE_PCN_UB 
NB_MODE 

Definition at line 51 of file vf_fieldmatch.c.

Enumerator
COMBMATCH_NONE 
COMBMATCH_SC 
COMBMATCH_FULL 
NB_COMBMATCH 

Definition at line 61 of file vf_fieldmatch.c.

enum comb_dbg
Enumerator
COMBDBG_NONE 
COMBDBG_PCN 
COMBDBG_PCNUB 
NB_COMBDBG 

Definition at line 68 of file vf_fieldmatch.c.

anonymous enum
Enumerator
mP 
mC 
mN 
mB 
mU 

Definition at line 471 of file vf_fieldmatch.c.

Function Documentation

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

Definition at line 154 of file vf_fieldmatch.c.

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

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

Definition at line 159 of file vf_fieldmatch.c.

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

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

Definition at line 164 of file vf_fieldmatch.c.

Referenced by filter_frame().

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

Definition at line 184 of file vf_fieldmatch.c.

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

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

Definition at line 194 of file vf_fieldmatch.c.

Referenced by filter_frame().

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 392 of file vf_fieldmatch.c.

Referenced by 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 413 of file vf_fieldmatch.c.

Referenced by compare_fields().

static int get_field_base ( int  match,
int  field 
)
static

Definition at line 473 of file vf_fieldmatch.c.

Referenced by compare_fields().

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

Definition at line 478 of file vf_fieldmatch.c.

Referenced by compare_fields().

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

Definition at line 485 of file vf_fieldmatch.c.

Referenced by filter_frame().

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

Definition at line 607 of file vf_fieldmatch.c.

Referenced by 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 620 of file vf_fieldmatch.c.

Referenced by filter_frame().

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

Definition at line 647 of file vf_fieldmatch.c.

Referenced by filter_frame().

static int filter_frame ( AVFilterLink inlink,
AVFrame in 
)
static

Definition at line 674 of file vf_fieldmatch.c.

Referenced by fieldmatch_init(), and request_inlink().

static int request_inlink ( AVFilterContext ctx,
int  lid 
)
static

Definition at line 821 of file vf_fieldmatch.c.

Referenced by request_frame().

static int request_frame ( AVFilterLink outlink)
static

Definition at line 837 of file vf_fieldmatch.c.

static int query_formats ( AVFilterContext ctx)
static

Definition at line 853 of file vf_fieldmatch.c.

static int config_input ( AVFilterLink inlink)
static

Definition at line 867 of file vf_fieldmatch.c.

Referenced by fieldmatch_init().

static av_cold int fieldmatch_init ( AVFilterContext ctx)
static

Definition at line 898 of file vf_fieldmatch.c.

static av_cold void fieldmatch_uninit ( AVFilterContext ctx)
static

Definition at line 941 of file vf_fieldmatch.c.

static int config_output ( AVFilterLink outlink)
static

Definition at line 959 of file vf_fieldmatch.c.

Variable Documentation

const AVOption fieldmatch_options[]
static

Definition at line 115 of file vf_fieldmatch.c.

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

Definition at line 671 of file vf_fieldmatch.c.

Referenced by filter_frame().

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

Definition at line 672 of file vf_fieldmatch.c.

Referenced by filter_frame().

const AVFilterPad fieldmatch_outputs[]
static
Initial value:
= {
{
.name = "default",
.request_frame = request_frame,
.config_props = config_output,
},
{ NULL }
}
#define NULL
Definition: coverity.c:32
static int config_output(AVFilterLink *outlink)
static int request_frame(AVFilterLink *outlink)

Definition at line 974 of file vf_fieldmatch.c.

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,
}
#define NULL
Definition: coverity.c:32
static av_cold int init(AVCodecContext *avctx)
Definition: avrndec.c:35
#define AVFILTER_FLAG_DYNAMIC_INPUTS
The number of the filter inputs is not determined just by AVFilter.inputs.
Definition: avfilter.h:105
static av_cold int uninit(AVCodecContext *avctx)
Definition: crystalhd.c:279
static int flags
Definition: log.c:55
static av_cold int fieldmatch_init(AVFilterContext *ctx)
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:186
static const AVFilterPad fieldmatch_outputs[]
static const AVFilterPad inputs[]
Definition: af_acontrast.c:193
static const AVFilterPad outputs[]
Definition: af_acontrast.c:203
static int query_formats(AVFilterContext *ctx)
static av_cold void fieldmatch_uninit(AVFilterContext *ctx)

Definition at line 984 of file vf_fieldmatch.c.