Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 2 additions & 0 deletions docs/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ The ``scenedetect`` API integrates into Python applications and supports custom

* :class:`HistogramDetector <scenedetect.detectors.histogram_detector.HistogramDetector>`: finds fast cuts using Y-channel (brightness) histogram changes in YUV

* :class:`SolidColorDetector <scenedetect.detectors.solid_color_detector.SolidColorDetector>`: reports the start and end of solid-color intervals

* :class:`ThresholdDetector <scenedetect.detectors.threshold_detector.ThresholdDetector>`: finds fades in and out using average RGB pixel brightness

* :doc:`api/output`: output helpers:
Expand Down
33 changes: 32 additions & 1 deletion docs/api/detectors.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Detectors

.. automodule:: scenedetect.detectors

.. seealso:: Each detector is also available as a ``detect-*`` command; see the ``detect-*`` commands in the :ref:`CLI reference <cli-detectors>`. The :option:`-m/--min-scene-len <scenedetect -m>` option sets ``min_scene_len`` for every detector.
.. seealso:: Scene cut detectors are available as ``detect-*`` commands in the :ref:`CLI reference <cli-detectors>`. The :option:`-m/--min-scene-len <scenedetect -m>` option sets their minimum scene length. Use :ref:`list-solid <command-list-solid>` to locate runs of solid-color frames.

.. note::

Expand Down Expand Up @@ -72,6 +72,37 @@ HistogramDetector
.. autoclass:: scenedetect.detectors.histogram_detector.HistogramDetector
:members:

SolidColorDetector
------------------

.. seealso:: **Command Line:** :ref:`list-solid <command-list-solid>` | **Config File:** :ref:`[list-solid] <config-list-solid>`

For example, to find solid-color sections lasting at least five frames:

.. code-block:: python

from scenedetect import SceneManager, open_video
from scenedetect.detectors import SolidColorDetector

detector = SolidColorDetector(min_frames=5)
manager = SceneManager()
manager.add_detector(detector)
with open_video("recording.mp4") as video:
manager.detect_scenes(video=video)
for start, end in detector.get_intervals():
print(start.get_timecode(), end.get_timecode(), (end - start).seconds)

The end time is exclusive. Adjacent solid frames belong to the same interval even
if their colors differ. Use a lower threshold to distinguish low-contrast detail
from a blank screen. To preserve fine detail during analysis, set
``manager.auto_downscale = False`` and ``manager.downscale = 1`` before detection.
On variable-frame-rate input, use timecodes for boundaries. The scene CSV's frame
numbers use the nominal frame rate. A run ending at the last observed frame uses
one nominal frame duration to estimate its exclusive end.

.. autoclass:: scenedetect.detectors.solid_color_detector.SolidColorDetector
:members:

ThresholdDetector
-----------------

Expand Down
47 changes: 47 additions & 0 deletions docs/cli.rst
Original file line number Diff line number Diff line change
Expand Up @@ -552,6 +552,53 @@ Options
Skip cutting list as first row in the CSV file. Set for RFC 4180 compliant output.


.. _command-list-solid:

.. program:: scenedetect list-solid


``list-solid``
------------------------------------------------------------------------


.. seealso:: **Python API:** :class:`~scenedetect.detectors.solid_color_detector.SolidColorDetector` | **Config File:** :ref:`[list-solid] <config-list-solid>`

Save solid-color frame intervals to CSV without changing scene cuts.

``Intervals use the standard scene CSV columns and source-video timecodes. Combine with``
``scene output commands to generate both reports in one detection pass.``

``Classification uses frames after global cropping and resizing. Use --downscale 1 before``
``this command to preserve small image details that downscaling can remove.``


Options
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^


.. option:: -f NAME, --filename NAME

Filename format to use. Supports $VIDEO_NAME.

Default: ``$VIDEO_NAME-Solid.csv``

.. option:: -o DIR, --output DIR

Output directory. Overrides global :option:`-o/--output <-o>`.

.. option:: --threshold

Maximum per-channel spatial standard deviation for a solid-color frame.

Default: ``2.0``

.. option:: --min-frames

Minimum number of consecutive solid-color frames to report.

Default: ``2``


.. _command-load-scenes:

