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

Motion Compensation Deinterlacer Ported from MPlayer libmpcodecs/vf_mcdeint.c. More...

#include "libavutil/opt.h"
#include "libavutil/pixdesc.h"
#include "libavcodec/avcodec.h"
#include "avfilter.h"
#include "formats.h"
#include "internal.h"

Go to the source code of this file.

Data Structures

struct  MCDeintContext
 

Macros

#define OFFSET(x)   offsetof(MCDeintContext, x)
 
#define FLAGS   AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
 
#define CONST(name, help, val, unit)   { name, help, 0, AV_OPT_TYPE_CONST, {.i64=val}, INT_MIN, INT_MAX, FLAGS, unit }
 
#define DELTA(j)   av_clip(j, -x, w-1-x)
 
#define GET_SCORE_EDGE(j)
 
#define GET_SCORE(j)
 
#define CHECK_EDGE(j)
 
#define CHECK(j)
 

Enumerations

enum  MCDeintMode {
  MODE_FAST = 0, MODE_MEDIUM, MODE_SLOW, MODE_EXTRA_SLOW,
  MODE_NB
}
 
enum  MCDeintParity { PARITY_TFF = 0, PARITY_BFF = 1 }
 

Functions

 AVFILTER_DEFINE_CLASS (mcdeint)
 
static int config_props (AVFilterLink *inlink)
 
static av_cold void uninit (AVFilterContext *ctx)
 
static int query_formats (AVFilterContext *ctx)
 
static int filter_frame (AVFilterLink *inlink, AVFrame *inpic)
 
 CHECK (-1) CHECK(-2)}}}}CHECK(1) CHECK(2)}}}}}if(diff0+diff1 > 0) temp-
 
 for (y=0;y< h;y++)
 
 if (ret< 0)
 
return ff_filter_frame (outlink, outpic)
 

Variables

static const AVOption mcdeint_options []
 
else int spatial_score = GET_SCORE(0) - 1
 
else temp = (diff0 + diff1 + FFABS(FFABS(diff0) - FFABS(diff1)) / 2) / 2
 
filp = *dstp = temp > 255U ? ~(temp>>31) : temp
 
 else
 
mcdeint parity = 1
 
end __pad0__
 
av_frame_freeinpic
 
static const AVFilterPad mcdeint_inputs []
 
static const AVFilterPad mcdeint_outputs []
 
AVFilter ff_vf_mcdeint
 

Detailed Description

Motion Compensation Deinterlacer Ported from MPlayer libmpcodecs/vf_mcdeint.c.

Known Issues:

The motion estimation is somewhat at the mercy of the input, if the input frames are created purely based on spatial interpolation then for example a thin black line or another random and not interpolateable pattern will cause problems. Note: completely ignoring the "unavailable" lines during motion estimation did not look any better, so the most obvious solution would be to improve tfields or penalize problematic motion vectors.

If non iterative ME is used then snow currently ignores the OBMC window and as a result sometimes creates artifacts.

Only past frames are used, we should ideally use future frames too, something like filtering the whole movie in forward and then backward direction seems like a interesting idea but the current filter framework is FAR from supporting such things.

Combining the motion compensated image with the input image also is not as trivial as it seems, simple blindly taking even lines from one and odd ones from the other does not work at all as ME/MC sometimes has nothing in the previous frames which matches the current. The current algorithm has been found by trial and error and almost certainly can be improved...

Definition in file vf_mcdeint.c.

Macro Definition Documentation

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

Definition at line 78 of file vf_mcdeint.c.

Definition at line 79 of file vf_mcdeint.c.

#define CONST (   name,
  help,
  val,
  unit 
)    { name, help, 0, AV_OPT_TYPE_CONST, {.i64=val}, INT_MIN, INT_MAX, FLAGS, unit }

Definition at line 80 of file vf_mcdeint.c.

#define DELTA (   j)    av_clip(j, -x, w-1-x)
#define GET_SCORE_EDGE (   j)
Value:
FFABS(srcp[-srcs+DELTA(-1+(j))] - srcp[+srcs+DELTA(-1-(j))])+\
FFABS(srcp[-srcs+DELTA(j) ] - srcp[+srcs+DELTA( -(j))])+\
FFABS(srcp[-srcs+DELTA(1+(j)) ] - srcp[+srcs+DELTA( 1-(j))])
BYTE int const BYTE * srcp
Definition: avisynth_c.h:676
#define DELTA(j)
#define FFABS(a)
Definition: common.h:61

Referenced by filter_frame().

#define GET_SCORE (   j)
Value:
FFABS(srcp[-srcs-1+(j)] - srcp[+srcs-1-(j)])+\
FFABS(srcp[-srcs +(j)] - srcp[+srcs -(j)])+\
FFABS(srcp[-srcs+1+(j)] - srcp[+srcs+1-(j)])
BYTE int const BYTE * srcp
Definition: avisynth_c.h:676
#define FFABS(a)
Definition: common.h:61
#define CHECK_EDGE (   j)
Value:
{ int score = GET_SCORE_EDGE(j);\
if (score < spatial_score){\
spatial_score = score;\
diff0 = filp[-fils+DELTA(j)] - srcp[-srcs+DELTA(j)];\
diff1 = filp[+fils+DELTA(-(j))] - srcp[+srcs+DELTA(-(j))];\
BYTE int const BYTE * srcp
Definition: avisynth_c.h:676
#define GET_SCORE_EDGE(j)
else int spatial_score
Definition: vf_mcdeint.c:248
#define DELTA(j)
* filp
Definition: vf_mcdeint.c:258
if(ret< 0)
Definition: vf_mcdeint.c:280

Referenced by filter_frame().

#define CHECK (   j)
Value:
{ int score = GET_SCORE(j);\
if (score < spatial_score){\
diff0 = filp[-fils+(j)] - srcp[-srcs+(j)];\
diff1 = filp[+fils-(j)] - srcp[+srcs-(j)];\
BYTE int const BYTE * srcp
Definition: avisynth_c.h:676
else int spatial_score
Definition: vf_mcdeint.c:248
#define GET_SCORE(j)
* filp
Definition: vf_mcdeint.c:258
if(ret< 0)
Definition: vf_mcdeint.c:280

Enumeration Type Documentation

Enumerator
MODE_FAST 
MODE_MEDIUM 
MODE_SLOW 
MODE_EXTRA_SLOW 
MODE_NB 

Definition at line 57 of file vf_mcdeint.c.

Enumerator
PARITY_TFF 

top field first

PARITY_BFF 

bottom field first

Definition at line 65 of file vf_mcdeint.c.

Function Documentation

AVFILTER_DEFINE_CLASS ( mcdeint  )
static int config_props ( AVFilterLink inlink)
static

Definition at line 99 of file vf_mcdeint.c.

static av_cold void uninit ( AVFilterContext ctx)
static

Definition at line 151 of file vf_mcdeint.c.

static int query_formats ( AVFilterContext ctx)
static

Definition at line 161 of file vf_mcdeint.c.

static int filter_frame ( AVFilterLink inlink,
AVFrame inpic 
)
static

Definition at line 172 of file vf_mcdeint.c.

CHECK ( 1)
for ( )

Definition at line 266 of file vf_mcdeint.c.

if ( )

Definition at line 280 of file vf_mcdeint.c.

return ff_filter_frame ( outlink  ,
outpic   
)

Variable Documentation

const AVOption mcdeint_options[]
static
Initial value:
= {
{ "mode", "set mode", OFFSET(mode), AV_OPT_TYPE_INT, {.i64=MODE_FAST}, 0, MODE_NB-1, FLAGS, .unit="mode" },
CONST("fast", NULL, MODE_FAST, "mode"),
CONST("medium", NULL, MODE_MEDIUM, "mode"),
CONST("slow", NULL, MODE_SLOW, "mode"),
CONST("extra_slow", NULL, MODE_EXTRA_SLOW, "mode"),
{ "parity", "set the assumed picture field parity", OFFSET(parity), AV_OPT_TYPE_INT, {.i64=PARITY_BFF}, -1, 1, FLAGS, "parity" },
CONST("tff", "assume top field first", PARITY_TFF, "parity"),
CONST("bff", "assume bottom field first", PARITY_BFF, "parity"),
{ "qp", "set qp", OFFSET(qp), AV_OPT_TYPE_INT, {.i64=1}, INT_MIN, INT_MAX, FLAGS },
{ NULL }
}
#define NULL
Definition: coverity.c:32
#define OFFSET(x)
Definition: vf_mcdeint.c:78
mode
Definition: f_perms.c:27
bottom field first
Definition: vf_mcdeint.c:67
#define CONST(name, help, val, unit)
Definition: vf_mcdeint.c:80
#define FLAGS
Definition: vf_mcdeint.c:79
mcdeint parity
Definition: vf_mcdeint.c:275
top field first
Definition: vf_mcdeint.c:66

Definition at line 82 of file vf_mcdeint.c.

else int spatial_score = GET_SCORE(0) - 1

Definition at line 248 of file vf_mcdeint.c.

Referenced by filter_frame().

else temp = (diff0 + diff1 + FFABS(FFABS(diff0) - FFABS(diff1)) / 2) / 2

Definition at line 257 of file vf_mcdeint.c.

Referenced by a64_compress_colram(), at1_subband_synthesis(), av_opencl_buffer_read_image(), av_opencl_buffer_write_image(), backward_filter(), bink_idct_c(), bink_idct_put_c(), bit8x8_c(), celt_decode_allocation(), comp_interp_index(), config_input(), dct_max8x8_c(), dct_sad8x8_c(), decode_8_pulses_31bits(), decode_plane(), decode_rgb_frame(), encode_mode(), ff_atrac_iqmf(), ff_block_permute(), ff_ea_idct_put_c(), ff_faandct(), ff_faandct248(), ff_faanidct(), ff_faanidct_add(), ff_faanidct_put(), ff_h264_chroma422_dc_dequant_idct(), ff_h264_luma_dc_dequant_idct(), ff_put_wav_header(), ff_svq3_luma_dc_dequant_idct_c(), ff_vorbis_inverse_coupling(), filter(), filter_frame(), find_new_headers(), flac_parse(), flac_parse_close(), formant_postfilter(), gain_scale(), gen_fcb_excitation(), get_tilt_comp(), h261_loop_filter(), hadamard8_diff8x8_c(), hadamard8_intra8x8_c(), handle_file(), hnm_flip_buffers(), http_write(), hybrid6_cx(), idct(), idct_put(), idctRowCondDC(), imdct_and_windowing(), imdct_and_windowing_eld(), inverse_quant(), ls_encode_runterm(), ls_get_code_runterm(), main(), matroska_parse_laces(), on2avc_reconstruct_channel(), postfilter(), pp_get_mode_by_name_and_quality(), quant_psnr8x8_c(), rd8x8_c(), read16(), read32(), read_time(), render_slice(), rtmp_server_handshake(), rv34_idct_add_c(), rv34_inv_transform_noround_c(), sbr_gain_calc(), sbr_make_f_derived(), sbr_make_f_master(), scale_coefs(), setup_classifs(), store_slice16_c(), store_slice2_c(), store_slice_c(), sub_left_prediction(), svq1_encode_plane(), tta_encode_frame(), unpack_bitstream(), vc1_inv_trans_8x8_c(), and wavpack_encode_block().

* filp = *dstp = temp > 255U ? ~(temp>>31) : temp

Definition at line 258 of file vf_mcdeint.c.

Referenced by filter_frame().

else
Initial value:
{
*dstp = *filp
BYTE * dstp
Definition: avisynth_c.h:676
* filp
Definition: vf_mcdeint.c:258

Definition at line 259 of file vf_mcdeint.c.

mcdeint parity = 1
end __pad0__

Definition at line 278 of file vf_mcdeint.c.

av_frame_free& inpic

Definition at line 279 of file vf_mcdeint.c.

Referenced by filter_frame(), and for().

const AVFilterPad mcdeint_inputs[]
static
Initial value:
= {
{
.name = "default",
.filter_frame = filter_frame,
.config_props = config_props,
},
{ NULL }
}
#define NULL
Definition: coverity.c:32
static int config_props(AVFilterLink *inlink)
Definition: vf_mcdeint.c:99
static int filter_frame(AVFilterLink *inlink, AVFrame *inpic)
Definition: vf_mcdeint.c:172

Definition at line 287 of file vf_mcdeint.c.

const AVFilterPad mcdeint_outputs[]
static
Initial value:
= {
{
.name = "default",
},
{ NULL }
}
#define NULL
Definition: coverity.c:32

Definition at line 297 of file vf_mcdeint.c.

AVFilter ff_vf_mcdeint
Initial value:
= {
.name = "mcdeint",
.description = NULL_IF_CONFIG_SMALL("Apply motion compensating deinterlacing."),
.priv_size = sizeof(MCDeintContext),
.priv_class = &mcdeint_class,
}
static const AVFilterPad mcdeint_inputs[]
Definition: vf_mcdeint.c:287
static const AVFilterPad outputs[]
Definition: af_ashowinfo.c:248
static const AVFilterPad mcdeint_outputs[]
Definition: vf_mcdeint.c:297
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:175
static av_cold void uninit(AVFilterContext *ctx)
Definition: vf_mcdeint.c:151
static int query_formats(AVFilterContext *ctx)
Definition: vf_mcdeint.c:161
static const AVFilterPad inputs[]
Definition: af_ashowinfo.c:239

Definition at line 305 of file vf_mcdeint.c.