The go-to format for video these days is .mp4 containers with h.264 compression. However, when we are working on video analysis (such as in Musical Gestures Toolbox for Python), this format is not ideal. While .mp4 files are small and nice-looking, they are based on removing a lot of “unnecessary” information. There are numerous video container formats (see comparison) but many of them are proprietary. I didn’t know much about Matroska before, but it seems to be a better solution being a free and open-source, hence “future-proof”, format.

Why Matroska?

Matroska, often associated with the .mkv file extension, is a versatile multimedia container format. It supports a wide range of codecs and allows for the inclusion of multiple audio tracks, subtitles, and metadata in a single file:

  1. Lossless Compression: Matroska supports lossless video codecs, ensuring that no data is discarded during compression. This is essential for tasks like frame-by-frame analysis or machine learning applications.

  2. Rich Metadata Support: The format allows embedding extensive metadata, which can be useful for tagging, categorization, or storing additional information about the video.

  3. Multiple Streams: With Matroska, you can include multiple audio tracks, subtitle streams, and even alternative video streams in a single file. This flexibility is invaluable for projects requiring multilingual support or comparisons between different video versions.

  4. Open Source and Extensible: Being open-source, Matroska is continuously updated and improved by the community. Its extensibility ensures compatibility with future technologies.

How to Convert to Matroska

Converting existing .mp4 files to Matroska is straightforward using tools like FFmpeg. For example, the following command converts an .mp4 file to .mkv without re-encoding:

ffmpeg -i input.mp4 -c copy output.mkv

This process is fast and retains the original quality of the video and audio streams.