提问人:Pasi Kähönen 提问时间:11/8/2023 最后编辑:Pasi Kähönen 更新时间:11/18/2023 访问量:92
无法使用 klv-metadata 获取 mpegts 从 udpsrc 流向管道末端
Unable to get mpegts with klv-metadata to flow to end of pipe from udpsrc
问:
我已经与这个问题作斗争了很长一段时间。我有来自 udpsrc 的 klv-metadata 的 mpegts 流和下面的 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/< - 任何一个文件都应该工作),整个管道都可以正常工作。
但是在我将其切换到 udpsrc 后,我在 EOS 之后只获得了几帧 klv-data,其他时候我一直收到“WARNING: from element /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 |
===============================================================================
答:
MPEG-TS 流中的 KLV 数据有 2 种定义的格式:异步和同步。当前的 gstreamer-plugins tsdemux 不支持 Synchronous。(我使用的是 v1.16.3,我相信从 v1.22 开始仍然如此)
您发布的测试文件包含异步 KLV。
PID: 0x01F1 (497) MPEG-2 PES private data | PES stream id: 0xBD
stream_id: 0xBD
意味着异步 KLV。这两个流都可以由 gstreamer 使用 使用 处理,或者通过 udp 进行流式处理,并使用 摄取 。此管道的工作原理是:filesrc
udpsrc
gst-launch-1.0 -v udpsrc port=$STREAM_PORT ! tsdemux name=demux demux. ! queue ! 'video/x-h264' ! filesink location="video.ts" demux. ! queue ! 'meta/x-klv' ! filesink buffer-mode=2 location="klv.ts"
您为 UDP 流发布的 tsduck 输出指示同步 KLV。
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 "video.ts" -map 0:1 -codec copy -f data "klv.ts"
评论
gst-launch-1.0 -v udpsrc port=$STREAM_PORT ! tsdemux name=demux demux. ! queue ! 'video/x-h264' ! filesink location="video.ts" demux. ! queue ! 'meta/x-klv' ! filesink buffer-mode=2 location="klv.ts"
tsparse