AutoHotkey Community

It is currently May 25th, 2012, 7:24 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 7 posts ] 
Author Message
PostPosted: December 15th, 2006, 9:17 pm 
Offline

Joined: December 15th, 2006, 8:43 pm
Posts: 4
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


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 17th, 2006, 11:49 am 
Offline

Joined: July 6th, 2004, 10:07 am
Posts: 171
Location: Manchester, England.
@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


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 8th, 2007, 5:22 am 
Offline

Joined: January 5th, 2007, 4:26 am
Posts: 8
Location: Mt.
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,


Report this post
Top
 Profile  
Reply with quote  
 Post subject: reply
PostPosted: January 10th, 2007, 10:07 pm 
Offline

Joined: December 22nd, 2005, 4:30 pm
Posts: 49
Location: Belgium
Hi,

I've posted a reply to your question yesterday (see your other topic http://www.autohotkey.com/forum/viewtopic.php?t=15462&highlight=
Hope this can help solve your problem

Littlebut0


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 10th, 2007, 12:57 pm 
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). :(


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: September 28th, 2007, 6:23 pm 
Offline

Joined: December 15th, 2006, 8:43 pm
Posts: 4
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


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 21st, 2007, 4:44 pm 
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


Report this post
Top
  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 7 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: spg SCOTT and 5 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group