gstreamer学习笔记:通过udp传输音视频

时间:2022-12-26 08:43:52

一、首先生成一个测试用的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

流程图如下:

gstreamer学习笔记:通过udp传输音视频


(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.

流程图如下:

gstreamer学习笔记:通过udp传输音视频