使用Gstreamer从相机捕获h.264流 [英] Capturing h.264 stream from camera with Gstreamer

查看:1180
本文介绍了使用Gstreamer从相机捕获h.264流的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm trying to capture H264 stream from locally installed Logitech C920 camera from /dev/video0 with Gstreamer 1.0 v4l2src element.

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

v4l2-ctl --list-formats shows that camera is capable to give H264 video format:

# 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.

任何帮助!

推荐答案

是否需要gstreamer?在H264模式和gstreamer上使用Logitech C920时,我也遇到很多问题.但是我设法将VLC用作RTSP服务器,以将C920与H264一起使用:

Is gstreamer mandatory for your needs? I also have lots of problems with the Logitech C920 in H264 mode and gstreamer. But I managed to use VLC as a RTSP server to use the C920 with 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

Then I can connect with another VLC to the URI rtsp://localhost:8554/live

如果您必须使用GStreamer,我只能将其与捕获实用程序一起使用,您可以在以下位置找到它: https://github.com. com/csete/bonecam -目录捕获"

If GStreamer is mandatory for you, I only managed to use it with a capture utility that you can find here: https://github.com/csete/bonecam - directory "capture"

您必须对其进行编译,但是如果您具有一些编程技能,则应该非常容易,因为只有一个C文件和一个脚本可以提供帮助.只需将主机"作为参数传递给脚本即可:

You have to compile it, but if you have some programming skills it shoud be very easy as there is only one C file and a script to help. Just pass "host" as a parameter to the script :

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

您可以使用"capture"实用程序进行类似的操作:

You can use the "capture" utility with something like that :

$ 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

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

If you do not like to specify the number of frame to get ("-c" parameter with "capture"), there is a fork to this utility that you can find here: https://github.com/DeLaGuardo/bonecam

我知道有一个分类为不好"的插件,对于gstreamer 0.10称为uvch264,该插件可以在C920上使用.但是我不知道gstreamer 1.0,也无法对其进行测试.

I know there is a plugin categorized as "bad", called uvch264 for gstreamer 0.10, that should work with the C920. But I do not know for gstreamer 1.0, and I could not test it.

UPD:

别忘了像

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

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

Without this option streaming only lasts for 60 seconds by default.

这篇关于使用Gstreamer从相机捕获h.264流的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