无法使用 klv 元数据获取 mpegts 以从 udpsrc 流到管道末端

问题描述 投票:0回答:1

我已经和这个问题斗争了一段时间了。我有 mpegts 流,其中包含来自 udpsrc 的 klv 元数据,并使用下面的 gstreamer 命令来处理它并将其传递到 rtspclientsink。

   gst-launch-1.0 -e udpsrc address=224.1.1.1 reuse=true port=50088 socket-timestamp=1 buffer-size=100000000  ! 'video/mpegts, systemstream=(boolean)true, packetsize=(int)188' !
        queue max-size-time=1700000000 max-size-buffers=50 ! tsparse set-timestamps=true ! 
        tsdemux parse-private-sections=true ignore-pcr=true name=demux
        demux. ! queue max-size-time=0 max-size-buffers=0 ! decodebin use-buffering=true ! videoconvert ! videorate ! videoscale ! x264enc tune=zerolatency bitrate=5500 key-int-max=30 ! mpegtsmux name=mux
        demux. ! queue max-size-time=0 max-size-buffers=0 ! meta/x-klv ! mux. mux. ! rtspclientsink location=rtsp://127.0.0.1:8554/testpath 

如果我将 udpsrc 切换到 filesrc (https://samples.ffmpeg.org/MPEG2/mpegts-klv/ <-- either of the files should work), the whole pipe works just fine.

但是当我将其切换到 udpsrc 后,在 EOS 之后我只获得了几帧的 klv-data,其他时候我不断收到“警告:来自元素 /GstPipeline:pipeline0/GstTSDemux:demux: CONTINUITY: Mismatch packet”。

我使用下面的 ffmpeg 命令将 rtsp 转发回 udp

ffmpeg -i rtsp://127.0.0.1:8554/testpath -map 0 -c copy -f mpegts udp://224.1.1.1:50068

然后我使用下面的命令来监听上面的udp转发。

gst-launch-1.0 -v -e udpsrc address=224.1.1.1 reuse=true port=50068 ! 'video/mpegts, systemstream=(boolean)true, packetsize=(int)188' ! tsdemux name=demux demux. ! queue ! h264parse ! 'video/x-h264, stream-format=byte-stream, alignment=au' ! avdec_h264 ! autovideosink demux. ! queue ! 'meta/x-klv' ! fdsink

就像我说的,整个流程一开始适用于 filesrc,但适用于 udpsrc 则不然。

非常感谢所有帮助。 已经谢谢了。

编辑:我的假设是 ffmpeg 文件中的 klv 数据比我正在使用的文件(我无法共享)少得多,并且 fdsink 管道无法使用它。但设法使用以下方法将数据写入文件

gst-launch-1.0 -e udpsrc address=224.1.1.1 port=50088 ! tsdemux name=demux demux. ! queue ! meta/x-klv ! filesink location=klv_output_night.bin

来自实际 udp 流的 ffprobe

Input #0, mpegts, from 'udp://<multicast-addr:port>':
  Duration: N/A, start: 288.961000, bitrate: N/A
  Program 1
    Metadata:
      service_name    : Service01
      service_provider: FFmpeg
  Stream #0:0[0x100]: Video: h264 (High) ([27][0][0][0] / 0x001B), yuv420p(progressive), 1280x722, 90k tbr, 90k tbn
  Stream #0:1[0xfc]: Data: klv (KLVA / 0x41564C4B)
Unsupported codec with id 98311 for input stream 1

以及使用 tsduck 制作的流的 10 秒分析。

===============================================================================
|  TRANSPORT STREAM ANALYSIS REPORT                                           |
|=============================================================================|
|  Transport Stream Id: .......... 1 (0x0001)  |  Services: .............. 1  |
|  Bytes: ......................... 6,549,920  |  PID's: Total: .......... 5  |
|  TS packets: ....................... 34,840  |         Clear: .......... 5  |
|     With invalid sync: .................. 0  |         Scrambled: ...... 0  |
|     With transport error: ............... 0  |         With PCR's: ..... 1  |
|     Suspect and ignored: ................ 0  |         Unreferenced: ... 0  |
|-----------------------------------------------------------------------------|
|  Transport stream bitrate, based on ....... 188 bytes/pkt    204 bytes/pkt  |
|  User-specified: .......................... 5,185,598 b/s    5,626,926 b/s  |
|  Estimated based on PCR's: ................ 5,185,598 b/s    5,626,926 b/s  |
|  Selected reference bitrate: .............. 5,185,598 b/s    5,626,926 b/s  |
|-----------------------------------------------------------------------------|
|  Broadcast time: ................................... 10 sec (0 min 10 sec)  |
|-----------------------------------------------------------------------------|
|  Srv Id  Service Name                              Access          Bitrate  |
|  0x0001  Service01 .................................... C    5,034,525 b/s  |
|                                                                             |
|  Note 1: C=Clear, S=Scrambled                                               |
|  Note 2: Unless specified otherwise, bitrates are based on 188 bytes/pkt    |
===============================================================================

===============================================================================
|  SERVICES ANALYSIS REPORT                                                   |
|=============================================================================|
|  Global PID's                                                               |
|  TS packets: 1,015, PID's: 2 (clear: 2, scrambled: 0)                       |
|-----------------------------------------------------------------------------|
|     PID  Usage                                     Access          Bitrate  |
|   Total  Global PID's ................................. C      151,073 b/s  |
|   Subt.  Global PSI/SI PID's (0x00-0x1F) .............. C      151,073 b/s  |
|  0x0000  PAT .......................................... C      126,514 b/s  |
|  0x0011  SDT/BAT ...................................... C       24,559 b/s  |
|=============================================================================|
|  Service: 0x0001 (1), TS: 0x0001 (1), Original Netw: 0xFF01 (65281)         |
|  Service name: Service01, provider: FFmpeg                                  |
|  Service type: 0x01 (Digital television service)                            |
|  TS packets: 33,825, PID's: 3 (clear: 3, scrambled: 0)                      |
|  PMT PID: 0x1000 (4096), PCR PID: 0x0100 (256)                              |
|-----------------------------------------------------------------------------|
|     PID  Usage                                     Access          Bitrate  |
|   Total  Digital television service ................... C    5,034,525 b/s  |
|  0x00FC  MPEG-2 PES private data ...................... C        2,977 b/s  |
|  0x0100  AVC video (1280x722, high profile, level 4.0,  C    4,905,034 b/s  |
|  0x1000  PMT .......................................... C      126,514 b/s  |
|          (C=Clear, S=Scrambled, +=Shared)                                   |
===============================================================================

===============================================================================
|  PIDS ANALYSIS REPORT                                                       |
|=============================================================================|
|  PID: 0x0000 (0)                                                       PAT  |
|-----------------------------------------------------------------------------|
|  Global PID                Transport:                Discontinuities:       |
|  Bitrate: ... 126,514 b/s  Packets: ........... 850  Expected: ......... 0  |
|  Access: .......... Clear  Adapt.F.: ............ 0  Unexpect: ......... 0  |
|                            Duplicated: .......... 0  Sections:              |
|                                                      Unit start: ..... 850  |
|=============================================================================|
|  PID: 0x0011 (17)                                                  SDT/BAT  |
|-----------------------------------------------------------------------------|
|  Global PID                Transport:                Discontinuities:       |
|  Bitrate: .... 24,559 b/s  Packets: ........... 165  Expected: ......... 0  |
|  Access: .......... Clear  Adapt.F.: ............ 0  Unexpect: ......... 0  |
|                            Duplicated: .......... 0  Sections:              |
|                                                      Unit start: ..... 165  |
|=============================================================================|
|  PID: 0x00FC (252)                                 MPEG-2 PES private data  |
|  PES stream id: 0xFC (MPEG-7 metadata stream)                               |
|  Service: 0x0001 (1) Service01                                              |
|-----------------------------------------------------------------------------|
|  Single Service PID        Transport:                Discontinuities:       |
|  Bitrate: ..... 2,977 b/s  Packets: ............ 20  Expected: ......... 0  |
|  Access: .......... Clear  Adapt.F.: ........... 10  Unexpect: ......... 0  |
|                            Duplicated: .......... 0  PES:                   |
|                                                      Packets: ......... 10  |
|                                                      Inv.Start: ........ 0  |
|  Clock values range:                                                        |
|                            PTS: ................ 10                         |
|                            from ................. 0                         |
|                            to ................... 0                         |
|                            Leaps: ............... 0                         |
|=============================================================================|
|  PID: 0x0100 (256)                                               AVC video  |
|  PES stream id: 0xE0 (Video 0)                                              |
|  1280x722, high profile, level 4.0, 4:2:0                                   |
|  Service: 0x0001 (1) Service01                                              |
|-----------------------------------------------------------------------------|
|  Single Service PID        Transport:                Discontinuities:       |
|  Bitrate: . 4,905,034 b/s  Packets: ........ 32,955  Expected: ......... 0  |
|  Access: .......... Clear  Adapt.F.: .......... 353  Unexpect: ......... 0  |
|                            Duplicated: .......... 0  PES:                   |
|                            TSrate: .. 5,185,598 b/s  Packets: ........ 304  |
|                                                      Inv.Start: ........ 0  |
|  Clock values range:                                                        |
|  PCR: ................ 51  PTS: ............... 304                         |
|  from ....... 316,791,000  from ......... 1,052,910                         |
|  to ......... 584,766,000  to ........... 1,955,160                         |
|  Leaps: ............... 0  Leaps: ............... 0                         |
|=============================================================================|
|  PID: 0x1000 (4096)                                                    PMT  |
|  Service: 0x0001 (1) Service01                                              |
|-----------------------------------------------------------------------------|
|  Single Service PID        Transport:                Discontinuities:       |
|  Bitrate: ... 126,514 b/s  Packets: ........... 850  Expected: ......... 0  |
|  Access: .......... Clear  Adapt.F.: ............ 0  Unexpect: ......... 0  |
|                            Duplicated: .......... 0  Sections:              |
|                                                      Unit start: ..... 850  |
===============================================================================

===============================================================================
|  TABLES & SECTIONS ANALYSIS REPORT                                          |
|=============================================================================|
|  PID: 0x0000 (0)                                                       PAT  |
|-----------------------------------------------------------------------------|
|  0x00 (0, PAT), TID ext: 0x0001 (1)                                         |
|      Repetition: ...... 12  ms  Section cnt: ...... 850                     |
|      Min repet.: ....... 1  ms  Table cnt: ........ 850                     |
|      Max repet.: ...... 12  ms  Version: ............ 0                     |
|=============================================================================|
|  PID: 0x0011 (17)                                                  SDT/BAT  |
|-----------------------------------------------------------------------------|
|  0x42 (66, SDT Actual), TID ext: 0x0001 (1)                                 |
|      Repetition: ...... 61  ms  Section cnt: ...... 165                     |
|      Min repet.: ...... 61  ms  Table cnt: ........ 165                     |
|      Max repet.: ...... 62  ms  Version: ............ 0                     |
|=============================================================================|
|  PID: 0x1000 (4096)                                                    PMT  |
|  Service: 0x0001 (1) Service01                                              |
|-----------------------------------------------------------------------------|
|  0x02 (2, PMT), TID ext: 0x0001 (1)                                         |
|      Repetition: ...... 12  ms  Section cnt: ...... 850                     |
|      Min repet.: ....... 1  ms  Table cnt: ........ 850                     |
|      Max repet.: ...... 12  ms  Version: ............ 0                     |
===============================================================================
udp rtsp gstreamer-1.0 mpeg2-ts klvdata
1个回答
0
投票

我认为这就是问题所在:

PID: 0x00FC (252)  MPEG-2 PES private data PES stream id: 0xFC

stream id: 0xFC
表示当前tsdemux不支持同步KLV。 Michael Fien 有一个非常旧的补丁,用于将 Sync KLV 添加到 tsdemux:

https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/issues/642

我预计代码会随着时间的推移而演变,所以不知道应用到当前的 tsdemux 代码有多困难。我也不知道它的坚固程度如何。我自己正在研究这个问题,但我的项目时间非常有限。

另一种选择是使用 ffmpeg。它似乎适用于同步 KLV 流:

ffmpeg -i udp://$STREAM_IP:$STREAM_PORT -map 0:0 -codec copy -f data "/tmp/video.ts" -map 0:1 -codec copy -f data "/tmp/data.ts"
© www.soinside.com 2019 - 2024. All rights reserved.