gstreamer应用笔记

gstreamer官网

GStreamer: open source multimedia framework

应用手册

GStreamer

一、getreamer安装(ubuntu)

gstreamer0.10和gstreamer1.0两个版本容易混淆

sudo add-apt-repository ppa:mc3man/trusty-media

sudo apt-get update

sudo apt-get install build-essential dpkg-dev flex bison autotools-dev automake liborc-dev autopoint libtool gtk-doc-tools

sudo apt-get install libgstreamer0.10-0 libgstreamer0.10-dev gstreamer0.10-tools gstreamer0.10-plugins-base libgstreamer-plugins-base0.10-dev gstreamer0.10-plugins-good gstreamer0.10-plugins-ugly gstreamer0.10-plugins-bad gstreamer0.10-ffmpeg

sudo apt-get install libgstreamer0.10-dev gstreamer-tools gstreamer0.10-tools gstreamer0.10-doc

sudo apt-get install gstreamer0.10-plugins-base gstreamer0.10-plugins-good gstreamer0.10-plugins-ugly gstreamer0.10-plugins-bad gstreamer0.10-plugins-bad-multiverse

若有需要还可以再安装如下gst插件:
gstreamer0.10-tools
gstreamer0.10-x
gstreamer0.10-plugins-base
gstreamer0.10-plugins-good
gstreamer0.10-plugins-ugly
gstreamer0.10-plugins-bad
gstreamer0.10-ffmpeg
gstreamer0.10-alsa
gstreamer0.10-schroedinger
gstreamer0.10-pulseaudio

有可能需要安装的软件:
sudo apt-get install bison
sudo apt-get install flex
sudo apt-get install zlib1g

mad解码插件
apt-get install libmad0-dev
apt-get install gstreamer0.10-plugins-ugly

安装音频库

sudo apt-get install gstreamer0.10-alsa

安装ffmpeg多媒体库

gst-ffmpeg
--enable-liba52       enable GPLed liba52 support [default=no]
--enable-liba52bin    open liba52.so.0 at runtime [default=no]
--enable-libamr-nb    enable libamr-nb floating point audio codec
--enable-libamr-wb    enable libamr-wb floating point audio codec
--enable-libfaac      enable FAAC support via libfaac [default=no]
--enable-libfaad      enable FAAD support via libfaad [default=no]
--enable-libfaadbin   open libfaad.so.0 at runtime [default=no]
--enable-libgsm       enable GSM support via libgsm [default=no]
--enable-libmp3lame   enable MP3 encoding via libmp3lame
--enable-libvorbis    enable Vorbis encoding via libvorbis,
                     native implementation exists [default=no]
--enable-libx264      enable H.264 encoding via x264 [default=no]
--enable-libxvid      enable Xvid encoding via xvidcore,
                      native MPEG-4/Xvid encoder exists [default=no]

插件太多了,几百上千个

List of Elements and Plugins

https://gstreamer.freedesktop.org/documentation/plugins.html

一劳永逸

sudo apt-get install gstreamer-plugins-*

sudo apt-get install gstreamer-*

二、 千里之行,始于"hello,world"

Tutorials

Basic tutorials

Basic tutorial 1: Hello world!

Basic tutorial 2: GStreamer concepts

Basic tutorial 3: Dynamic pipelines

Basic tutorial 4: Time management

Basic tutorial 5: GUI toolkit integration

Basic tutorial 6: Media formats and Pad Capabilities

Basic tutorial 7: Multithreading and Pad Availability

Basic tutorial 8: Short-cutting the pipeline

Basic tutorial 9: Media information gathering

Basic tutorial 10: GStreamer tools

Basic tutorial 11: Debugging tools

Basic tutorial 12: Streaming

Basic tutorial 13: Playback speed

Basic tutorial 14: Handy elements

Basic tutorial 16: Platform-specific elements

除了这16个入门samples,后面的pipelines Command line tools 和 Plugin 插件开发也是多媒体类应用极好的教材

官网才是最应该多关注的地方

Basic tutorial 1: Hello world!

