Repository navigation
Fix avdeinterlace buffering - #1340
Conversation
|
This should not be necessary if you are using the avdeinterlace link as intended. The link should be added automatically as a normalizer link, not manually by the application. If you use the loader constructor for MLT:Chain, then it will call mlt_chain_attach_normalizers() and the avdeinterlace filter will only be applied if necessary. Line 41 in 77ae5f8 |
| source.set("progressive", 0); | ||
| Filter brightness(profile, "brightness"); | ||
| brightness.set("level", "0=0;1=1"); | ||
| source.attach(brightness); |
There was a problem hiding this comment.
This test is still doing unexpected things. The source should belong to the chain and it should not have filters attached to it. You are putting filters before the normalizers. Attach the filters to the chain, not to the source producer.
Can you reproduce your problem without adding filters to the encapsulated source producer?
There was a problem hiding this comment.
Pushed a cleaner test where blipflash is rendered interlaced first, then used in the test instead of the dummy clips using filters approach I did earlier. It still reproduces the problem.
|
Thanks for the reply I may be missing something, but I do not see how the way the avdeinterlace link is added matters for this bug. I updated the test to use the Chain constructor. The test still fails on master, passes after the fix. Let me know what you think. Separately, one CI is red. I believe this is due to using old Ffmpeg (4.4). The reason seems to be as follows:
Guidance appreciated on how to fix that. My 2 cents is either to drop support for 4.4 or add a version guard on the buffersrc, which will make the segfault go away at the cost of differences in behavior depending on ffmpeg version. |
|
Thank you for changing the test. I do not want a test in our repository that sets a bad example for how the framework should be used.
That is a helpful comment. Now I understand the problem better. In general, I do not think many applications are sharing a single producer multiple times in a playlist. The framework does not prohibit it. But I do not know if it is a best practice. I'll let @ddennedy chime in on that. Using mlt_frame_original_position() in a link as a continuity indicator is not a good idea because there would be a link ahead of it that is skipping/repeating frames. But, in the specific case of avdelinterlace, that is unlikely because it should usually be the first normalizer. But again, I don't really want to set a bad example in the code. Can you work around this limitation by not sharing producers?
@ddennedy how would you feel about dropping support for FFMpeg 4.4? It looks like it is not actually working anyway (even though it compiles) |
I cannot speak for all applications, but as a kdenlive maintainer I can tell you that kdenlive keeps one producer per bin clip per track, and every timeline clip is a cut of it. We got hit by the buffering bug, hence this PR to attempt to resolve it.
I do not know either, but just pointing out that MLT's own function
Is there an alternative preferred continuity signal? For example, could the link detect that the frame came from a different cut?
Currently in kdenlive it's a pretty deeply ingrained pattern, so it would not be a "workaround" so much as a redesign. It would be great if we can avoid it. |
|
Yes, it is perfectly fine to share producers like this. I would only caution against using the same shared producer in a transition. Yes, we can drop FFmpeg 4. Debian stable has 7. This is due to using ubuntu-22.04 in |
|
Based on the discussion I think that using the original frame position is our best option. Could this simpler patch solve the problem? |
|
@bmatherly I do not think your patch is valid. We need to detect two kinds of discontinuities:
Previously, 2 was tackled but not 1. With your patch, it's the opposite. Mine should cover both. For ffmpeg 4 support drop, what's the plan, should I address it in this PR as well? |
I think number two is fine with this patch. If the source is cut and frames are inserted in between, then the avdeinterlace link would still see continuous frames because the "in between" frames would never reach it. In fact, I think we have the opposite problem right now - using the playlist frame continuity can cause the link to reset when it is not necessary. Can you test it? |
|
I see what you mean. I pushed a corrected version of your idea, lmk what you think |
I think we have landed on a good solution. Thank you for your collaboration. I have a PR here that should fix the build error. Maybe you can rebase on it. Or just cherry pick it into this PR. |
There was a problem hiding this comment.
🟡 Changes recommended
The implementation drops timeline-discontinuity detection instead of tracking both timeline and source continuity as described.
1 open finding
What changed in this PR
Updates avdeinterlace buffering to detect source-position discontinuities and prevent stale look-ahead frames.
Changes:
- Tracks continuity using original source positions.
- Adds regression coverage for repeated source cuts.
- Guards AVFrame cleanup when filter data is unavailable.
| File | Description |
|---|---|
src/modules/avformat/link_avdeinterlace.c |
Revises buffering continuity and cleanup logic. |
src/tests/test_mod_avformat/test_mod_avformat.cpp |
Adds source-discontinuity regression testing. |
🧠 Review effort: Balanced
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
|
This is good to go from my perspective. |

Problem
avdeinterlace detects discontinuities using timeline positions only. Consecutive playlist clips can reuse the same source while restarting its position, without interrupting timeline continuity. YADIF (and likely other interlacer using look-ahead) then returns stale buffered look-ahead content at the cut.
Fix
Track the expected original source position alongside the timeline position. Reset the deinterlacer when either becomes discontinuous.