Files
meetingroom-netscreen/push_screen.py

50 lines
1.8 KiB
Python
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.
import subprocess
import psutil
import os
import time
import tkinter as tk
from tkinter import messagebox
# 配置项仅需改这里的服务器IP
SERVER_IP = "192.168.1.100" # MediaMTX服务器内网IP
MEDIAMTX_PATH = r"D:\ScreenCast\mediamtx\mediamtx.exe"
FFMPEG_PATH = r"D:\ScreenCast\ffmpeg\bin\ffmpeg.exe"
STREAM_PATH = "screen" # 投屏流路径模式1/2
# 检查MediaMTX是否运行
def check_mediamtx_running():
for proc in psutil.process_iter(['name']):
if proc.info['name'] == 'mediamtx.exe':
return True
return False
# 启动MediaMTX如果未运行
def start_mediamtx():
if not check_mediamtx_running():
subprocess.Popen([MEDIAMTX_PATH], cwd=r"D:\ScreenCast\mediamtx", creationflags=subprocess.CREATE_NEW_CONSOLE)
time.sleep(3) # 等待启动
messagebox.showinfo("提示", "MediaMTX已启动")
# 屏幕推流(全屏)
def push_full_screen():
start_mediamtx()
# 封装FFmpeg命令低延迟推流
cmd = [
FFMPEG_PATH,
"-f", "gdigrab", "-framerate", "30", "-i", "desktop",
"-c:v", "libx264", "-preset", "ultrafast", "-tune", "zerolatency",
"-f", "rtsp", f"rtsp://{SERVER_IP}:8554/{STREAM_PATH}"
]
subprocess.Popen(cmd, creationflags=subprocess.CREATE_NEW_CONSOLE)
messagebox.showinfo("提示", f"全屏投屏已启动!接收端可打开浏览器访问:\n http://{SERVER_IP}:8889/webrtc.html?src=screen ")
# 主界面(点击按钮即可)
if __name__ == "__main__":
root = tk.Tk()
root.title("投屏源控制")
root.geometry("300x150")
btn1 = tk.Button(root, text="一键全屏投屏", command=push_full_screen, width=20, height=2)
btn1.pack(pady=20)
root.mainloop()