wiki手册也非常全面,几乎所有应用方向都说明

OZ9AEC Website - Amateur radio, space, technology and other geeky stuff by Alexandru Csete

IBM社区gstreamer教程

IBM Developer

三、 gstreamer 进阶...

1、播放视频文件

   以MP4格式为例,其它格式可以 通过gst-inspect-1.0 |  grep  查找对应的demux,decode,sink等插件,当然也可以使用auto开头的插件,或者playbin会自动选择播放,只是没有自己指定那么灵活,方便调试和验证一些功能。

    1)硬解(vaapi)播放MP4文件:

     gst-launch-1.0 filesrc location=FilePath/test.mp4 ! qtdemux ! vaapidecode ! vaapisink

    2) 软解,只要将解码器vaapidecode换成avdec_h264,播放器vaapisink换成 ximagesink即可

2、播放RTSP视频流

    1) 硬解。

     gst-launch-1.0 rtspsrc location=rtsp://username:passwd@ipaddr:port  latency=0 ! rtph264depay  !  capsfilter caps="video/x-h264"  ! h264parse  ! vaapidecode  !  vaapipostproc  width=800 height=600  !  vaapisink sync=false

    2)软解。

   gst-launch-1.0 rtspsrc location=rtsp://username:passwd@ipaddr:port  latency=0 ! rtph264depay ! capsfilter caps="video/x-h264" ! h264parse ! avdec_h264 ! videoconvert ! videoscale ! video/x-raw,width=800,height=600 ! ximagesink

3、 播放Udp视频流

    Udp播放需要根据发送端数据源封装格式来决定采用哪些Gstreamer插件,如果进行了RTP封装,则需要先用rtph264depay进行解包,如果包含自定义帧头的情况,应该编程对帧头进行处理,不然会显示异常,比如部分花屏现象,以下是对裸流进行播放。    

1)硬解

     gst-launch-1.0 udpsrc port=2101 ! h264parse ! vaapidecode ! vaapisink

2)软解

     gst-launch-1.0  udpsrc port=2101 ! h264parse ! avdec_h264 !  autovideosink

参考使用 Gstreamer 命令播放视频文件及视频流_gstreamer 播放视频_MJZ0508的博客-CSDN博客

4、gstreamer rtsp推流/拉流

    1)gstreamer rtsp拉流播放

    linux环境下用GStreamer实现rtsp取流播放_linux rtsp 取流并播放音频_月上柳青的博客-CSDN博客

    2)gstereamer rtsp推流

    gstreamer的rtsp推流_gstreamer rtsp 推流_Kerr_hg的博客-CSDN博客

    3) On the Raspberry:

$ gst-launch-1.0 rtspsrc location=rtsp://192.168.2.112:8080/stream.sdp ! rtph264depay ! h264parse ! omxh264dec ! autovideosink

5、rtpbin Network/RTP

send

Encode and payload H263 video captured from a v4l2src. Encode and payload AMR audio generated from audiotestsrc. The video is sent to session 0 in rtpbin and the audio is sent to session 1. Video packets are sent on UDP port 5000 and audio packets on port 5002. The video RTCP packets for session 0 are sent on port 5001 and the audio RTCP packets for session 0 are sent on port 5003. RTCP packets for session 0 are received on port 5005 and RTCP for session 1 is received on port 5007. Since RTCP packets from the sender should be sent as soon as possible and do not participate in preroll, sync=false and async=false is configured on udpsink

gst-launch-1.0 rtpbin name=rtpbin \
        v4l2src ! videoconvert ! ffenc_h263 ! rtph263ppay ! rtpbin.send_rtp_sink_0 \
                  rtpbin.send_rtp_src_0 ! udpsink port=5000                            \
                  rtpbin.send_rtcp_src_0 ! udpsink port=5001 sync=false async=false    \
                  udpsrc port=5005 ! rtpbin.recv_rtcp_sink_0                           \
        audiotestsrc ! amrnbenc ! rtpamrpay ! rtpbin.send_rtp_sink_1                   \
                  rtpbin.send_rtp_src_1 ! udpsink port=5002                            \
                  rtpbin.send_rtcp_src_1 ! udpsink port=5003 sync=false async=false    \
                  udpsrc port=5007 ! rtpbin.recv_rtcp_sink_1

