Files

48 lines
1.8 KiB
Python
Executable File
Raw Permalink 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 packages.domain.chroma_key_config import CHROMA_KEY_PRESETS # noqa: F401
from packages.domain.chroma_key_config import apply_chroma_key_if_needed # noqa: F401
from packages.domain.chroma_key_config import (
ChromaKeyConfig,
)
from packages.domain.chroma_key_config import ( # noqa: F401 — 向后兼容
build_chromakey_filter as _build_chromakey_filter_base,
)
from packages.domain.chroma_key_config import build_colorkey_filter as _build_colorkey_filter_base
from packages.domain.chroma_key_config import 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)