GStreamer实现视频本地播放并RTP上传到网络VLC播放

本文介绍了如何使用gst-launch在命令行方式下实现本地视频文件的播放,并基于RTP上传到网络使用VLC播放 。

send端实现了本地音视频播放和网络传输。(见末尾代码)

Receive端实现了接收网络音视频数据并播放,但是,receive端的没有实现,提示faac解码错误,可能是我选择的视频格式问题,虽改用vlc播放器播放。

 

步骤如下:

1,首先将send端命令在命令行下执行,如果无误并且能正确播放视频表明gstreamer所需插件完整并且视频文件无误。

2,新建一文件,不妨命名为sd.sdp,内容如下:

m=video5000 RTP/AVP 96

a=rtpmap:96H264

a=framerate:15

c=IN IP4 192.168.0.114

 

5000为接收端口 192.168.0.114为接收IP,需正确设置

3,执行send端命令后,启动VLC打开sd.sdp,如果幸运的话,就能看到视频了,稍有延迟,效果还不错。

 

send:

gst-launch-v  gstrtpbin name=rtpbinlatency=100         uridecodebinuri=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.109 port=5000  async=false        rtpbin.send_rtcp_src_0 ! queue2 !udpsink host=192.168.0.109 port=5001 async=false        udpsrcport=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.109port=5002  async=false        rtpbin.send_rtcp_src_1 ! queue2 !udpsink host=192.168.0.109 port=5003 async=false        udpsrc port=5007 ! queue2 !rtpbin.recv_rtcp_sink_1

 

 

receive:

gst-launch -vgstrtpbin name=rtpbin latency=100      udpsrc caps="application/x-rtp, media=(string)video,clock-rate=(int)90000, encoding-name=(string)H264, ssrc=(uint)340005641,payload=(int)96, clock-base=(uint)2625017333, seqnum-base=(uint)5894"             port=5000 ! queue !rtpbin.recv_rtp_sink_0  rtpbin. !rtph264depay ! tee name=teevideo teevideo. ! 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 teevideo. ! queue !"video/x-h264,width=320,height=240,framerate=(fraction)25/1" !matroskamux name=mux mux. ! filesink location="test_copy.avi"             udpsrccaps="application/x-rtp, media=(string)audio, clock-rate=(int)44100,encoding-name=(string)MP4A-LATM, cpresent=(string)0, config=(string)40002420,ssrc=(uint)4204015526, payload=(int)96, clock-base=(uint)4274968681,seqnum-base=(uint)44386"       port=6002 ! queue ! rtpbin.recv_rtp_sink_1  rtpbin. ! rtpmp4adepay ! tee name=teeaudioteeaudio. ! queue ! faad ! audioconvert ! autoaudiosink     teeaudio. ! queue ! faad ! audioconvert !faac ! mux.     udpsrc port=6003 ! queue! rtpbin.recv_rtcp_sink_1      rtpbin.send_rtcp_src_1 ! queue ! udpsink port=6007  sync=true async=false

 

代码实现时注意:

1,decodebin与其它元件连接时,不能直接gst_element_link,实现请参考下列代码:

  g_signal_connect( decoder ,"pad-added", G_CALLBACK(newPad), tee0);

  假设tee0为将要连接的元件,newPad为连接元件的实现,参考如下:

voidnewPad(GstElement *uridecodebin, GstPad  *pad, gpointer    data)                              

{

       GstPad *sinkpad;

       GstElement *ele = (GstElement *) data;

     

     

       sinkpad = gst_element_get_static_pad (ele, "sink");

     

        int ret = gst_pad_link (pad, sinkpad);

          if( ret!= GST_PAD_LINK_OK)

          {

            printf("file:%s %d : error!\n",__FILE__ , __LINE__);

          }

          else

          {

              printf("decodebin add\n");

          }

 

       gst_object_unref (sinkpad);

}

 

2,元件比较多,创建,添加,连接时需细心。

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值