recv

Receive H263 on port 5000, send it through rtpbin in session 0, depayload, decode and display the video. Receive AMR on port 5002, send it through rtpbin in session 1, depayload, decode and play the audio. Receive server RTCP packets for session 0 on port 5001 and RTCP packets for session 1 on port 5003. These packets will be used for session management and synchronisation. Send RTCP reports for session 0 on port 5005 and RTCP reports for session 1 on port 5007.

gst-launch-1.0 -v rtpbin name=rtpbin                                          \
    udpsrc caps="application/x-rtp,media=(string)video,clock-rate=(int)90000,encoding-name=(string)H263-1998" \
            port=5000 ! rtpbin.recv_rtp_sink_0                                \
        rtpbin. ! rtph263pdepay ! ffdec_h263 ! xvimagesink                    \
     udpsrc port=5001 ! rtpbin.recv_rtcp_sink_0                               \
     rtpbin.send_rtcp_src_0 ! udpsink port=5005 sync=false async=false        \
    udpsrc caps="application/x-rtp,media=(string)audio,clock-rate=(int)8000,encoding-name=(string)AMR,encoding-params=(string)1,octet-align=(string)1" \
            port=5002 ! rtpbin.recv_rtp_sink_1                                \
        rtpbin. ! rtpamrdepay ! amrnbdec ! alsasink                           \
     udpsrc port=5003 ! rtpbin.recv_rtcp_sink_1                               \
     rtpbin.send_rtcp_src_1 ! udpsink port=5007 sync=false async=false

参考:

rtpbin

GStreamer RTP Streaming

https://community.nxp.com/docs/DOC-94646 

6、录音

录音:

gst-launch -e pulsesrc ! audioconvert ! lamemp3enc target=1 bitrate=64 cbr=true ! filesink location=audio.mp3

gst-launch -e pulsesrc device="alsa_input.pci-0000_02_02.0.analog-stereo" ! audioconvert ! \
   lamemp3enc target=1 bitrate=64 cbr=true ! filesink location=audio.mp3

 播放录音:

gst-launch-1.0 filesrc location=audio.mp3 ! decodebin ! audioconvert ! audioresample ! autoaudiosink

还是上面的wiki

​​​​​​OZ9AEC Website - Amateur radio, space, technology and other geeky stuff by Alexandru Csete

7、录视频

命令:gst-launch-1.0 -e rtspsrc location=rtsp://admin:admin@192.168.1.2 ! rtph264depay ! "video/x-h264, stream-format=byte-stream" ! filesink location=test.264

说明:主要是用gst-lanuch工具连接相关插件将rtsp video stream 保存为.264文件,然后可以利用相关播放器(如:kmpplayer)进行播放,亦可以供live555MediaServer生成rtsp stream;("video/x-h264, stream-format=byte-stream"这个caps一定要连接才行)
原文:https://blog.csdn.net/u010005508/article/details/52710302

8、视频收发(监控,预览)

send:

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=127.0.0.1 port=5000 sync=false

recv:
gst-launch  udpsrc  port=5000 ! application/x-rtp, clock-rate=90000,payload=96 ! rtph263pdepay queue-delay=0 ! ffdec_h263 ! xvimagesink

以Freescale平台为例,实时码流收发命令行如下:

Server侧(发送方):

gst-launch -v videotestsrc ! video/x-raw-yuv,width=640,height=480 ! vpuenc codec=avc ! rtph264pay pt=96 ! udpsink host=127.0.0.1 port=1234

Client侧(接收方):

gst-launch -vvv udpsrc port=1234 caps="application/x-rtp, media=(string)video, clock-rate=(int)90000, encoding-name=(string)H264" ! rtph264depay ! vpudec ! mfw_isink

9、音频收发(语音对讲)

模拟声音数据

1)send.sh

