[轉]GStreamer資料(攝像頭采集,視頻保存,遠程監控)DVR


http://blog.csdn.net/wzwxiaozheng/archive/2010/12/26/6099397.aspx

GStreamer資料整理(包括攝像頭采集,視頻保存,遠程監控,流媒體RTP傳輸)

1,gstreamer開發手冊,gstreamer官網(這些都不用說了吧)

 

2,gst-launch的用法,這也不用說了吧。(白菜,雞蛋,西紅柿,磚頭,鼠標……..)

 

3,http://blog.chinaunix.net/u/6646/showart_164960.html

lqplayer--基於gstreamer和qt的linux下的簡單播放器。

實現了基於QT+GST的一個播放器。我下載源碼后編譯出現了幾個BUG,如下:

(1),源碼編譯不通過,media.cpp下有個地方大概是第54行,g_free(tag_list);,把這個地方注釋掉,資源沒有申請到還free,當然出錯了。(此BUG花了我幾十分鍾的時間)

(2),界面上的按鈕都不能使用,pthread_create(&tid, NULL, cb_run_loop, this);這句要注釋掉,我們的主循環使用的是QT的主循環,這個就不必了吧,要不就進GST的死循環了。(這個小BUG花了我某個星期六的一個清晨)

在這里還要說一下快放和慢放的問題:

gint64 value = m_frontend->sliderTiming->value();

 m_speed = m_speed+1;

 

        gst_element_seek (m_pipeline, m_speed, GST_FORMAT_TIME, GST_SEEK_FLAG_FLUSH,

                          GST_SEEK_TYPE_SET, value * GST_MSECOND*1000  ,

                          GST_SEEK_TYPE_SET, GST_CLOCK_TIME_NONE);

 

當m_speed為負值時可實現倒放,但是不穩定,僅幾秒鍾就會出現GST_MESSAGE_EOS。

 

當m_speed為負值時,我這樣實現

gst_element_seek (m_pipeline, m_speed, GST_FORMAT_TIME, GST_SEEK_FLAG_FLUSH,

                          GST_SEEK_TYPE_SET, GST_CLOCK_TIME_NONE  ,

                          GST_SEEK_TYPE_SET, value * GST_MSECOND*1000);

無非就是調了個位置,效果好了許多,不妨試一下。(為啥呢,我也不知道,此BUG花了我三四天的時間)

 

  4,http://www.pierrox.net/dvr/releases/dvr-3.99.4.tar.bz2

   基於QT3的,實現了GST的采集編碼,並保存為avi文件。總感覺這東西寫的有些地方讓人不爽,又說不出是哪里來。

 

  5,http://blog.chinaunix.net/u3/94516/showart_2269637.html

    GStreamer發送視頻/音頻流至服務器端並播放、保存。

    Client實現了gstreamer視頻文件的RTP發送,寫個vlc的配置文件,使用vlc打開可以在網絡上進行觀看(vlc的使用和配置文件使用可以從網上搜一下,還是比較多的),效果還不錯.源碼實現時稍顯繁瑣。Decodebin的連接要注意一下。還有就是gstrtpbin的連接要仔細看一下,剛開始感覺有些麻煩,錯誤了好幾次。后來才明了了。(此功能的源碼實現花了我一整天的時間,早9-晚11)

    Server端,試了,沒成功,后來就沒仔細看。

 

  6,http://www.since1985i.com/tag/gstreamer

    Gstreamer實現攝像頭采集並顯示。不過是命令行下的,相對上面RTP網絡的例子來說,這個用源碼實現可就是小case了吧。同樣結合上面RTP傳輸的例子,也同樣使用vlc來播放,就可以實現網絡攝像頭。(哇塞,網絡攝像頭耶!遠程監控耶!攝像頭采集花了我兩個月的時間吧,當時還年輕,后來發現是攝像頭的問題,當然,這個也算是BUG,總結經驗就是十幾塊的攝像頭是靠不住的)

 

總結:上面有了攝像頭采集保存的例子,有利用QT+GST實現播放器的例子,有RTP傳輸的例子,這樣就可以實現用QT做界面,Gstreamer做后台的集采集編碼保存,還有本地視頻回放,網絡視頻監控於一體的DVR軟件了。嗯,功能還挺全的。有意思吧~~

 

結束語:向以上幾位哥們兒致敬。剛開始做民工,有你們的分享我很慶幸。

 

==========================================================================================

==================下邊這個實在看不懂 留下研究=============================================

 

http://blog.csdn.net/wzwxiaozheng/archive/2011/01/12/6130818.aspx

