Operator ID: daft.las.functions.video.video_blackborder_crop.VideoBlackBorderCrop
Video black border detection and cropping
Details | Caution and prerequisites |
|---|---|
Costs | Before calling an operator, you need to understand the model invocation costs associated with using the operator. For details, see Large model invocation billing. |
Authentication (API Key) | Before calling an operator, you need to generate an API Key for operator invocation. It is recommended to configure the API Key as an environment variable to ensure safer operator calls. For details, see Obtain and configure API Key. |
BaseURL | Before calling an operator, you need to determine the BaseURL for operator invocation based on the region where your current LAS service is deployed. This is used to configure the path parameter values for operator calls. |
Input column name | Note |
|---|---|
input_col | An array containing input video paths (supports local paths, HTTP/HTTPS URLs, TOS/S3 URLs). |
output_col | An array containing the paths of the cropped output files. |
An array containing the paths of the cropped results (string type). Returns the output path on success; returns None on failure.
If a parameter does not have a default value, it is required.
Parameter name | Type | Default value | Description |
|---|---|---|---|
detection_method | str | threshold_ratio | Black border detection algorithm.
Default value: "threshold_ratio" |
black_threshold | int | 10 | Black border determination threshold; pixel values less than this value are considered black borders (0-255). |
valid_pixel_ratio | float | 0.1 | Threshold for the proportion of non-black pixels in valid rows and columns (0-1). |
sample_frames | int | 20 | Number of sampled frames for black border recognition; more samples lead to more accurate recognition. |
is_keep_audio | bool | true | Whether to retain audio. |
timeout | int | None | Timeout for processing a single video (seconds); no limit if set to None. |
core_region_ratio | float | 0.5 | Core region ratio, used to assist judgment. |
continuous_black_rows | int | 3 | Threshold for the number of consecutive black border rows. |
continuous_black_cols | int | 3 | Threshold for the number of consecutive black border columns. |
dark_region_brightness | int | 50 | Dark region brightness threshold. |
edge_sensitivity | float | 1.0 | Edge detection sensitivity. |
The following code demonstrates how to use Daft (for distributed environments) to run the operator for video black border detection and cropping.
from __future__ import annotations import os import daft from daft import col from daft.las.functions.udf import las_udf from daft.las.functions.video import VideoBlackBorderCrop if __name__ == "__main__": # The content will be saved to the specified TOS path. Therefore, you need to set environment variables to ensure you have permission to write to TOS, including: ACCESS_KEY, SECRET_KEY, TOS_ENDPOINT, TOS_REGION, TOS_TEST_DIR TOS_DIR = os.getenv("TOS_TEST_DIR", "tos_bucket") output_tos_dir = f"tos://{TOS_DIR}/video/video_blackborder_crop" if os.getenv("DAFT_RUNNER", "native") == "ray": import logging import ray def configure_logging(): logging.basicConfig( level=logging.INFO, format="%(asctime)s - %(name)s - %(levelname)s - %(message)s", datefmt="%Y-%m-%d %H:%M:%S.%s".format(), ) logging.getLogger("tracing.span").setLevel(logging.WARNING) logging.getLogger("daft_io.stats").setLevel(logging.WARNING) logging.getLogger("DaftStatisticsManager").setLevel(logging.WARNING) logging.getLogger("DaftFlotillaScheduler").setLevel(logging.WARNING) logging.getLogger("DaftFlotillaDispatcher").setLevel(logging.WARNING) ray.init(dashboard_host="0.0.0.0", runtime_env={"worker_process_setup_hook": configure_logging}) daft.set_runner_ray() daft.set_execution_config(actor_udf_ready_timeout=600) daft.set_execution_config(min_cpu_per_task=0) tos_dir_url = os.getenv("TOS_DIR_URL", "las-cn-beijing-public-online.tos-cn-beijing.volces.com") samples = { "input_path": [f"https://{tos_dir_url}/public/shared_video_dataset/sample.mp4"], "output_path": [f"{output_tos_dir}/test_blackborder_video_cropped_histogram.mp4"], } ds = daft.from_pydict(samples) constructor_kwargs = { "detection_method": "histogram", "black_threshold": 50, "sample_frames": 10, "is_keep_audio": True, "core_region_ratio": 0.5, "continuous_black_rows": 3, "continuous_black_cols": 3, "dark_region_brightness": 50, } ds = ds.with_column( "crop_result", las_udf(VideoBlackBorderCrop, construct_args=constructor_kwargs)(col("input_path"), col("output_path")), ) ds.show() # ╭────────────────────────────────┬────────────────────────────────┬────────────────────────────────╮ # │ input_path ┆ output_path ┆ crop_result │ # │ --- ┆ --- ┆ --- │ # │ String ┆ String ┆ String │ # ╞════════════════════════════════╪════════════════════════════════╪════════════════════════════════╡ # │ https://las-ai-qa-online.tos-… ┆ https://las-ai-qa-online.tos-… ┆ https://las-ai-qa-online.tos-… │ # ╰────────────────────────────────┴────────────────────────────────┴────────────────────────────────╯