MCPcopy Create free account
hub / github.com/ZLMediaKit/pymkui / FFMpegTranscoder

Class FFMpegTranscoder

backend/plugins/ffmpeg_transcoder.py:32–175  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

30# ── 插件类 ────────────────────────────────────────────────────────────
31
32class FFMpegTranscoder(PluginBase):
33 name = "ffmpeg_transcoder"
34 version = "1.0.0"
35 description = (
36 "FFmpeg 转码插件(on_media_changed)。"
37 "流上线时启动 FFmpeg 进程进行转码,"
38 "流下线时停止 FFmpeg 进程。"
39 "支持自定义命令行参数,支持 {vhost}/{app}/{stream} 变量替换。"
40 )
41 type = "on_media_changed"
42 interruptible = False # 监听型:不拦截事件,继续派发后续插件
43 multi_binding = True # 支持多实例,每实例使用不同的转码参数
44
45 def params(self) -> dict:
46 return {
47 "ffmpeg_cmd": {
48 "type": "str",
49 "description": (
50 "FFmpeg 命令行参数,支持变量:{vhost} {app} {stream},"
51 "例如:-i rtsp://localhost:554/{app}/{stream} -c:v libx264 -c:a aac -f flv rtmp://localhost/live/{stream}_transcoded"
52 ),
53 "default": "",
54 },
55 "vhost_filter": {
56 "type": "str",
57 "description": "来源 vhost 过滤,支持通配符 *,默认匹配所有",
58 "default": "*",
59 },
60 "app_filter": {
61 "type": "str",
62 "description": "来源 app 过滤,支持通配符 *,默认匹配所有",
63 "default": "*",
64 },
65 "stream_filter": {
66 "type": "str",
67 "description": "来源 stream 过滤,支持通配符 *,默认匹配所有",
68 "default": "*",
69 },
70 "schema_filter": {
71 "type": "str",
72 "description": (
73 "只对指定来源协议触发,多个用英文逗号分隔,"
74 "例如 rtsp,rtmp。空则匹配所有协议。"
75 ),
76 "default": "",
77 },
78 }
79
80 def run(self, **kwargs) -> bool:
81 is_register: bool = kwargs.get("is_register", False)
82 sender = kwargs.get("sender")
83 binding_params: dict = kwargs.get("binding_params") or {}
84
85 if sender is None:
86 return False
87
88 # 同步获取来源流信息(sender是临时对象,不可在异步协程中引用)
89 try:

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected