Updated on 2025-12-19 GMT+08:00

Videos

Videos are handled internally using Decord and OpenCV libraries.

  • Supported formats: MP4, AVI, MOV, MKV, FLV, WMV, M4V, 3GP.
  • Supported codecs: MPEG-4, MPEG-2, VP8, VP9, AV1, MS-MPEG-4.

The video object includes specific attributes and methods for further processing.

Table 1 Attributes

Property

Type

Description

filename

str

Path of the video file (if loaded from a file).

format

str

Video format (e.g., mp4, avi).

data

bytes

Video data.

Table 2 Methods

Method

Parameter

Return Value

Description

__init__

filename: Union[str, os.PathLike] = None,data: Union[str, bytes] = None

None

Constructor: Loads video from a file or binary data.

video_reader (property)

decord.VideoReader

Dynamic property: Returns a decord VideoReader object (lazily initialized).

truncate

start_time: float (start time, in seconds) <br>end_time: float (end time, in seconds) <br>shape: Optional[tuple[int, int]] (target resolution) <br>fps: float = None (target frame rate) <br>codec: str = "avc1" (encoding format) <br>format: str = "mp4" (output format)

Video

Trims a video segment, allowing adjustments to resolution, frame rate, and encoding format. Returns a new video object.

from_struct (class method)

obj: dict (must include either filename or data)

Video

Creates a video object from a dictionary (such as JSON).