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

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

#include "libavutil/attributes.h"
#include "libavutil/opt.h"
#include "libavcodec/avcodec.h"
#include "libavutil/pixdesc.h"
#include "avfilter.h"
#include "filters.h"
#include "video.h"

Go to the source code of this file.

Data Structures

struct  MCDeintContext
 

Macros

#define OFFSET(x)
 
#define FLAGS   AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
 
#define CONST(name, help, val, u)
 
#define DELTA(j)
 
#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 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
 
else temp = (diff0 + diff1 + FFABS(FFABS(diff0) - FFABS(diff1)) / 2) / 2
 
filp = *dstp = temp > 255U ? ~(temp>>31) : temp
 
mcdeint parity = 1
 
end __pad0__
 
av_frame_freeinpic
 
static const AVFilterPad mcdeint_inputs []
 
const FFFilter 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 an 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

◆ OFFSET

#define OFFSET ( x)
Value:

Definition at line 83 of file vf_mcdeint.c.

◆ FLAGS

Definition at line 84 of file vf_mcdeint.c.

◆ CONST

#define CONST ( name,
help,
val,
u )
Value:
{ name, help, 0, AV_OPT_TYPE_CONST, {.i64=val}, INT_MIN, INT_MAX, FLAGS, .unit = u }
static double val(void *priv, double ch)
Definition aeval.c:77
#define FLAGS
Definition cmdutils.c:598
static void help(void)
Definition dct.c:457
@ AV_OPT_TYPE_CONST
Special option type for declaring named constants.
Definition opt.h:298
#define u(width, name, range_min, range_max)
Definition cbs_apv.c:68
const char * name
Definition qsvenc.c:142

Definition at line 85 of file vf_mcdeint.c.

◆ DELTA

#define DELTA ( j)
Value:
av_clip(j, -x, w-1-x)
#define av_clip
Definition common.h:100
uint8_t w
Definition llvidencdsp.c:39

◆ GET_SCORE_EDGE

#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))])
#define FFABS(a)
Absolute value, Note, INT_MIN / INT64_MIN result in undefined behavior as they are not representable ...
Definition common.h:74
#define DELTA(j)

Referenced by filter_frame().

◆ GET_SCORE

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

◆ CHECK_EDGE

#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))];\
* filp
Definition vf_mcdeint.c:276
#define GET_SCORE_EDGE(j)

Referenced by filter_frame().

◆ CHECK

