您的位置:首页 > 理论基础 > 计算机网络

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

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

首先,参考网上一哥们儿写的博客,网址如下:(致敬)

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

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,元件比较多,创建,添加,连接时需细心。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: