从rtsp摄像头捕获视频流并将其写入文件

问题描述 投票:0回答:1

我正在尝试捕获来自 rtsp 摄像头的视频流并将其写入文件。将 Jetson Xavier AGX 与 Jetpack 4.5 [L4T 32.5.0] 结合使用

我正在使用下面的Python应用程序来执行任务:

cap = cv2.VideoCapture("rtspsrc location=rtsp://10.34.134.1/Streaming/channels/1/ user-id=myuser user-pw=mypass !  rtph264depay ! h264parse ! nvv4l2decoder ! nvvidconv ! video/x-raw, format=BGRx ! videoconvert ! video/x-raw,format=BGR ! appsink")

w = cap.get(cv2.CAP_PROP_FRAME_WIDTH)
h = cap.get(cv2.CAP_PROP_FRAME_HEIGHT)
fps = cap.get(cv2.CAP_PROP_FPS)
print('Src opened, %dx%d @ %d fps' % (w, h, fps))

gst_out = "appsrc ! video/x-raw, format=BGR ! queue ! videoconvert ! video/x-raw,format=BGRx ! nvvidconv ! nvv4l2h264enc ! h264parse ! matroskamux ! filesink location=test.mkv "
out = cv2.VideoWriter(gst_out, cv2.CAP_GSTREAMER, 0, float(fps), (int(w), int(h)))
if not out.isOpened():
   print("Failed to open output")
   exit()

if cap.isOpened():
   while True:
      ret_val, img = cap.read()
      if not ret_val:
         break;
      out.write(img);
      cv2.waitKey(1)
else:
   print ("pipeline open failed")

cap.release()
out.release()

打开流不起作用。我收到以下错误:

[错误:[电子邮件受保护]] 全局 /io/opencv/modules/videoio/src/cap.cpp (164) 打开 VIDEOIO(CV_IMAGES):引发 OpenCV 异常:

OpenCV(4.6.0) /io/opencv/modules/videoio/src/cap_images.cpp:253: 错误:(-5:参数错误)CAP_IMAGES:找不到起始编号(在 文件名):rtspsrc 位置=rtsp://10.34.134.1/Streaming/channels/1/ user-id=myuser 用户密码=mypass! rtph264depay ! h264解析! nvv4l2解码器! NVVID转换 !视频/x-raw,格式=BGRx!视频转换!视频/x-raw,格式=BGR! 函数‘icvExtractPattern’中的appsink

我可以以某种方式修改提供给 cv2.VideoCapture 的字符串以便正确读取 rtsp 流吗?

python opencv video-streaming gstreamer nvidia-jetson
1个回答
0
投票

您可以指定 gstreamer 后端进行捕获(似乎它尝试使用 IMAGE 后端),例如:

cap = cv2.VideoCapture("rtspsrc location=rtsp://10.34.134.1/Streaming/channels/1/ user-id=myuser user-pw=mypass !  rtph264depay ! h264parse ! nvv4l2decoder ! nvvidconv ! video/x-raw, format=BGRx ! videoconvert ! video/x-raw,format=BGR ! appsink drop=1", cv2.CAP_GSTREAMER)
© www.soinside.com 2019 - 2024. All rights reserved.