Video segment splitting processor that intelligently splits by fixed duration
Input column name | Description |
|---|---|
video_paths | Array containing input video paths Default value: None |
video_binaries | Array containing video binary data Default value: None |
video_formats | Array containing input video formats (such as 'mp4', 'avi', and more); format information can be provided when specifying video_binaries Default value: None |
output_basenames | Optional, array of output subdirectory names (file names) |
The fields of the processed struct include:
If a parameter does not have a default value, it is required
Parameter name | Type | Default value | Description |
|---|---|---|---|
segment_duration | float | 5.0 | Duration of each segment (seconds), must be > 0 Default value: 5.0 |
min_segment_duration | float | 0.0 | Remaining segments shorter than this value will be discarded (seconds) Default value: 0.0 |
output_tos_dir | str | TOS path for saving video segments; if an empty string, segments will not be uploaded Default value: "" | |
output_segments_binary | bool | False | Whether to output binary data for video segments Default value: False |
output_video_format | str or None | Globally specify the output video format (such as "mp4", "avi", and more); this takes precedence over the input file extension and the video_format column |
The following code demonstrates how to use Daft (for distributed scenarios) to run the operator to split videos by duration.
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 VideoSplitByDuration if __name__ == "__main__": # The split videos will be saved to the specified TOS path after splitting. Therefore, you need to set environment variables to ensure write permissions 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_split_by_duration" 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) # Construct the URL using environment variables tos_dir_url = os.getenv("TOS_DIR_URL", "las-cn-beijing-public-online.tos-cn-beijing.volces.com") samples = { "video_path": [ f"https://{tos_dir_url}/public/shared_video_dataset/sample.mp4" ] } ds = daft.from_pydict(samples) splitter = las_udf( VideoSplitByDuration, construct_args={ "segment_duration": 60.0, "min_segment_duration": 1.0, "output_tos_dir": output_tos_dir, }, ) ds = ds.with_column("results", splitter(col("video_path"))) ds.show() # ╭─────────────────────────────────────────┬──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮ # │ video_path ┆ results │ # │ --- ┆ --- │ # │ Utf8 ┆ Struct[segments: List[Utf8], segments_binary: List[Binary]] │ # ╞═════════════════════════════════════════╪══════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════╡ # │ https://las-cn-beijing-publi-… ┆ {segments: ["tos://tos_bucket/video/video_split_by_duration/sample/segment_1.mp4", "tos://tos_bucket/video/video_split_by_durat… │ # ╰─────────────────────────────────────────┴──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