MCPcopy Create free account
hub / github.com/Breakthrough/PySceneDetect / save_images_command

Function save_images_command

scenedetect/_cli/__init__.py:1505–1580  ·  view source on GitHub ↗
(
    ctx: click.Context,
    output: str | None = None,
    filename: str | None = None,
    num_images: int | None = None,
    jpeg: bool = False,
    webp: bool = False,
    quality: int | None = None,
    png: bool = False,
    compression: int | None = None,
    frame_margin: str | None = None,
    scale: float | None = None,
    height: int | None = None,
    width: int | None = None,
)

Source from the content-addressed store, hash-verified

1503)
1504@click.pass_context
1505def save_images_command(
1506 ctx: click.Context,
1507 output: str | None = None,
1508 filename: str | None = None,
1509 num_images: int | None = None,
1510 jpeg: bool = False,
1511 webp: bool = False,
1512 quality: int | None = None,
1513 png: bool = False,
1514 compression: int | None = None,
1515 frame_margin: str | None = None,
1516 scale: float | None = None,
1517 height: int | None = None,
1518 width: int | None = None,
1519):
1520 ctx = ctx.obj
1521 assert isinstance(ctx, CliContext)
1522 assert ctx.video_stream is not None
1523
1524 if "://" in ctx.video_stream.path:
1525 error_str = "\nThe save-images command is incompatible with URLs."
1526 logger.error(error_str)
1527 raise click.BadParameter(error_str, param_hint="save-images")
1528 num_flags = sum([1 if flag else 0 for flag in [jpeg, webp, png]])
1529 if num_flags > 1:
1530 logger.error(".")
1531 raise click.BadParameter("Only one image type can be specified.", param_hint="save-images")
1532 elif num_flags == 0:
1533 image_format = ctx.config.get_value("save-images", "format").lower()
1534 jpeg = image_format == "jpeg"
1535 webp = image_format == "webp"
1536 png = image_format == "png"
1537
1538 if not any((scale, height, width)):
1539 scale = ctx.config.get_value("save-images", "scale")
1540 height = ctx.config.get_value("save-images", "height")
1541 width = ctx.config.get_value("save-images", "width")
1542 scale_method = ctx.config.get_value("save-images", "scale-method")
1543 quality = (
1544 (DEFAULT_WEBP_QUALITY if webp else DEFAULT_JPG_QUALITY)
1545 if ctx.config.is_default("save-images", "quality")
1546 else ctx.config.get_value("save-images", "quality")
1547 )
1548 compression = ctx.config.get_value("save-images", "compression", compression)
1549 image_extension = "jpg" if jpeg else "png" if png else "webp"
1550 valid_params = get_cv2_imwrite_params()
1551 if image_extension not in valid_params or valid_params[image_extension] is None:
1552 error_strs = [
1553 f"Image encoder type `{image_extension.upper()}` not supported.",
1554 "The specified encoder type could not be found in the current OpenCV module.",
1555 "To enable this output format, please update the installed version of OpenCV.",
1556 "If you build OpenCV, ensure the the proper dependencies are enabled. ",
1557 ]
1558 logger.debug("\n".join(error_strs))
1559 raise click.BadParameter("\n".join(error_strs), param_hint="save-images")
1560 output = ctx.config.get_value("save-images", "output", output)
1561
1562 save_images_args = {

Callers

nothing calls this directly

Calls 4

get_cv2_imwrite_paramsFunction · 0.90
get_valueMethod · 0.80
is_defaultMethod · 0.80
add_commandMethod · 0.80

Tested by

no test coverage detected