Skip to content

Commit 3d6aedd

Browse files
committed
[cli] Make argument names consistent with CLI options in command handlers
1 parent 51e09d7 commit 3d6aedd

File tree

4 files changed

+40
-42
lines changed

4 files changed

+40
-42
lines changed

scenedetect/_cli/__init__.py

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1049,7 +1049,7 @@ def save_html_command(
10491049
if include_images and not ctx.save_images:
10501050
save_images_command.callback()
10511051
save_html_args = {
1052-
"html_name_format": ctx.config.get_value("save-html", "filename", filename),
1052+
"filename": ctx.config.get_value("save-html", "filename", filename),
10531053
"image_width": ctx.config.get_value("save-html", "image-width", image_width),
10541054
"image_height": ctx.config.get_value("save-html", "image-height", image_height),
10551055
"include_images": include_images,
@@ -1128,18 +1128,15 @@ def list_scenes_command(
11281128
ctx = ctx.obj
11291129
assert isinstance(ctx, CliContext)
11301130

1131-
create_file = not ctx.config.get_value("list-scenes", "no-output-file", no_output_file)
1132-
output_dir = ctx.config.get_value("list-scenes", "output", output)
1133-
name_format = ctx.config.get_value("list-scenes", "filename", filename)
11341131
list_scenes_args = {
11351132
"col_separator": ctx.config.get_value("list-scenes", "col-separator"),
11361133
"cut_format": ctx.config.get_value("list-scenes", "cut-format"),
11371134
"display_scenes": ctx.config.get_value("list-scenes", "display-scenes"),
11381135
"display_cuts": ctx.config.get_value("list-scenes", "display-cuts"),
1139-
"scene_list_output": create_file,
1140-
"scene_list_name_format": name_format,
1136+
"no_output_file": ctx.config.get_value("list-scenes", "no-output-file", no_output_file),
1137+
"filename": ctx.config.get_value("list-scenes", "filename", filename),
11411138
"skip_cuts": ctx.config.get_value("list-scenes", "skip-cuts", skip_cuts),
1142-
"output_dir": output_dir,
1139+
"output": ctx.config.get_value("list-scenes", "output", output),
11431140
"quiet": ctx.config.get_value("list-scenes", "quiet", quiet) or ctx.quiet_mode,
11441141
"row_separator": ctx.config.get_value("list-scenes", "row-separator"),
11451142
}
@@ -1322,7 +1319,7 @@ def split_video_command(
13221319
split_video_args = {
13231320
"name_format": ctx.config.get_value("split-video", "filename", filename),
13241321
"use_mkvmerge": mkvmerge,
1325-
"output_dir": ctx.config.get_value("split-video", "output", output),
1322+
"output": ctx.config.get_value("split-video", "output", output),
13261323
"show_output": not ctx.config.get_value("split-video", "quiet", quiet),
13271324
"ffmpeg_args": args,
13281325
}
@@ -1506,10 +1503,10 @@ def save_images_command(
15061503
"frame_margin": ctx.config.get_value("save-images", "frame-margin", frame_margin),
15071504
"height": height,
15081505
"image_extension": image_extension,
1509-
"image_name_template": ctx.config.get_value("save-images", "filename", filename),
1506+
"filename": ctx.config.get_value("save-images", "filename", filename),
15101507
"interpolation": scale_method,
15111508
"num_images": ctx.config.get_value("save-images", "num-images", num_images),
1512-
"output_dir": output,
1509+
"output": output,
15131510
"scale": scale,
15141511
"show_progress": not ctx.quiet_mode,
15151512
"threading": ctx.config.get_value("save-images", "threading"),
@@ -1565,9 +1562,9 @@ def save_qp_command(
15651562
assert isinstance(ctx, CliContext)
15661563

15671564
save_qp_args = {
1568-
"filename_format": ctx.config.get_value("save-qp", "filename", filename),
1569-
"output_dir": ctx.config.get_value("save-qp", "output", output),
1570-
"shift_start": not ctx.config.get_value("save-qp", "disable-shift", disable_shift),
1565+
"filename": ctx.config.get_value("save-qp", "filename", filename),
1566+
"output": ctx.config.get_value("save-qp", "output", output),
1567+
"disable_shift": ctx.config.get_value("save-qp", "disable-shift", disable_shift),
15711568
}
15721569
ctx.add_command(cli_commands.save_qp, save_qp_args)
15731570

scenedetect/_cli/commands.py

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -46,16 +46,16 @@ def save_html(
4646
show: bool,
4747
):
4848
"""Handles the `save-html` command."""
49-
(image_filenames, output_dir) = (
49+
(image_filenames, output) = (
5050
context.save_images_result
5151
if context.save_images_result is not None
52-
else (None, context.output_dir)
52+
else (None, context.output)
5353
)
5454

5555
html_filename = Template(html_name_format).safe_substitute(VIDEO_NAME=context.video_stream.name)
5656
if not html_filename.lower().endswith(".html"):
5757
html_filename += ".html"
58-
html_path = get_and_create_path(html_filename, output_dir)
58+
html_path = get_and_create_path(html_filename, output)
5959
write_scene_list_html(
6060
output_html_filename=html_path,
6161
scene_list=scenes,
@@ -72,17 +72,18 @@ def save_qp(
7272
context: CliContext,
7373
scenes: SceneList,
7474
cuts: CutList,
75-
output_dir: str,
76-
filename_format: str,
77-
shift_start: bool,
75+
output: str,
76+
filename: str,
77+
disable_shift: bool,
7878
):
7979
"""Handler for the `save-qp` command."""
8080
del scenes # We only use cuts for this handler.
8181
qp_path = get_and_create_path(
82-
Template(filename_format).safe_substitute(VIDEO_NAME=context.video_stream.name),
83-
output_dir,
82+
Template(filename).safe_substitute(VIDEO_NAME=context.video_stream.name),
83+
output,
8484
)
8585
start_frame = context.start_time.frame_num if context.start_time else 0
86+
shift_start = not disable_shift
8687
offset = start_frame if shift_start else 0
8788
with open(qp_path, "wt") as qp_file:
8889
qp_file.write(f"{0 if shift_start else start_frame} I -1\n")
@@ -95,9 +96,9 @@ def list_scenes(
9596
context: CliContext,
9697
scenes: SceneList,
9798
cuts: CutList,
98-
scene_list_output: bool,
99-
scene_list_name_format: str,
100-
output_dir: str,
99+
no_output_file: bool,
100+
filename: str,
101+
output: str,
101102
skip_cuts: bool,
102103
quiet: bool,
103104
display_scenes: bool,
@@ -108,15 +109,15 @@ def list_scenes(
108109
):
109110
"""Handles the `list-scenes` command."""
110111
# Write scene list CSV to if required.
111-
if scene_list_output:
112-
scene_list_filename = Template(scene_list_name_format).safe_substitute(
112+
if not no_output_file:
113+
scene_list_filename = Template(filename).safe_substitute(
113114
VIDEO_NAME=context.video_stream.name
114115
)
115116
if not scene_list_filename.lower().endswith(".csv"):
116117
scene_list_filename += ".csv"
117118
scene_list_path = get_and_create_path(
118119
scene_list_filename,
119-
output_dir,
120+
output,
120121
)
121122
logger.info("Writing scene list to CSV file:\n %s", scene_list_path)
122123
with open(scene_list_path, "w") as scene_list_file:
@@ -170,8 +171,8 @@ def save_images(
170171
frame_margin: int,
171172
image_extension: str,
172173
encoder_param: int,
173-
image_name_template: str,
174-
output_dir: ty.Optional[str],
174+
filename: str,
175+
output: ty.Optional[str],
175176
show_progress: bool,
176177
scale: int,
177178
height: int,
@@ -189,8 +190,8 @@ def save_images(
189190
frame_margin=frame_margin,
190191
image_extension=image_extension,
191192
encoder_param=encoder_param,
192-
image_name_template=image_name_template,
193-
output_dir=output_dir,
193+
image_name_template=filename,
194+
output_dir=output,
194195
show_progress=show_progress,
195196
scale=scale,
196197
height=height,
@@ -199,7 +200,7 @@ def save_images(
199200
threading=threading,
200201
)
201202
# Save the result for use by `save-html` if required.
202-
context.save_images_result = (images, output_dir)
203+
context.save_images_result = (images, output)
203204

204205

205206
def split_video(
@@ -208,7 +209,7 @@ def split_video(
208209
cuts: CutList,
209210
name_format: str,
210211
use_mkvmerge: bool,
211-
output_dir: str,
212+
output: str,
212213
show_output: bool,
213214
ffmpeg_args: str,
214215
):
@@ -231,15 +232,15 @@ def split_video(
231232
split_video_mkvmerge(
232233
input_video_path=context.video_stream.path,
233234
scene_list=scenes,
234-
output_dir=output_dir,
235+
output_dir=output,
235236
output_file_template=name_format,
236237
show_output=show_output,
237238
)
238239
else:
239240
split_video_ffmpeg(
240241
input_video_path=context.video_stream.path,
241242
scene_list=scenes,
242-
output_dir=output_dir,
243+
output_dir=output,
243244
output_file_template=name_format,
244245
arg_override=ffmpeg_args,
245246
show_progress=not context.quiet_mode,

scenedetect/_cli/context.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ def __init__(self):
101101
self.merge_last_scene: bool = None
102102
self.min_scene_len: FrameTimecode = None
103103
self.default_detector: ty.Tuple[ty.Type[SceneDetector], ty.Dict[str, ty.Any]] = None
104-
self.output_dir: str = None
104+
self.output: str = None
105105
self.stats_file_path: str = None
106106

107107
# Output Commands (e.g. split-video, save-images):
@@ -111,8 +111,8 @@ def __init__(self):
111111

112112
def add_command(self, command: ty.Callable, command_args: ty.Dict[str, ty.Any]):
113113
"""Add `command` to the processing pipeline. Will be called after processing the input."""
114-
if "output_dir" in command_args and command_args["output_dir"] is None:
115-
command_args["output_dir"] = self.output_dir
114+
if "output" in command_args and command_args["output"] is None:
115+
command_args["output"] = self.output
116116
logger.debug("Adding command: %s(%s)", command.__name__, command_args)
117117
self.commands.append((command, command_args))
118118

@@ -238,9 +238,9 @@ def handle_options(
238238
# Load the input video to obtain a time base for parsing timecodes.
239239
self._open_video_stream(input_path, framerate, backend)
240240

241-
self.output_dir = self.config.get_value("global", "output", output)
242-
if self.output_dir:
243-
logger.debug("Output directory set:\n %s", self.output_dir)
241+
self.output = self.config.get_value("global", "output", output)
242+
if self.output:
243+
logger.debug("Output directory set:\n %s", self.output)
244244

245245
self.min_scene_len = self.parse_timecode(
246246
min_scene_len

scenedetect/_cli/controller.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ def _save_stats(context: CliContext) -> None:
154154
if not context.stats_file_path:
155155
return
156156
if context.stats_manager.is_save_required():
157-
path = get_and_create_path(context.stats_file_path, context.output_dir)
157+
path = get_and_create_path(context.stats_file_path, context.output)
158158
logger.info("Saving frame metrics to stats file: %s", path)
159159
with open(path, mode="w") as file:
160160
context.stats_manager.save_to_csv(csv_file=file)

0 commit comments

Comments
 (0)