python處理RSTP視頻流

python連接海康攝像頭,並以彈出框的方式播放實時視頻流,python

這種方式是以彈出框的形式播放。本地測試能夠,實際業務場景不建議使用。能夠採用rtsp轉rtmp的方式ide

@shared_task
def parse_video(rtsp_address=None):
    winname = 'Video'
    if not rtsp_address:
        raise exceptions.ParseError('攝像頭rstp地址錯誤!')

    cap = cv2.VideoCapture(rtsp_address)
    if not cap.isOpened():
        raise exceptions.ParseError('視頻播放失敗!')

    while cap.isOpened():
        ret, frame = cap.read()
        if not ret:
            break

        cv2.putText(frame, 'Please press "ESC" to close the window', (900, 20), cv2.FONT_HERSHEY_SIMPLEX, 0.5, (55, 255, 155), 1)
        cv2.imshow(winname, frame)
        k = cv2.waitKey(1)

        if cv2.getWindowProperty(winname, cv2.WND_PROP_AUTOSIZE) < 1:
            break
        if k == 27:
            break

    cap.release()
    cv2.destroyAllWindows()
相關文章
相關標籤/搜索