如何在 Gstreamer 中使用 mpegtsmux 进行网络摄像头流式传输

How to do webcam streaming with mpegtsmux in Gstreamer

我是 gstreamer 的新手,我想使用 mpeg2-ts 通过网络流式传输网络摄像头视频。我可以使用以下管道流式传输视频,但我不知道如何使用 mpegmux 使用 mpeg2-ts 流式传输视频。任何帮助都会很棒!谢谢。

我的工作流水线(没有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

我已经尝试了下面的一些方法,但仍然无法正常工作。发件人给出错误 "Could not link mux with rtph264pay" 并且接收者给出 "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

请注意,我在接收器中使用 tsdemux 而不是 mpegtsdemux,因为它将输出“无元素 "mpegtsdemux"”。但是,如果我输入 $ gst-inspect-1.0 mpegtsdemux 它会打印:

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

我不知道为什么 gst-launch-1.0 找不到 mpegtsdemux


编辑: 感谢@otopolsky,我找到了一个工作流水线(见下文)。而且,如果 tsparse 放在 tsdemux.

之前,he/she 不必在接收器中使用大写字母是正确的
// 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

还有几个问题:

  1. 为什么我不需要在接收方添加rtpmp2tdepay? (如果我将它添加到管道中的任何位置,将生成 "Could not link rtpmp2tdepay with xx"。)
  2. 流媒体视频的质量会比不使用 mpegtsmux 的视频质量差。这是为什么?是因为它使用 mpeg2-ts 吗?有什么提高流媒体质量的技巧吗?

你必须做的:

x264enc ! mpegtsmux ! rtpmp2tpay ! udpsink

喜欢回答..

tsdemux 是元素,而 mpegtsdemux 是包含此元素的插件。它还包含 tsparse,如 inspect 的消息中所述。也许如果您在 tsdemux 之前使用 tsparse,则您不需要有关接收器中上限的额外信息(我对此不太确定)。

给您的另一个提示:如果您使用 zerolatency,它将放弃速度预设或任何其他质量处理。

HTH