Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Scene Detection frames mismatch causes invalid frame access crashes #927

Merged

Conversation

BoatsMcGee
Copy link
Contributor

Scene Detection currently uses FFmpeg, even when the chunking method used later encodes the video with a VapourSynth script. This leads to a mismatch in the frame count and crashes on the offending chunk. Scene Detection should instead use the same decoding method as Av1an does when encoding chunks in order to avoid this mismatch.

Additionally, when testing this fix I discovered a race condition that fails scene detection when retrieving the frame count in a thread. I don't fully understand why this occurs but moving the resolution of that thread before scene detection starts resolves that race condition.

This issue can be replicated by improperly cutting a lossless clip and using that as the input while specifying a chunking method that generates/uses a VapourSynth script.

As a workaround, users can instead input a VapourSynth script instead of the clip itself and the Scene Detection should perform the same function as this PR.

Thank you,
- Boats M.

Boats McGee added 2 commits February 24, 2025 10:42
Fix Scene Detection uses incompatible decode method leading to accessing invalid frames
Copy link
Collaborator

@shssoichiro shssoichiro left a comment

Choose a reason for hiding this comment

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

Thank you, this seems like it makes sense. This will need a rebase after #923 is merged to fix the CI, but other than that it looks good.

@master-of-zen master-of-zen merged commit f88cc27 into master-of-zen:master Mar 3, 2025
4 of 5 checks passed
Khaoklong51 pushed a commit to Khaoklong51/Av1an that referenced this pull request Mar 3, 2025
…es (master-of-zen#927)

* Fix frame count mismatch between FFmpeg and VapourSynth
Fix Scene Detection uses incompatible decode method leading to accessing invalid frames

* Fix race condition in Scene Detection causes End of File Error

---------

Co-authored-by: Boats McGee <{ID}+{username}@users.noreply.github.com>
@BoatsMcGee BoatsMcGee deleted the total-frames-mismatch branch March 3, 2025 17:04
Khaoklong51 pushed a commit to Khaoklong51/Av1an that referenced this pull request Mar 4, 2025
…es (master-of-zen#927)

* Fix frame count mismatch between FFmpeg and VapourSynth
Fix Scene Detection uses incompatible decode method leading to accessing invalid frames

* Fix race condition in Scene Detection causes End of File Error

---------

Co-authored-by: Boats McGee <{ID}+{username}@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants