feat(video): 添加硬件加速支持

- 定义硬件加速类型常量(none、qsv、cuda)
- 配置QSV和CUDA编码参数及预设
- 在WorkerConfig中添加硬件加速配置选项
- 实现基于硬件加速类型的编码参数动态获取
- 添加FFmpeg硬件加速解码和滤镜参数
- 检测并报告系统硬件加速支持信息
- 在API客户端中上报硬件加速配置和支持状态
This commit is contained in:
2026-01-13 13:34:27 +08:00
parent a26c44a3cd
commit 71bd2e59f9
7 changed files with 364 additions and 22 deletions

View File

@@ -9,6 +9,8 @@ import os
from dataclasses import dataclass, field
from typing import List, Optional
from constant import HW_ACCEL_NONE, HW_ACCEL_QSV, HW_ACCEL_CUDA, HW_ACCEL_TYPES
# 默认支持的任务类型
DEFAULT_CAPABILITIES = [
@@ -54,6 +56,9 @@ class WorkerConfig:
download_timeout: int = 300 # 秒,下载超时
upload_timeout: int = 600 # 秒,上传超时
# 硬件加速配置
hw_accel: str = HW_ACCEL_NONE # 硬件加速类型: none, qsv, cuda
@classmethod
def from_env(cls) -> 'WorkerConfig':
"""从环境变量创建配置"""
@@ -98,6 +103,11 @@ class WorkerConfig:
download_timeout = int(os.getenv('DOWNLOAD_TIMEOUT', '300'))
upload_timeout = int(os.getenv('UPLOAD_TIMEOUT', '600'))
# 硬件加速配置
hw_accel = os.getenv('HW_ACCEL', HW_ACCEL_NONE).lower()
if hw_accel not in HW_ACCEL_TYPES:
hw_accel = HW_ACCEL_NONE
return cls(
api_endpoint=api_endpoint,
access_key=access_key,
@@ -110,7 +120,8 @@ class WorkerConfig:
capabilities=capabilities,
ffmpeg_timeout=ffmpeg_timeout,
download_timeout=download_timeout,
upload_timeout=upload_timeout
upload_timeout=upload_timeout,
hw_accel=hw_accel
)
def get_work_dir_path(self, task_id: str) -> str:
@@ -120,3 +131,15 @@ class WorkerConfig:
def ensure_temp_dir(self) -> None:
"""确保临时目录存在"""
os.makedirs(self.temp_dir, exist_ok=True)
def is_hw_accel_enabled(self) -> bool:
"""是否启用了硬件加速"""
return self.hw_accel != HW_ACCEL_NONE
def is_qsv(self) -> bool:
"""是否使用 QSV 硬件加速"""
return self.hw_accel == HW_ACCEL_QSV
def is_cuda(self) -> bool:
"""是否使用 CUDA 硬件加速"""
return self.hw_accel == HW_ACCEL_CUDA