2013-04-03 292 views
9

我試圖從本地安裝的Logitech C920攝像機從/dev/video0Gstreamer 1.0v4l2src元素捕獲H264流。從Gstreamer攝像頭捕獲h.264流

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. 

任何幫助!

回答

9

是您需要的GStreamer強制性?羅技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://本地主機:8554 /現場

如果GStreamer是我只設法使用一個捕獲實用程序,你可以在這裏找到:https://github.com/csete/bonecam - 目錄「捕獲」

你必須編譯它,但如果你有一些編程技巧,它應該很容易,因爲那裏只有一個C文件和一個腳本來幫助。剛剛通過的「主機」作爲參數傳遞給腳本:

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

您可以使用「捕獲」實用程序與類似的東西:

$ 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」參數與「捕獲」),這個工具有一個分支,你可以在這裏找到:https://github.com/DeLaGuardo/bonecam

我知道有一個插件歸類爲「壞」,稱爲uvch264 gstreamer 0.10,這應該與C920一起工作。但我不知道gstreamer 1.0,我無法測試它。

UPD:

不要忘記添加--rtsp-timeout=-1cvlc命令行像

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

沒有這個選項只流持續60秒默認。

+0

非常感謝! 'cvlc'就像一個魅力!我在Rasperry Pi上使用它。 –

+0

C920處於H264模式?你確定?由於Raspberry Pi上的USB問題,我在使用Raspberry Pi啓用相機的H264模式時遇到了很多問題。由於這個問題,一些H264幀丟失了,所以視頻很奇怪。事實上,正因爲如此,我在一個Beaglebone上使用了C920。 無論如何,如果它適合你,我想在固件中有一個更新來解決這個問題。 –

+0

我以前有丟幀的USB問題。我在這裏安裝了新的Rapbian內核(https://github.com/raspberrypi/linux/issues/238)。丟幀問題消失。現在流式傳輸H264視頻非常流暢。 –

1

我一直在嘗試做同樣的事情,並且得到了同樣的錯誤。我相信我在使用GStreamer 1.0.6。

我發現了什麼,甚至可能由於Fergal巴特勒的回答,是以下頁面:

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

這裏Youness阿拉維描述了他作出帶來的GStreamer H264攝像機支持uvch264_src元素。

他在GStreamer 1.0中描述了他的文章中的掛起端口。所以在上週我一直在研究這個。事實證明,已將移植到GStreamer 1.0,但僅限於開發者版本(版本1.1.2)。

你可以得到1.1.2版本在這裏:

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

這就是所謂的 「uvch264src」 現在,它的GST-插件壞的一部分。我認爲它也出現在版本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墊)只是掛鉤src.vfsrc直上一個fakesink。我還應該提到,儘管這條管線對我來說很有用,但我對「在分段事件之前有數據流」有很多警告。所以顯然我沒有做正確的事,但我不確定是什麼。

無論如何,在完成了1.1.2和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

0

嘗試使用videoconvert自動將視頻轉換成由視頻理解的格式沉

gst-launch-1.0 -vvv v4l2src device=/dev/video0 ! videoconvert ! ... 
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錄製。