get video duration using MediaInfo.dll

Get help with using AutoHotkey and its commands and hotkeys
sbrady19
Posts: 128
Joined: 12 Apr 2018, 05:22
Location: Virginia Beach

get video duration using MediaInfo.dll

14 Feb 2019, 09:20

here is some code but it does NOT give me the duration of a video file. I feel like I'm close but feel like the syntax is off. any help would be appreciated.

Code: Select all

#SingleInstance, Force
DllCall( "LoadLibrary", Str,"MediaInfo_InfoTip.dll" )


Loop, C:\Users\Audio1\Desktop\QCLoudness\*.mxf
{
video := A_LoopFilename
stringtrimright, filename, video, 4
fileext := A_LoopFileext


hnd := MediaInfo_New()
MediaInfo_Open( hnd, video )
resolution=% MediaInfo_Get( hnd, 1,0, "Width", 1  ) "x" MediaInfo_Get( hnd, 1,0, "Height", 1 )
duration=% MediaInfo_Get( hnd, 1,0, "Duration/String3", 1 )
stringtrimright, durationshort1, duration, 4
stringtrimleft, durationshort2, durationshort1, 1
StringReplace, durationshort3, durationshort2, :,·,all

MsgBox %durationshort3%    111
}
return





MediaInfo_New() {
 Return DllCall( "mediainfo_InfoTip.dll\MediaInfo_New", "Ptr" )
}
MediaInfo_Open( hnd, MediaFile ) {
 Return DllCall( "mediainfo_InfoTip.dll\MediaInfo_Open", "Ptr",hnd
               , "Str",MediaFile, "UInt") ; not sure about the return type, but it isn't used
}
MediaInfo_Get( hnd, StrK=0, StrN=0, Comm="", InfK=0, Srch=0 ) {
 Return DllCall( "mediainfo_InfoTip.dll\MediaInfo_Get", "Ptr",hnd
               , "Int",StrK, "Int",StrN, "Str",Comm, "Int",InfK, "Int",Sech, "Str" )
}
MediaInfo_Close( hnd ) {
 Return DllCall( "mediainfo_InfoTip.dll\MediaInfo_Close", "Ptr",hnd )
}

User avatar
gregster
Posts: 1858
Joined: 30 Sep 2013, 06:48

Re: get video duration using MediaInfo.dll

14 Feb 2019, 09:48

What about this: https://www.autohotkey.com/boards/viewtopic.php?f=76&t=62012&p=263455#p263472 ?
This works for me on 32 bit... dll version and AHK version.
(I downloaded an mxf-testfile, because I had none.)
sbrady19
Posts: 128
Joined: 12 Apr 2018, 05:22
Location: Virginia Beach

Re: get video duration using MediaInfo.dll

14 Feb 2019, 09:51

the msgbox gave me a 0..........so it didnt work for me, man this is frustrating
sbrady19
Posts: 128
Joined: 12 Apr 2018, 05:22
Location: Virginia Beach

Re: get video duration using MediaInfo.dll

14 Feb 2019, 09:54

I must not be using the right dll file.
sbrady19
Posts: 128
Joined: 12 Apr 2018, 05:22
Location: Virginia Beach

Re: get video duration using MediaInfo.dll

14 Feb 2019, 10:08

here is the path to the dll file

C:\Program Files (x86)\MediaInfo.Dll\MediaInfo_InfoTip.dll
sbrady19
Posts: 128
Joined: 12 Apr 2018, 05:22
Location: Virginia Beach

Re: get video duration using MediaInfo.dll

14 Feb 2019, 10:09

I either have the wrong dll file downloaded and installed or the syntax is wrong in the code.
User avatar
gregster
Posts: 1858
Joined: 30 Sep 2013, 06:48

Re: get video duration using MediaInfo.dll

14 Feb 2019, 10:15

