openCV和多处理读取错误[H264 @ 0x7FA02816F2C0]错误在解码MB 26 11,Bytestream -7时

发布于 2025-01-25 19:51:37 字数 1717 浏览 1 评论 0 原文

我读了此线程,并使用线程使流工作。

正如在投票的答案中所建议的那样,我使用不同的功能来读取流并处理帧如下。

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

一切都按照线程的预期工作:

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

使用多处理,但是无法解码帧:

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

eRROMESSAGE像 [H264 @ 0x7FA02816F2C0]错误,在解码MB 26 11,Bytestream -7 对于每个帧中。 快速旁注,“ noc scorestl” 永远不会打印,因此可以始终抓住框架

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

北陌 2025-02-01 19:51:37

仍然没有直接工作,但是由于接收功能不是很重。我最终以不同的线程和所有其他功能(例如准备)运行它,这些功能都更加复杂,并且CPU在不同的过程中界定。这使我的应用保持足够的水平。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文