我正在使用OpenCV VideoCapture捕获视频帧.捕获工作正常,因为我能够使用这样的帧:
cv::VideoCapture cap("v4l2src device=/dev/video1 ! videoscale ! videorate ! video/x-raw, width=640, height=360, framerate=30/1 ! videoconvert ! appsink");
cv::imshow("feed", frame);
Run Code Online (Sandbox Code Playgroud)
我还想通过网络发送流,这是我被卡住的地方.不知怎的,我在appsrc管道部分失败了.我想将流编码为jpeg并将其发送给vie udp.这就是我得到的:
cv::VideoWriter writer
writer.open("appsrc ! videoconvert ! jpegenc ! jpegparse ! rtpjpegpay pt=96 ! udpsink host=192.168.1.25 port=5000", 0, (double)30, cv::Size(640, 360), true);
Run Code Online (Sandbox Code Playgroud)
看起来上面的行没有做任何事情.在writer << frame没有做任何事情.此gstreamer命令也不显示任何内容:
gst-launch-1.0 udpsrc port=5000 caps = "application/x-rtp, media=(string)video, clock-rate=(int)90000, encoding-name=(string)JPEG, payload=(int)96" ! rtpjpegdepay ! jpegdec ! decodebin ! videoconvert ! autovideosink
Run Code Online (Sandbox Code Playgroud)
我不知道我在哪里失败了writer.open.如果我运行像这样的gstreamer命令,他们的工作:
gst-launch-1.0 v4l2src device=/dev/video1 ! videoscale ! videorate ! video/x-raw, …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用gstreamer从opencv流式传输一些图像,但管道出现了一些问题。我是gstreamer和opencv的新手。我在树莓派3上用gstreamer为python3编译了opencv 3.2。我有一个与raspivid一起使用的bash脚本。
raspivid -fps 25 -h 720 -w 1080 -vf -n -t 0 -b 2000000 -o - | gst-launch-1.0 -v fdsrc ! h264parse ! rtph264pay config-interval=1 pt=96 ! gdppay ! tcpserversink host=192.168.1.27 port=5000
Run Code Online (Sandbox Code Playgroud)
我想转换此管道,以便从opencv中使用它,并将其输入我的算法处理的图像。我做了一些研究,发现可以将videoWriter与appsrc一起使用,而不是fdsrc,但是出现以下错误
GStreamer Plugin: Embedded video playback halted; module appsrc0 reported: Internal data flow error.
Run Code Online (Sandbox Code Playgroud)
我想出的python脚本是以下方式导入cv2
cap = cv2.VideoCapture(0)
# Define the codec and create VideoWriter object
fourcc = cv2.VideoWriter_fourcc(*'MJPG')
out = cv2.VideoWriter('appsrc ! h264parse ! '
'rtph264pay config-interval=1 pt=96 ! '
'gdppay ! tcpserversink host=192.168.1.27 port=5000 ', …Run Code Online (Sandbox Code Playgroud) 我试图将opencv图像放入python中的gstreamer rtsp服务器.我在mediafactory中写了一些问题,我是gst-rtsp-server ancd的新手,这里有很少的文档,所以我不确切知道我是否使用了正确的方法.我正在使用一个线程来启动MainLoop,我正在使用主线程创建一个缓冲区来推入mediafactory管道的appsrc元素.我使用正确的方法来获得我的目标吗?谁能帮我?我的代码如下:
from threading import Thread
from time import clock
import cv2
import gi
gi.require_version('Gst', '1.0')
gi.require_version('GstRtspServer', '1.0')
from gi.repository import Gst, GstRtspServer, GObject
class SensorFactory(GstRtspServer.RTSPMediaFactory):
def __init__(self, **properties):
super(SensorFactory, self).__init__(**properties)
self.launch_string = 'appsrc ! video/x-raw,width=320,height=240,framerate=30/1 ' \
'! videoconvert ! x264enc speed-preset=ultrafast tune=zerolatency ' \
'! rtph264pay config-interval=1 name=pay0 pt=96'
self.pipeline = Gst.parse_launch(self.launch_string)
self.appsrc = self.pipeline.get_child_by_index(4)
def do_create_element(self, url):
return self.pipeline
class GstServer(GstRtspServer.RTSPServer):
def __init__(self, **properties):
super(GstServer, self).__init__(**properties)
self.factory = SensorFactory()
self.factory.set_shared(True)
self.get_mount_points().add_factory("/test", self.factory)
self.attach(None)
GObject.threads_init()
Gst.init(None)
server …Run Code Online (Sandbox Code Playgroud) 我能够通过 VLC 命令行接收/查看 UDP h264 数据包(即 VLC --network-caching 0 --demux h264 udp://...)
我计划通过 OpenCV 算法处理这些帧。但是,我似乎找不到将 VLC 帧发送到我的 Python OpenCV 脚本的方法。
是否可以通过管道在单独的脚本中通过 Numpy 处理 VLC 流输出?
我之前曾尝试使用其 VideoCapture 功能直接流式传输到 OpenCV,但由于某种原因,视频停顿并停止在扭曲的黑色图像处。目前,似乎合并 VLC 是唯一的解决方案(尽管我不完全确定为什么 VLC 优于其他方法)。
谢谢你。
编辑:
以下是终端上的错误消息片段。前几帧似乎有问题,但我不知道为什么该流在 VLC 上有效。从客户端,我首先发送一个默认的关键帧数据,然后发送视频源 h264 数据。
[h264 @ 0x7f9c50020200] top block unavailable for requested intra mode -1
[h264 @ 0x7f9c50020200] error while decoding MB 7 0, bytestream 7208
[h264 @ 0x7f9c50020200] top block unavailable for requested intra mode -1
[h264 @ 0x7f9c50020200] error while decoding MB …Run Code Online (Sandbox Code Playgroud)