[FFmpeg-user] adjusting when Matroska clusters are restarted

Dave Rice dave at dericed.com
Mon Apr 16 19:36:58 EEST 2018


Hi all,

The command below creates a short matroska file with a video and audio track:

ffmpeg -f lavfi -i testsrc2=r=30000/1001:s=1920x1080:d=1 -f lavfi -i aevalsrc=exprs=0:d=1 -c:v v210 -c:a pcm_s24le -y -vframes 2 test.mkv
ffmpeg version N-51550-g41d7c4d381 Copyright (c) 2000-2018 the FFmpeg developers
  built with Apple LLVM version 9.0.0 (clang-900.0.38)
  configuration: --prefix=/usr/local/Cellar/ffmpeg/HEAD-41d7c4d --enable-shared --enable-pthreads --enable-version3 --enable-hardcoded-tables --enable-avresample --cc=clang --host-cflags= --host-ldflags= --enable-gpl --enable-ffplay --enable-libfreetype --enable-libmp3lame --enable-libx264 --enable-libxvid --enable-opencl --enable-videotoolbox --disable-lzma
  libavutil      56.  9.100 / 56.  9.100
  libavcodec     58. 14.100 / 58. 14.100
  libavformat    58. 10.100 / 58. 10.100
  libavdevice    58.  2.100 / 58.  2.100
  libavfilter     7. 13.100 /  7. 13.100
  libavresample   4.  0.  0 /  4.  0.  0
  libswscale      5.  0.102 /  5.  0.102
  libswresample   3.  0.101 /  3.  0.101
  libpostproc    55.  0.100 / 55.  0.100
Input #0, lavfi, from 'testsrc2=r=30000/1001:s=1920x1080:d=1':
  Duration: N/A, start: 0.000000, bitrate: N/A
    Stream #0:0: Video: rawvideo (I420 / 0x30323449), yuv420p, 1920x1080 [SAR 1:1 DAR 16:9], 29.97 tbr, 29.97 tbn, 29.97 tbc
Input #1, lavfi, from 'aevalsrc=exprs=0:d=1':
  Duration: N/A, start: 0.000000, bitrate: 2822 kb/s
    Stream #1:0: Audio: pcm_f64le, 44100 Hz, mono, dbl, 2822 kb/s
Stream mapping:
  Stream #0:0 -> #0:0 (rawvideo (native) -> v210 (native))
  Stream #1:0 -> #0:1 (pcm_f64le (native) -> pcm_s24le (native))
Press [q] to stop, [?] for help
Output #0, matroska, to 'test.mkv':
  Metadata:
    encoder         : Lavf58.10.100
    Stream #0:0: Video: v210 (v210 / 0x30313276), yuv422p(progressive), 1920x1080 [SAR 1:1 DAR 16:9], q=2-31, 1325778 kb/s, 29.97 fps, 1k tbn, 29.97 tbc
    Metadata:
      encoder         : Lavc58.14.100 v210
    Stream #0:1: Audio: pcm_s24le ([1][0][0][0] / 0x0001), 44100 Hz, mono, s32, 1058 kb/s
    Metadata:
      encoder         : Lavc58.14.100 pcm_s24le
frame=    2 fps=0.0 q=-0.0 Lsize=   10804kB time=00:00:00.03 bitrate=2603133.6kbits/s speed=0.537x    
video:10800kB audio:3kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.009456%

When running this through mkvalidator I get a warning:

mkvalidator test.mkv
WRN0C2: The timecode of the Cluster at 5530555 is not incrementing (may be intentional)
mkvalidator 0.5.2: the file appears to be valid
	file "test.mkv"
	created with Lavf58.10.100 / Lavf58.10.100

With `mkvinfo -v test.mkv`, I can see how the encoded data is arranged into Clusters:

|+ Cluster
| + Cluster timestamp: 00:00:00.000000000
| + Simple block: key, track number 1, 1 frame(s), timestamp 00:00:00.000000000
|  + Frame with size 5529600
|+ Cluster
| + Cluster timestamp: 00:00:00.000000000
| + Simple block: key, track number 2, 1 frame(s), timestamp 00:00:00.000000000
|  + Frame with size 3072
| + Simple block: key, track number 1, 1 frame(s), timestamp 00:00:00.033000000
|  + Frame with size 5529600

So track 2 at 0 is stored in a Cluster with track 1 at 00.033. I see the Matroska muxer has options for Clusters with cluster_size_limit and cluster_time_limit but is there a way to start a new Cluster for every frame (or every keyframe) from track 1? Ideally I’d like the Cluster timestamps to be unique and timed along with the video track or at least to mux in a way that avoids the mkvalidator warning.
Dave Rice


More information about the ffmpeg-user mailing list