iT邦幫忙

0

Python RTSP 突然會無預警卡死

  • 分享至 

  • xImage
import cv2
from matplotlib import pyplot as plt
import queue
import threading
import time

class VideoCapture:
    def __init__(self, name):
        self.cap = cv2.VideoCapture(name)
        self.q = queue.Queue()
        t = threading.Thread(target=self._reader)
        t.daemon = True
        t.start()

  # read frames as soon as they are available, keeping only most recent one
    def _reader(self):
        while True:
            ret, frame = self.cap.read()
            if not ret:
                break
            if not self.q.empty():
                try:
                    self.q.get_nowait()   # discard previous (unprocessed) frame
                except queue.Empty:
                    pass
            self.q.put(frame)

    def read(self):
        return self.q.get()

cap = cv2.VideoCapture('rtsp://admin:Admin1234@192.168.1.146:554/cam/realmonitor?channel=1&subtype=0')

while True:
    start = time.time()
    _,frame =  cap.read()
    w,h, _ = frame.shape
    end = time.time()

    tmp = end-start
    print(1/tmp)
    
    #print(w,h)
    frame = cv2.resize(frame, (h//2, w//2), interpolation=cv2.INTER_AREA)
    cv2.imshow('frME',frame)
    if  cv2.waitKey(1) & 0xFF == ord('q'):
       break


    
cap.release()
cv2.destroyAllWindows()    

放久沒有錯誤突然過幾天就卡在一個畫面然後就掛了,請問有什麼可能性??

圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

2 個回答

0
PPTaiwan
iT邦好手 1 級 ‧ 2023-04-14 16:28:29

問一下 GPT4 如何 https://sharegpt.com/c/gKDWfjP

https://ithelp.ithome.com.tw/upload/images/20230414/20104851IMAX3YyZ0E.png

alanotmt iT邦新手 4 級 ‧ 2023-04-14 16:57:48 檢舉

好像還滿有用的誒,這些點我加入看看會不會再次當掉

0
souda
iT邦好手 1 級 ‧ 2023-04-15 10:00:51

串流模式很多~建議您都嘗試看看
rtsp rtmp hls obs 等等之類的.

我要發表回答

立即登入回答