Log in

View Full Version : Extract infos from MKV file


tHe gLouCh
24th June 2003, 07:35
Is there api reference to mkxds.dll ?
I want to know how to extract (in Delphi) infos from the MKV file ? Numbers of streams, duration of the video, etc...

ChristianHJW
24th June 2003, 09:06
Get Mosu's mkvtoolnix binaries, there is a proggie called mkvinfo in the package. http://www.bunkus.org/videotools/mkvtoolnix/index.html#dlinst_binaries

robUx4
24th June 2003, 09:12
We don't have anything like that yet. For the moment only the TCMP CDL do that, the Windows shell extension and most probably MPC.

I guess you can tell all these things by inspecting the data in DirectShow (the length and the number of pins connected).

robUx4
24th June 2003, 09:13
Otherwise when you load a file in your player, you can "pre-open" it with some codeof yours, using libmatroska. Then you can get all info you want. (it won't work well with data from the network)

jcsston
25th June 2003, 00:42
Originally posted by robUx4
We don't have anything like that yet. For the moment only the TCMP CDL do that, the Windows shell extension and most probably MPC.

I guess you can tell all these things by inspecting the data in DirectShow (the length and the number of pins connected).
I'm adding a Delphi/Visual Basic interface to the Shell Ext .dll so you would be able to get the most of the same infomation that the Shell Ext and CDL can read :)

tHe gLouCh
25th June 2003, 00:45
Originally posted by jcsston
I'm adding a Delphi/Visual Basic interface to the Shell Ext .dll so you would be able to get the most of the same infomation that the Shell Ext and CDL can read :)

Where can I get it ? :)

jcsston
25th June 2003, 01:50
It's not quite ready yet ;)
@tHe gLouCh: Do you think you could translate Visual Basic headers into something that Delphi can use?

jcsston
25th June 2003, 02:43
tHe gLouCh Here's a version for you to try ;)
http://www.geocities.com/jcsston/matroskaprop.htm
I only have Track Count, getting the Track UID, Track Type, Track CodecID, Track Length, and Setting the display size wrapped in C functions to be called by an VB/Delphi app.

tHe gLouCh
25th June 2003, 07:19
Originally posted by jcsston
It's not quite ready yet ;)
@tHe gLouCh: Do you think you could translate Visual Basic headers into something that Delphi can use?
I've just downloaded your file. I will try today to adapt the .frm file to Delphi :sly:

tHe gLouCh
25th June 2003, 14:26
Well, it's not working !! :mad:
Could someone tell me why ?

unit mkv;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;

type
TForm1 = class(TForm)
Button1: TButton;
Memo1: TMemo;
procedure Button1Click(Sender: TObject);
private
{ Déclarations privées }
public
{ Déclarations publiques }
end;

var
Form1: TForm1;
const
MatroskaProp = 'MatroskaProp.Dll';

function CreateParserObject(var parserObj: LongInt; filename: string): LongInt; cdecl; external MatroskaProp;
function FillParserObject(parserObj: LongInt; parseTags: Boolean; parseWholeFile: Boolean): LongInt; cdecl; external MatroskaProp;
function DeleteParserObject(parserObj: LongInt): LongInt; cdecl; external MatroskaProp;

function GetTrackCount(parserObj: LongInt): LongInt; cdecl; external MatroskaProp;
function GetTrackUID(parserObj: LongInt; track_no: LongInt): LongInt; cdecl; external MatroskaProp;
function GetTrackType(parserObj: LongInt; track_no: LongInt): LongInt; cdecl; external MatroskaProp;
function GetTrackTypeLen(parserObj: LongInt; track_no: LongInt): LongInt; cdecl; external MatroskaProp;
function GetTrackTypeStr(parserObj: LongInt; track_no: LongInt; var track_type_name: string): LongInt; cdecl; external MatroskaProp;
function GetTrackCodecIDLen(parserObj: LongInt; track_no: LongInt): LongInt; cdecl; external MatroskaProp;
function GetTrackCodecIDStr(parserObj: LongInt; track_no: LongInt; var codec_name: string): LongInt; cdecl; external MatroskaProp;
function GetTrackLength(parserObj: LongInt; track_no: LongInt): LongInt; cdecl; external MatroskaProp;

function SetAR(parserObj: LongInt; display_x: Integer; display_y: Integer): LongInt; stdcall; cdecl; external MatroskaProp;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
var
par, track_count, t_uid, ps: LongInt;
I: integer;
test: string;
str_len: Integer;
codecID: string;
Handle: THandle;
sl:Tstrings;
begin
Handle := LoadLibrary(MatroskaProp);
if Handle <> 0 then
begin
sl:=TStringList.Create;
//Print "Parser", "Track No", "Return value", "Return Value2"
ps := CreateParserObject(par, 'F:\toto\test_2.mkv');
sl.Add(IntToStr(ps));

