Skip to content

matroskademux: Set DTS on the first buffer to workaround frame-reordering

Seungha Yang requested to merge seungha.yang/gstreamer:mkvdemux-dts into main

demuxer doesn't set DTS on buffer which is fine for normal playback but can be an issue in case of transmuxing. Set it on the first buffer for baseparse to be able to guess DTS of this stream.

Not a nice hack but I'm not sure what's a correct approach.

An issue case is transmuxing bframe encoded h264/mkv to mp4 Encoding pipeline:

gst-launch-1.0.exe videotestsrc num-buffers=100 ! video/x-raw,format=NV12 ! x264enc bframes=2 key-int-max=10 ! h264parse ! matroskamux ! filesink location=mux.mkv

gst-discoverer-1.0.exe mux.mkv
Analyzing file:///C:/Work/gstreamer/mux.mkv
Done discovering file:///C:/Work/gstreamer/mux.mkv

Properties:
  Duration: 0:00:03.333333333
  Seekable: yes
  Live: no
  container #0: Matroska
    video #1: H.264 (High Profile)
      Stream ID: 92b82821c5a2f489f736c2a1e1d0b7414bb76440f0ce11c956ff65d572bfd4ab/001:15903578687128276141
      Width: 320
      Height: 240
      Depth: 24
      Frame rate: 30/1
      Pixel aspect ratio: 1/1
      Interlaced: false
      Bitrate: 1436643
      Max bitrate: 0

Remuxing (see file duration)

gst-launch-1.0.exe filesrc location=mux.mkv ! matroskademux ! h264parse ! mp4mux ! filesink location=remux.mp4

gst-discoverer-1.0.exe remux.mp4
Analyzing file:///C:/Work/gstreamer/remux.mp4
Done discovering file:///C:/Work/gstreamer/remux.mp4

Properties:
  Duration: 0:00:06.301333333
  Seekable: yes
  Live: no
  container #0: Quicktime
    video #1: H.264 (High Profile)
      Stream ID: 7c38f993f3da195596fa9044a8b91f3fa11e1e449625a0b474daf5ce616144dd/001
      Width: 320
      Height: 240
      Depth: 24
      Frame rate: 30/1
      Pixel aspect ratio: 1/1
      Interlaced: false
      Bitrate: 1436643
      Max bitrate: 1756080

And timestamp of resulting remuxed mp4 file is pretty broken

The transmuxing worked in 1.16 but regressed by the commit !351 (merged)

Edited by Seungha Yang

Merge request reports