Adaptive video compression
Input column names | Note |
|---|---|
video_paths | Column of video file paths (local, TOS, HTTP, and so on); choose either video_paths or video_binaries |
video_binaries | Column of video binary data; choose either video_binaries or video_paths |
video_formats | Column of video format strings, used with video_binaries |
output_basenames | Column of output file base names (without extension) |
Column of compressed video paths
If a parameter does not have a default value, it is required
Parameter name | Type | Default value | Description |
|---|---|---|---|
output_tos_dir | str | Save the compressed video to this TOS directory; if empty, do not save. Format: "tos://bucket/path/" Default value: "" | |
max_output_size_mb | float | 50.0 | Maximum output file size (MB). Default value: 50.0 |
target_fps | float | 5.0 | Target value for frame rate adjustment. Default value: 5.0 |
min_resolution_height | int | 360 | Minimum resolution height (pixels), maintain aspect ratio. Default value: 360 |
allowed_formats | list | [mp4, avi, mov] | List of video formats allowed for direct output when the video size meets the requirement. Default value: ["mp4", "avi", "mov"] |
rank | int or None | Specify the GPU device ID to use (effective in multi-card environments). Default value: None |
The following code demonstrates how to use Daft (for distributed scenarios) to run the operator for adaptive video compression and intelligently control the file size.
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 VideoAdaptiveCompress if __name__ == "__main__": TOS_TEST_DIR = os.getenv("TOS_TEST_DIR", "tos_bucket") samples = { "video_path": [f"tos://{TOS_TEST_DIR}/video_adaptive_compress/sample.mp4"], } ds = daft.from_pydict(samples) output_tos_dir = f"tos://{TOS_TEST_DIR}/video_adaptive_compress" constructor_kwargs = { "output_tos_dir": output_tos_dir, "max_output_size_mb": 50.0, "target_fps": 5.0, "min_resolution_height": 360, "rank": None, } ds = ds.with_column( "compressed_video_path", las_udf(VideoAdaptiveCompress, construct_args=constructor_kwargs, num_gpus=1, batch_size=1, concurrency=1)( col("video_path") ), ) ds.show() # ╭────────────────────────────────┬──────────────────────────────────╮ # │ video_path ┆ compressed_video_path │ # │ --- ┆ --- │ # │ Utf8 ┆ Utf8 │ # ╞════════════════════════════════╪══════════════════════════════════╡ # │ tos://tos_bucket/video_adapt… ┆ tos://tos_bucket/video_adapt… │ # ╰────────────────────────────────┴──────────────────────────────────╯