.. program:: scenedetect load-scenes
Expand Down
41 changes: 41 additions & 0 deletions docs/cli/config_sections.inc
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,47 @@ Options of :ref:`list-scenes <command-list-scenes>` (Python API: :func:`~scenede
# Overrides `display-scenes` and `display-cuts`.
#quiet = no

.. _config-list-solid:

[list-solid]
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Options of :ref:`list-solid <command-list-solid>` (Python API: :class:`~scenedetect.detectors.solid_color_detector.SolidColorDetector`).

.. list-table::
:class: config-keys
:header-rows: 1
:widths: 28 32 40

* - Key
- Default
- CLI option
* - ``threshold``
- ``2.0``
- :option:`--threshold <scenedetect list-solid --threshold>`
* - ``min-frames``
- ``2``
- :option:`--min-frames <scenedetect list-solid --min-frames>`
* - ``filename``
- ``$VIDEO_NAME-Solid.csv``
- :option:`-f/--filename <scenedetect list-solid -f>`
* - ``output``
- *none*
- :option:`-o/--output <scenedetect list-solid -o>`

.. code-block:: ini

[list-solid]
# Maximum standard deviation in each color channel, in 8-bit pixel values.
#threshold = 2.0

# Ignore runs shorter than this many consecutive frames.
#min-frames = 2

# CSV filename and folder. The folder defaults to the global output directory.
#filename = $VIDEO_NAME-Solid.csv
#output = /usr/tmp/reports

.. _config-load-scenes:

[load-scenes]
Expand Down
1 change: 1 addition & 0 deletions docs/cli_index.inc
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
- **Scene Lists & Exports**

- :ref:`list-scenes <command-list-scenes>`
- :ref:`list-solid <command-list-solid>`
- :ref:`save-html <command-save-html>`
- :ref:`save-edl <command-save-edl>`
- :ref:`save-fcp <command-save-fcp>`
Expand Down
6 changes: 6 additions & 0 deletions docs/generate_cli_docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,11 @@ class Counterpart:
command="list-scenes",
api=(f":func:`~{_OUT}.write_scene_list`",),
),
Counterpart(
"Solid-color intervals (CSV)",
command="list-solid",
api=(f":class:`~{_DET}.solid_color_detector.SolidColorDetector`",),
),
Counterpart(
"Scene list (HTML)",
command="save-html",
Expand Down Expand Up @@ -824,6 +829,7 @@ def create_help(ctx: click.Context, commands: list[str]) -> str:
"Scene Lists & Exports",
(
"list-scenes",
"list-solid",
"save-html",
"save-edl",
"save-fcp",
Expand Down
12 changes: 12 additions & 0 deletions scenedetect.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,18 @@
#quiet = no


[list-solid]
# Maximum standard deviation in each color channel, in 8-bit pixel values.
#threshold = 2.0

# Ignore runs shorter than this many consecutive frames.
#min-frames = 2

# CSV filename and folder. The folder defaults to the global output directory.
#filename = $VIDEO_NAME-Solid.csv
#output = /usr/tmp/reports


[load-scenes]
# Name of column used to mark scene cut points.
#start-col-name = Start Frame
Expand Down
83 changes: 83 additions & 0 deletions scenedetect/_cli/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
ContentDetector,
HashDetector,
HistogramDetector,
SolidColorDetector,
ThresholdDetector,
)
from scenedetect.platform import get_cv2_imwrite_params, get_system_version_info
Expand Down Expand Up @@ -1022,6 +1023,8 @@ def load_scenes_command(ctx: click.Context, input: str | None, start_col_name: s
assert isinstance(ctx, CliContext)

check_not_stdin(ctx, "load-scenes")
if ctx.solid_detector is not None:
raise click.ClickException("The list-solid command cannot be used with load-scenes.")
logger.debug("Will load scenes from %s (start_col_name = %s)", input, start_col_name)
assert ctx.scene_manager is not None
if ctx.scene_manager.get_num_detectors() > 0:
Expand Down Expand Up @@ -1142,6 +1145,85 @@ def save_html_command(
"""


@click.command("list-solid", cls=Command)
@click.option(
"--filename",
"-f",
metavar="NAME",
type=click.STRING,
default=None,
help="Filename format to use. Supports $VIDEO_NAME.{}".format(
USER_CONFIG.get_help_string("list-solid", "filename")
),
)
@click.option(
"--output",
"-o",
metavar="DIR",
type=click.Path(exists=False, dir_okay=True, writable=True, resolve_path=False),
help="Output directory. Overrides global -o/--output.{}".format(
USER_CONFIG.get_help_string("list-solid", "output", show_default=False)
),
)
@click.option(
"--threshold",
type=_click_range("list-solid", "threshold"),
default=None,
help="Maximum per-channel spatial standard deviation for a solid-color frame.{}".format(
USER_CONFIG.get_help_string("list-solid", "threshold")
),
)
@click.option(
"--min-frames",
type=_click_range("list-solid", "min-frames"),
default=None,
help="Minimum number of consecutive solid-color frames to report.{}".format(
USER_CONFIG.get_help_string("list-solid", "min-frames")
),
)
@click.pass_context
def list_solid_command(
ctx: click.Context,
filename: str | None,
output: str | None,
threshold: float | None,
min_frames: int | None,
):
"""Save solid-color frame intervals to CSV without changing scene cuts.

Intervals use the standard scene CSV columns and source-video timecodes. Combine with
scene output commands to generate both reports in one detection pass.

Classification uses frames after global cropping and resizing. Use --downscale 1 before
this command to preserve small image details that downscaling can remove.
"""
ctx = ctx.obj
assert isinstance(ctx, CliContext)
if ctx.solid_detector is not None:
raise click.ClickException("The list-solid command must only be specified once.")
if ctx.load_scenes_input:
raise click.ClickException("The list-solid command cannot be used with load-scenes.")
if ctx.frame_skip:
raise click.ClickException("The list-solid command cannot be used with --frame-skip.")
assert ctx.scene_manager is not None
try:
ctx.solid_detector = SolidColorDetector(
threshold=ctx.config.get_value("list-solid", "threshold", threshold),
min_frames=ctx.config.get_value("list-solid", "min-frames", min_frames),
)
except ValueError as ex:
raise click.BadParameter(str(ex), param_hint="list-solid") from ex
ctx.scene_manager.add_detector(ctx.solid_detector)
ctx.add_command(
cli_commands.list_solid,
{
"filename": ctx.config.get_value("list-solid", "filename", filename),
"output": ctx.config.get_value("list-solid", "output", output),
},
requires_scenes=False,
)


@click.command("list-scenes", cls=Command, help=LIST_SCENES_HELP)
@click.option(
"--output",
Expand Down Expand Up @@ -2082,6 +2164,7 @@ def save_otio_command(

# Output
scenedetect.add_command(list_scenes_command)
scenedetect.add_command(list_solid_command)
scenedetect.add_command(save_chapters_command)
scenedetect.add_command(save_edl_command)
scenedetect.add_command(save_html_command)
Expand Down
24 changes: 24 additions & 0 deletions scenedetect/_cli/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,30 @@ def save_keyframes(
logger.info(f"Keyframes written to: {keyframes_path}")


def list_solid(
context: CliContext,
scenes: SceneList,
cuts: CutList,
filename: str,
output: str | None,
):
"""Write solid-color intervals using the standard scene CSV columns."""
del scenes, cuts
assert context.video_stream is not None
assert context.solid_detector is not None
filename = Template(filename).safe_substitute(VIDEO_NAME=context.video_stream.name)
if not filename.lower().endswith(".csv"):
filename += ".csv"
path = get_and_create_path(filename, output)
logger.info("Writing solid-color intervals to CSV file:\n %s", path)
with open(path, "w", newline="") as report:
write_scene_list(
output_csv_file=report,
scene_list=context.solid_detector.get_intervals(),
include_cut_list=False,
)


def list_scenes(
context: CliContext,
scenes: SceneList,
Expand Down
6 changes: 6 additions & 0 deletions scenedetect/_cli/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,12 @@ def default_to_str(value: ConfigValue) -> str:
"load-scenes": {
"start-col-name": "Start Frame",
},
"list-solid": {
"filename": "$VIDEO_NAME-Solid.csv",
"output": None,
"threshold": RangeValue(2.0, min_val=0.0, max_val=127.5),
"min-frames": RangeValue(2, min_val=1, max_val=None),
},
"list-scenes": {
"cut-format": TimecodeFormat.TIMECODE,
"col-separator": EscapedChar(","),
Expand Down
Loading