在網上閑逛搜GST,不小心發現了一個網址

http://wiki.oz9aec.net/index.php/Gstreamer_cheat_sheet

是WIKI的GStreamer小抄,應該是這樣翻譯吧。

看了這個網址我就笑了。

上面講了gstreamer字符疊加,畫中畫,屏牆等的實現,附帶實現的命令,這樣實現源碼就小case了。

本文描述了gstreamer可實現的功能,主要是針對本硬盤錄像機軟件功能來說的,以gst-launch命令行的方式,簡潔明了,並附有插圖。大部分是網絡資源,小部分是自己研究。難免有疏漏,敬請指正。

 

參考網址:

1,http://wiki.oz9aec.net/index.php/Gstreamer_cheat_sheet#Video_Wall:_Live_from_Pluto

,gstreamer實現攝像頭采集 ,gstreamer實現視頻顯示 ,將4/3顯示轉換為16/9 ,實現h264編碼並保存 ,將保存的視頻播放,gstreamer實現視頻截圖 ,gstreamer實現字符疊加 ,gstreamer實現RTP網絡服務端及客戶端 ,gstreamer實現畫中畫,gstreamer實現屏牆效果

 

 

1,gstreamer實現攝像頭采集:

gst-launch v4l2src ! xvimagesink   gst-launch v4l2src !  video/x-raw-yuv,width=320,height=240,framerate=20/1 ! xvimagesink(未通過)   gst-launch v4l2src ! video/x-raw-yuv,format=\(fourcc\)YUY2,width=320,height=240 ! xvimagesink (通過,)

 

2,gstreamer實現視頻顯示

gst-launch videotestsrc ! ximagesink (通過) 

 

  

3,gstreamer實現字符疊加

gst-launch videotestsrc ! timeoverlay ! xvimagesink (通過)   gst-launch -v videotestsrc ! video/x-raw-yuv, framerate=25/1, width=640, height=360 ! \    timeoverlay halign=left valign=bottom text="Stream time:" shaded-background=true ! xvimagesink (通過) 添加timeoverlay的效果,timeoverlay基於textoverlay 
  其它一些相關元件的使用: gst-launch videotestsrc ! cairotimeoverlay ! xvimagesink  (未通過) gst-launch videotestsrc ! clockoverlay ! xvimagesink (通過) gst-launch videotestsrc ! clockoverlay halign=right valign=bottom shaded-background=true time-format="%Y.%m.%D" ! ffmpegcolorspace ! ximagesink (通過) gst-launch -e v4l2src ! video/x-raw-yuv,format=\(fourcc\)YUY2,width=1280,height=720,framerate=5/1 ! \    ffmpegcolorspace ! \    timeoverlay halign=right valign=top ! clockoverlay halign=left valign=top time-format="%Y/%m/%d %H:%M:%S" ! \    tee name="splitter" ! queue ! xvimagesink sync=false splitter. ! \    queue ! videorate ! video/x-raw-yuv,framerate=1/1 ! \    theoraenc bitrate=256 ! oggmux ! filesink location=webcam.ogg (未通過) 

 

4,gstreamer實現RTP網絡服務端及客戶端

客戶端: gst-launch -v gstrtpbin name=rtpbin latency=100 , udpsrc caps="application/x-rtp, media=(string)video, clock-rate=(int)90000, encoding-name=(string)H264, ssrc=(uint)340005641,clock-base=(uint)2625017333, payload=(int)96,  seqnum-base=(uint)5894" port=5000 ! queue ! rtpbin.recv_rtp_sink_0  rtpbin. ! rtph264depay ! queue ! ffdec_h264 ! videoscale ! autovideosink udpsrc port=5001 ! queue ! rtpbin.recv_rtcp_sink_0 rtpbin.send_rtcp_src_0 ! queue ! udpsink port=5005  sync=true  async=false (在windows底下成功,linux應該也沒問題)   服務端: gst-launch -v  gstrtpbin name=rtpbin latency=100 \         uridecodebin uri=file:///home/miia/test.avi name=decoder \         decoder. ! tee name=tee0 \         tee0. ! queue2 ! ffmpegcolorspace ! videoscale ! autovideosink \         tee0. ! queue2 ! ffmpegcolorspace ! x264enc ! rtph264pay pt=96 ! queue2 ! rtpbin.send_rtp_sink_0 \         rtpbin.send_rtp_src_0 ! queue2 ! udpsink host=192.168.0.105 port=5000  async=false\         rtpbin.send_rtcp_src_0 ! queue2 ! udpsink host=192.168.0.105 port=5001 async=false\         udpsrc port=5005 ! queue2 ! rtpbin.recv_rtcp_sink_0 \          \         decoder. ! tee name=tee1 \         tee1. ! queue2 ! audioconvert ! autoaudiosink \         tee1. ! queue2 !  audioconvert ! faac !     rtpmp4apay pt=96 ! queue2 ! rtpbin.send_rtp_sink_1 \         rtpbin.send_rtp_src_1 ! queue2 ! udpsink host=192.168.0.105 port=5002  async=false\         rtpbin.send_rtcp_src_1 ! queue2 ! udpsink host=192.168.0.105 port=5003 async=false\         udpsrc port=5007 ! queue2 ! rtpbin.recv_rtcp_sink_1 (在linux底下成功)  
From man gst-launch: Network streaming       Stream video using RTP and network elements.       gst-launch v4l2src ! video/x-raw-yuv,width=128,height=96,format='(fourcc)'UYVY ! ffmpegcolorspace ! ffenc_h263       ! video/x-h263 ! rtph263ppay pt=96 ! udpsink host=192.168.1.1 port=5000 sync=false       Use this command on the receiver       gst-launch  udpsrc  port=5000 ! application/x-rtp, clock-rate=90000,payload=96 ! rtph263pdepay queue-delay=0 !       ffdec_h263 ! xvimagesink    

 

