Opened 6 years ago

Closed 5 years ago

#5745 closed defect (needs_more_info)

The ‘fieldmatch’ filter sometimes fails to mark combed frames as interlaced.

Reported by: Alexander Behringer Owned by:
Priority: normal Component: avfilter
Version: git-master Keywords: fieldmatch
Cc: Blocked By:
Blocking: Reproduced by developer: no
Analyzed by developer: no



If the fieldmatch filter produces a combed frame, it is (according to the docs) supposed to mark this frame as interlaced, so that subsequent deinterlacing filters set to only deinterlace interlaced frames to remove the remaining combing.

However, under certain circumstances the combing score for the final match never gets calculated, leaving it at its default value of -1, which never will trigger the interlaced marking. With default settings the combing score for the final match is only calculated, if the combed frame is part of a (detected) scene change. If combmatch is set to 0, scene changes are never even checked for.

As a workaround, if the final match is of type p, c or n, you can set the debug option combdbg to pcn, which as a side effect also calculates the combing score for the final match. If the final match is potentially of type u or b, you even need to set combdbg to pcnub to calculate these scores as well.

Another workaround is to set combmatch to full, which calculates the combing scores for the final match as well, but also alters the matching behavior.


Here is an artificial example: The following video contains fields, for which no fitting matching partner can be found:

ffplay -f "lavfi" 'nullsrc=s=512x512,geq=lum=255*gt(mod(X+Y-10*N\,W)\,W/4):cr=128:cb=128,telecine=pattern=2222222222211111111'

If this is send through the fieldmatch filter, it will inevitable produce combed frames:

ffplay -f "lavfi" 'nullsrc=s=512x512,geq=lum=255*gt(mod(X+Y-10*N\,W)\,W/4):cr=128:cb=128,telecine=pattern=2222222222211111111,fieldmatch'

Adding a deinterlacer set to only deinterlace interlaced frames should fix this, but fails because of this bug:

ffplay -f "lavfi" 'nullsrc=s=512x512,geq=lum=255*gt(mod(X+Y-10*N\,W)\,W/4):cr=128:cb=128,telecine=pattern=2222222222211111111,fieldmatch,w3fdif=deint=interlaced'

As mentioned earlier, adding combdbg=pcn to the options of fieldmatch works around that:

ffplay -f "lavfi" 'nullsrc=s=512x512,geq=lum=255*gt(mod(X+Y-10*N\,W)\,W/4):cr=128:cb=128,telecine=pattern=2222222222211111111,fieldmatch=combdbg=pcn,w3fdif=deint=interlaced'

Possible solution

Check if the combing score for the final match has been calculated and if not calculated it before using it to potentially mark the frame as interlaced.

Change History (4)

comment:1 by Carl Eugen Hoyos, 6 years ago

Please provide a real-world input video: Afaict fieldmatch uses heuristics, and I hope they are meant to work best on real-world video.

comment:2 by Carl Eugen Hoyos, 6 years ago

But if you have a fix for the issue you see, please do not hesitate to send a patch made with git format-patch to the development mailing list.

comment:3 by Alexander Behringer, 6 years ago

After I came across this issue, I experimented a bit and read the filter source code (libavfilter/vf_fieldmatch.c) and found the described problem of the missing combing score calculation there.

The problem is independent of any heuristics of the field matcher (with the exception of the scene change detection, which is intentionally not triggered by my test video) since it is about the comb detection at the end of the filter (near the end of the filter_frame function). Its an program logic issue, not a random or heuristics problem.

My example is constructed to trigger and thus show and help debugging the problem. But if this is not enough, you can use any truly interlaced video as input. With truly interlaced I mean a video whose fields are not constructed from progressive material (via telecine for example). If you work with (de-)interlacing filters, you should have some test video yourself.

With such a video the following will produce combed frames, although it should not:

ffplay some_truly_interlaced_source -vf 'fieldmatch,w3fdif=deint=interlaced'

But the following will produce deinterlaced content:

ffplay some_truly_interlaced_source -vf 'fieldmatch=combdbg=pcn,w3fdif=deint=interlaced'

Since I have nearly no experience in programming in C or working with the FFmpeg libaries, I will refrain from proposing a patch. I just wanted to document the existence of the problem.

comment:4 by Carl Eugen Hoyos, 5 years ago

Resolution: needs_more_info
Status: newclosed
Note: See TracTickets for help on using tickets.