Skip to content

Commit f1703c2

Browse files
committed
[cli] Add new temporal-margin option + flag to save-images
1 parent edddcbe commit f1703c2

File tree

3 files changed

+25
-2
lines changed

3 files changed

+25
-2
lines changed

scenedetect/_cli/__init__.py

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
)
3939
from scenedetect._cli.context import USER_CONFIG, CliContext, check_split_video_requirements
4040
from scenedetect.backends import AVAILABLE_BACKENDS
41+
from scenedetect.common import FrameTimecode
4142
from scenedetect.detectors import (
4243
AdaptiveDetector,
4344
ContentDetector,
@@ -1400,8 +1401,17 @@ def split_video_command(
14001401
metavar="N",
14011402
default=None,
14021403
type=click.INT,
1403-
help="Number of frames to ignore at beginning/end of scenes when saving images. Controls temporal padding on scene boundaries.%s"
1404-
% (USER_CONFIG.get_help_string("save-images", "num-images")),
1404+
help="[DEPRECATED] Use --temporal-margin instead. Number of frames to ignore at beginning/end of scenes when saving images.%s"
1405+
% (USER_CONFIG.get_help_string("save-images", "frame-margin")),
1406+
)
1407+
@click.option(
1408+
"-M",
1409+
"--temporal-margin",
1410+
metavar="TIME",
1411+
default=None,
1412+
type=click.STRING,
1413+
help="Amount of time to ignore at the beginning/end of each scene. Discards frame-margin if set. Can be specified as seconds (0.1), frames (3), or timecode (00:00:00.100).%s"
1414+
% (USER_CONFIG.get_help_string("save-images", "temporal-margin")),
14051415
)
14061416
@click.option(
14071417
"--scale",
@@ -1442,6 +1452,7 @@ def save_images_command(
14421452
png: bool = False,
14431453
compression: ty.Optional[int] = None,
14441454
frame_margin: ty.Optional[int] = None,
1455+
temporal_margin: ty.Optional[str] = None,
14451456
scale: ty.Optional[float] = None,
14461457
height: ty.Optional[int] = None,
14471458
width: ty.Optional[int] = None,
@@ -1487,6 +1498,14 @@ def save_images_command(
14871498
raise click.BadParameter("\n".join(error_strs), param_hint="save-images")
14881499
output = ctx.config.get_value("save-images", "output", output)
14891500

1501+
# Get temporal_margin value (from CLI arg or config), converting to FrameTimecode
1502+
temporal_margin_value = ctx.config.get_value("save-images", "temporal-margin", temporal_margin)
1503+
temporal_margin_tc = None
1504+
if temporal_margin_value is not None:
1505+
temporal_margin_tc = FrameTimecode(
1506+
timecode=temporal_margin_value, fps=ctx.video_stream.frame_rate
1507+
)
1508+
14901509
save_images_args = {
14911510
"encoder_param": compression if png else quality,
14921511
"frame_margin": ctx.config.get_value("save-images", "frame-margin", frame_margin),
@@ -1498,6 +1517,7 @@ def save_images_command(
14981517
"output": output,
14991518
"scale": scale,
15001519
"show_progress": not ctx.quiet_mode,
1520+
"temporal_margin": temporal_margin_tc,
15011521
"threading": ctx.config.get_value("save-images", "threading"),
15021522
"width": width,
15031523
}

scenedetect/_cli/commands.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,7 @@ def save_images(
191191
width: int,
192192
interpolation: Interpolation,
193193
threading: bool,
194+
temporal_margin: ty.Optional["FrameTimecode"] = None,
194195
):
195196
"""Handles the `save-images` command."""
196197
del cuts # save-images only uses scenes.
@@ -210,6 +211,7 @@ def save_images(
210211
width=width,
211212
interpolation=interpolation,
212213
threading=threading,
214+
temporal_margin=temporal_margin,
213215
)
214216
# Save the result for use by `save-html` if required.
215217
context.save_images_result = (images, output)

scenedetect/_cli/config.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,7 @@ class XmlFormat(Enum):
419419
"quality": RangeValue(_PLACEHOLDER, min_val=0, max_val=100),
420420
"scale": 1.0,
421421
"scale-method": Interpolation.LINEAR,
422+
"temporal-margin": TimecodeValue("0.04s"),
422423
"threading": True,
423424
"width": 0,
424425
},

0 commit comments

Comments
 (0)