使用Gstreamer从相机捕获h.264流

时间:2013-04-03 12:56:24

标签: h.264 gstreamer v4l2

我正尝试使用/dev/video0 Gstreamer 1.0元素从v4l2src本地安装的Logitech C920相机捕获H264流。

v4l2-ctl --list-formats表示相机能够提供H264视频格式:

# v4l2-ctl --list-formats
ioctl: VIDIOC_ENUM_FMT
        ...

        Index       : 1
        Type        : Video Capture
        Pixel Format: 'H264' (compressed)
        Name        : H.264

        ...

但管道

# gst-launch-1.0 -vvv v4l2src device=/dev/video0 ! video/x-h264, width=800, height=448, framerate=30/1 ! fakesink

不断给我not-negotiated (-4)错误:

/GstPipeline:pipeline0/GstV4l2Src:v4l2src0.GstPad:src: caps = video/x-h264, width=(int)800, height=(int)448, interlace-mode=(string)progressive, pixel-aspect-ratio=(fraction)1/1, framerate=(fraction)30/1
/GstPipeline:pipeline0/GstCapsFilter:capsfilter0.GstPad:src: caps = video/x-h264, width=(int)800, height=(int)448, interlace-mode=(string)progressive, pixel-aspect-ratio=(fraction)1/1, framerate=(fraction)30/1
/GstPipeline:pipeline0/GstFakeSink:fakesink0.GstPad:sink: caps = video/x-h264, width=(int)800, height=(int)448, interlace-mode=(string)progressive, pixel-aspect-ratio=(fraction)1/1, framerate=(fraction)30/1
/GstPipeline:pipeline0/GstCapsFilter:capsfilter0.GstPad:sink: caps = video/x-h264, width=(int)800, height=(int)448, interlace-mode=(string)progressive, pixel-aspect-ratio=(fraction)1/1, framerate=(fraction)30/1
ERROR: from element /GstPipeline:pipeline0/GstV4l2Src:v4l2src0: Internal data flow error.
Additional debug info:
gstbasesrc.c(2809): gst_base_src_loop (): /GstPipeline:pipeline0/GstV4l2Src:v4l2src0:
streaming task paused, reason not-negotiated (-4)
Execution ended after 67687169 ns.

任何帮助!

5 个答案:

答案 0 :(得分:10)

gstreamer是否符合您的需求? Logitech C920在H264模式和gstreamer中也存在很多问题。但我设法使用VLC作为RTSP服务器将C920用于H264:

$ cvlc -v v4l2:///dev/video0:chroma="H264":width=1024:height=570:fps=30 \
       --sout="#rtp{sdp=rtsp://:8554/live}"

然后我可以将另一个VLC连接到URI rtsp:// localhost:8554 / live

如果GStreamer对你来说是强制性的,我只能设法使用你可以在这里找到的捕获工具:https://github.com/csete/bonecam - 目录“capture”

你必须编译它,但是如果你有一些编程技巧,它应该很容易,因为只有一个C文件和一个脚本可以提供帮助。只需将“host”作为参数传递给脚本:

# Get the bonecam/capture content or git clone the directory, and then
$ cd bonecam/capture
$ ./build host

你可以使用“capture”实用程序:

$ v4l2-ctl -d /dev/video0 --set-fmt-video=width=1024,height=570,pixelformat=1
$ v4l2-ctl -d /dev/video0 --set-parm=30
$ ./bonecam/capture/capture -d /dev/video0 -c 100000 -o | \
      gst-launch -e filesrc location=/dev/fd/0 ! legacyh264parse ! rtph264pay ! udpsink host=10.0.0.42 port=5000

如果您不想指定要获取的帧数(“-c”参数带有“capture”),则可以在此处找到此实用程序的分支:https://github.com/DeLaGuardo/bonecam

我知道有一个分类为“坏”的插件,gstreamer 0.10称为uvch264,应该与C920配合使用。但我不知道gstreamer 1.0,我无法测试它。

<强> UPD:

不要忘记将--rtsp-timeout=-1添加到cvlc命令行,如

$ cvlc -v v4l2:///dev/video0:chroma="H264":width=1024:height=570:fps=30 \
       --sout="#rtp{sdp=rtsp://:8554/live}" --rtsp-timeout=-1

如果没有此选项,默认情况下,流式传输仅持续60秒。

答案 1 :(得分:3)

我一直在尝试做同样的事情而且我得到了同样的错误。我相信我使用的是GStreamer 1.0.6。

我发现的,甚至可能归功于Fergal Butler的答案,如下页:

http://kakaroto.homelinux.net/2012/09/uvc-h264-encoding-cameras-support-in-gstreamer/

这里Youness Alaoui描述了他为向GStreamer提供H264相机支持而制作的uvch264_src元素。

他在文章中将GStreamer 1.0的端口描述为待定。所以在过去的一周里我一直在研究这个问题。事实证明现已移植到GStreamer 1.0,但仅限于开发人员版本(版本1.1.2)。

您可以在此处获取版本1.1.2:

http://gstreamer.freedesktop.org/src/

现在它被称为“uv​​ch264src”,它是gst-plugins-bad的一部分。我认为它也存在于1.1.1版本中,但我还没有真正研究过它。

我在安装它时遇到了一些困难,我认为主要是因为与我的PC上安装的GST 1.0软件包发生冲突(所以我自己的错)。但请注意,它依赖于libgudev-1.0-dev和libusb-1.0-0-dev,所以首先安装这些软件包 - 我需要一段时间来解决这个问题。我错过了这两个软件包。

这是我开始使用uvch264的管道:

gst-launch-1.0 uvch264src device=/dev/video0 name=src auto-start=true src.vfsrc ! video/x-raw, format=YUY2, width=160, height=90, framerate=5/1 ! xvimagesink src.vidsrc ! queue ! video/x-h264, width=800, height=448, framerate=30/1 ! h264parse ! avdec_h264 ! xvimagesink

如果你不想使用预览视频(来自vfsrc pad),只需将src.vfsrc直接连接到fakesink。我还要提一下,即使这个管道对我有用,我也会收到很多关于“在段事件之前得到数据流”的警告。所以显然我做的不对,但我不确定是什么。

无论如何,在完全安装并运行了uvch264src的所有麻烦之后,我决定再次给v4l2src一个快速的去。事实证明,v4l2src完全支持H264:/。 (见简答。)


简答:

因此,对您的问题的简短回答是,如果您乐意从源代码安装1.1.2,您将能够以与尝试相同的方式完成您想要的操作。你不应该需要uvch264src。我已经测试了你的管道,它在我的安装上运行良好。我也尝试过这个简单的管道,在屏幕上显示视频,它也适用于我:

gst-launch-1.0 -e v4l2src device=/dev/video0 ! video/x-h264, width=800, height=448, framerate=30/1 ! avdec_h264 ! xvimagesink sync=false

答案 2 :(得分:0)

答案 3 :(得分:0)

尝试使用videoconvert自动将视频转换为视频接收器所理解的格式

gst-launch-1.0 -vvv v4l2src device=/dev/video0 ! videoconvert ! ...

答案 4 :(得分:0)

我还有罗技C920相机,并使用以下管道从相机录制H.264视频:

gst-launch-1.0 v4l2src device=/dev/video0 ! video/x-h264,width=1280,height=720,framerate=30/1 ! mpegtsmux ! filesink location=output.ts

这要求摄像机生成H.264数据,然后将其复用到MPEG transport stream容器中,然后写入磁盘。我可以使用Totem成功播放生成的文件。

以上管道记录在720p。如果您将请求的格式更改为width=1920,height=1080,相机也可以以1080p录制。