您的位置:首页 > 运维架构

[转]GStreamer资料(摄像头采集,视频保存,远程监控)DVR

2015-07-25 10:12 495 查看
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软件了。嗯,功能还挺全的。有意思吧~~

结束语:向以上几位哥们儿致敬。刚开始做民工,有你们的分享我很庆幸。

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

==================下边这个实在看不懂 留下研究=============================================

[转载]关于GStreamer的一个牛X网页(字符叠加,画中画,屏墙)

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.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: