Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 1584

Python • MJPEG live streaming failed

$
0
0
CODE

import cv2

cap = cv2.VideoCapture(0,cv2.CAP_V4L2)
assert cap.isOpened()
cap.set(cv2.CAP_PROP_FOURCC, cv2.VideoWriter_fourcc(*'MJPG'))
cap.set(cv2.CAP_PROP_FRAME_WIDTH, 1280)
cap.set(cv2.CAP_PROP_FRAME_HEIGHT, 720)

while True:
ret, frame = cap.read()
if not ret:
break
cv2.imshow("Live Camera Feed", frame)

if cv2.waitKey(1) == 27:
break

release_camera(cap)

Streaming a USB camera with MJPEG format instead of UYVY. It works when running the code for the first time, every attempt afterwards will provide the following error:

Traceback (most recent call last):
File "/home/test.py", line 10, in <module>
ret, frame = cap.read()
^^^^^^^^^^
cv2.error: OpenCV(4.6.0) ./modules/imgcodecs/src/loadsave.cpp:816: error: (-215:Assertion failed) !buf.empty() in function 'imdecode_'



------------------
(program exited with code: 1)
Press return to continue

Kindly advise

Statistics: Posted by tove — Wed Jun 11, 2025 6:25 am



Viewing all articles
Browse latest Browse all 1584

Trending Articles