视频运动分计算
更新时间:2026-06-15
简介
视频运动分计算
功能描述
- Farneback
- TV-L1
- DIS:ULTRAFAST、FAST、MEDIUM、accurate
- MEMFOF(深度学习光流)
- 多指标支持:返回多种多层次计算指标
- mean_score: 原始均值
- median_score: 中位数
- dynamic_mean_score: 尺寸自适应均值
- high_percentile_score: 原始95分位
- dynamic_high_percentile_score: 尺寸自适应95分位
- density_score: 运动密度分
算子参数
输入
| 输入 | 含义 |
|---|---|
| video_paths | 视频文件路径列(本地、BOS、HTTP等),与video_binaries二选一 |
| video_binaries | 视频二进制数据列,与video_paths二选一 |
| video_formats | 视频格式字符串列,配合video_binaries使用 |
输出
| 输出 | 含义 |
|---|---|
| standardized_score | 标准化分数 |
| motion_pattern | 运动模式分类 |
| mean_score | 原始均值 |
| median_score | 中位数 |
| dynamic_mean_score | 尺寸自适应均值 |
| high_percentile_score | 原始95分位 |
| dynamic_high_percentile_score | 尺寸自适应95分位 |
| density_score | 运动密度分 |
| video_resolution | 视频分辨率[width, height] |
| total_frames | 视频总帧数 |
| sample_frames_count | 实际采样帧数 |
| used_algorithm | 使用的光流算法 |
| used_metric | 使用的运动分指标 |
| status | 处理状态 |
参数
| 参数名称 | 类型 | 默认值 | 描述 |
|---|---|---|---|
| optical_flow_algorithm | str | 'farneback' | 稠密光流算法类型 可选值:["farneback", "tv-l1", "dis-ultrafast", "dis-fast", "dis-medium", "dis-accurate", "memfof"] 默认值:"farneback" |
| sample_ratio | float | 0.125 | 视频采样帧数比例,用于平衡计算效率与精度 默认值:0.125 |
| mag_threshold | float | 0.01 | 运动幅值阈值,过滤微小噪声位移(像素) 默认值:1.5 |
| flow_threshold | float | 6 | - |
| smooth_window | int | 5 | - |
| downsample_ratio | float | 1.0 | 帧降采样比例(0.0-1.0),1.0为原始分辨率 默认值:1.0 |
| high_motion_threshold | float | 0.02 | 高动态视频判断阈值 默认值:0.02 |
| batch_size | int | 10 | 批处理大小 默认值: 10 |
| model_path | str | '/opt/aihc/models' | 模型文件存储路径(用于MEMFOF) 默认值: "/opt/aihc/models" |
| algorithm_params | dict[str, Any] | None | 算法特定参数字典 默认值: None |
| rank | int | 0 | 指定使用的GPU设备编号(多卡环境有效) 默认值: 0 |
| num_workers | int | 4 | 多线程工作进程数 默认值: 4 |
| use_cuda | bool | True | 是否启用CUDA加速 默认值: True |
| max_gpu_memory | float | 0.8 | GPU最大内存使用率限制(0.0-1.0) 默认值: 0.8 |
| min_frame_size | int | 32 | 最小帧尺寸(宽/高),低于此值会被缩放 默认值: 32 |
调用示例
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_motion_score import VideoMotionScore
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 = {
20 "video_paths": ["bos://bucket/test/aihc/test_data/test_video.mp4"],
21 }
22 ds = daft.from_pydict(samples)
23 constructor_kwargs = {
24 "optical_flow_algorithm": 'farneback',
25 "sample_ratio": 0.125,
26 "mag_threshold": 0.01,
27 "flow_threshold": 6,
28 "smooth_window": 5,
29 }
30 ds = ds.with_column(
31 "result",
32 aihc_udf(
33 VideoMotionScore,
34 construct_args=constructor_kwargs,
35 num_cpus=1,
36 concurrency=4,
37 batch_size=8,
38 )(col("video_paths"), col("video_binaries"), col("video_formats")),
39 )
40 ds.show()
评价此篇文章
