运行来自opencv videowriter api的gstreamer管道命令,以将连续的图像流传输到hlssink

问题描述 投票:0回答:1

[我正在尝试使用opencv videowriter api从视频卡设备流式传输连续图像,下面是执行操作的opencv代码段,我的问题是我正在获取帧,但没有获取在/中生成的任何index.m3u8文件。 var / www文件夹,我是opencv的新手,并且gstreamer无法确定这是否可以从opencv实现,或者我必须使用其他某种机制

输入视频设备是仅支持MJEPG编解码器的视频卡

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()
python opencv gstreamer http-live-streaming hlsl
1个回答
0
投票

OpenCv的VideoWriter仅在其GStreamer接口上支持BGR帧。可能VideoCapture还将图像转换为BGR。

因此,您无需在gstreamer管道中解码jpeg。但是x264enc并不总是接受BGR作为输入,因此您应该在videoconvert和x264enc`]之间添加appsrc

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))
© www.soinside.com 2019 - 2024. All rights reserved.