I am trying to use OpenCV (python bindings) to connect to a UDP multicast network and restore individual received frames for further processing.
I can connect to my multicast via VLC, and the VLC displays the broadcast without any problems. VLC reports that the codec that it uses for decoding is H264 - MPEG-4 AVC (part 10).
When I try to decode using OpenCV, I see my video stream, but many frames look fragmented. The frames look as if the last row of pixels had just been repeated to fill the rest of the image (sometimes 75% or more of the whole image). OpenCV reports decoding errors (error while decoding MB ...., bytestream).
Is there a way to get OpenCV to use any VLC codec? I tried to specify a specific codec to use in my code for OpenCV, but it does not seem to have any effect.
The code I'm using is below:
import numpy as np
import cv2
from cv2 import cv
cap = cv2.VideoCapture()
cap.set(cv.CV_CAP_PROP_FOURCC, cv.CV_FOURCC('A','V','C','1'))
cwi=cap.open(r'myurlandport')
counter = 0
while(cap.isOpened()):
ret, frame = cap.read()
counter += 1
if counter % 30 == 0:
cv2.imshow('frame', frame)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
cap.release()
cv2.destroyAllWindows()
source
share