FF Plug - 可扩展的视频处理框架
基于FFMPEG的插件化视频处理系统,让视频处理更简单、更强大
插件系统
插件化架构
基于Python的插件系统,轻松扩展新功能
开发者友好
简单的API接口,完整的开发文档,快速上手开发
开箱即用
内置常用视频处理插件:格式转换、压缩、剪辑等
活跃社区
丰富的插件生态,分享交流平台
插件开发示例
# 导入必要的模块
from typing import Dict
from utils.plugin_system.interface import PluginInterface
from utils.plugin_system.types import PluginInfo
from enum import Enum
from utils.ffmpeg_handler import FFmpegHandler
import os
from datetime import datetime
# 定义插件类型枚举
class PluginType(Enum):
PYTHON = "python"
DLL = "dll"
# 示例插件类,继承自PluginInterface接口
class DemoPlugin(PluginInterface):
def __init__(self):
# 初始化插件基本信息
self.name = "演示插件"
self.description = "这是一个用于测试的示例插件,支持自定义FFmpeg命令"
self.version = "1.0.0"
self.author = "开发者"
self.plugin_type = PluginType.PYTHON
self.ffmpeg = FFmpegHandler()
def get_info(self) -> Dict:
# 返回插件的基本信息
return {
"name": self.name,
"description": self.description,
"version": self.version,
"author": self.author,
"type": self.plugin_type.value
}
def _get_custom_command(self, input_path: str, output_file: str) -> str:
# 从配置文件读取自定义FFmpeg命令
plugin_dir = os.path.dirname(os.path.abspath(__file__))
config_file = os.path.join(plugin_dir, "demo_plugin_ffmpeg.txt")
try:
if os.path.exists(config_file):
with open(config_file, 'r', encoding='utf-8') as f:
command_template = f.readline().strip()
if command_template:
# 替换命令模板中的输入输出占位符
return command_template.replace('{input}', input_path).replace('{output}', output_file)
except Exception as e:
print(f"读取配置文件失败: {str(e)}")
# 默认的FFmpeg命令:直接复制视频和音频流
return f'-i "{input_path}" -c:v copy -c:a copy -progress pipe:1 -nostats "{output_file}"'
def process_video(self, input_path: str, output_path: str, progress_callback=None) -> bool:
# 视频处理的主要方法
try:
# 生成带时间戳的输出文件名
filename, ext = os.path.splitext(os.path.basename(input_path))
timestamp = datetime.now().strftime('%Y%m%d_%H%M%S')
output_file = os.path.join(
output_path,
f"processed_{filename}_{timestamp}{ext}"
)
# 创建输出目录
os.makedirs(output_path, exist_ok=True)
# 验证输入文件
if not os.path.exists(input_path):
print(f"输入文件不存在: {input_path}")
return False
# 获取并执行FFmpeg命令
command = self._get_custom_command(input_path, output_file)
return self.ffmpeg.execute_command(command, progress_callback)
except Exception as e:
print(f"处理失败: {str(e)}")
import traceback
print(traceback.format_exc())
return False
常见问题
支持哪些操作系统?
目前支持Windows 10/11, macOS 10.15+, 主流Linux发行版
如何安装使用?
下载后解压即可使用,无需安装。详细使用方法请查看使用文档。
是否支持批量处理?
支持批量转换和处理,提供命令行接口。
联系我们
QQ: 213316