6

How to read the metadata of a MKV movie files in C# (or C or C++ or AS3)?

for example such

creator
metadatacreator
hasKeyframes
hasVideo
hasAudio
hasMetaData
canSeekToEnd
duration
datasize
videosize
videocodecid
audiosize
audiocodecid
audiosamplerate
audiosamplesize
stereo
filesize
lasttimestamp
lastkeyframetimestamp
lastkeyframelocation
keyframes (filepositions, times)
width
height
framerate
videodatarate
audiodatarate
Rella
  • 65,003
  • 109
  • 363
  • 636

4 Answers4

5

There is always attempting to parse the header yourself.

Also I've seen references to the EBML library being used to decode MKV files. Good luck!

monksy
  • 14,156
  • 17
  • 75
  • 124
3

I recently posted C# version to https://github.com/OlegZee/nebml. It contains Title editor sample which demostrate inline editing of certain properties.

olegz
  • 1,189
  • 10
  • 20
  • I know this was a long time ago. I have had a look at your project and it looks quite... complex. Is there any documentation available? – Jan May 29 '13 at 07:36
  • What's is particularly complex? In fact there're two modules: one defines Ebml reader/writer and another one describes structure for MKV. – olegz May 30 '13 at 03:05
  • When I looked at it, I was expecting something similar to an API. Something like 'Matroshka file = new Matroshka(); file.Load(...); file.Title="foobar";'. Then I looked at the example solution more closely and hoped that I could find anything that I could place inside a wrapper to get the mentioned behaviour, but I couldn't figure out how to use it at all... – Jan May 30 '13 at 16:18
  • @Jan: it's not that simple :( Unfortunately it has to deal with huge file size so I'm just updating comment records in-place. Let me know which kind of record do you plan to modify: just metadata or streams? I would be happy to implement complete API but I'm afraid it's not that easy and users will send me deathwishes every time they get broken MKV file especially if it happens on 1:05.00 from the beginning :) – olegz Jun 05 '13 at 14:34
  • haha, I can imagine. To be honest, I was just looking to change meta data. ATM only the title to be exact. I'd be willing to lend a hand if you are looking for support? – Jan Jun 05 '13 at 16:25
  • @Jan: well, such kind API for metadata is feasible. I will check if I can dive into my code quickly and will update it anytime soon. – olegz Jun 09 '13 at 16:20
  • @olegz I have looked at your project. However I could not understand that how I can extract a subtitle from a mkv video. Can you help me for this ? – Sinan AKYAZICI Sep 07 '13 at 09:51
  • It’s on GitHub now and there’s nuget package with the same name – olegz Aug 24 '21 at 17:12
1

You might try asking this over at doom9 forums in their development section. Also mediainfo.dll might also work for you.

Jeff C.
  • 11
  • 1
0

The simplest way to get a lot of this is to spawn an instance of mkvinfo and parse its output. One problem with what you are asking is that a Matroska file can have an unlimited number of video and audio streams. So you would have to enumerate the streams in the file prior to getting these properties.

David Chappelle
  • 1,243
  • 5
  • 13
  • 29