Analysis of the process of processing RSTP video stream in Python

Time:2021-2-26

This article mainly introduces the process analysis of RSTP video stream processing by python. The sample code is introduced in great detail, which has a certain reference learning value for everyone’s study or work. Friends in need can refer to it

Python links the Haikang camera and plays the real-time video stream in the form of pop-up box,

This method is played in the form of pop-up box. Local testing is OK, but it is not recommended for actual business scenarios. RTSP to RTMP can be used

@shared_task
def parse_video(rtsp_address=None):
  winname = 'Video'
  if not rtsp_address:
    raise  exceptions.ParseError ('camera RSTP address error! ")

  cap = cv2.VideoCapture(rtsp_address)
  if not cap.isOpened():
    raise  exceptions.ParseError ('video playback failed!)

  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()

The above is the whole content of this article, I hope to help you learn, and I hope you can support developer more.

Recommended Today

Practice analysis of rust built-in trait: partialeq and EQ

Abstract:Rust uses traits in many places, from simple operator overloading to subtle features like send and sync. This article is shared from Huawei cloud community《Analysis of rust built-in trait: partialeq and EQ》Author: debugzhang Rust uses traits in many places, from simple operator overloading to subtle features like send and sync. Some traits can be automatically […]