Repository navigation
[backends] Remove genpts option from fflags in PyAV backend #590 - #592
Open
Breakthrough wants to merge 1 commit into
Open
Breakthrough wants to merge 1 commit into
Breakthrough wants to merge 1 commit into
Conversation
Breakthrough
force-pushed
the
issue-590-pyav-genpts-fix
branch
2 times, most recently
from
October 26, 2026 02:31
c143ffd to
fdb87ce
Compare
PyAV sets `AVFMT_FLAG_GENPTS` on every input (see PyAV-Org/PyAV#2477 / PyAV-Org/PyAV#2478). On containers that store DTS only (AVI, MPEG-TS) and contain B-frames, or streams that have no timestamps at all, the generated PTS can come out in the incorrect decode order. This was causing the PyAV backend to report non-monotonic timestamps in these cases, resulting in incorrect splits (#590). This PR now ensures we set `fflags=-genpts` to override the `+genpts` flag from PyAV. We also fallback from PTS to DTS, and count frames when there are no timestamps entirely. We also add support for when PyAV exposes `Frame.best_effort_timestamp` in a future release (tested locally with the development changes linked above). Lastly, a one-time warning is logged if timestamps are detected going backwards. Users hitting this issue should update PyAV to 19.1+ to resolve it. We cannot pin to PyAV 19.1+ because it requires Python 3.12, but `scenedetect` supports 3.10+ and 3.11 is supported until October 2027. Follow-ups kept as TODOs: - AVI tick rate and frame counts in `_get_duration` - MPEG-TS seeks that land after the target position
Breakthrough
force-pushed
the
issue-590-pyav-genpts-fix
branch
from
October 27, 2026 00:01
fdb87ce to
8a0991e
Compare
| import pytest | ||
|
|
||
| from scenedetect.backends.pyav import MAX_CONSECUTIVE_DECODE_FAILURES, VideoStreamAv, _to_fraction | ||
| import scenedetect.backends.pyav as pyav_backend |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PyAV sets
AVFMT_FLAG_GENPTSon every input (see PyAV-Org/PyAV#2477 / PyAV-Org/PyAV#2478).On containers that store DTS only (AVI, MPEG-TS) and contain B-frames, or streams that have no
timestamps at all, the generated PTS can come out in the incorrect decode order. This was
causing the PyAV backend to report non-monotonic timestamps in these cases, resulting in
incorrect splits (#590).
This PR now ensures we set
fflags=-genptsto override the+genptsflag from PyAV. We alsofallback from PTS to DTS, and count frames when there are no timestamps entirely. We also add
support for when PyAV exposes
Frame.best_effort_timestampin a future release (tested locallywith the development changes linked above). Lastly, a one-time warning is logged if timestamps
are detected going backwards. Users hitting this issue should update PyAV to 19.1+ to resolve it.
We cannot pin to PyAV 19.1+ because it requires Python 3.12, but
scenedetectsupports 3.10+and 3.11 is supported until October 2027.
Follow-ups kept as TODOs:
_get_duration