1

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

Tom S
  • 591
  • 1
  • 5
  • 21
  • 1
    Thank you for the provided links. They all are talking about threading however, which I got to work. The problem described however is in context of multiprocessing. – Tom S May 04 '22 at 07:08

1 Answers1

0

Still haven't got this to work directly, but since the Receive function is not very compute heavy. I ended up running it in a different thread and all other functions such as Prepare, which are all quite a bit more complex and CPU bounded in different processes. This keep parallelism at an sufficient level for my application.

Tom S
  • 591
  • 1
  • 5
  • 21