Hi.
Here's a little example of how to call mediainfo.dll.
Some details about MediaInfo (taken from
http://mediainfo.sourceforge.net):
Quote:
MediaInfo supplies technical and tag information about a video or audio file. This is free software (free of charge and free to access source code: GPL or LGPL licence).
What information can I get from MediaInfo?
* General: title, author, director, album, track number, date, duration...
* Video: codec, aspect, fps, bitrate...
* Audio: codec, sample rate, channels, language, bitrate...
* Text: language of subtitle
* Chapters: number of chapters, list of chapters
What format (container) does MediaInfo support?
* Video: MKV, OGM, AVI, DivX, WMV, QuickTime, Real, MPEG-1, MPEG-2, MPEG-4, DVD (VOB)...
(Codecs: DivX, XviD, MSMPEG4, ASP, H.264, AVC...)
* Audio: OGG, MP3, WAV, RA, AC3, DTS, AAC, M4A, AU, AIFF...
* Subtitles: SRT, SSA, ASS, SAMI...
Here's the code (tested with mediainfo.dll 0.7.4.1):
Code:
;use your own paths here
PathToMediaInfoDLL := "C:\Documents and Settings\Administrator\My Documents\autohotkey\MediaInfo.dll"
PathToAVIFile := "C:\Documents and Settings\Administrator\My Documents\autohotkey\6x09.avi"
hModule := DllCall("LoadLibrary", "str", PathToMediaInfoDLL) ; Avoids the need for subsequent DllCalls to load the library
;get info about parameters, etc. This time we use ANSI (MediaInfoA_) version of the function
Info_ParametersPtr:=DllCall("mediainfo\MediaInfoA_Option", "UInt", 0, "str", "Info_Parameters", "str", "") ;see also Info_Parameters_CSV
VarSetCapacity(Info_Parameters, 30000) ;prepare to hold large data
Info_Parameters:=ExtractData(Info_ParametersPtr) ;dll returns a pointer, we build a string from that
;clipboard:=Info_Parameters ;easier to read
MsgBox "MediaInfo_Option - Info_Parameters"`n`n%Info_Parameters%
Info_CapacitiesPtr:=DllCall("mediainfo\MediaInfoA_Option", "UInt", 0, "str", "Info_Capacities", "str", "")
VarSetCapacity(Info_Capacities, 30000)
Info_Capacities:=ExtractData(Info_CapacitiesPtr)
MsgBox "MediaInfo_Option - Info_Capacities"`n`n%Info_Capacities%
Info_CodecsPtr:=DllCall("mediainfo\MediaInfoA_Option", "UInt", 0, "str", "Info_Codecs", "str", "")
VarSetCapacity(Info_Codecs, 30000)
Info_Codecs:=ExtractData(Info_CodecsPtr)
MsgBox "MediaInfo_Option - Info_Codecs"`n`n%Info_Codecs%
handle := dllcall("mediainfo\MediaInfo_New") ;initialize mediainfo
GetUnicodeString(PathToAVIFileUni,PathToAVIFile) ;we translate path to unicode, as we're gonna call unicode (MediaInfo_) version of the function
resultopenfile := dllcall("mediainfo\MediaInfo_Open", "UInt", handle, "str", PathToAVIFileUni) ;open the file
msgbox errorlevel %errorlevel%, resultopenfile %resultopenfile% ;if resultopenfile=1 -> success
;some examples
;Inform with Complete=false
DllCall("mediainfo\MediaInfoA_Option", "UInt", 0, "str", "Complete", "str", "") ;set the last "" to "1" for complete=true
capac:=VarSetCapacity(inform, 30000)
inform := dllcall("mediainfo\MediaInfo_Inform", "UInt", handle, "int", 0) ;we use unicode version of the function
informANSI := GetAnsiStringFromUnicodePointer(inform) ;translate unicode to ansi
msgbox errorlevel %errorlevel%, inform:`n`n%informANSI%
;Get with Stream=General and Parameter=AudioCount
Info_GetPtr:=DllCall("mediainfo\MediaInfoA_Get", "UInt", handle, "int", 0, "int", 0, "str", "AudioCount", "int", 1, "int", 0)
Info_Get := ExtractData(Info_GetPtr)
msgbox Get with Stream=General and Parameter=AudioCount`n%Info_Get%
;Get with Stream=video and Parameter=FrameRate
FrameRatePtr:=DllCall("mediainfo\MediaInfoA_Get", "UInt", handle, "int", 1, "int", 0, "str", "FrameRate", "int", 1, "int", 0)
FrameRate := extractdata(FrameRatePtr)
msgbox get with stream=general and parameter=FrameRate`n%FrameRate%
handle := DllCall("mediainfo\MediaInfo_Delete", "UInt", handle) ;Delete MediaInfo handle
DllCall("FreeLibrary", "UInt", hModule) ; To conserve memory, the DLL may be unloaded after using it.
;credits for this function go to PhiLho (http://www.autohotkey.com/forum/topic12460.html)
; Some API functions require a WCHAR string.
GetUnicodeString(ByRef @unicodeString, _ansiString)
{
local len
len := StrLen(_ansiString)
VarSetCapacity(@unicodeString, len * 2 + 1, 0)
; http://msdn.microsoft.com/library/default.asp?url=/library/en-us/intl/unicode_17si.asp
DllCall("MultiByteToWideChar"
, "UInt", 0 ; CodePage: CP_ACP=0 (current Ansi), CP_UTF7=65000, CP_UTF8=65001
, "UInt", 0 ; dwFlags
, "Str", _ansiString ; LPSTR lpMultiByteStr
, "Int", len ; cbMultiByte: -1=null terminated
, "UInt", &@unicodeString ; LPCWSTR lpWideCharStr
, "Int", len) ; cchWideChar: 0 to get required size
}
;credits for this function go to PhiLho (http://www.autohotkey.com/forum/topic12460.html)
; Some API functions return a WCHAR string.
GetAnsiStringFromUnicodePointer(_unicodeStringPt)
{
local len, ansiString
len := DllCall("lstrlenW", "UInt", _unicodeStringPt)
VarSetCapacity(ansiString, len, 0)
DllCall("WideCharToMultiByte"
, "UInt", 0 ; CodePage: CP_ACP=0 (current Ansi), CP_UTF7=65000, CP_UTF8=65001
, "UInt", 0 ; dwFlags
, "UInt", _unicodeStringPt ; LPCWSTR lpWideCharStr
, "Int", len ; cchWideChar: size in WCHAR values, -1=null terminated
, "Str", ansiString ; LPSTR lpMultiByteStr
, "Int", len ; cbMultiByte: 0 to get required size
, "UInt", 0 ; LPCSTR lpDefaultChar
, "UInt", 0) ; LPBOOL lpUsedDefaultChar
Return ansiString
}
;credits for this function go to Goyyah (http://www.autohotkey.com/forum/viewtopic.php?p=91578#91578)
ExtractData(pointer) {
Loop {
errorLevel := ( pointer+(A_Index-1) )
Asc := *( errorLevel )
IfEqual, Asc, 0, Break ; Break if NULL Character
String := String . Chr(Asc)
}
Return String
}
It's an adaptation of an example AutoIt script which can be found here:
http://sourceforge.net/forum/forum.php?thread_id=1579921&forum_id=297610. You may want to check this one out as well, as mine is only a subset of the AutoIt one.
I'm just starting with AHK, so feel free to correct my code if you think it can be improved.
Cheers,
mprost