首先,是安装Gstreamer。
使用apt-get安装,执行下面命令:
sudo apt-get install gstreamer1.0-tools
sudo apt-get install libgstreamer1.0-0 libgstreamer1.0-0-dbg libgstreamer1.0-dev liborc-0.4-0 liborc-0.4-0-dbg
liborc-0.4-dev liborc-0.4-doc gir1.2-gst-plugins-base-1.0 gir1.2-gstreamer-1.0 gstreamer1.0-alsa gstreamer1.0-doc
gstreamer1.0-omx gstreamer1.0-plugins-bad gstreamer1.0-plugins-bad-dbg gstreamer1.0-plugins-bad-doc
gstreamer1.0-plugins-base gstreamer1.0-plugins-base-apps gstreamer1.0-plugins-base-dbg gstreamer1.0-plugins-base-doc gstreamer1.0-plugins-good gstreamer1.0-plugins-good-dbg gstreamer1.0-plugins-good-doc
gstreamer1.0-plugins-ugly gstreamer1.0-plugins-ugly-dbg gstreamer1.0-plugins-ugly-doc
gstreamer1.0-pulseaudio gstreamer1.0-tools gstreamer1.0-x libgstreamer-plugins-bad1.0-0
libgstreamer-plugins-bad1.0-dev libgstreamer-plugins-base1.0-0 libgstreamer-plugins-base1.0-dev
在局域网测试OK:
树莓派端发送:
gst-launch-1.0 -v v4l2src device=/dev/video0 ! 'video/x-raw,width=1280,height=720,framerate=10/1' !
videoconvert ! omxh264enc ! 'video/x-h264, profile=(string)high' ! rtph264pay ! udpsink host=192.168.8.100 port=5600
PC端接收:
gst-launch-1.0 -v udpsrc port=5600 caps='application/x-rtp, media=(string)video, clock-rate=(int)90000,
encoding-name=(string)H264' ! rtph264depay ! avdec_h264 ! autovideosink fps-update-interval=1000 sync=false
局域网测试OK
树莓派发送端:
gst-launch-1.0 -v v4l2src device=/dev/video0 ! 'video/x-raw,width=1280,height=720,framerate=10/1' ! videoconvert ! omxh264enc ! 'video/x-h264, profile=(string)high' ! rtph264pay ! "application/x-rtp,payload=(int)103,clock-rate=(int)90000" ! udpsink host=192.168.8.100 port=9004
PC接收端,由于命令太长就写成了bash脚本,下面的指令可以拷贝到bash脚本中运行:
PEER_V=5004
PEER_IP=127.0.0.1
SELF_V=9004
CAPS_V="media=(string)video,clock-rate=(int)90000, encoding-name=(string)H264,payload=(int)103"
bash -c `gst-launch-1.0 -v \
rtpsession name=r sdes="applications/x-rtp,cname=(string)\"user\@example.com\"" \
udpsrc port=$SELF_V \
! "application/x-rtp,$CAPS_V" \
! r.recv_rtp_sink \
r.recv_rtp_src \
! rtph264depay \
! decodebin \
! autovideosink \
udpsrc port=$((SELF_V)) \
! r.recv_rtcp_sink \
r.send_rtcp_src \
! udpsink host=$PEER_IP port=$((PEER_V+1)) sync=false async=false`