5,gstreamer實現視頻截圖

  gst-launch -e v4l2src ! video/x-raw-yuv,format=\(fourcc\)YUY2,width=1280,height=720,framerate=5/1 ! ffmpegcolorspace ! \    timeoverlay halign=right valign=bottom ! clockoverlay halign=left valign=bottom time-format="%Y/%m/%d %H:%M:%S" ! \    videorate ! video/x-raw-rgb,framerate=1/1 ! ffmpegcolorspace ! pngenc snapshot=false ! multifilesink location="frame%05d.png" (未通過) 

 

6,gstreamer實現畫中畫效果

gst-launch -e videotestsrc pattern="snow" ! video/x-raw-yuv, framerate=10/1, width=200, height=150 ! videomixer name=mix ! \    ffmpegcolorspace ! xvimagesink videotestsrc ! video/x-raw-yuv, framerate=10/1, width=640, height=360 ! mix. (通過,效果跟圖片一樣) 在一個窗口中同時顯示兩個視頻界面 
  gst-launch videotestsrc pattern="snow" ! video/x-raw-yuv, framerate=10/1, width=200, height=150 ! \   videomixer name=mix sink_1::xpos=20 sink_1::ypos=20 sink_1::alpha=0.5 sink_1::zorder=3 sink_2::xpos=100 sink_2::ypos=100 sink_2::zorder=2 ! \    ffmpegcolorspace ! xvimagesink videotestsrc pattern=13 ! video/x-raw-yuv, framerate=10/1, width=200, height=150 ! mix. \    videotestsrc ! video/x-raw-yuv, framerate=10/1, width=640, height=360 ! mix. 設置視頻界面的位置和效果,alpha透明效果 
gst-launch \    videomixer name=mix sink_1::xpos=20 sink_1::ypos=20 sink_1::alpha=0.5 sink_1::zorder=3 sink_2::xpos=100 sink_2::ypos=100 sink_2::zorder=2 ! \    ffmpegcolorspace ! xvimagesink \    videotestsrc ! video/x-raw-yuv, framerate=10/1, width=640, height=360 !  mix.sink_0 \    videotestsrc pattern="snow" ! video/x-raw-yuv, framerate=10/1, width=200, height=150 !  mix.sink_1 \    videotestsrc pattern=13 ! video/x-raw-yuv, framerate=10/1, width=200, height=150 !  mix.sink_2 (通過,效果非常好,跟圖片一樣) 
gst-launch -e videotestsrc pattern="snow" ! video/x-raw-yuv, framerate=10/1, width=200, height=150 !  videobox border-alpha=0 top=-20 left=-25 ! \    videomixer name=mix ! ffmpegcolorspace ! xvimagesink videotestsrc ! video/x-raw-yuv, framerate=10/1, width=640, height=360 ! mix.   Videobox的使用: 
  gst-launch -e videotestsrc pattern="snow" ! video/x-raw-yuv, framerate=10/1, width=200, height=150 ! \   videobox border-alpha=0  alpha=0.6 top=-20 left=-25 ! videomixer name=mix ! ffmpegcolorspace ! xvimagesink \   videotestsrc ! video/x-raw-yuv, framerate=10/1, width=640, height=360 ! mix. (通過) Videobox和alpha效果 
  gst-launch -e videotestsrc pattern="snow" ! video/x-raw-yuv, framerate=10/1, width=200, height=150 ! \    videobox border-alpha=1.0 top=-2 bottom=-2 left=-2 right=-2 ! videobox border-alpha=0 alpha=0.6 top=-20 left=-25 ! \    videomixer name=mix ! ffmpegcolorspace ! xvimagesink videotestsrc ! video/x-raw-yuv, framerate=10/1, width=640, height=360 ! mix. (通過,效果略有出入,不透明) border-alpha,加邊框的透明效果 
  gst-launch -e videomixer name=mix ! ffmpegcolorspace ! xvimagesink \    videotestsrc pattern=1 ! video/x-raw-yuv, framerate=5/1, width=320, height=180 ! videobox border-alpha=0 top=0 left=0 ! mix. \    videotestsrc pattern=15 ! video/x-raw-yuv, framerate=5/1, width=320, height=180 ! videobox border-alpha=0 top=0 left=-320 ! mix. \    videotestsrc pattern=13 ! video/x-raw-yuv, framerate=5/1, width=320, height=180 ! videobox border-alpha=0 top=-180 left=0 ! mix. \    videotestsrc pattern=0 ! video/x-raw-yuv, framerate=5/1, width=320, height=180 ! videobox border-alpha=0 top=-180 left=-320 ! mix. \    videotestsrc pattern=3 ! video/x-raw-yuv, framerate=5/1, width=640, height=360 ! mix. (通過) 

 

