Skip to content

Keep cuts exactly min_scene_len frames apart at 29.97 and 59.94 fps - #578

Merged
Breakthrough merged 3 commits into
Breakthrough:mainfrom
theluckystrike:fix/577-ntsc-min-scene-len
Oct 12, 2026
Merged

Breakthrough merged 3 commits into
Breakthrough:mainfrom
theluckystrike:fix/577-ntsc-min-scene-len

Conversation

@theluckystrike

Copy link
Copy Markdown
Contributor

Fixes #577

ContentDetector dropped a cut that sat exactly min_scene_len frames after the previous one on 29.97 and 59.94 fps video. Since 0.7 FlashFilter works in time units, so an integer frame length is turned into seconds with length divided by float(frame_rate). For NTSC rates that float isn't exact and the threshold lands a hair above the true gap, so an exact N frame gap fails the check and the cut is lost.

When the length is given in frames, FlashFilter now compares frame counts directly, through the same integer path of FrameTimecode that the other detectors already use. Lengths given in seconds behave exactly as before.

This also covers the smaller OpenCV form from the issue. There, positions are rounded to whole microseconds, so a gap can come out 1 microsecond short of N divided by fps. Comparing frame counts doesn't care about that rounding.

The new tests feed FlashFilter positions the way PyAV reports them (exact PTS) and the way OpenCV reports them (rounded microseconds), at 30000/1001 and 60000/1001, in merge and suppress mode, with no video file. One case is min_scene_len=17 at 29.97 from the issue. 8 of the 10 fail without the change and all pass with it, and tests/test_detectors.py passes too. ruff check and ruff format are clean on both files.

The PyAV backend tests fail on my machine with PyAV 19, from an AVRational conversion in common.py. They fail the same way without this change.

Michael

@Breakthrough
Breakthrough force-pushed the fix/577-ntsc-min-scene-len branch from 49746d2 to b3770ce Compare October 10, 2026 01:30

@Breakthrough Breakthrough left a comment •

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the fix. A few small things need to be addressed before we can land this:

  1. _filter_secs is still computed from length / float(frame_rate) in both filter methods, even when it is never used for the comparison when _filter_length > 0. Let's just skip it in this case.
  2. Please add a [bugfix] entry under the 0.7.2 section at the bottom of website/pages/changelog.md referencing
    #577.
  3. I'd prefer the new tests live in test_detectors.py, or next to the existing FlashFilter tests in
    test_timecode.py) rather than a new file.

As you noted, the PyAV 19 failures are unrelated - those should be fixed on main now.

Thanks for the PR!

Skip the unused seconds conversion when min_scene_len is given in frames,
move the FlashFilter NTSC tests into test_timecode.py, and add a changelog
entry.
@theluckystrike

Copy link
Copy Markdown
Contributor Author

Thanks for the review. All three points are done in 4de3571. The seconds conversion is skipped when the length is in frames, the changelog has a [bugfix] entry for #577, and the tests now sit next to the FlashFilter test in test_timecode.py. There's also an assert that clears the pyright error in check_format.

…ene-len

# Conflicts:
#	website/pages/changelog.md
@Breakthrough Breakthrough added this to the 0.7.2 milestone Oct 11, 2026
@Breakthrough
Breakthrough self-requested a review October 12, 2026 01:53

@Breakthrough Breakthrough left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR.

@Breakthrough
Breakthrough merged commit a20c991 into Breakthrough:main Oct 12, 2026
27 checks passed
@theluckystrike

theluckystrike commented Oct 12, 2026 via email •

Copy link
Copy Markdown
Contributor Author

@Breakthrough Breakthrough mentioned this pull request Oct 12, 2026
17 of 39 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ContentDetector drops cuts exactly min_scene_len frames apart on 29.97/59.94 fps video (regression in 0.7)

2 participants