How to read the metadata of a MKV movie files in C#?
Asked Answered
E

5

7

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
Estebanesteem answered 5/1, 2010 at 4:46 Comment(0)
S
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!

Shoot answered 5/1, 2010 at 4:53 Comment(0)
A
3

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

Acknowledge answered 8/4, 2011 at 16:1 Comment(8)
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?Electrophoresis
What's is particularly complex? In fact there're two modules: one defines Ebml reader/writer and another one describes structure for MKV.Acknowledge
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...Electrophoresis
@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 :)Acknowledge
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?Electrophoresis
@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.Acknowledge
@Acknowledge 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 ?Sepia
It’s on GitHub now and there’s nuget package with the same nameAcknowledge
B
1

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

Bartonbartosch answered 26/4, 2010 at 2:40 Comment(0)
E
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.

Elwira answered 4/8, 2015 at 20:50 Comment(0)
P
0

In 2024, I have a similar question. I wanted to extract arbitrary tracks from an mkv file based on mkvinfo's output data (EBML?). Was about to write a kludgy parser to get what I needed from that output, when I discovered mkvmerge outputs the same info as json.

mkvmerge --redirect-output "myMkv-info.json" --identification-format "json" --identify myMkv.mkv

Almost every programming language can parse json to hashmap/dictionary/object. Or use the jq utility to extract only the data you need.

More details: mkvmerge --identify

Pyrite answered 10/8 at 16:40 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.