'Open UDP Stream with open cv

I try to open the UDP video stream with OpenCV, unfortunately, I get an error but when I open the Stream with FFmpeg ffplay udp://127.0.0.1:46002 everything work fine.

Here my code:

import cv2

cap = cv2.VideoCapture('udp://127.0.0.1:46002', cv2.CAP_FFMPEG)
if not cap.isOpened():
    print('VideoCapture not opened')
    exit(-1)

while True:
    ret, frame = cap.read()
    if not ret:
        print('frame empty')
        break
    cv2.imshow('image', frame)
    if cv2.waitKey(1) & 0XFF == ord('q'):
         break

cap.release()
cv2.destroyAllWindows()

here is the error that I get:

[h264 @ 1135fa40] no frame!
[h264 @ 1135fa40] non-existing PPS 0 referenced
[h264 @ 1135fa40] non-existing PPS 0 referenced
[h264 @ 1135fa40] decode_slice_header error
[h264 @ 1135fa40] non-existing PPS 0 referenced
[h264 @ 1135fa40] decode_slice_header error
[h264 @ 1135fa40] no frame!
[h264 @ 1135fa40] non-existing PPS 0 referenced
[h264 @ 1135fa40] non-existing PPS 0 referenced
[h264 @ 1135fa40] decode_slice_header error
[h264 @ 1135fa40] non-existing PPS 0 referenced
[h264 @ 1135fa40] decode_slice_header error
[h264 @ 1135fa40] no frame!
[h264 @ 1135fa40] non-existing PPS 0 referenced
[h264 @ 1135fa40] non-existing PPS 0 referenced
[h264 @ 1135fa40] decode_slice_header error
[h264 @ 1135fa40] non-existing PPS 0 referenced
[h264 @ 1135fa40] decode_slice_header error
[h264 @ 1135fa40] no frame!


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source