<html><head><meta http-equiv="Content-Type" content="text/html charset=us-ascii"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class="">After testing the Motion Adaptive deinterlacing mode and finding it produced lots of flicker/judder and not much deinterlacing I traced the error back to the below.</div><div class=""><br class=""></div><div class="">Although it seems a little counter-intuitive, the "forward_refs" are actually the frames older than the current one, and the "backward_refs" are those later.</div><div class=""><br class=""></div><div class="">In addition, the forward_refs (previously the backward_refs) have to be ordered such that [0] is most recent, [1] older, etc; before this patch it was the opposite.</div><div class=""><br class=""></div><div class="">Just to be 100% sure, I have also cross-referenced this approach with how FFmpeg does it:</div><div class=""><br class=""></div><div class=""><a href="https://github.com/FFmpeg/FFmpeg/blob/master/libavfilter/vf_deinterlace_vaapi.c" class="">https://github.com/FFmpeg/FFmpeg/blob/master/libavfilter/vf_deinterlace_vaapi.c</a></div><div class=""><br class=""></div><div class="">See function deint_vaapi_filter_frame.</div><div class=""><br class=""></div><div class="">---</div><div class=""> modules/hw/vaapi/filters.c | 26 +++++++++++++++-----------</div><div class=""> 1 file changed, 15 insertions(+), 11 deletions(-)</div><div class=""><br class=""></div><div class="">diff --git a/modules/hw/vaapi/filters.c b/modules/hw/vaapi/filters.c</div><div class="">index b63b7ae312..efb1583f1b 100644</div><div class="">--- a/modules/hw/vaapi/filters.c</div><div class="">+++ b/modules/hw/vaapi/filters.c</div><div class="">@@ -752,13 +752,17 @@ Deinterlace_UpdateReferenceFrames(void * p_data)</div><div class=""> </div><div class=""> if (p_deint_data->backward_refs.sz)</div><div class=""> for (unsigned int i = 0; i < p_deint_data->backward_refs.sz; ++i)</div><div class="">+ {</div><div class="">+ unsigned int const idx = p_deint_data->forward_refs.sz + 1 + i;</div><div class="">+</div><div class=""> p_deint_data->backward_refs.surfaces[i] =</div><div class="">- vlc_vaapi_PicGetSurface(p_deint_data->history.pp_pics[i]);</div><div class="">+ vlc_vaapi_PicGetSurface(p_deint_data->history.pp_pics[idx]);</div><div class="">+ }</div><div class=""> </div><div class=""> if (p_deint_data->forward_refs.sz)</div><div class=""> for (unsigned int i = 0; i < p_deint_data->forward_refs.sz; ++i)</div><div class=""> {</div><div class="">- unsigned int const idx = p_deint_data->backward_refs.sz + 1 + i;</div><div class="">+ unsigned int const idx = p_deint_data->forward_refs.sz - 1 - i;</div><div class=""> </div><div class=""> p_deint_data->forward_refs.surfaces[i] =</div><div class=""> vlc_vaapi_PicGetSurface(p_deint_data->history.pp_pics[idx]);</div><div class="">@@ -923,20 +927,20 @@ OpenDeinterlace_InitHistory(void * p_data, VAProcPipelineCaps const * pipeline_c</div><div class=""> return VLC_ENOMEM;</div><div class=""> </div><div class=""> p_deint_data->history.pp_cur_pic =</div><div class="">- p_deint_data->history.pp_pics + sz_backward_refs;</div><div class="">+ p_deint_data->history.pp_pics + sz_forward_refs;</div><div class=""> p_deint_data->history.num_pics = 0;</div><div class=""> p_deint_data->history.sz = history_sz;</div><div class=""> </div><div class=""> if (history_sz - 1)</div><div class=""> {</div><div class="">- p_deint_data->backward_refs.surfaces =</div><div class="">+ p_deint_data->forward_refs.surfaces =</div><div class=""> malloc((history_sz - 1) * sizeof(VASurfaceID));</div><div class="">- if (!p_deint_data->backward_refs.surfaces)</div><div class="">+ if (!p_deint_data->forward_refs.surfaces)</div><div class=""> return VLC_ENOMEM;</div><div class=""> }</div><div class=""> </div><div class="">- p_deint_data->forward_refs.surfaces =</div><div class="">- p_deint_data->backward_refs.surfaces + sz_backward_refs;</div><div class="">+ p_deint_data->backward_refs.surfaces =</div><div class="">+ p_deint_data->forward_refs.surfaces + sz_forward_refs;</div><div class=""> </div><div class=""> p_deint_data->backward_refs.sz = sz_backward_refs;</div><div class=""> p_deint_data->forward_refs.sz = sz_forward_refs;</div><div class="">@@ -962,8 +966,8 @@ OpenDeinterlace(vlc_object_t * obj)</div><div class=""> return VLC_SUCCESS;</div><div class=""> </div><div class=""> error:</div><div class="">- if (p_data->backward_refs.surfaces)</div><div class="">- free(p_data->backward_refs.surfaces);</div><div class="">+ if (p_data->forward_refs.surfaces)</div><div class="">+ free(p_data->forward_refs.surfaces);</div><div class=""> if (p_data->history.pp_pics)</div><div class=""> free(p_data->history.pp_pics);</div><div class=""> free(p_data);</div><div class="">@@ -977,8 +981,8 @@ CloseDeinterlace(vlc_object_t * obj)</div><div class=""> filter_sys_t *const filter_sys = filter->p_sys;</div><div class=""> struct deint_data *const p_data = filter_sys->p_data;</div><div class=""> </div><div class="">- if (p_data->backward_refs.surfaces)</div><div class="">- free(p_data->backward_refs.surfaces);</div><div class="">+ if (p_data->forward_refs.surfaces)</div><div class="">+ free(p_data->forward_refs.surfaces);</div><div class=""> if (p_data->history.pp_pics)</div><div class=""> {</div><div class=""> while (p_data->history.num_pics)</div><div class="">-- </div><div class="">2.11.0</div><div class=""><br class=""></div></body></html>