I'm trying to stream continuos image from video card device using opencv videowriter api , below is the opencv code snippet which does the action, my problem is that i am getting the frame but not getting any index.m3u8 file generated inside /var/www folder i am new to opencv and gstreamer couldn't able to figure is this possible to achieve from opencv or i have to use some other mechanism
input video device is a video card which supports only MJEPG codec
import cv2
cap = cv2.VideoCapture('/dev/video0')
framerate = 30.0
out = cv2.VideoWriter('appsrc ! image/jpeg ! '
'jpegdec ! x264enc tune=zerolatency ! '
'mpegtsmux ! hlssink location=/var/www/segment-%05d.ts '
'playlist-location=/var/www/index.m3u8 max-files=20 target-duration=15',
0, framerate, (640, 480))
while cap.isOpened():
ret, frame = cap.read()
if ret:
out.write(frame)
else:
break
# Release everything if job is finished
cap.release()
out.release()
OpenCv's VideoWriter
only supports BGR frames on its GStreamer interface. Probably VideoCapture
will also convert image to BGR.
So you don't need to decode jpeg in your gstreamer pipeline. However x264enc
does not always accept BGR as input, so you should add videoconvert
between appsrc
and x264enc`
t = cv2.VideoWriter('appsrc ! videoconvert ! x264enc tune=zerolatency ! '
'mpegtsmux ! hlssink location=/var/www/segment-%05d.ts '
'playlist-location=/var/www/index.m3u8 max-files=20 target-duration=15',
0, framerate, (640, 480))