使用python阅读rtmp直播视频



我正在使用rtmp服务器(NGINX(流式传输会话。我获得的流url为CCD_ 1。我如何读取python代码(或任何其他代码(中的实时流来进行实时转录?

您必须使用允许此类过程的库之一,最常用的库之一是OpenCV。

通过pip安装:

python3 -m pip install opencv-python

代码示例

import cv2  # Import OpenCV lib
cap = cv2.VideoCapture('<your RTMP url>') # Open video source as object
while cap.isOpened():  # Untill end of file/error occured
ret, frame = cap.read()  # Read frame as object - numpy.ndarray, ret is a confirmation of a successfull retrieval of the frame
if ret: 
<your code here>
else:
break
cap.release()

最新更新