Log in

View Full Version : Calculating CRC32 Hash of MKV tracks


tip
16th March 2010, 08:50
Hi to all,

Does anybody know of an application that calculates hashes (CRC32,MD5,SHA1 etc) of mkv tracks? For ex: I want to calculate video tracks hash. I can do that by extracting h264 stream to a .h264 file using mkvextract then calculate its hash. But when dealing with 10+ Gb files this process is very slow and painful. If i could directly calculate hash without extracting video track it would be really nice.

I know a bit of scripting/coding and if there is a dll file that lets me read mkv tracks byte-by-byte I thing I can write a hash calculator using it.

Thanx everybody in advance
Tip

Guest
16th March 2010, 14:22
Why do you need the video hash versus just the hash of the whole file? What do you intend to do with the hash?

tip
16th March 2010, 22:15
I sometimes add subtitles or change title/name of a track. All these changes effects file hash. If I can only calculate video tracks hash it would be distinctive and reliable...

Guest
16th March 2010, 22:51
Just redo your hash if you alter the file.

tip
16th March 2010, 23:58
I use mmg to add subtitles etc. Even it returns with error code 0 I personally experienced problems with couple of result files. So if i could compare these two files video tracks hash I could say if there was an error while creating second one.

Guest
17th March 2010, 00:19
To support MKV in my tools I started from the core parser code from Haali. He offers it here (scroll down and look for it on the right):

http://haali.su/mkv/

Inspector.Gadget
17th March 2010, 00:19
You should talk to mosu about possible mkvmerge errors that don't throw an error code. I'm sure he'd be interested to know, and could probably help you eliminate mkvmerge as the possible source of any errors with remuxed files.

Guest
17th March 2010, 02:20
Definitely agree with the Inspector. OP might also consider posting about the problem you have, rather than ask about some possible solution you thought of. Always start by saying what your exact problem is! Here you might have posted about "muxing problems with mkv".

tip
17th March 2010, 08:51
Thanks for your suggestions but i just gave an example why I want to calculate video tracks hash. There are several other reasons why I want to do it. Not to be rude but I clearly explained what I want to do, why do you keep assuming that I want something different then I stated?

If you can explain me how I can read mkv tracks byte-by-byte I would be very glad but please do not suggest me that I am not aware of what I want to know.

Thanks again for your replies.
Tip

Guest
17th March 2010, 14:19
Thanks for your suggestions but i just gave an example why I want to calculate video tracks hash. There are several other reasons why I want to do it. Not to be rude but I clearly explained what I want to do, why do you keep assuming that I want something different then I stated? Forum rule 12 tells you not to whine when you get an answer you don't like. What are the other reasons? How can we properly answer your question if you withhold important information?

If you can explain me how I can read mkv tracks byte-by-byte I would be very glad but please do not suggest me that I am not aware of what I want to know. I gave you a link to a library for reading MKV files.

tip
17th March 2010, 23:27
I don't want to keep arguing over some silly thingy but I don't think that I whine about the answers I got. I honestly think it is similar to this: I asked 2+2=? and the answers were 3*2=6. I can't see the correlation between my questions and your answers. But I really thank you for your honest efforts and my intention is not to offend you.


I've sent an e-mail to him and I am waiting for his answer. Thank you for the link.

Guest
17th March 2010, 23:35
Do I take it then that you do not intend to answer these:

What are the other reasons? How can we properly answer your question if you withhold important information?

Or did you just overlook them?

tip
18th March 2010, 07:36
Why do you need all of my reasons? I just want to be able to calculate hashes of raw mkv streams. Do I need any reason for that at all? Will it change your your answer if I'd say "it's just me being curious" or "I want to calculate video tracks hashes because my hard drive might be dieing and mkvmerge sometimes screws up my resulting file. This way I can be sure that it copied the video and sound tracks fine."

Due to your insistance I also considered that maybe what I want to do can be used for some illegal purposes. But I can't come up with any example, so if it is the case -if i unwillingly try to do something that can be used illegally- my honest apologies...

Sincerely
Tip

Guest
18th March 2010, 14:47
Sorry for trying to help you. Don't worry, it won't happen again.

tip
18th March 2010, 15:23
I'm sorry too if I offended you...

tip
18th March 2010, 15:36
If anyone wonders same thing I do, here is the reply I've got from Mosu (mkvtoolnix's creator):


Depends on your knowledge of programming. Existing tools don't allow you to do that with the flick of a simple switch.

You have two options, one that requires quite a bit of time and space for each file to be hashed but less knowledge about programming/scripting and another that requires knowledge about programming but that doesn't need temporary files and only scans a file once.

1. You can ask mkvextract to extract each track into a raw file without adding any further container information. This is can be achieved by the "--raw" switch. If you also want to take the CodecPrivate element into account use "--full-raw". Then you can md5/sha1/etc that temporary file.

The workflow would look like this: 1. Run "mkvmerge --identify yourfile.mkv" and parse the output so that you know which tracks are present. 2. Run "mkvextract" on all tracks. 3. Run the checksum algorithm on the resulting extracted files. 4. Delete the temporary files.

2. You could modify e.g. mkvinfo to calculate the checksums.

3. You could write your own program that parses a Matroska file, e.g. based on Haali's Matroska parser (either the DirectShow splitter or the low level file access library source code he provides).

roozhou
25th March 2010, 18:57
Try to modify ffmpeg and add a bitstream filter that calculates hash.