I think, Infotip is not the right one, it is much smaller: I use the larger "MediaInfo.Dll" from here: https://mediaarea.net/en/MediaInfo/Download/Windows, like in the original code.
I downloaded the zip-version /without installer:
Screenshot_2019-02-14 MediaInfo - Download MediaInfo for Microsoft Windows.png
Screenshot_2019-02-14 MediaInfo - Download MediaInfo for Microsoft Windows.png (5.21 KiB) Viewed 131 times
Perhaps the CLI (Command Line Interface) would be an alternative...
sbrady19
Posts: 128
Joined: 12 Apr 2018, 05:22
Location: Virginia Beach

Re: get video duration using MediaInfo.dll

14 Feb 2019, 10:23

ok thanks, where do I put the MediaInfo.dll file since there is no installer ?????????????
User avatar
gregster
Posts: 1858
Joined: 30 Sep 2013, 06:48

Re: get video duration using MediaInfo.dll

14 Feb 2019, 10:26

Whereever you like, just make sure to add the complete path to the dll in the script... you can do it via SetWorkingDir in the snippet that worked for me.
sbrady19
Posts: 128
Joined: 12 Apr 2018, 05:22
Location: Virginia Beach

Re: get video duration using MediaInfo.dll

14 Feb 2019, 10:44

dll is on the desktop, so is the .ahk file.........still not working.

Code: Select all

#SingleInstance, Force
SetWorkingDir "C:\Users\Audio1\Desktop\"  
DllCall( "LoadLibrary", Str,"MediaInfo.dll" )


VidFil :=  "C:\Users\Audio1\Desktop\QCLoudness\SUV52 Michele Rigby Assad AM v1.mxf" 
MsgBox % Media_GetVideoDuration( VidFil )  123123


Media_GetVideoDuration( VidFil ) {
 hnd := MediaInfo_New()
 MediaInfo_Open( hnd, VidFil )
 If ( MediaInfo_Get( hnd, 1,0, "StreamKind", 1 ) <> "Video" )
  Return 0, MediaInfo_Close( hnd )
Return MediaInfo_Get( hnd, 1,0, "Duration/String3", 1 ), MediaInfo_Close( hnd )
}

;  Video Properties - MediaInfo.Dll  www.autohotkey.com/forum/topic66500.html

MediaInfo_New() {
 Return DllCall( "mediainfo\MediaInfo" ( A_IsUnicode ? "" : "A" ) "_New" )
}

MediaInfo_Open( hnd, MediaFile ) {
 Return DllCall( "mediainfo.dll\MediaInfo" ( A_IsUnicode ? "" : "A" ) "_Open", UInt,hnd
               , Str,MediaFile, UInt )
}

MediaInfo_Get( hnd, StrK=0, StrN=0, Comm="", InfK=0, Srch=0 ) {
 Return DllCall( "mediainfo.dll\MediaInfo" ( A_IsUnicode ? "" : "A" ) "_Get", UInt,hnd
               , Int,StrK, Int,StrN, Str,Comm, Int,InfK, Int,Sech, Str )
}

MediaInfo_Close( hnd ) {
 Return DllCall( "mediainfo\MediaInfo" ( A_IsUnicode ? "" : "A" ) "_Close", UInt,hnd )
}
User avatar
gregster
Posts: 1858
Joined: 30 Sep 2013, 06:48

Re: get video duration using MediaInfo.dll

14 Feb 2019, 11:03

Same here - Desktop, but I get 00:00:10.640 which is the duration of my test file: 10 secs and 460 ms.

Just to make sure
Let's copy AutoHotkeyU32.exe from your main AHK folder to the desktop and remame it to the name of your script - but keep the exe extension:

mfxscript.ahk << your script
AutoHotkeyU32.exe -> rename to mfxscript.exe

Now run mfxscript.exe and see if it works.


Btw, you have some lost code here at the end:

Code: Select all

MsgBox % Media_GetVideoDuration( VidFil )  123123

Return to “Ask For Help”

Who is online

Users browsing this forum: Bing [Bot], Flipeador, Rohwedder, scriptors and 67 guests