 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
mprost
Joined: 15 Dec 2006 Posts: 4
|
Posted: Fri Dec 15, 2006 8:17 pm Post subject: mediainfo.dll calling example |
|
|
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 |
|
| Back to top |
|
 |
Dippy46
Joined: 06 Jul 2004 Posts: 171 Location: Manchester, England.
|
Posted: Sun Dec 17, 2006 10:49 am Post subject: |
|
|
@mprost
Questions are always being asked about how to work with DLL's . Learning by example has in my opinion to be the best method.
This is an EXCELLENT example that you have produced and should be a guide to other people who want to learn about DLL's
I haven't the time to test the code but I think this DLL will provide me with some of the fuctionality I've been looking for. Nice find
Regards
Dave. _________________ Simple ideas lie within reach, only of complex minds |
|
| Back to top |
|
 |
dreadycarpenter
Joined: 05 Jan 2007 Posts: 8 Location: Mt.
|
Posted: Mon Jan 08, 2007 4:22 am Post subject: |
|
|
hello, I'm fairly new to AHK , so I am having a hard time understanding how to use DllCall to retrieve mediainfo.
Could someone give me a simple example how to get these as a var:
Video Format
Video Bitrate
Audio Format
Audio Bitrate
Resolution
Framerate
Filesize
here is the script I would like to add dllcall to retrieve info for each avi
| Code: | movdir=v:\newmovies
Loop, %movdir%\*.avi, 0, 0
{
;DllCall?? to get VidFormat, VidBitRate, AudFormat, AudBitRate, Res, FrameRate, FileSize
FileAppend, `r`n%VidFormat%`;%VidBitRate%`;%AudFormat%`;%AudBitRate%`;%Res%`;%FrameRate%`;%FileSize%,AmcImport.csv
}
|
I have posted a deeper explanation here, but no replies yet.
thanks to anyone that can help...
Cheers, |
|
| Back to top |
|
 |
littlebut0
Joined: 22 Dec 2005 Posts: 49 Location: Belgium
|
|
| Back to top |
|
 |
BoBoĻ Guest
|
Posted: Mon Sep 10, 2007 11:57 am Post subject: |
|
|
Would that allow to extract generic info (like artist/titel/track/duration) from an online stream like Last.FM or Shoutcast ??
Had a try already but not shure if it's not working because of it's not possible or I'm to stupid (TBH, I tend to that reason).  |
|
| Back to top |
|
 |
mprost
Joined: 15 Dec 2006 Posts: 4
|
Posted: Fri Sep 28, 2007 5:23 pm Post subject: |
|
|
Sorry for answering so late.
I don't think that is possible (http://mediainfo.sourceforge.net/en/Support/Formats), but I don't know a lot about this DLL. Maybe you can find more guidance at the mediainfo forums.
mprost |
|
| Back to top |
|
 |
hermes as guest Guest
|
Posted: Sun Oct 21, 2007 3:44 pm Post subject: |
|
|
I would love it if you could just script a simple load of inputs to get the following music tags out of mp3 files:
artist
album
track
tracknumber |
|
| Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|