jetson视频录制
This commit is contained in:
@@ -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] 线程结束")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user