Operator ID: daft.las.functions.video.video_aspect_ratio_adjust.VideoAspectRatioAdjust
Video aspect ratio adjustment adapts the video frame to the specified aspect ratio.
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_paths | Column for input video file paths |
output_paths | Column for output video file paths |
Adjusted video path column
If a parameter does not have a default value, it is required.
Parameter name | Type | Default value | Description |
|---|---|---|---|
target_width | int | Output video width (pixels) | |
target_height | int | Output video height (pixels) | |
mode | str | pad | Processing mode, options:
|
video_codec | str | libx264 | Video encoder |
audio_codec | str | aac | Audio encoder |
extra_params | list[str] or None | Additional ffmpeg parameter list | |
timeout | int or None | ffmpeg execution timeout (seconds) |
The following code demonstrates how to use Daft (for distributed scenarios) to run the operator for video aspect ratio adjustment. Both input and output use TOS paths. Therefore, you need to set environment variables to ensure permission to read and write TOS, including: ACCESS_KEY, SECRET_KEY, TOS_ENDPOINT, TOS_REGION, TOS_TEST_DIR.
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 VideoAspectRatioAdjust if __name__ == "__main__": # Both input and output use TOS paths. Therefore, you need to set environment variables to ensure permission to read and write TOS, including: ACCESS_KEY, SECRET_KEY, TOS_ENDPOINT, TOS_REGION, TOS_TEST_DIR. TOS_TEST_DIR_URL = os.getenv("TOS_TEST_DIR_URL", "las-cn-beijing-public-online.tos-cn-beijing.volces.com") TOS_TEST_DIR = os.getenv("TOS_TEST_DIR", "tos_bucket") 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", ) 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) samples = { "input_path": [f"https://{TOS_TEST_DIR_URL}/public/shared_video_dataset/sample.mp4"], "output_path": [f"tos://{TOS_TEST_DIR}/video/video_aspect_ratio_adjust/sample_4x3.mp4"], } ds = daft.from_pydict(samples) constructor_kwargs = { "target_width": 1280, "target_height": 768, "mode": "pad", } ds = ds.with_column( "adjusted_path", las_udf(VideoAspectRatioAdjust, construct_args=constructor_kwargs)( col("input_path"), col("output_path"), ), ) ds.show() # ╭────────────────────────────────┬────────────────────────────────┬────────────────────────────────╮ # │ input_path ┆ output_path ┆ adjusted_path │ # │ --- ┆ --- ┆ --- │ # │ String ┆ String ┆ String │ # ╞════════════════════════════════╪════════════════════════════════╪════════════════════════════════╡ # │ https://las-cn-beijing-publi-… ┆ tos://tos_bucket/video/video_… ┆ tos://tos_bucket/video/video_… │ # ╰────────────────────────────────┴────────────────────────────────┴────────────────────────────────╯