Gstreamer:RTP 流到 VP8/webm 录制不会产生可查找的文件

问题描述

我正在使用 Gstreamer 将 WebRTC 流捕获到 webm 文件。我注意到在 rtp 流中使用 VP8 编码时,生成文件在任何播放器(例如 Chrome 或 VLC)中都不可查找。通过可搜索,我的意思是你不能从流中的任意点播放文件,它只能从播放的一开始就开始。

我已经将 h264 编码与 rtp 一起使用,并且生成的 mp4 文件是可查找的。此外,删除 rtp 编码/解码会为 VP8 生成一个可查找的输出文件

以下是产生这些结果的测试管道。

# produces a valid webm file that is not seekable (I need this to be seekable)
gst-launch-1.0 -e \
  autovideosrc ! autovideoconvert ! vp8enc ! rtpvp8pay ! rtpvp8depay ! webmmux ! \
  filesink location=test.webm

# produces a valid webm file that is seekable
gst-launch-1.0 -e \
  autovideosrc ! autovideoconvert ! vp8enc ! webmmux ! \
  filesink location=test.webm

# produces a valid mp4 file that is seekable
gst-launch-1.0 -e \
  autovideosrc ! autovideoconvert ! x264enc ! rtph264pay ! rtph264depay ! h264parse ! mp4mux ! \
  filesink location=test.mp4


有没有一种方法可以创建可查找的 rtp/VP8/matroska 录音?这是 Gstreamer 中的错误吗?

我在 Ubuntu 上同时使用了 Gstreamer 1.14 和 1.18,结果相同。

解决方法

这是 webm 格式的一个奇怪之处,它也会影响 MediaRecorder API。 见here

简而言之,您需要在停止录制时更新文件开头的持续时间元数据。