How to do webcam streaming with mpegtsmux in Gstreamer

j0e1in picture j0e1in · Apr 12, 2016 · Viewed 9.2k times · Source

I'm new to gstreamer, and I want to stream webcam video through network with mpeg2-ts. I am able to stream video using following pipeline, but I don't know how to stream it with mpeg2-ts using mpegmux. Any help would be great! Thanks.

My working pipline (without mpegmux) :

// Sender
gst-launch-1.0 -ve v4l2src \
! video/x-raw, framerate=30/1 \
! videoconvert \
! x264enc noise-reduction=10000 speed-preset=fast tune=zerolatency byte-stream=true threads=4 key-int-max=15 intra-refresh=true  \
! rtph264pay pt=96 \
! udpsink host=localhost port=5000

// Receiver
gst-launch-1.0 -ve udpsrc port=5000 \
! application/x-rtp, media=video, clock-rate=90000, encoding-name=H264, payload=96 \
! rtph264depay \
! h264parse \
! avdec_h264 \
! videoconvert \
! ximagesink sync=false

I've tried some methods like below, but still can't get it to work. Sender gives error "Could not link mux with rtph264pay" and receiver gives "Could not link mux with udpsrc".

// Sender
gst-launch-1.0 -ve v4l2src \
! video/x-raw, framerate=30/1 \
! videoconvert \
! x264enc noise-reduction=10000 speed-preset=fast tune=zerolatency byte-stream=true threads=4 key-int-max=15 intra-refresh=true \
! rtph264pay pt=96 \
! mpegtsmux name=mux mux. \
! udpsink host=localhost port=5000

// Reveiver
gst-launch-1.0 -ve udpsrc port=5000 \
! application/x-rtp, media=video, clock-rate=90000, encoding-name=H264, payload=96 \
! tsdemux name=demux demux.video_00 \
! rtph264depay \
! h264parse \
! avdec_h264 \
! videoconvert \
! ximagesink sync=false

Note that, I use tsdemux instead of mpegtsdemux in the receiver because it will output ' no element "mpegtsdemux" '. However, I if type $ gst-inspect-1.0 mpegtsdemux it prints:

Plugin Details:
  Name                     mpegtsdemux
  Description              MPEG TS demuxer
  Filename                 /usr/lib/x86_64-linux-gnu/gstreamer-1.0/libgstmpegtsdemux.so
  Version                  1.2.4
  License                  unknown
  Source module            gst-plugins-bad
  Source release date      2014-04-18
  Binary package           GStreamer Bad Plugins (Ubuntu)
  Origin URL               https://launchpad.net/distros/ubuntu/+source/gst-plugins-bad1.0

  tsdemux: MPEG transport stream demuxer
  tsparse: MPEG transport stream parser

  2 features:
  +-- 2 elements

I have no idea why gst-launch-1.0 can't find mpegtsdemux.


EDIT: Thanks to @otopolsky, I've figured out a working pipeline(see below). And also, he/she is right about not having to use caps in receiver if tsparse is placed before tsdemux.

// Sender
gst-launch-1.0 -ve v4l2src \
! video/x-raw, framerate=30/1 \
! videoconvert \
! x264enc noise-reduction=10000 tune=zerolatency byte-stream=true threads=4 key-int-max=15 intra-refresh=true \
! mpegtsmux \
! udpsink host=localhost port=5000

// Receiver
gst-launch-1.0 -ve udpsrc port=5000 \
! tsparse \
! tsdemux \
! h264parse \
! avdec_h264 \
! videoconvert \
! ximagesink sync=false

Just a few more questions:

  1. Why I don't need to add rtpmp2tdepay in the receiver side? (If I add it anywhere in the pipeline, the "Could not link rtpmp2tdepay with xx" will be generated.)
  2. The quality of the streaming video would be worse than the one without using mpegtsmux. Why is that? Is it because it uses mpeg2-ts? Is there any tips for improving the streaming quality?

Answer

nayana picture nayana · Apr 12, 2016

You have to do:

x264enc ! mpegtsmux ! rtpmp2tpay ! udpsink

Like in this answer..

The tsdemux is element however mpegtsdemux is plugin containing this element. It also contains tsparse as noted in inspect's message.. maybe if you use tsparse before tsdemux you dont need extra information about the caps in receiver(I am not exactly sure about this).

Another hint for you: if you use zerolatency it will discard the speed preset or any other quality handling.

HTH