Skip to content

Commit 2bf1172

Browse files
authored
[export-html] Add new --show flag, remove dependency on save-images (#447)
* [export-html] Add --show option to display result in browser (#442) * [export-html] Invoke `save-images` automatically
1 parent 5bf97d7 commit 2bf1172

File tree

5 files changed

+53
-25
lines changed

5 files changed

+53
-25
lines changed

scenedetect.cfg

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,9 @@
240240
# Filename format of created HTML file. Can use $VIDEO_NAME in the name.
241241
#filename = $VIDEO_NAME-Scenes.html
242242

243+
# Automatically open resulting HTML when processing is complete.
244+
#show = no
245+
243246
# Override <img> element width/height.
244247
#image-height = 0
245248
#image-width = 0

scenedetect/_cli/__init__.py

Lines changed: 34 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -959,9 +959,10 @@ def load_scenes_command(
959959
)
960960
@click.option(
961961
"--no-images",
962+
"-n",
962963
is_flag=True,
963964
flag_value=True,
964-
help="Export the scene list including or excluding the saved images.%s"
965+
help="Do not include images with the result.%s"
965966
% (USER_CONFIG.get_help_string("export-html", "no-images")),
966967
)
967968
@click.option(
@@ -980,30 +981,43 @@ def load_scenes_command(
980981
help="Height in pixels of the images in the resulting HTML table.%s"
981982
% (USER_CONFIG.get_help_string("export-html", "image-height", show_default=False)),
982983
)
984+
@click.option(
985+
"--show",
986+
"-s",
987+
is_flag=True,
988+
flag_value=True,
989+
default=None,
990+
help="Automatically open resulting HTML when processing is complete.%s"
991+
% (USER_CONFIG.get_help_string("export-html", "show")),
992+
)
983993
@click.pass_context
984994
def export_html_command(
985995
ctx: click.Context,
986996
filename: ty.Optional[ty.AnyStr],
987997
no_images: bool,
988998
image_width: ty.Optional[int],
989999
image_height: ty.Optional[int],
1000+
show: bool,
9901001
):
991-
"""Export scene list to HTML file. Requires save-images unless --no-images is specified."""
1002+
"""Export scene list to HTML file.
1003+
1004+
To customize image generation, specify the `save-images` command before `export-html`. This command always uses the result of the preceeding `save-images` command, or runs it with the default config values unless `--no-images` is set.
1005+
"""
9921006
# TODO: Rename this command to save-html to align with other export commands. This will require
9931007
# that we allow `export-html` as an alias on the CLI and via the config file for a few versions
9941008
# as to not break existing workflows.
9951009
ctx = ctx.obj
9961010
assert isinstance(ctx, CliContext)
997-
998-
no_images = no_images or ctx.config.get_value("export-html", "no-images")
999-
if not ctx.save_images and not no_images:
1000-
raise click.BadArgumentUsage(
1001-
"export-html requires that save-images precedes it or --no-images is specified."
1002-
)
1011+
include_images = not ctx.config.get_value("export-html", "no-images", no_images)
1012+
# Make sure a save-images command is in the pipeline for us to use the results from.
1013+
if include_images and not ctx.save_images:
1014+
save_images_command.callback()
10031015
export_html_args = {
10041016
"html_name_format": ctx.config.get_value("export-html", "filename", filename),
10051017
"image_width": ctx.config.get_value("export-html", "image-width", image_width),
10061018
"image_height": ctx.config.get_value("export-html", "image-height", image_height),
1019+
"include_images": include_images,
1020+
"show": ctx.config.get_value("export-html", "show", show),
10071021
}
10081022
ctx.add_command(cli_commands.export_html, export_html_args)
10091023

@@ -1362,18 +1376,18 @@ def split_video_command(
13621376
@click.pass_context
13631377
def save_images_command(
13641378
ctx: click.Context,
1365-
output: ty.Optional[ty.AnyStr],
1366-
filename: ty.Optional[ty.AnyStr],
1367-
num_images: ty.Optional[int],
1368-
jpeg: bool,
1369-
webp: bool,
1370-
quality: ty.Optional[int],
1371-
png: bool,
1372-
compression: ty.Optional[int],
1373-
frame_margin: ty.Optional[int],
1374-
scale: ty.Optional[float],
1375-
height: ty.Optional[int],
1376-
width: ty.Optional[int],
1379+
output: ty.Optional[ty.AnyStr] = None,
1380+
filename: ty.Optional[ty.AnyStr] = None,
1381+
num_images: ty.Optional[int] = None,
1382+
jpeg: bool = False,
1383+
webp: bool = False,
1384+
quality: ty.Optional[int] = None,
1385+
png: bool = False,
1386+
compression: ty.Optional[int] = None,
1387+
frame_margin: ty.Optional[int] = None,
1388+
scale: ty.Optional[float] = None,
1389+
height: ty.Optional[int] = None,
1390+
width: ty.Optional[int] = None,
13771391
):
13781392
"""Create images for each detected scene.
13791393

scenedetect/_cli/commands.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
import logging
1919
import typing as ty
20+
import webbrowser
2021
from string import Template
2122

2223
from scenedetect._cli.context import CliContext
@@ -43,13 +44,16 @@ def export_html(
4344
image_width: int,
4445
image_height: int,
4546
html_name_format: str,
47+
include_images: bool,
48+
show: bool,
4649
):
4750
"""Handles the `export-html` command."""
4851
(image_filenames, output_dir) = (
4952
context.save_images_result
5053
if context.save_images_result is not None
5154
else (None, context.output_dir)
5255
)
56+
5357
html_filename = Template(html_name_format).safe_substitute(VIDEO_NAME=context.video_stream.name)
5458
if not html_filename.lower().endswith(".html"):
5559
html_filename += ".html"
@@ -58,10 +62,12 @@ def export_html(
5862
output_html_filename=html_path,
5963
scene_list=scenes,
6064
cut_list=cuts,
61-
image_filenames=image_filenames,
65+
image_filenames=image_filenames if include_images else None,
6266
image_width=image_width,
6367
image_height=image_height,
6468
)
69+
if show:
70+
webbrowser.open(html_path)
6571

6672

6773
def save_qp(

scenedetect/_cli/config.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,7 @@ def format(self, timecode: FrameTimecode) -> str:
300300
"image-height": 0,
301301
"image-width": 0,
302302
"no-images": False,
303+
"show": False,
303304
},
304305
"list-scenes": {
305306
"cut-format": TimecodeFormat.TIMECODE,

website/pages/changelog.md

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -584,12 +584,16 @@ Development
584584
## PySceneDetect 0.6.5 (TBD)
585585

586586
- [bugfix] Fix new detectors not working with `default-detector` config option
587-
- [bugfix] Fix crash when using `save-images` with OpenCV backend [#455](https://github.com/Breakthrough/PySceneDetect/issues/455)
588-
- [bugfix] Fix `SyntaxWarning` due to incorrect escaping [#400](https://github.com/Breakthrough/PySceneDetect/issues/400)
589-
- [bugfix] Fix `ContentDetector` crash when using callbacks [#416](https://github.com/Breakthrough/PySceneDetect/issues/416) [#420](https://github.com/Breakthrough/PySceneDetect/issues/420)
587+
- [bugfix] Fix crash when using `save-images`/`save_images()` with OpenCV backend [#455](https://github.com/Breakthrough/PySceneDetect/issues/455)
590588
- [general] Timecodes of the form `MM:SS[.nnn]` are now processed correctly [#443](https://github.com/Breakthrough/PySceneDetect/issues/443)
591-
- [api] The `save_to_csv` function now works correctly with paths from the `pathlib` module
589+
- [feature] Add new `--show` flag to `export-html` command to launch browser after processing (#442)
590+
- [improvement] The `export-html` command now implicitly invokes `save-images` with default parameters
591+
- The output of the `export-html` command will always use the result of the `save-images` command that *precedes* it
592592
- [general] Updates to Windows distributions:
593593
- The MoviePy backend is now included with Windows distributions
594594
- Bundled Python interpreter is now Python 3.13
595595
- Updated PyAV 10 -> 13.1.0 and OpenCV 4.10.0.82 -> 4.10.0.84
596+
- [improvement] `save_to_csv` now works with paths from `pathlib`
597+
- [bugfix] Fix `SyntaxWarning` due to incorrect escaping [#400](https://github.com/Breakthrough/PySceneDetect/issues/400)
598+
- [bugfix] Fix `ContentDetector` crash when using callbacks [#416](https://github.com/Breakthrough/PySceneDetect/issues/416) [#420](https://github.com/Breakthrough/PySceneDetect/issues/420)
599+

0 commit comments

Comments
 (0)