From d0f7b0b91dfddec4164e6e5cb87fb0c28a6716f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=93=E6=99=BA=E8=88=AA?= <23373333@buaa.edu.cn> Date: Sat, 7 Feb 2026 17:01:37 +0800 Subject: [PATCH] =?UTF-8?q?jetson=E8=A7=86=E9=A2=91=E5=BD=95=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- reproject/main.py | 44 +++++++++++++++++++++++++------------------- 1 file changed, 25 insertions(+), 19 deletions(-) diff --git a/reproject/main.py b/reproject/main.py index cc0ce45..811775c 100644 --- a/reproject/main.py +++ b/reproject/main.py @@ -190,7 +190,7 @@ def analysis_thread(): "pose": result["pose"], "emo_label": result["emotion_label"], "emo_va": result["emotion_va"], - } + } ) elif result["has_face"]: payload.update( @@ -246,30 +246,36 @@ def video_stream_thread(): print(f"[Video] 准备连接服务器 {SERVER_HOST}:{SERVER_PORT} ...") 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 - # gst_pipeline = ( - # f"appsrc ! " - # f"video/x-raw, format=BGR ! " - # f"queue ! " - # f"videoconvert ! " - # f"video/x-raw, format=RGBA ! " - # f"nvvidconv ! " - # f"nvv4l2h264enc bitrate={bitrate} control-rate=1 profile=High ! " - # f"h264parse ! " - # f"qtmux ! " - # f"filesink location={filename} " - # ) - # out = cv2.VideoWriter(gst_pipeline, cv2.CAP_GSTREAMER, 0, fps, (width, height)) - out1 = cv2.VideoWriter('output1.mp4', fourcc, 30.0, (1280, 720)) + width = 1280 + height = 720 + fps = 30 + bitrate = 2000000 # 建议设为 2Mbps (2000000) 或 4Mbps,1Mbps 对 720p 来说有点糊 + filename = "output.mp4" + gst_pipeline = ( + f"appsrc ! " + f"video/x-raw, format=BGR, width={width}, height={height}, framerate={fps}/1 ! " # 1. 明确声明输入参数 + f"queue ! " + f"videoconvert ! " # 2. CPU转换 (BGR -> BGRx) + f"video/x-raw, format=BGRx ! " # nvvidconv 对 BGRx 支持比 BGR 好 + f"nvvidconv ! " # 3. 硬件转换 (搬运到 NVMM) + f"video/x-raw(memory:NVMM), format=NV12 ! " # 编码器只吃 NV12 格式的 NVMM 数据 + f"nvv4l2h264enc bitrate={bitrate} control-rate=1 profile=High ! " + f"h264parse ! " + f"qtmux ! " + f"filesink location={filename} " + ) + + # 注意:cv2.CAP_GSTREAMER 是必须的 + out = cv2.VideoWriter(gst_pipeline, cv2.CAP_GSTREAMER, 0, float(fps), (width, height)) + # out1 = cv2.VideoWriter('output1.mp4', fourcc, 30.0, (1280, 720)) # out2 = cv2.VideoWriter('output2.mp4', fourcc, 30.0, (1280, 720)) while not stop_event.is_set(): try: frame = video_queue.get(timeout=1) server.provide_frame(frame) - # out1.write(frame) + out.write(frame) # out2.write(frame) except queue.Empty: continue @@ -320,7 +326,7 @@ def video_stream_thread(): # except Exception as e: # print(f"[Video] 重连中... {e}") # time.sleep(3) - out1.release() + out.release() # out2.release() print("[Video] 线程结束")