#define CHECK ( j)
Value:
{ int score = GET_SCORE(j);\
if (score < spatial_score){\
spatial_score= score;\
diff0 = filp[-fils+(j)] - srcp[-srcs+(j)];\
diff1 = filp[+fils-(j)] - srcp[+srcs-(j)];\
#define GET_SCORE(j)

Enumeration Type Documentation

◆ MCDeintMode

Enumerator
MODE_FAST 
MODE_MEDIUM 
MODE_SLOW 
MODE_EXTRA_SLOW 
MODE_NB 

Definition at line 60 of file vf_mcdeint.c.

◆ MCDeintParity

Enumerator
PARITY_TFF 

top field first

PARITY_BFF 

bottom field first

Definition at line 68 of file vf_mcdeint.c.

Function Documentation

◆ AVFILTER_DEFINE_CLASS()

AVFILTER_DEFINE_CLASS ( mcdeint )

◆ config_props()

static int config_props ( AVFilterLink * inlink)
static

Definition at line 104 of file vf_mcdeint.c.

◆ uninit()

static av_cold void uninit ( AVFilterContext * ctx)
static

Definition at line 165 of file vf_mcdeint.c.

◆ filter_frame()

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

Definition at line 174 of file vf_mcdeint.c.

◆ CHECK()

CHECK ( - 1)

◆ for()

for ( )

Definition at line 284 of file vf_mcdeint.c.

◆ if()

if ( )

Definition at line 298 of file vf_mcdeint.c.

◆ ff_filter_frame()

return ff_filter_frame ( outlink ,
outpic  )

Variable Documentation

◆ mcdeint_options

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, .unit = "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 }
}
@ MODE_NB
#define NULL
Definition coverity.c:32
#define OFFSET(x)
@ AV_OPT_TYPE_INT
Underlying C type is int.
Definition opt.h:258
#define CONST(name, help, val, u)
Definition vf_bwdif.c:189
@ MODE_FAST
Definition signature.h:43
Definition swscale.c:71
@ MODE_EXTRA_SLOW
Definition vf_mcdeint.c:64
@ MODE_SLOW
Definition vf_mcdeint.c:63
@ MODE_MEDIUM
Definition vf_mcdeint.c:62
@ PARITY_BFF
bottom field first
Definition vf_mcdeint.c:70
@ PARITY_TFF
top field first
Definition vf_mcdeint.c:69
mcdeint parity
Definition vf_mcdeint.c:293

Definition at line 87 of file vf_mcdeint.c.

◆ else

else
Initial value:
{
int spatial_score = GET_SCORE(0) - 1

Definition at line 265 of file vf_mcdeint.c.

◆ temp

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

Definition at line 275 of file vf_mcdeint.c.

Referenced by a64_compress_colram(), acb_search(), adpcm_decode_frame(), apv_add_configuration_entry(), apv_add_frameinfo(), at1_subband_synthesis(), av_div_sf(), av_exif_set_entry(), backward_filter(), bink_idct_c(), bink_idct_put_c(), bit8x8_c(), blur_power(), box_slice(), calculate_blockiness(), calculate_rotation_matrix(), categorize_regions(), celt_frame_mdct(), CHECK(), checkasm_check_aes(), checkasm_mfspr(), colorscale_matrix(), comp_autocorr(), comp_interp_index(), compose2D2(), compute_vif2(), config_input(), dct_max8x8_c(), dct_sad8x8_c(), decode_8_pulses_31bits(), decode_bayer_frame(), decode_plane(), decode_rgb_frame_TMPL(), decompose2D2(), decompress_p(), decompress_p3(), diagonal_transformation(), do_block_ssd(), do_block_ssd16(), draw_response(), encode_mode(), estimate_pitch(), exif_parse_ifd_list(), ff_atrac_iqmf(), ff_avg_h264_qpel16_mc12_lasx(), ff_avg_h264_qpel16_mc12_lsx(), ff_avg_h264_qpel16_mc12_mmi(), ff_avg_h264_qpel16_mc21_lasx(), ff_avg_h264_qpel16_mc21_lsx(), ff_avg_h264_qpel16_mc21_mmi(), ff_avg_h264_qpel16_mc22_mmi(), ff_avg_h264_qpel16_mc23_lasx(), ff_avg_h264_qpel16_mc23_lsx(), ff_avg_h264_qpel16_mc23_mmi(), ff_avg_h264_qpel16_mc32_lasx(), ff_avg_h264_qpel16_mc32_lsx(), ff_avg_h264_qpel16_mc32_mmi(), ff_avg_h264_qpel8_mc12_lasx(), ff_avg_h264_qpel8_mc12_lsx(), ff_avg_h264_qpel8_mc12_mmi(), ff_avg_h264_qpel8_mc21_lasx(), ff_avg_h264_qpel8_mc21_lsx(), ff_avg_h264_qpel8_mc21_mmi(), ff_avg_h264_qpel8_mc22_mmi(), ff_avg_h264_qpel8_mc23_lasx(), ff_avg_h264_qpel8_mc23_lsx(), ff_avg_h264_qpel8_mc23_mmi(), ff_avg_h264_qpel8_mc32_lasx(), ff_avg_h264_qpel8_mc32_lsx(), ff_avg_h264_qpel8_mc32_mmi(), ff_block_permute(), ff_cbs_h2645_write_slice_data(), ff_ea_idct_put_c(), ff_faandct(), ff_faandct248(), ff_faanidct(), ff_faanidct_add(), ff_faanidct_put(), ff_g723_1_inverse_quant(), ff_mkdir_p(), ff_put_h264_qpel16_mc12_lasx(), ff_put_h264_qpel16_mc12_lsx(), ff_put_h264_qpel16_mc12_mmi(), ff_put_h264_qpel16_mc21_lasx(), ff_put_h264_qpel16_mc21_lsx(), ff_put_h264_qpel16_mc21_mmi(), ff_put_h264_qpel16_mc22_mmi(), ff_put_h264_qpel16_mc23_lasx(), ff_put_h264_qpel16_mc23_lsx(), ff_put_h264_qpel16_mc23_mmi(), ff_put_h264_qpel16_mc32_lasx(), ff_put_h264_qpel16_mc32_lsx(), ff_put_h264_qpel16_mc32_mmi(), ff_put_h264_qpel8_mc12_lasx(), ff_put_h264_qpel8_mc12_lsx(), ff_put_h264_qpel8_mc12_mmi(), ff_put_h264_qpel8_mc21_lasx(), ff_put_h264_qpel8_mc21_lsx(), ff_put_h264_qpel8_mc21_mmi(), ff_put_h264_qpel8_mc22_mmi(), ff_put_h264_qpel8_mc23_lasx(), ff_put_h264_qpel8_mc23_lsx(), ff_put_h264_qpel8_mc23_mmi(), ff_put_h264_qpel8_mc32_lasx(), ff_put_h264_qpel8_mc32_lsx(), ff_put_h264_qpel8_mc32_mmi(), ff_put_wav_header(), ff_queue_destroy(), ff_simple_idct_add_lasx(), ff_simple_idct_lasx(), ff_simple_idct_put_lasx(), ff_snow_inner_add_yblock_ssse3(), ff_spatial_dwt(), ff_spatial_idwt(), ff_spatial_idwt_buffered_slice(), ff_store_slice2_c(), ff_store_slice_c(), filter(), filter_frame(), find_new_headers(), flac_parse(), flac_parse_close(), formant_postfilter(), ftx_2d(), gain_scale(), gen_fcb_excitation(), get_fcb_param(), get_tilt_comp(), h261_loop_filter(), hadamard8_diff8x8_c(), hadamard8_intra8x8_c(), handle_file(), handle_file(), harmonic_filter(), harmonic_noise_sub(), hblur(), horizontal_compose53i(), horizontal_compose_daub97i_TMPL(), horizontal_compose_dirac53i_TMPL(), horizontal_compose_haar0i_TMPL(), horizontal_compose_haar1i_TMPL(), horizontal_compose_haari_TMPL(), horizontal_decompose53i(), horizontal_decompose97i(), http_write(), hybrid6_cx(), hypot(), idct(), idct_put(), idctRowCondDC(), imdct_and_windowing(), imdct_and_windowing_768(), imdct_and_windowing_960(), imdct_and_windowing_eld(), AACDecContext::INTFLOAT_ALIGNED_UNION(), invert_step(), ivr_read_header(), kbd_window_init(), levinson_durbin(), libjxl_process_output(), lpc2lsp(), ls_encode_runterm(), ls_get_code_runterm(), magy_huffman_compute_bits(), main(), main(), main(), matrix_multiply(), mjpegenc_huffman_compute_bits(), on2avc_reconstruct_channel(), p8idct(), pack_bitstream(), pgx_get_number(), planar_rgb_to_uv_lasx(), planar_rgb_to_y_lasx(), postfilter(), qian_thresholding(), quant_psnr8x8_c(), queue_frame(), rd8x8_c(), read10in32_gray(), read16(), read32(), read_time(), render_slice(), rotate(), row_fdct(), rtmp_server_handshake(), rv34_idct_add_c(), rv34_inv_transform_noround_c(), rv34_row_transform(), sbc_unpack_frame(), sbr_gain_calc(), sbr_gain_calc(), sbr_make_f_derived(), sbr_make_f_master(), scale_coefs(), set_noise_profile(), setup_classifs(), simple_idct_add_msa(), simple_idct_msa(), simple_idct_put_msa(), snow_horizontal_compose97i(), soft_thresholding(), spatial_compose53i_dy(), spatial_compose53i_dy_buffered(), spatial_compose97i_dy(), spatial_compose97i_dy_buffered(), spatial_decompose53i(), spatial_decompose97i(), spatial_idwt_slice(), ssim360_plane_16bit(), ssim360_plane_8bit(), ssim360_tape(), ssim_plane(), ssim_plane_16bit(), store_slice16_c(), store_slice_c(), store_slice_c(), sub_acb_contrib(), sub_left_prediction(), svq1_encode_plane(), svq3_luma_dc_dequant_idct_c(), synth_percept_filter(), tta_encode_frame(), unpack_bitstream(), vblur(), vc1_inv_trans_8x8_c(), video_frame(), vif_filter1d(), vvc_extradata_to_annexb(), wavpack_encode_block(), yuv2rgb_full_X_template_lasx(), yuv2rgb_full_X_template_lsx(), yuv2rgb_X_template_lasx(), and yuv2rgb_X_template_lsx().

◆ filp

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

Definition at line 276 of file vf_mcdeint.c.

Referenced by filter_frame().

◆ parity

◆ __pad0__

end __pad0__

Definition at line 295 of file vf_mcdeint.c.

◆ inpic

◆ mcdeint_inputs

const AVFilterPad mcdeint_inputs[]
static
Initial value:
= {
{
.name = "default",
.filter_frame = filter_frame,
.config_props = config_props,
},
}
static int filter_frame(DBEDecodeContext *s, AVFrame *frame)
Definition dolby_e.c:1067
@ AVMEDIA_TYPE_VIDEO
Definition avutil.h:200
static int config_props(AVBitStreamFilterLink *link)
Definition source.c:181

Definition at line 305 of file vf_mcdeint.c.

◆ ff_vf_mcdeint

const FFFilter ff_vf_mcdeint
Initial value:
= {
.p.name = "mcdeint",
.p.description = NULL_IF_CONFIG_SMALL("Apply motion compensating deinterlacing."),
.p.priv_class = &mcdeint_class,
.priv_size = sizeof(MCDeintContext),
}
static av_cold void uninit(AVBitStreamFilterContext *ctx)
#define FILTER_INPUTS(array)
Definition filters.h:264
#define FILTER_OUTPUTS(array)
Definition filters.h:265
#define FILTER_PIXFMTS(...)
Definition filters.h:250
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
Definition internal.h:88
@ AV_PIX_FMT_YUV420P
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
Definition pixfmt.h:73
@ AV_PIX_FMT_YUV444P
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
Definition pixfmt.h:78
static const AVFilterPad mcdeint_inputs[]
Definition vf_mcdeint.c:305
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 314 of file vf_mcdeint.c.