ps := FillParserObject(par, False, True);
sl.Add(IntToStr(ps));

track_count := GetTrackCount(par);
sl.Add(IntToStr(ps));
for I := 0 to track_count do
begin
ps := GetTrackType(par, t_uid);
{if ps > -1 then
sl.Add(IntToStr(ps) + ' ' + IntToStr(I) + ' ' + IntToStr(t_uid));}
ps := GetTrackLength(par, I);
{if ps > -1 then
sl.Add(IntToStr(ps) + ' ' + IntToStr(I) + ' ' + IntToStr(t_uid));}

str_len := GetTrackTypeLen(par, I);
{if str_len > -1 then
begin
ps := GetTrackTypeStr(par, I, test);
sl.Add(IntToStr(ps) + ' ' + IntToStr(I) + ' ' + test);
end;}

str_len := GetTrackCodecIDLen(par, I);
{if str_len > -1 then
begin
ps := GetTrackCodecIDStr(par, I, codecID);
sl.Add(IntToStr(ps) + ' ' + IntToStr(I) + ' ' + codecId);
end;}

ps := GetTrackLength(par, I);
{if ps > -1 then
sl.Add(IntToStr(ps) + ' ' + IntToStr(I));}

ps := SetAR(par, 640, 480);
{if ps > -1 then
sl.Add(IntToStr(ps));}
end;

ps := DeleteParserObject(par);
sl.Add(IntToStr(ps));
FreeLibrary(Handle);
if sl<>nil then sl.Free;

end;
end;

end.

jcsston
25th June 2003, 21:38
When does it fail?
I'll explain what somethings are used for.

par should have the memory address of the parser object created when you call CreateParserObject If after calling CreateParserObject and par equals 0 then that will be the source of all your problems.

For the strings. you first call the Len functions and create a string that long, (filled with spaces or anything). And then pass the filled string to the Str function.

If you cannot get it working, send me a few different exe's and I can see exactly what the Dll functions are getting.

tHe gLouCh
25th June 2003, 23:44
I cannot get it:angry:

All variables are declared 32bits signed integers.

1) ps := CreateParserObject(par, 'F:\toto\Test_1_Movie.mkv');
Ok par=4137424
2) GetTrackLength -> 0 (???)
3) where I is track numberstr_len := GetTrackTypeLen(par, I);
if str_len > -1 then
begin
test:='';
for J := 1 to str_len do
test:=test+' ';
ps := GetTrackTypeStr(par, I, test);
end;I obtain Str_Len = 16 (it seems ok!) "Test_1_Movie.mkv"
When I pass test (='________________' 16 spaces) to GetTrackTypeStr -> compiler error "Inaccesible value", and crash !!

[Toff]
26th June 2003, 00:12
I'm not a delphi expert neither a VB expert but i see some different calling convention :


function GetTrackLength(parserObj: LongInt; track_no: LongInt): LongInt; cdecl; external MatroskaProp;

function SetAR(parserObj: LongInt; display_x: Integer; display_y: Integer): LongInt; stdcall; cdecl; external MatroskaProp;


Shouldn't it be stdcall everywhere ?

tHe gLouCh
26th June 2003, 00:16
Thanx, but it was corrected since I post the code!

Liisachan
13th July 2003, 10:47
I think I found a very small problem w MatroskaProp.dll v.1.1:

If an MKV file has 10 or more tracks, tracks wont be sorted correctly by number in the shell ext. but will be softed by name; for instance, if you had an 11-track MKV, you'd get this order in the "Matroska Info" tab:
Track 1
Track 10
Track 11
Track 2
Track 3
...

jcsston
14th July 2003, 07:42
Originally posted by Liisachan
I think I found a very small problem w MatroskaProp.dll v.1.1:

If an MKV file has 10 or more tracks, tracks wont be sorted correctly by number in the shell ext. but will be softed by name; for instance, if you had an 11-track MKV, you'd get this order in the "Matroska Info" tab:
Track 1
Track 10
Track 11
Track 2
Track 3
...
:) Thanks, that has been fixed. (I had to so your great 18 track sample would look right ;) )

jcsston
22nd July 2003, 22:21
@tHe gLouCh, Dark-Cracker: Have you been able to use the .dll?

Dark-Cracker
22nd July 2003, 22:57
i don't have already really play with the dll :) but my first test have work without problem. once my harddisk will be repeared i will restart to play with it :)

Bye.