7,gstreamer實現屏牆效果

   gst-launch -e videomixer name=mix ! ffmpegcolorspace ! xvimagesink \    videotestsrc pattern=0 ! video/x-raw-yuv, framerate=1/1, width=350, height=250 ! \      textoverlay font-desc="Sans 24" text="CAM1" valign=top halign=left shaded-background=true ! \      videobox border-alpha=0 top=-200 left=-50 ! mix. \    videotestsrc pattern="snow" ! video/x-raw-yuv, framerate=1/1, width=350, height=250 ! \      textoverlay font-desc="Sans 24" text="CAM2" valign=top halign=left shaded-background=true ! \      videobox border-alpha=0 top=-200 left=-450 ! mix. \    videotestsrc pattern=13 ! video/x-raw-yuv, framerate=1/1, width=350, height=250 ! \      textoverlay font-desc="Sans 24" text="CAM3" valign=top halign=left shaded-background=true ! \      videobox border-alpha=0 top=-200 left=-850 ! mix. \    multifilesrc location="pluto.jpg" caps="image/jpeg,framerate=1/1" ! jpegdec ! \     textoverlay font-desc="Sans 26" text="Live from Pluto" halign=left shaded-background=true auto-resize=false ! \      ffmpegcolorspace ! video/x-raw-yuv,format=\(fourcc\)AYUV ! mix. (修改幾個參數后,通過,但效果不好,根據環境不同,所修改的參數不同。在本次試驗中,把最后一行的format=\(fourcc\)AYUV去掉,則通過。本來應該顯示三個畫面,這次經驗顯示不全,不知道什么原因。不過經調試三個畫面都顯示了,但是,圖片被黑框檔掉一塊兒,沒有示例圖片好看) 
  
可執行的命令行:(通過,需多次執行) gst-launch -e videomixer name=mix ! ffmpegcolorspace ! ximagesink \   videotestsrc pattern=0 ! video/x-raw-yuv, framerate=10/1, width=350, height=250 ! \      textoverlay font-desc="Sans 24" text="CAM1" valign=top halign=left shaded-background=true ! \      videobox border-alpha=0 top=-200 left=-850 ! mix. \    videotestsrc pattern="snow" ! video/x-raw-yuv, framerate=10/1, width=350, height=250 ! \      textoverlay font-desc="Sans 24" text="CAM2" valign=top halign=left shaded-background=true ! \     videobox border-alpha=0 top=-200 left=-450 ! mix. \    videotestsrc pattern=13 ! video/x-raw-yuv, framerate=10/1, width=350, height=250 ! \      textoverlay font-desc="Sans 24" text="CAM3" valign=top halign=left shaded-background=true ! \      videobox border-alpha=0 top=-200 left=-50 ! mix. \    multifilesrc location="pluto.jpg" caps="image/jpeg,framerate=10/1" ! jpegdec ! \      textoverlay font-desc="Sans 26" text="Live from Pluto" halign=left shaded-background=true auto-resize=false ! \      ffmpegcolorspace ! video/x-raw-yuv ! mix.


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM