Video timestamp splitting processor, supports splitting by specified time range
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 so on); format information can be provided when specifying video_binaries Default value: None |
timestamp_ranges | List of timestamp ranges for each row, supported formats: - [(start,end), (start,end)] or [[start,end], [start,end]] - single (start,end) or [start,end] |
output_basenames | Optional, array of output subdirectory names (file names) |
The processed struct fields include:
If a parameter does not have a default value, it is required
Parameter name | Type | Default value | Description |
|---|---|---|---|
output_tos_dir | str | TOS path for saving video segments; if empty string, do not upload Default value: "" | |
output_segments_binary | bool | False | Whether to output binary data of video segments Default value: False |
output_video_format | str or None | Globally specify output video format (such as "mp4", "avi", and so on); takes precedence over input file suffix and video_format column |
The following code demonstrates how to use Daft (for distributed scenarios) to run the operator and split video by timestamp.
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 VideoSplitByTimestamps if __name__ == "__main__": # The split video will be saved to the specified TOS path after modification. Therefore, environment variables must be set 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_timestamps" 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) # Build 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" ], "timestamp_ranges": [[(0.0, 2.0), (2.0, 4.0)]], } ds = daft.from_pydict(samples) splitter = las_udf( VideoSplitByTimestamps, construct_args={ "output_tos_dir": output_tos_dir, "output_segments_binary": False, "output_video_format": "mp4", }, ) # Use Daft for distributed processing ds = ds.with_column("results", splitter(col("video_path"), None, None, col("timestamp_ranges"))) ds.show() # ╭────────────────────────────────┬────────────────────────────────────────┬─────────────────────────────────────────────────────────────╮ # │ video_path ┆ timestamp_ranges ┆ results │ # │ --- ┆ --- ┆ --- │ # │ Utf8 ┆ List[Struct[_0: Float64, _1: Float64]] ┆ Struct[segments: List[Utf8], segments_binary: List[Binary]] │ # ╞════════════════════════════════╪════════════════════════════════════════╪═════════════════════════════════════════════════════════════╡ # │ https://las-cn-beijing-publi-… ┆ [{_0: 0, ┆ {segments: ["tos://tos_bucket/video/video_split_b… │ # │ ┆ }, {_0: 2, ┆ │ # │ ┆ _1… ┆ │ # ╰────────────────────────────────┴────────────────────────────────────────┴─────────────────────────────────────────────────────────────╯