How to do webcam streaming with mpegtsmux in Gstreamer
Asked Answered
M

1

7

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?
Martine answered 12/4, 2016 at 5:34 Comment(4)
to the update, 1, not exactly sure, I personaly have big gaps in understanding of parse/pay/depay stuff.. but I guess the packets already contains 188 bytes each (which is mpeg ts packet size), which then isnt needed to be depayloaded (as its 1:1).. I dont know how is it that you cannot put the depay anywhere.. check the caps of src/sink with gst-inspect-1.0 element .. 2, to the quality.. I think the processing is different somehow - very low quality is achieved with zerolatency, so this is maybe causing this.. what about removing zerolatency and add some nice speed preset?Lactoprotein
Thanks for your explanations. As for quality, setting speed-preset to any value lower than ultrafast(which has the same quality as zerolatency) will make streaming very laggy on my device, so I would use zerolatency for now.Martine
By removing rtpmp2tpay in sender, the video quality is much better now. It seems to be redundant.Martine
interesting, but then its no longer RTP stream, but only plain ts over IP - you loose some functions of RTP (but maybe you dont need them).. sometimes I had problems with tsoverip which was making glitches in video at receiver, but rtp was not doing this.. I wonder what you call better quality..Lactoprotein
L
6

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

Lactoprotein answered 12/4, 2016 at 6:57 Comment(1)
Thank you! I would never find this out by myself. I got a working pipeline. Just a few more questions, if you don't mind. (Please see EDIT in the question.)Martine

© 2022 - 2024 — McMap. All rights reserved.