gst-launch-1.0 rtpbin name=rtpbin \
audiotestsrc ! amrnbenc ! rtpamrpay ! rtpbin.send_rtp_sink_1                   \
rtpbin.send_rtp_src_1 ! udpsink port=5002                            \
rtpbin.send_rtcp_src_1 ! udpsink port=5003 sync=false async=false    \
 udpsrc port=5007 ! rtpbin.recv_rtcp_sink_1

2)recv.sh

gst-launch-1.0 -v rtpbin name=rtpbin                                          \
    udpsrc caps="application/x-rtp,media=(string)audio,clock-rate=(int)8000,encoding-name=(string)AMR,encoding-params=(string)1,octet-align=(string)1" \
            port=5002 ! rtpbin.recv_rtp_sink_1                                \
        rtpbin. ! rtpamrdepay ! amrnbdec ! alsasink                           \
     udpsrc port=5003 ! rtpbin.recv_rtcp_sink_1                               \
     rtpbin.send_rtcp_src_1 ! udpsink port=5007 sync=false async=false

真实声卡

1) send.sh

gst-launch-1.0 rtpbin name=rtpbin \
        pulsesrc ! amrnbenc ! rtpamrpay ! rtpbin.send_rtp_sink_1                   \
                  rtpbin.send_rtp_src_1 ! udpsink port=5002                   \         
                  rtpbin.send_rtcp_src_1 ! udpsink port=5003 sync=false async=false  \  
                  udpsrc port=5007 ! rtpbin.recv_rtcp_sink_1

2) recv.sh

gst-launch-1.0 -v rtpbin name=rtpbin                                          \
    udpsrc caps="application/x-rtp,media=(string)audio,clock-rate=(int)8000,encoding-name=(string)AMR,encoding-params=(string)1,octet-align=(string)1" \
            port=5002 ! rtpbin.recv_rtp_sink_1                                \
        rtpbin. ! rtpamrdepay ! amrnbdec ! alsasink                           \
     udpsrc port=5003 ! rtpbin.recv_rtcp_sink_1                               \
     rtpbin.send_rtcp_src_1 ! udpsink port=5007 sync=false async=false

模拟声音和实际声卡只有发送端采集程序不同,模拟采集是audiotestsrc,实际声卡采集是pulsesrc

中国移动和对讲amr实时语音解码播放

gst-launch-1.0 udpsrc port=6000 caps="application/x-rtp, media=(string)audio, clock-rate=(int)8000, encoding-name=(string)AMR, payload=(int)106" ! rtpamrdepay ! decodebin name=decoder ! queue ! audioconvert ! autoaudiosink

tcpdump -i eth0 -w dump.pcap

gstreamer中通过UDP(RTP)远程播放MP3

send.sh

gst-launch-1.0 -v filesrc location = Hopy_Always.mp3 ! decodebin ! audioconvert ! rtpL16pay ! udpsink host=127.0.0.1 port=6000

recv.sh

gst-launch-1.0 udpsrc port=6000 caps='application/x-rtp, media=(string)audio, clock-rate=(int)44100, channels=(int)2' ! rtpjitterbuffer latency=400 ! rtpL16depay ! pulsesink

Gstreamer 测试udpsink udpsrc播放mp3文件

Gstreamer 测试udpsink udpsrc播放mp3文件_zhujinghao09的博客-CSDN博客

10、gstreamer 播放mp3源码(播放器) ,入门开发极好的samples

Ubuntu下使用GStreamer开发简单的mp3播放器_北雨南萍的博客-CSDN博客

https://www.cnblogs.com/274914765qq/p/5090299.html

11、Gstreamer的音视频同步

Gstreamer的音视频同步_gstreamer 音视频不同步_maeom的博客-CSDN博客

12、播放音频

gst-launch-1.0 playbin uri=file:///home/dong/Hopy_Always.mp3
gst-launch-1.0 filesrc location=Hopy_Always.mp3 ! decodebin ! audioconvert ! audioresample ! autoaudiosink

13、Gstreamer视频传输测试gst-launch

Gstreamer视频传输测试gst-launch_wifibroadcast_meng_tianshi的博客-CSDN博客

