多进程确保视频流畅度

This commit is contained in:
邓智航
2026-01-26 22:06:52 +08:00
parent 3282d4d77e
commit 1875072f5b
3 changed files with 194 additions and 55 deletions

View File

@@ -92,7 +92,7 @@ def capture_thread():
"""
采集线程:优化了分发逻辑,对视频流进行降频处理
"""
cap = cv2.VideoCapture(0)
cap = cv2.VideoCapture(1)
cap.set(cv2.CAP_PROP_FRAME_WIDTH, 1280)
cap.set(cv2.CAP_PROP_FRAME_HEIGHT, 720)
@@ -244,8 +244,9 @@ def video_stream_thread():
发送线程:优化了 Socket 设置和压缩参数
"""
print(f"[Video] 准备连接服务器 {SERVER_HOST}:{SERVER_PORT} ...")
server = WebRTCServer(fps=60)
server = WebRTCServer(60, 5, "ws://10.128.50.6:5000")
server.start()
print("[Video] WebRTC 服务器启动完成")
fourcc = cv2.VideoWriter_fourcc(*'avc1')
# jetson-nvenc 编码器
# bitrate = 1000000 # 1 Mbps
@@ -268,7 +269,9 @@ def video_stream_thread():
try:
frame = video_queue.get(timeout=1)
# small_frame = cv2.resize(apply_soft_roi(frame), (1280, 720))
# print("[Video] 获取一帧视频")
server.provide_frame(frame)
# print("[Video] 已提供给 WebRTC 服务器")
# out1.write(frame)
# out2.write(frame)
except queue.Empty: