get video duration using MediaInfo.dll

Get help with using AutoHotkey and its commands and hotkeys
sbrady19
Posts: 145
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 )
}

gregster
Posts: 2665
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: 145
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: 145
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: 145
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: 145
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.
gregster
Posts: 2665
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 884 times
Perhaps the CLI (Command Line Interface) would be an alternative...
sbrady19
Posts: 145
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 ?????????????
gregster
Posts: 2665
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: 145
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 )
}
gregster
Posts: 2665
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
gregster
Posts: 2665
Joined: 30 Sep 2013, 06:48

Re: get video duration using MediaInfo.dll

23 Feb 2019, 20:11

gregster wrote:
14 Feb 2019, 11:03
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.

Well, you never reported back, but forum member 'just me' already translated the functions used above to 64 bit unicode, if you are still interested in this:

Code: Select all

#SingleInstance, Force
DllCall( "LoadLibrary", Str,"C:\Users\g\Desktop\MediaInfo64\MediaInfo.dll" )		; <<< full path

VidFil :=  "C:\Users\g\Desktop\freeMXF-mxf1.mxf" 
MsgBox % Media_GetVideoDuration( VidFil )

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
; 64 bit unicode versions by 'just me' , see https://www.autohotkey.com/boards/viewtopic.php?f=76&t=30668&p=143413#p143406
MediaInfo_New() {
 Return DllCall( "mediainfo\MediaInfo_New", "Ptr" )
}
MediaInfo_Open( hnd, MediaFile ) {
 Return DllCall( "mediainfo.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.dll\MediaInfo_Get", "Ptr",hnd
               , "Int",StrK, "Int",StrN, "Str",Comm, "Int",InfK, "Int",Sech, "Str" )
}
MediaInfo_Close( hnd ) {
 Return DllCall( "mediainfo\MediaInfo_Close", "Ptr",hnd )
}
Just make sure to link to the 64 bit dll version. Add it directly in the "LoadLibrary" dll-call, not via the work directory.

Also this: https://www.autohotkey.com/boards/viewtopic.php?p=16966#p16966
0x00
Posts: 79
Joined: 22 Jan 2019, 13:12

Re: get video duration using MediaInfo.dll

25 Feb 2019, 13:50

So,Why Use MediaInfo AT ALL. When there's an AMAZING function by SKAN. Filexpro() : File Extended Properties Object

Example To Get Some Basic Video Info Including of course Length:

Code: Select all

Props := ["Path","Length","Bit rate","Dimension","System.Video.FrameHeight"
,"System.Video.FrameRate"
,"System.Video.FrameWidth"
,"System.Video.HorizontalAspectRatio"
,"System.Video.StreamNumber"
,"System.Video.TotalBitrate"
,"System.Video.VerticalAspectRatio"]

Obj := Filexpro( "D:\@Music\@MEG MYERS\Meg Myers - Jealous Sea _Official Music Video.mp4", "video", Props* )
L := ""
For Key, Val in Obj
	L .= Key A_Tab Val "`n"
MsgBox % L
gregster
Posts: 2665
Joined: 30 Sep 2013, 06:48

Re: get video duration using MediaInfo.dll

25 Feb 2019, 16:04

So,Why Use MediaInfo AT ALL. When there's an AMAZING function by SKAN. Filexpro() : File Extended Properties Object
Close, but no cigar :) . Good question, though... :ugeek: I have used the GetDetailsOf() method before in other functions, even recently.

The point here is the container format mfx - with mfx, I get nothing when I use SKAN's or other functions.

When I use mp4s, it's ok. I get the System.Video properties - but for 'length', I need to replace the word with the corresponding word of my Windows system language (probably not necessary for sbrady19).

These mp4-properties are also/can be displayed in the file explorer (that's where SKAN's function comes in), but for mfx I get there nothing, again. So, the function can't help me, I would assume. Perhaps that would be different if I would install more codecs (but I wouldn't bet on it), but mediainfo.dll I can use without installing... and it's not depending on the system language.
So, I would still see use for mediainfo. But sbrady could surely try SKAN's function. Perhaps he is lucky and it works on his system - he seems to work a lot with videos.

Do you get (better) results with mfx? Perhaps I am overlooking something... but:
SKAN wrote: These properties are to meant to be shown in Windows Explorer and searched with "Advanced Query Syntax".
If Explorer could show all properties for all file formats, it would become horribly slow/unusable and may become unstable
when trying to read a badly written property.
These methods use simple lookup and shouldn't be compared with professional level software.

BUT.. I do feel these methods have been poorly implemented. When it works, it works fantastic.
0x00
Posts: 79
Joined: 22 Jan 2019, 13:12

Re: get video duration using MediaInfo.dll

25 Feb 2019, 23:00

Point taken,I too do work with videos a lot,but just with more conventional formats,so you're certainly right in your assertion that mediainfo has its merits especially with obscure formats. But SKAN's function, "When it works, it works fantastic."

And no I haven't had better luck with mfx, you didn't miss anything, it only retrieves extended file properties. I simply prefer it because I don't use obscure(video) formats and because it works with any type of file, and given my system's en-Us I have no language issues. So it seems I OVERLOOKED mediainfo because of my 'not so esoteric' requirements, touché. I'll certainly keep it around for when I encounter an obscure format though. :salute:
gregster
Posts: 2665
Joined: 30 Sep 2013, 06:48

Re: get video duration using MediaInfo.dll

25 Feb 2019, 23:16

Yeah, no worries :thumbup: , I hadn't encountered the mfx format, either, before this request. But I have used mediainfo.dll before, although not recently (I still used 32 bit Windows back then).
When I can, I prefer windows built-in methods, too. But it is good to have it in one's toolset...

Return to “Ask For Help”

Who is online

Users browsing this forum: Bing [Bot], Odlanir, Rafaews and 49 guests