14、How to listen to the pulseaudio RTP Stream and play

RTP

15、Gstreamer cheat sheet —— Picture in Picture / Video Wall / Text Overlay / Time Overlay ... ... ..

OZ9AEC Website - Amateur radio, space, technology and other geeky stuff by Alexandru Csete

16、用树莓派做 RTMP 流直播服务器,可推送至斗鱼直播

用树莓派做 RTMP 流直播服务器,可推送至斗鱼直播 | 树莓派实验室

17、gstreamer学习笔记:通过gst-launch工具抓取播放的音频数据并通过upd传输

gst-launch数据转换(pcm,aac,ts), rtp收发

gstreamer学习笔记:通过gst-launch工具抓取播放的音频数据并通过upd传输_gst-launch-1.0 播放音频_fanchenxinok的博客-CSDN博客

18、gstreamer实现摄像头的远程采集,udp传输,本地显示和保存为AVI文件 发送端

send

Gstreamer实现摄像头的远程采集,udp传输,本地显示和保存为AVI文件 发送端_zhujinghao09的博客-CSDN博客

recv

Gstreamer实现摄像头的远程采集,udp传输,本地显示和保存为AVI文件 接收保存显示端_zhujinghao09的博客-CSDN博客

19、QtGStreamer dvr

https://blog.csdn.net/lg1259156776/article/details/53413877

https://blog.csdn.net/xueyeguiren8/article/details/54581536

20、基于Gstreamer的实时视频流的分发

基于Gstreamer的实时视频流的分发_文强先生的博客-CSDN博客

21、gstreamer学习笔记:将音视频合成MPEG2-TS流并打包通过rtp传输

https://blog.csdn.net/u010312436/article/details/53668083

22、gstreamer之RTSP Server一个进程提供多路不同视频

https://blog.csdn.net/quantum7/article/details/82999132

23、GStreamer资料整理(包括摄像头采集,视频保存,远程监控,流媒体RTP传输)

https://blog.csdn.net/wzwxiaozheng/article/details/6099397

24、使用GStreamer作v4l2摄像头采集和输出到YUV文件及屏幕的相关测试

https://blog.csdn.net/shallon_luo/article/details/5400708

25、Gstreamer中添加x265编解码器

https://blog.csdn.net/songwater/article/details/34855883

26、Gstreamer One Liners

https://metalab.at/wiki/Gstreamer_One_Liners

ARM平台基于嵌入式Linux Gstreamer 使用

https://www.eefocus.com/toradex/blog/16-05/379143_e4fcb.html

常见gstreamer pipeline 命令—— TI 3730 dvsdk

https://blog.csdn.net/songwater/article/details/34800017

gstreamer中的好东西,appsink和appsrc

https://blog.csdn.net/jack0106/article/details/5909935

基于DM3730平台的gstreamer音视频传输调试

https://blog.csdn.net/goalietech/article/details/24887955

gstreamer appsrc appsink应用

gstreamer向appsrc发送帧画面的代码

https://blog.csdn.net/quantum7/article/details/82226608

gstreamer向appsrc发送编码数据的代码

https://blog.csdn.net/quantum7/article/details/82250524

gstreamer学习笔记:分享几个appsink和appsrc的example

https://blog.csdn.net/u010312436/article/details/53610599

Here are two basic send/receive  h264 video stream pipelines:

gst-launch-0.10 v4l2src ! ffmpegcolorspace ! videoscale ! video/x-raw-yuv,width=640,height=480 ! vpuenc ! h264parse ! rtph264pay ! udpsink host=localhost port=5555

gst-launch-0.10 udpsrc port=5555 ! application/x-rtp,encoding-name=H264,payload=96 ! rtph264depay ! h264parse ! ffdec_h264 ! videoconvert ! ximagesink

gstreamer使用进阶

gstreamer使用进阶_jack0106的博客-CSDN博客

# 整理了这么多,梳理一下指令,组织一下模块代码,应付常规的多媒体应用绰绰有余了!

  • 1
    点赞
  • 22
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值