Files
xiaoxia-saas/apps/worker/video_processing/chroma_key_engine.py
T
CI Bot ea2cd42c59
CI/CD Pipeline / Check if frontend-only change (pull_request) Successful in 22s
CI/CD Pipeline / Validate - Type Check (mypy) (pull_request) Successful in 1m8s
CI/CD Pipeline / Validate - Migration (alembic) (pull_request) Successful in 1m5s
CI/CD Pipeline / Frontend Lint (pull_request) Successful in 44s
CI/CD Pipeline / Build Staging API Image (pull_request) Has been skipped
CI/CD Pipeline / Build Staging Web Image (pull_request) Has been skipped
CI/CD Pipeline / Build Staging Worker Image (pull_request) Has been skipped
CI/CD Pipeline / PR Build Worker Image (pull_request) Successful in 52s
CI/CD Pipeline / Validate - Code Quality (pull_request) Failing after 2m59s
CI/CD Pipeline / PR Build Web Image (pull_request) Successful in 2m6s
PR Automation / Auto Merge on CI Green + Approved (pull_request) Successful in 1m5s
Preview Deploy / Deploy Preview Environment (pull_request) Successful in 51s
AI Code Review / AI Code Review (pull_request) Successful in 2m48s
PR Automation / Auto Approve on CI Green (pull_request) Successful in 3m53s
CI/CD Pipeline / PR Build API Image (pull_request) Successful in 5m24s
CI/CD Pipeline / Frontend Unit Tests (pull_request) Has been skipped
CI/CD Pipeline / Build Production API Image (pull_request) Has been skipped
CI/CD Pipeline / Build Production Web Image (pull_request) Has been skipped
CI/CD Pipeline / Build Production Worker Image (pull_request) Has been skipped
CI/CD Pipeline / Deploy Staging (Watchtower auto-deploy) (pull_request) Has been skipped
CI/CD Pipeline / Unit Tests (pull_request) Successful in 2m42s
CI/CD Pipeline / Integration Tests (pull_request) Successful in 2m14s
CI/CD Pipeline / Deploy Production (pull_request) Has been skipped
CI/CD Pipeline / Staging E2E Tests (pull_request) Has been skipped
CI/CD Pipeline / Staging API Integration Tests (pull_request) Has been skipped
CI/CD Pipeline / ACR Image Cleanup (pull_request) Has been skipped
CI/CD Pipeline / Canary Release to Production (pull_request) Has been cancelled
CI/CD Pipeline / Production Browser E2E (pull_request) Has been skipped
ACR Cleanup / ACR Image Cleanup (pull_request_target) Has been cancelled
Preview Cleanup / Cleanup Preview Environment (pull_request) Successful in 24s
test(wave118): 抽离chroma_key_config领域模型 + 45单测
- 抽离ChromaKeyConfig数据类、5个预设、颜色归一化、colorkey/chromakey滤镜构建到packages/domain/chroma_key_config.py
- chroma_key_engine.py: 248→46行 (-81%),保留ChromaKeyEngine薄包装类+模块级向后兼容导入
- 45个纯逻辑单测全绿,原有91个测试无回归
- 合计136 passed
2026-07-27 07:59:47 +08:00

47 lines
1.6 KiB
Python
Executable File
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"""绿幕抠像引擎 — 基于 FFmpeg colorkey / chromakey 滤镜.
支持将指定颜色(默认绿色)变为透明,可用于虚拟背景、画中画背景替换等场景。
注:核心领域模型已抽离到 packages/domain/chroma_key_config.py
本模块保留薄包装层,确保向后兼容。
"""
from __future__ import annotations
import logging
from typing import Optional
from packages.domain.chroma_key_config import ( # noqa: F401 — 向后兼容
CHROMA_KEY_PRESETS,
ChromaKeyConfig,
apply_chroma_key_if_needed,
build_chromakey_filter as _build_chromakey_filter_base,
build_colorkey_filter as _build_colorkey_filter_base,
normalize_color as _normalize_color_base,
)
logger = logging.getLogger(__name__)
class ChromaKeyEngine:
"""绿幕抠像引擎.
薄包装层,实际逻辑委托给 packages.domain.chroma_key_config。
"""
def __init__(self, config: ChromaKeyConfig):
self.config = config
@staticmethod
def _normalize_color(color_str: str) -> str:
"""将颜色字符串转为 FFmpeg colorkey 接受的格式."""
return _normalize_color_base(color_str)
def build_filter(self, input_label: str, output_label: str) -> str:
"""构建 colorkey 滤镜字符串."""
return _build_colorkey_filter_base(self.config, input_label, output_label)
def build_filter_chromakey(self, input_label: str, output_label: str) -> str:
"""使用 chromakey 滤镜(更高级的版本,支持更多参数)."""
return _build_chromakey_filter_base(self.config, input_label, output_label)