1. 程式人生 > >gstreamer學習筆記:通過udp傳輸音視訊

gstreamer學習筆記:通過udp傳輸音視訊

一、首先生成一個測試用的avi檔案

(1)播放音樂

gst-launch-1.0 filesrc location=/xxx/xxx.wav ! wavparse ! autoaudiosink

(2)將抓取pulseaudio的音訊資料和videotestsrc產生的視訊資料合成mux.avi多媒體檔案

gst-launch-1.0 -e avimux name="mux" ! filesink location=mux.avi videotestsrc pattern=ball ! \
"video/x-raw,framerate=60/1,width=720,height=480" ! videoconvert ! mux. pulsesrc \
device=alsa_output.pci-0000_00_05.0.analog-stereo.monitor ! avenc_aac ! aacparse ! mux.

二、通過udp傳輸音視訊

(1)傳送端:

gst-launch -v gstrtpbin name=rtpbin latency=100 uridecodebin uri=file:///xxx/mux.avi name=decoder \
decoder. ! tee name=tee0\
tee0. ! queue2 ! ffmpegcolorspace ! videoscale ! ximagesink \
tee0. ! queue2 ! ffmpegcolorspace ! x264enc ! rtph264pay pt=96 ! queue2 ! rtpbin.send_rtp_sink_0 rtpbin.send_rtp_src_0 !\
queue2 ! udpsink host=xx.xx.xxx.xx port=5000 async=false\
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=xx.xx.xxx.xx

port=5003 async=false

流程圖如下:

(2)接收端(儲存為.avi格式檔案)

gst-launch -v gstrtpbin name=rtpbin latency=100 \
udpsrc caps="application/x-rtp,media=(string)video,clock-rate=(int)90000,encoding-name=(string)H264,sprop-parameter-sets=(string)\"Z0LAH9kAtD2wEQAAAwABdzWUAA8YMkgA\\,aMuMsg\\=\\=\",ssrc=(uint)2094326868,payload=(int)96,clock-base=(uint)2855623946,seqnum-base=(uint)57709" \
port=5000 ! queue ! rtpbin.recv_rtp_sink_0  rtpbin. ! rtph264depay ! tee name=teevideo teevideo. !  ffdec_h264 ! videoscale ! ffmpegcolorspace ! autovideosink \
teevideo. ! queue ! "video/x-h264,width=720,height=480,framerate=(fraction)25/1" ! ffdec_h264 ! ffmpegcolorspace ! jpegenc ! avimux name=mux mux. ! filesink location="test.avi" \
udpsrc caps="application/x-rtp,media=(string)audio,clock-rate=(int)44100,encoding-name=(string)MP4A-LATM,cpresent=(string)0,config=(string)40002420,ssrc=(uint)277283185,payload=(int)96,clock-base=(uint)3973143737,seqnum-base=(uint)63683" \
port=5003 ! queue ! rtpbin.recv_rtp_sink_1  rtpbin. ! rtpmp4adepay ! tee name=teeaudio teeaudio. ! queue ! faad ! audioconvert ! autoaudiosink \
teeaudio. ! queue ! aacparse ! mux.

流程圖如下: