视频首帧提取
更新时间:2026-06-15
简介
视频起始帧识别
功能描述
- 从视频中提取第一帧作为封面图片
- 支持多种图片格式输出
- 高效处理,只读取视频头部信息
- 支持路径输入、二进制输入和BOS输出
- 输入:MP4 (.mp4), AVI (.avi), MOV (.mov), MKV (.mkv)等常见视频格式
- 输出:JPEG (.jpg), PNG (.png), BMP (.bmp)等常见图片格式
算子参数
输入
| 输入 | 含义 |
|---|---|
| video_paths | 视频文件路径列(本地、BOS、HTTP等),与video_binaries二选一 |
| video_binaries | 视频二进制数据列,与video_paths二选一 |
| video_formats | 视频格式字符串列,配合video_binaries使用 |
| output_basenames | 输出文件基础名称列(不含扩展名) |
输出
| 输出 | 含义 |
|---|---|
| result | 提取的起始帧图片路径列 |
参数
| 参数名称 | 类型 | 默认值 | 描述 |
|---|---|---|---|
| output_tos_dir | str | '' | 将提取的起始帧图片保存到该BOS目录中,如果为空则不保存到BOS。 格式:"bos://bucket/path/" 默认值:"" |
| output_format | str | 'jpg' | 输出图片的格式。 可选值:["jpg", "jpeg", "png", "bmp"] 默认值:"jpg" |
| rank | int | None | 指定使用的GPU设备编号(多卡环境有效)。 说明:0表示第一张GPU,1表示第二张GPU,None表示自动选择 适用:仅在GPU处理时有效 默认值:None |
| skip_black_frames | bool | False | 是否跳过黑屏帧,提取第一个非黑屏帧。 默认值:False |
| black_threshold | float | 0.1 | 黑屏检测阈值(像素级阈值),值越小检测越严格。 默认值:0.1 |
调用示例
Python
1from __future__ import annotations
2
3import os
4
5import daft
6from daft import col
7
8from daft.aihc.common.udf import aihc_udf
9from daft.aihc.functions.video.video_first_frame import VideoFirstFrame
10
11if __name__ == "__main__":
12 if os.getenv("DAFT_RUNNER", "native") == "ray":
13 import ray
14 ray.init(dashboard_host="0.0.0.0", ignore_reinit_error=True)
15 daft.set_runner_ray()
16 daft.set_execution_config(actor_udf_ready_timeout=6000, min_cpu_per_task=0)
17
18 # TODO: 根据实际场景准备样本数据
19 samples = {"video_paths": [...], "video_binaries": [...]}
20 ds = daft.from_pydict(samples)
21 constructor_kwargs = {
22 "output_tos_dir": '',
23 "output_format": 'jpg',
24 "rank": None,
25 "skip_black_frames": False,
26 "black_threshold": 0.1,
27 }
28 ds = ds.with_column(
29 "result",
30 aihc_udf(
31 VideoFirstFrame,
32 construct_args=constructor_kwargs,
33 num_cpus=1,
34 concurrency=4,
35 batch_size=8,
36 )(col("video_paths"), col("video_binaries"), col("video_formats")),
37 )
38 ds.show()
评价此篇文章
