I read this thread and got the stream working using threading. opencv read error:[h264 @ 0x8f915e0] error while decoding MB 53 20, bytestream -7.
As suggested in the upvoted answer I use different functions for reading the stream and processing the frames as follows.
def Receive(stream, raw_frame_queue):
print("start Receive")
cap = cv2.VideoCapture(stream)
while True:
ret, frame = cap.read()
if not ret:
print("Not successfull")
break
raw_frame_queue.put(frame)
time.sleep(0.25)
cap.release()
def Prepare(raw_frame_queue):
print("Start preparing")
frame_buffer = deque([], 30)
while True:
if raw_frame_queue.empty():
continue
frame_buffer.append(raw_frame_queue.get())
lots of other stuff
everything works as expected with threading:
import queue
import threading
raw_frame_queue = queue.Queue()
if __name__=='__main__':
p1 = threading.Thread(target=Receive, args=((RTSP_URL, raw_frame_queue)))
p2 = threading.Thread(target=Prepare, args=((raw_frame_queue),))
p1.start()
p2.start()
Using multiprocessing however the frames can't be decoded:
from multiprocessing import Process, Queue
raw_frame_queue = Queue()
if __name__=='__main__':
p1 = Process(target=Receive, args=((RTSP_URL, raw_frame_queue)))
p2 = Process(target=Prepare, args=((raw_frame_queue),))
p1.start()
p2.start()
The errormessage are something like [h264 @ 0x7fa02816f2c0] error while decoding MB 26 11, bytestream -7
for every single frame.
Quick sidenote, "Not successfull"
is never printed, so the frames can always be grabbed