Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
713ac1e
Introduce frame position and duration types for VFR support
MuhammadBilalKhan267 Oct 25, 2026
3d8c695
Port FlashFilter to frame positions and durations
MuhammadBilalKhan267 Oct 26, 2026
005c1d0
[api] Port ContentDetector to FramePosition
MuhammadBilalKhan267 Oct 27, 2026
75efbc4
[style] Fix ContentDetector formatting
MuhammadBilalKhan267 Oct 27, 2026
a964060
[api] Port AdaptiveDetector to FramePosition
MuhammadBilalKhan267 Oct 27, 2026
0bc3f7c
[api] Port HashDetector to FramePosition
MuhammadBilalKhan267 Oct 27, 2026
7843d4b
[api] Port HistogramDetector to FramePosition
MuhammadBilalKhan267 Oct 27, 2026
d3282b9
[refactor] Remove duplicate minimum check from ThresholdDetector
MuhammadBilalKhan267 Oct 27, 2026
9704a20
[api] Port TransNet V2 to FramePosition
MuhammadBilalKhan267 Oct 27, 2026
a2fc7c0
[style] Format files
MuhammadBilalKhan267 Oct 27, 2026
ed6d674
[api] Port scene management and add timestamp peeking
MuhammadBilalKhan267 Nov 14, 2026
0b6e3c1
Merge main' into fix/569-vfr-inaccurate-frame-nums
MuhammadBilalKhan267 Nov 15, 2026
d1e4404
[api] Port scene exports to FramePosition [skip ci]
MuhammadBilalKhan267 Nov 15, 2026
d9ab513
[api] Port image extraction to FramePosition [skip ci]
MuhammadBilalKhan267 Nov 17, 2026
a38d67a
Merge main into fix/569-vfr-inaccurate-frame-nums. Port FFMETADATA to…
MuhammadBilalKhan267 Nov 17, 2026
ccbd50e
[api] Port CLI to frame positions [skip ci]
MuhammadBilalKhan267 Nov 21, 2026
42911b7
[api] Separate stream metadata and support expanded splits [skip ci]
MuhammadBilalKhan267 Nov 21, 2026
c315b63
[api] Port benchmark and golden cut extraction [skip ci]
MuhammadBilalKhan267 Nov 21, 2026
26e1352
[api] Remove FrameTimecode and its legacy module [skip ci]
MuhammadBilalKhan267 Nov 21, 2026
de3c7e0
[api] Add FramePosition compatibility helpers [skip ci]
MuhammadBilalKhan267 Nov 22, 2026
b10d5e5
Merge upstream/main into VFR branch [skip ci]
MuhammadBilalKhan267 Nov 22, 2026
21a72bc
[tests] Port timecode and NTSC regressions to the new types [skip ci]
MuhammadBilalKhan267 Nov 22, 2026
a8757a4
[tests] Cover FramePosition and FrameDuration contracts [skip ci]
MuhammadBilalKhan267 Nov 22, 2026
9ca4019
[tests] Port video stream tests to FramePosition [skip ci]
MuhammadBilalKhan267 Nov 23, 2026
3e07978
[tests] Port PyAV backend tests to the new timing API [skip ci]
MuhammadBilalKhan267 Nov 24, 2026
1331355
[tests] Port OpenCV backend tests to the new timing API [skip ci]
MuhammadBilalKhan267 Nov 24, 2026
83585d8
[tests] Port concat tests to the new timing API [skip ci]
MuhammadBilalKhan267 Nov 24, 2026
679f0ff
[tests] Port fan-out tests to the new timing API [skip ci]
MuhammadBilalKhan267 Nov 24, 2026
bcd346c
[tests] Port VFR regression tests to FramePosition [skip ci]
MuhammadBilalKhan267 Nov 24, 2026
28c0e23
[tests] Port detector tests to FramePosition [skip ci]
MuhammadBilalKhan267 Nov 24, 2026
bd67b41
[api] Expose frame numbering in detect() [skip ci]
MuhammadBilalKhan267 Nov 24, 2026
ccf8765
[tests] Port threshold detector tests to FramePosition [skip ci]
MuhammadBilalKhan267 Nov 24, 2026
738c47e
[tests] Port SceneManager tests to FramePosition [skip ci]
MuhammadBilalKhan267 Nov 24, 2026
908d311
[tests] Port StatsManager tests to FramePosition [skip ci]
MuhammadBilalKhan267 Nov 24, 2026
13395b2
[tests] Port output tests to FramePosition [skip ci]
MuhammadBilalKhan267 Nov 24, 2026
6738438
[tests] Port CLI tests to FramePosition [skip ci]
MuhammadBilalKhan267 Nov 25, 2026
8353fa3
[api] Port callback examples and remove deprecated modules [skip ci]
MuhammadBilalKhan267 Nov 25, 2026
f3e45bb
[tests] Port release tests to FramePosition and duration API [skip ci]
MuhammadBilalKhan267 Nov 25, 2026
cbacfc4
[tests] Cover CLI numbering and paired CSV loading [skip ci]
MuhammadBilalKhan267 Nov 25, 2026
bc57df9
[bugfix] Handle source end limits consistently in API and CLI [skip ci]
MuhammadBilalKhan267 Nov 25, 2026
a465c4f
[tests] Cover timestamp cutoffs with frame skipping [skip ci]
MuhammadBilalKhan267 Nov 25, 2026
bc6f613
[api] Fix subtraction errors and refresh port documentation [skip ci]
MuhammadBilalKhan267 Nov 25, 2026
64a5959
Merge upstream/main into fix/569-vfr-inaccurate-frame-nums
MuhammadBilalKhan267 Nov 25, 2026
ad86f63
[tests] Fix detector ranges and PNG encoding parameters
MuhammadBilalKhan267 Nov 25, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,9 @@ for i, scene in enumerate(scene_list):
% (
i + 1,
scene[0].get_timecode(),
scene[0].frame_num,
scene[0].frame_number,
scene[1].get_timecode(),
scene[1].frame_num,
scene[1].frame_number,
)
)
```
Expand Down
2 changes: 1 addition & 1 deletion benchmark/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def _run_predictions(
pred_scene_list = detect(str(sample.video_file), detector_cls(), backend=backend)
elapsed = time.time() - start
predictions[sample.video_file] = Prediction(
predicted_cuts=[scene[1].frame_num for scene in pred_scene_list],
predicted_cuts=[scene[1].frame_number for scene in pred_scene_list],
ground_truth=sample.ground_truth,
elapsed=elapsed,
)
Expand Down
5 changes: 2 additions & 3 deletions benchmark/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,7 @@ def _read_tab_separated_cuts(scene_file: str) -> list[Frames]:
"""Parse a BBC/AutoShot-style annotation file.

Each line is tab-separated; the second column is the 0-based frame index of a
hard cut. Returns 1-based frame indices, matching the convention used by
:class:`scenedetect.FrameTimecode`.
hard cut. Returns 1-based frame indices for the benchmark evaluator.
"""
with open(scene_file) as f:
return [int(line.strip().split("\t")[1]) + 1 for line in f]
Expand Down Expand Up @@ -153,7 +152,7 @@ class ClipShotsDataset(Dataset):
Each annotation entry is ``{"transitions": [[start, end], ...], "frame_num": float}``.
Hard cuts are single-frame spans (``end == start + 1``); wider spans are gradual
transitions. Unlike the BBC/AutoShot annotations, ClipShots frame indices already match
PySceneDetect's boundary-frame convention (the prediction's ``frame_num`` lines up with
PySceneDetect's boundary-frame convention (the prediction's ``frame_number`` lines up with
``transition[1]`` directly), so no offset is applied here.

Loading rules:
Expand Down
3 changes: 1 addition & 2 deletions benchmark/evaluator.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@
from statistics import mean
from typing import TypeAlias

# 1-based frame number, matching the convention used by the BBC/AutoShot text annotations and by
# PySceneDetect's :class:`FrameTimecode`. Used for cut positions and for tolerance windows.
# 1-based frame number used by the benchmark evaluator for cut positions and tolerance windows.
#
# Ironically, all the work we did in v0.7 to support VFR is meaningless for most existing benchmarks
# since they are all CFR. In the future we should consider extending the API to support temporal
Expand Down
2 changes: 1 addition & 1 deletion benchmark/sweep.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ def worker(i: int, params: dict[str, Any]) -> None:
t0 = time.time()
sm.detect_scenes(video=stream)
elapsed = time.time() - t0
cuts = [scene[1].frame_num for scene in sm.get_scene_list()]
cuts = [scene[1].frame_number for scene in sm.get_scene_list()]
results[i] = (cuts, elapsed)
except BaseException as exc:
errors[i] = exc
Expand Down
10 changes: 5 additions & 5 deletions docs/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

The ``scenedetect`` API integrates into Python applications and supports custom detectors and video backends. See `Usage`_ below for common examples. The ``scenedetect`` package is organized into these submodules:

* :ref:`Functions <scenedetect-functions>`: high-level functions such as :func:`scenedetect.detect() <scenedetect.detect>` to analyze a video with any :ref:`detector <scenedetect-detectors>` (:ref:`example <scenedetect-usage>`) and return a list of timecode pairs
* :ref:`Functions <scenedetect-functions>`: high-level functions such as :func:`scenedetect.detect() <scenedetect.detect>` to analyze a video with any :ref:`detector <scenedetect-detectors>` (:ref:`example <scenedetect-usage>`) and return a list of frame position pairs

* :doc:`api/detectors`: built-in detectors:

Expand Down Expand Up @@ -39,7 +39,7 @@ The ``scenedetect`` API integrates into Python applications and supports custom

* Multiple videos can be read as one continuous stream with :class:`VideoStreamConcat <scenedetect.backends.concat.VideoStreamConcat>` (for example, ``open_video(["part1.mp4", "part2.mp4"])``)

* :doc:`api/common`: common types such as :class:`FrameTimecode <scenedetect.common.FrameTimecode>` for timecode handling
* :doc:`api/common`: common types such as :class:`FramePosition <scenedetect.common.FramePosition>`, :class:`FrameDuration <scenedetect.common.FrameDuration>`, and :class:`Timecode <scenedetect.common.Timecode>` for frame positions and timing

* :doc:`api/scene_manager`: :class:`SceneManager <scenedetect.scene_manager.SceneManager>` runs scene detection on a video with one or more detectors

Expand All @@ -58,9 +58,9 @@ Most common types and functions can be imported directly from the top-level ``sc

The PySceneDetect API may change before v1.0. Pin ``scenedetect`` to a minor release in your dependencies:

.. code:: python
.. code:: text

scenedetect~=0.7.0
scenedetect~=0.8.0


.. _scenedetect-usage:
Expand All @@ -78,7 +78,7 @@ Find scene cuts in a video with :func:`scenedetect.detect`:
for (scene_start, scene_end) in scenes:
print(f"{scene_start}-{scene_end}")

``scenes`` is a list of :class:`FrameTimecode <scenedetect.common.FrameTimecode>` pairs giving the start and end of each scene. Pass ``show_progress=True`` to :func:`detect <scenedetect.detect>` to show a progress bar with estimated time remaining.
``scenes`` is a list of :class:`FramePosition <scenedetect.common.FramePosition>` pairs giving the start and exclusive end of each scene. Pass ``show_progress=True`` to :func:`detect <scenedetect.detect>` to show a progress bar with estimated time remaining.

This example uses :class:`ContentDetector <scenedetect.detectors.content_detector.ContentDetector>` to find fast cuts. You can choose from several :ref:`detectors <scenedetect-detectors>` for fast cuts and fades. PySceneDetect can also export scene lists in several formats and :ref:`split the input video <scenedetect-output>` when ``ffmpeg`` is installed:

Expand Down
9 changes: 7 additions & 2 deletions docs/api/common.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,17 @@ Common
Timecodes
---------

.. autoclass:: scenedetect.common.FrameTimecode
.. autoclass:: scenedetect.common.FramePosition
:members:

.. autoclass:: scenedetect.common.FrameDuration
:members:

.. autoclass:: scenedetect.common.Timecode
:members:

.. autofunction:: scenedetect.common.parse_frame_or_time

.. autofunction:: scenedetect.common.framerate_to_fraction


Expand All @@ -30,7 +35,7 @@ Type Aliases

.. autodata:: scenedetect.common.CutList

.. autodata:: scenedetect.common.TimecodePair
.. autodata:: scenedetect.common.PositionPair

.. autodata:: scenedetect.common.TimecodeLike

Expand Down
136 changes: 136 additions & 0 deletions docs/api/migration_guide.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,142 @@

.. _scenedetect-migration-guide:

----------------------
Migration Guide (v0.8)
----------------------

Version 0.8 separates frame ordinals from presentation timestamps. This avoids deriving VFR
frame numbers from an approximate frame rate. The guide below covers migration from v0.7;
the earlier v0.6-to-v0.7 guide follows for reference.

Positions, timestamps, and durations
------------------------------------

``FrameTimecode`` has been removed. Use these types from ``scenedetect`` or
``scenedetect.common``:

- :class:`~scenedetect.common.FramePosition` identifies a frame with ``frame_number`` and
``timecode``. Scene lists, detector results, callbacks, and ``VideoStream.position`` use this type.
- :class:`~scenedetect.common.Timecode` stores ``pts`` and ``time_base``. Its ``seconds`` property
returns their exact product as a :class:`fractions.Fraction`. The timestamp's accuracy still
depends on the backend and source.
- :class:`~scenedetect.common.FrameDuration` stores a difference as ``frames`` and ``elapsed``
seconds. Subtract two positions from the same stream and numbering sequence to obtain one.

A position does not contain a frame rate. Do not calculate its frame number from its timestamp:
VFR frames can have different presentation intervals.

.. code:: python

from scenedetect import ContentDetector, detect

scenes = detect("video.mp4", ContentDetector())
for start, end in scenes:
duration = end - start
print(start.frame_number, start.timecode.get_timecode())
print(duration.frames, float(duration.elapsed))

Update accesses as follows:

.. list-table::
:header-rows: 1
:widths: 45 55

* - Previous access
- Current access
* - ``position.frame_num``
- ``position.frame_number``
* - ``position.seconds``
- ``position.timecode.seconds`` for exact seconds
* - ``position.get_timecode()``
- Still supported; forwards to ``position.timecode.get_timecode()``
* - ``position.get_frames()``
- Still supported; returns ``position.frame_number``
* - ``position.get_seconds()``
- Still supported; returns seconds as ``float``

``FramePosition.seconds`` also remains a ``float`` convenience property. ``pts`` and
``time_base`` forward to its ``Timecode``, and ``str(position)`` formats that timestamp.
``frame_num`` is a deprecated alias and emits ``DeprecationWarning``. Position ordering uses
``frame_number`` within one numbering sequence; equality compares both fields. The old
``FrameTimecode(value, fps)`` constructor and its frame-rate-based arithmetic have no replacement
on ``FramePosition``.

Frame numbering and seeks
-------------------------

``detect()``, ``open_video()``, and backend constructors accept ``frame_numbering``:

- ``FrameNumbering.RELATIVE`` is the default. After a successful seek, the next frame read has
ordinal 0. Its timestamp remains on the source timeline.
- ``FrameNumbering.SOURCE`` counts ordinals from the source beginning. Reaching a seek target can
require decoding the preceding frames.

Integer ``VideoStream.seek()`` targets are zero-based **source** ordinals in both modes.
For example, ``seek(200)`` makes the next read return source frame 200, labelled 0 in RELATIVE
mode or 200 in SOURCE mode. Seconds and timecode targets select the first frame encountered at
or after the requested time. Position ordering does not establish an order across separate
RELATIVE seek sequences.

Before a frame is recorded, ``video.position`` is ``None`` and ``video.frame_number`` is -1.
SOURCE seeks can record preceding frames while seeking. ``peek_timecode()`` returns the next
frame's timestamp without advancing the recorded position.

The high-level ``detect(start_time=..., end_time=...)`` uses source coordinates for both limits.
A timestamp start with an integer end requires SOURCE numbering. When using ``SceneManager``
directly after a seek, integer ``end_time`` values use the stream's current numbering sequence.
The CLI exposes the numbering choice as ``--frame-numbering relative`` or
``--frame-numbering source``.

Frame-or-time inputs
--------------------

``TimecodeLike`` now accepts ``int``, ``float``, ``str``, or ``Timecode``.
:func:`~scenedetect.common.parse_frame_or_time` preserves the input unit instead of converting
through a frame rate:

- Integers and digit-only strings, such as ``15`` and ``"15"``, denote frames.
- Floats, decimal strings, strings ending in ``s``, and clock strings denote seconds.
- ``Timecode`` inputs use their exact ``pts * time_base`` value.

The parser returns ``int`` for frames or ``Fraction`` for seconds. A bare ``Fraction`` is not a
``TimecodeLike`` input; wrap exact seconds in ``Timecode`` when passing them to these APIs.

Stream metadata and custom integrations
---------------------------------------

``VideoStream.duration`` now returns source duration in seconds as ``Fraction | None``.
Use ``VideoStream.frame_count`` for the reported total frame count, as ``int | None``.
Both describe the source independently of the numbering origin. Metadata may be inaccurate
and may be revised during decoding. ``VideoStream.base_timecode`` has been removed.

Custom detectors now receive ``position: FramePosition`` in ``process_frame()`` and
``post_process()``, and return ``list[FramePosition]``. ``post_process()`` receives the last
position read. Update callback annotations and any code that constructs cuts to use positions
with both an ordinal and timestamp. ``TimecodePair`` has been replaced by ``PositionPair``.

Construct ``StatsManager()`` without a base timecode. ``get_metrics()``, ``set_metrics()``, and
``metrics_exist()`` accept an integer frame number or ``FramePosition``. Use a position with
``set_metrics()`` to retain its timestamp for CSV export; integer-only entries have a blank
timecode column.

The deprecated ``scenedetect.frame_timecode``, ``scenedetect.scene_detector``, and
``scenedetect.video_splitter`` modules have been removed. Import detector classes from
``scenedetect.detector`` and output functions from ``scenedetect.output``, or use their
existing top-level ``scenedetect`` exports.

Loading scene CSV files
-----------------------

``load-scenes`` now requires paired frame numbers and timestamps for both scene boundaries.
The default columns are ``Start Frame``, ``Start Time (seconds)``, ``End Frame``, and
``End Time (seconds)``, matching the scene-list CSV writer. For custom headers, use
``--start-frame-col-name``, ``--start-time-col-name``, ``--end-frame-col-name``, and
``--end-time-col-name``. The old single ``--start-col-name`` option has been removed.
The loader reads the saved pairs without scanning the video or inferring ordinals from FPS.
Requested time limits must retain complete saved scenes; a limit inside a saved scene is rejected.


----------------------
Migration Guide (v0.7)
----------------------
Expand Down
41 changes: 35 additions & 6 deletions docs/cli.rst
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,12 @@ Options

Override frame rate with value as frames/sec.

.. option:: --frame-numbering

Relative restarts frame numbering at 0 after a seek. Source counts frames from the beginning of the video.

Default: ``relative``

.. option:: -m TIMECODE, --min-scene-len TIMECODE

Minimum length of any scene. TIMECODE can be specified as number of frames (-m 10), time in seconds (-m 2.5), or timecode (-m 00:02:53.633).
Expand Down Expand Up @@ -151,6 +157,9 @@ Global options, their config file keys, and their Python API counterparts.
* - :option:`-f/--frame-rate <scenedetect -f>`
-
- :func:`~scenedetect.open_video` (``frame_rate``)
* - :option:`--frame-numbering <scenedetect --frame-numbering>`
- :ref:`[global] frame-numbering <config-global>`
- :attr:`~scenedetect.video_stream.VideoStream.frame_numbering`
* - :option:`-m/--min-scene-len <scenedetect -m>`
- :ref:`[global] min-scene-len <config-global>`
- :ref:`Detector <scenedetect-detectors>` argument ``min_scene_len``
Expand Down Expand Up @@ -563,7 +572,9 @@ Options

.. seealso:: **Python API:** *none (CLI only)* | **Config File:** :ref:`[load-scenes] <config-load-scenes>`

Load scenes from CSV instead of detecting. Can be used with CSV generated by :ref:`list-scenes <command-list-scenes>`. Scenes are loaded using the specified column as cut locations (frame number or timecode).
Load saved scene ranges from CSV instead of detecting. Requires start/end frame and time columns, defaulting to those written by :ref:`list-scenes <command-list-scenes>`.

Time limits select complete saved scenes. Limits inside a saved scene are rejected.


Examples
Expand All @@ -572,7 +583,7 @@ Examples

``scenedetect -i video.mp4 load-scenes -i scenes.csv``

``scenedetect -i video.mp4 load-scenes -i scenes.csv --start-col-name "Start Timecode"``
``scenedetect -i video.mp4 load-scenes -i scenes.csv --start-time-col-name "Start Timecode" --end-time-col-name "End Timecode"``


Options
Expand All @@ -583,12 +594,30 @@ Options

Scene list to read cut information from.

.. option:: -c STRING, --start-col-name STRING
.. option:: --start-frame-col-name

Name of column used to mark scene cuts.
Column containing one-based scene start frames.

Default: ``"Start Frame"``

.. option:: --start-time-col-name

Column containing scene start times.

Default: ``"Start Time (seconds)"``

.. option:: --end-frame-col-name

Column containing exclusive scene end ordinals.

Default: ``"End Frame"``

.. option:: --end-time-col-name

Column containing scene end times.

Default: ``"End Time (seconds)"``


.. _command-save-chapters:

Expand Down Expand Up @@ -874,7 +903,7 @@ Options

Save detected cuts using keyframe format v1.

Frame numbers are currently approximate for variable framerate (VFR) video.
Frame numbers zero-based.


Options
Expand Down Expand Up @@ -1053,7 +1082,7 @@ Options

.. option:: --expand

Extend the first/last output clips to cover the full input video, even if `time -s/-e` limited the analysis window. Useful for keeping content outside the analyzed region attached to the adjacent split.
Extend the first/last output clips to cover the full input video, even if `time -s/-e` limited the analysis window. Useful for keeping content outside the analyzed region attached to the adjacent split. Expanded filename boundary variables use zero for the first start and a blank last end.


.. _command-time:
Expand Down
Loading
Loading