jetson视频录制

This commit is contained in:
邓智航
2026-02-07 17:01:37 +08:00
parent 8b651bec5a
commit d0f7b0b91d

View File

@@ -190,7 +190,7 @@ def analysis_thread():
"pose": result["pose"], "pose": result["pose"],
"emo_label": result["emotion_label"], "emo_label": result["emotion_label"],
"emo_va": result["emotion_va"], "emo_va": result["emotion_va"],
} }
) )
elif result["has_face"]: elif result["has_face"]:
payload.update( payload.update(
@@ -246,30 +246,36 @@ def video_stream_thread():
print(f"[Video] 准备连接服务器 {SERVER_HOST}:{SERVER_PORT} ...") print(f"[Video] 准备连接服务器 {SERVER_HOST}:{SERVER_PORT} ...")
server = WebRTCServer(60, 5, "ws://10.128.50.6:5000") server = WebRTCServer(60, 5, "ws://10.128.50.6:5000")
server.start() server.start()
print("[Video] WebRTC 服务器启动完成")
fourcc = cv2.VideoWriter_fourcc(*'avc1') fourcc = cv2.VideoWriter_fourcc(*'avc1')
# jetson-nvenc 编码器 # jetson-nvenc 编码器
# bitrate = 1000000 # 1 Mbps width = 1280
# gst_pipeline = ( height = 720
# f"appsrc ! " fps = 30
# f"video/x-raw, format=BGR ! " bitrate = 2000000 # 建议设为 2Mbps (2000000) 或 4Mbps1Mbps 对 720p 来说有点糊
# f"queue ! " filename = "output.mp4"
# f"videoconvert ! " gst_pipeline = (
# f"video/x-raw, format=RGBA ! " f"appsrc ! "
# f"nvvidconv ! " f"video/x-raw, format=BGR, width={width}, height={height}, framerate={fps}/1 ! " # 1. 明确声明输入参数
# f"nvv4l2h264enc bitrate={bitrate} control-rate=1 profile=High ! " f"queue ! "
# f"h264parse ! " f"videoconvert ! " # 2. CPU转换 (BGR -> BGRx)
# f"qtmux ! " f"video/x-raw, format=BGRx ! " # nvvidconv 对 BGRx 支持比 BGR 好
# f"filesink location={filename} " f"nvvidconv ! " # 3. 硬件转换 (搬运到 NVMM)
# ) f"video/x-raw(memory:NVMM), format=NV12 ! " # 编码器只吃 NV12 格式的 NVMM 数据
# out = cv2.VideoWriter(gst_pipeline, cv2.CAP_GSTREAMER, 0, fps, (width, height)) f"nvv4l2h264enc bitrate={bitrate} control-rate=1 profile=High ! "
out1 = cv2.VideoWriter('output1.mp4', fourcc, 30.0, (1280, 720)) 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)) # out2 = cv2.VideoWriter('output2.mp4', fourcc, 30.0, (1280, 720))
while not stop_event.is_set(): while not stop_event.is_set():
try: try:
frame = video_queue.get(timeout=1) frame = video_queue.get(timeout=1)
server.provide_frame(frame) server.provide_frame(frame)
# out1.write(frame) out.write(frame)
# out2.write(frame) # out2.write(frame)
except queue.Empty: except queue.Empty:
continue continue
@@ -320,7 +326,7 @@ def video_stream_thread():
# except Exception as e: # except Exception as e:
# print(f"[Video] 重连中... {e}") # print(f"[Video] 重连中... {e}")
# time.sleep(3) # time.sleep(3)
out1.release() out.release()
# out2.release() # out2.release()
print("[Video] 线程结束") print("[Video] 线程结束")