Files
meetingroom-netscreen/manage_server.py

97 lines
3.9 KiB
Python
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.
import subprocess
import psutil
import time
import os
import tkinter as tk
from tkinter import messagebox
# 基础配置
SERVER_IP = "192.168.1.100"
MEDIAMTX_PATH = r"D:\ScreenCast\mediamtx\mediamtx.exe"
FFMPEG_PATH = r"D:\ScreenCast\ffmpeg\bin\ffmpeg.exe"
# 32台终端IP列表替换为实际终端IP
TERMINAL_IPS = [f"192.168.1.{i}" for i in range(11, 43)] # 示例192.168.1.11~43
# 停止所有相关进程
def stop_all():
# 停止MediaMTX
for proc in psutil.process_iter(['name']):
if proc.info['name'] in ['mediamtx.exe', 'ffmpeg.exe']:
proc.kill()
# 停止终端Chrome可选
for ip in TERMINAL_IPS:
try:
subprocess.run(f"ssh {ip} taskkill /f /im chrome.exe", shell=True, capture_output=True)
except:
pass
messagebox.showinfo("提示", "所有服务已停止!")
# 模式11台投屏→31台接收
def mode1():
# 启动投屏源推流本地执行push_screen.py
subprocess.Popen(["python", r"D:\ScreenCast\push_screen.py"], creationflags=subprocess.CREATE_NEW_CONSOLE)
time.sleep(5)
# 批量启动31台终端接收排除投屏源IP比如192.168.1.10
for ip in TERMINAL_IPS:
if ip != "192.168.1.10": # 投屏源IP
# 远程执行auto_receive.py需开启终端SSH/共享脚本)
subprocess.run(f"ssh {ip} python D:\ScreenCast\auto_receive.py screen", shell=True)
messagebox.showinfo("提示", "模式1已启动1台投屏→31台接收")
# 模式2投屏+第三方会议投屏流→31台+HDMI输出到矩阵
def mode2():
# 启动投屏推流
subprocess.Popen([
FFMPEG_PATH,
"-f", "gdigrab", "-framerate", "30", "-i", "desktop",
"-c:v", "libx264", "-preset", "ultrafast", "-tune", "zerolatency",
"-f", "rtsp", f"rtsp://{SERVER_IP}:8554/screen"
], creationflags=subprocess.CREATE_NEW_CONSOLE)
# 启动HDMI输出到矩阵mpv需提前解压到D:\ScreenCast
subprocess.Popen([
r"D:\ScreenCast\mpv.exe",
f"rtsp://{SERVER_IP}:8554/screen",
"--vo=direct3d", "--screen=1", "--fullscreen"
], creationflags=subprocess.CREATE_NEW_CONSOLE)
# 批量启动31台终端接收
for ip in TERMINAL_IPS:
if ip != "192.168.1.10":
subprocess.run(f"ssh {ip} python D:\ScreenCast\auto_receive.py screen", shell=True)
messagebox.showinfo("提示", "模式2已启动投屏→31台+HDMI输出到会议")
# 模式3会议流→32台接收采集卡采集会议流
def mode3():
# 采集卡采集矩阵的会议流推到MediaMTX
subprocess.Popen([
FFMPEG_PATH,
"-f", "dshow", "-i", "video=采集卡设备名称",
"-c:v", "libx264", "-preset", "ultrafast", "-tune", "zerolatency",
"-f", "rtsp", f"rtsp://{SERVER_IP}:8554/meeting"
], creationflags=subprocess.CREATE_NEW_CONSOLE)
# 批量启动32台终端接收会议流
for ip in TERMINAL_IPS:
subprocess.run(f"ssh {ip} python D:\ScreenCast\auto_receive.py meeting", shell=True)
messagebox.showinfo("提示", "模式3已启动会议流→32台接收")
# 主界面
def main():
root = tk.Tk()
root.title("会议投屏运维总控")
root.geometry("400x300")
btn1 = tk.Button(root, text="模式11台投屏→31台接收", command=mode1, width=30, height=2)
btn1.pack(pady=10)
btn2 = tk.Button(root, text="模式2投屏+HDMI输出到矩阵", command=mode2, width=30, height=2)
btn2.pack(pady=10)
btn3 = tk.Button(root, text="模式3会议流→32台接收", command=mode3, width=30, height=2)
btn3.pack(pady=10)
btn4 = tk.Button(root, text="停止所有服务", command=stop_all, width=30, height=2)
btn4.pack(pady=10)
root.mainloop()
if __name__ == "__main__":
main()