使用 gstreamer 将本地 mpeg-ts 文件流式传输到 udp

Streaming a local mpeg-ts file to udp using gstreamer

我需要使用 gstreamer 广播 mpeg-ts 视频文件而不对其进行转码。视频编码为:H264 - MPEG-4 AVC(第 10 部分)(h264)

我试过用

直播
gst-launch-1.0 filesrc location=my_video.ts ! h264parse ! rtph264pay ! udpsink host=127.0.0.1 port=49444

一起玩
gst-launch-1.0 udpsrc caps=" application/x-rtp,media=(string)video,clock-rate=(int)90000,encoding-name=(string)H264,payload=(int)96,ssrc=(uint)2674837201,clock-base=(uint)2959668548,seqnum-base=(uint)14300" port=49444 ! rtph264depay ! decodebin ! autovideosink

但我在接收方的视频已损坏(但它与原始视频仍然有点相似):

并且在接收者的控制台中有很多警告:

WARNING: from element /GstPipeline:pipeline0/GstRtpH264Depay:rtph264depay0: Could not decode stream.
Additional debug info:
gstrtph264depay.c(1205): gst_rtp_h264_depay_process (): /GstPipeline:pipeline0/GstRtpH264Depay:rtph264depay0:
Undefined packet type

我做错了什么?我猜问题出在 udpsrc 元素的 caps 参数中,因为我只是从网络上的一些示例中复制粘贴了它。如果这是问题所在,我怎样才能找到 caps 参数的正确值?

您不能直接从 ts 文件转到 h264parse,您需要先对 ts 流进行解复用 - 这是通过 tsdemux 完成的。

这是神奇的烟斗:

gst-launch-1.0 filesrc location=dummy_h264.ts ! tsparse set-timestamps=true ! video/mpegts ! tsdemux ! video/x-h264 ! h264parse disable-passthrough=true ! rtph264pay ! udpsink -v host=127.0.0.1 port=9999

如果没有 tsparse set-timestamp,它可能无法工作,因为时间戳信息可能不存在于您的 ts 文件中 - 您必须检查是否有正确的 PCR 帧 - 也许使用一些 mpeg ts 分析器。

和调试输出 - 你从谈论 udpsink 的行中取出大写字母:

Setting pipeline to PAUSED ...
Pipeline is PREROLLING ...
/GstPipeline:pipeline0/MpegTSParse2:mpegtsparse2-0.GstPad:src: caps = "video/mpegts\,\ systemstream\=\(boolean\)true\,\ packetsize\=\(int\)188"
/GstPipeline:pipeline0/GstCapsFilter:capsfilter0.GstPad:src: caps = "video/mpegts\,\ systemstream\=\(boolean\)true\,\ packetsize\=\(int\)188"
/GstPipeline:pipeline0/GstTSDemux:tsdemux0.GstPad:sink: caps = "video/mpegts\,\ systemstream\=\(boolean\)true\,\ packetsize\=\(int\)188"
/GstPipeline:pipeline0/GstCapsFilter:capsfilter0.GstPad:sink: caps = "video/mpegts\,\ systemstream\=\(boolean\)true\,\ packetsize\=\(int\)188"
/GstPipeline:pipeline0/GstCapsFilter:capsfilter2: caps = video/x-h264
/GstPipeline:pipeline0/GstCapsFilter:capsfilter2.GstPad:src: caps = "video/x-h264\,\ stream-format\=\(string\)byte-stream\,\ alignment\=\(string\)nal"
/GstPipeline:pipeline0/GstH264Parse:h264parse0.GstPad:sink: caps = "video/x-h264\,\ stream-format\=\(string\)byte-stream\,\ alignment\=\(string\)nal"
/GstPipeline:pipeline0/GstCapsFilter:capsfilter2.GstPad:sink: caps = "video/x-h264\,\ stream-format\=\(string\)byte-stream\,\ alignment\=\(string\)nal"
/GstPipeline:pipeline0/GstH264Parse:h264parse0.GstPad:src: caps = "video/x-h264\,\ stream-format\=\(string\)avc\,\ alignment\=\(string\)au\,\ pixel-aspect-ratio\=\(fraction\)1/1\,\ width\=\(int\)320\,\ height\=\(int\)240\,\ framerate\=\(fraction\)30/1\,\ parsed\=\(boolean\)true\,\ profile\=\(string\)high\,\ level\=\(string\)2\,\ codec_data\=\(buffer\)01640014ffe1001967640014acd94141fb0110000003001000000303c8f142996001000568ebecb22c"
/GstPipeline:pipeline0/GstRtpH264Pay:rtph264pay0.GstPad:src: caps = "application/x-rtp\,\ media\=\(string\)video\,\ clock-rate\=\(int\)90000\,\ encoding-name\=\(string\)H264\,\ packetization-mode\=\(string\)1\,\ profile-level-id\=\(string\)640014\,\ sprop-parameter-sets\=\(string\)\"Z2QAFKzZQUH7ARAAAAMAEAAAAwPI8UKZYA\\=\\=\\,aOvssiw\\=\"\,\ payload\=\(int\)96\,\ ssrc\=\(uint\)3030226714\,\ timestamp-offset\=\(uint\)3947899684\,\ seqnum-offset\=\(uint\)32736"
------------TAKE THIS ONE:--------------
/GstPipeline:pipeline0/GstUDPSink:udpsink0.GstPad:sink: caps = "application/x-rtp\,\ media\=\(string\)video\,\ clock-rate\=\(int\)90000\,\ encoding-name\=\(string\)H264\,\ packetization-mode\=\(string\)1\,\ profile-level-id\=\(string\)640014\,\ sprop-parameter-sets\=\(string\)\"Z2QAFKzZQUH7ARAAAAMAEAAAAwPI8UKZYA\\=\\=\\,aOvssiw\\=\"\,\ payload\=\(int\)96\,\ ssrc\=\(uint\)3030226714\,\ timestamp-offset\=\(uint\)3947899684\,\ seqnum-offset\=\(uint\)32736"
/GstPipeline:pipeline0/GstRtpH264Pay:rtph264pay0.GstPad:sink: caps = "video/x-h264\,\ stream-format\=\(string\)avc\,\ alignment\=\(string\)au\,\ pixel-aspect-ratio\=\(fraction\)1/1\,\ width\=\(int\)320\,\ height\=\(int\)240\,\ framerate\=\(fraction\)30/1\,\ parsed\=\(boolean\)true\,\ profile\=\(string\)high\,\ level\=\(string\)2\,\ codec_data\=\(buffer\)01640014ffe1001967640014acd94141fb0110000003001000000303c8f142996001000568ebecb22c"
/GstPipeline:pipeline0/GstRtpH264Pay:rtph264pay0: timestamp = 3947910934
/GstPipeline:pipeline0/GstRtpH264Pay:rtph264pay0: seqnum = 32736
Pipeline is PREROLLED ...
Setting pipeline to PLAYING ...
New clock: GstSystemClock
^Chandling interrupt.
Interrupt: Stopping pipeline ...
Execution ended after 0:00:03.631302966
Setting pipeline to PAUSED ...
Setting pipeline to READY ...
Setting pipeline to NULL ...
Freeing pipeline ...

那就这样玩吧:

gst-launch-1.0 udpsrc port=9999 ! application/x-rtp\,\ media\=\... ! queue ! rtph264depay ! decodebin ! videoconvert ! glimagesink

请注意,您不必在已经转义的大写字母周围添加 "..