Powered by Blogger.

Video Streaming with Gstreamer - 01

Tuesday, December 4, 2012

I wanted to send a video through the network few days back, on Ubuntu using Python. It took a several days to figure out how to perform such a task. I found out that Gstreamer is a good tool to start with, it has many capabilities. Today I was able to complete what I wanted to do, sending a video and receiving in the other end. Still work is not finished, I need to synchronize several streams together at the receiver as well. I will keep updating the progress and any interesting findings. So this will be a start of several future posts.

Please note that I am still new to this particular field, the purpose of this post is just sharing my experience with others. Please correct me if you find any mistakes or wrong ways of doing things in this post.

1. Sending a video file from a PC to another PC through network or Internet

Receiver's IP is 192.168.1.104. I used following codes in the Ubuntu terminal.

This is the sender's code:

gst-launch -v \
filesrc location=/home/x101.avi ! \
decodebin ! \
x264enc ! \
rtph264pay ! \
udpsink host=192.168.1.104 port=5000

This is the receiver's code:

gst-launch \
udpsrc port=5000 caps = "application/x-rtp, media=(string)video, clock-rate=(int)90000, encoding-name=(string)H264, sprop-parameter-sets=(string)\"Z01AFeygbCPNLgIgAAADAC7msoAB4sWywA\\=\\=\\,aOvssg\\=\\=\", payload=(int)96, ssrc=(uint)861153369, clock-base=(uint)4026289255, seqnum-base=(uint)30449" ! \
gstrtpbin ! \
rtph264depay ! \
queue ! \
ffdec_h264 ! \
autovideosink

I used a 'avi' type video file. When you enter the code at the sender you will get a text output in the terminal. Copy the things under 'caps' field and use it in the receiver's 'caps' field.

2. Receiving and displaying two videos in the same window

Videomixer is a very useful tool to view more than one videos in the same window. Here we send two videos from the same PC and receives in second PC through different ports.

Sender's code:

gst-launch -v \
filesrc location=/home/x101.avi ! decodebin ! x264enc ! rtph264pay ! udpsink host=192.168.1.104 port=5000 \
filesrc location=/home/x102.avi ! decodebin ! x264enc ! rtph264pay ! udpsink host=192.168.1.104 port=5001


Receiver's code:

gst-launch -e \
videomixer name=mix ! ffmpegcolorspace ! xvimagesink \
\
udpsrc port=5000 caps = "application/x-rtp, media=(string)video, clock-rate=(int)90000, encoding-name=(string)H264, sprop-parameter-sets=(string)\"Z01AFeygbCPNLgIgAAADAC7msoAB4sWywA\\=\\=\\,aOvssg\\=\\=\", payload=(int)96, ssrc=(uint)861153369, clock-base=(uint)4026289255, seqnum-base=(uint)30449" ! gstrtpbin ! rtph264depay ! queue ! ffdec_h264 ! \
videobox border-alpha=0 top=0 left=0 ! mix.  \
\
udpsrc port=5001 caps = "application/x-rtp, media=(string)video, clock-rate=(int)90000, encoding-name=(string)H264, sprop-parameter-sets=(string)\"Z01AFeygbCPNLgIgAAADAC7msoAB4sWywA\\=\\=\\,aOvssg\\=\\=\", payload=(int)96, ssrc=(uint)861153369, clock-base=(uint)4026289255, seqnum-base=(uint)30449" ! gstrtpbin ! rtph264depay ! queue ! ffdec_h264 ! \
videobox border-alpha=0 top=-125 left=0 ! mix. multifilesrc location=/home/Image.jpg caps="image/jpeg,framerate=1/1" ! jpegdec ! ffmpegcolorspace ! video/x-raw-yuv,format=\(fourcc\)AYUV ! mix.


No comments: