Jump to content

.avi Get File Lenght


Recommended Posts

i try find a solution get an avis length...

...i found this in vb script... can i convert the "get length" part in autoit comands?..

VB Code

Private Declare Function AVIFileOpen Lib "avifil32" _
  Alias "AVIFileOpenA" ( _
  ppfile As Long, _
  ByVal szFile As String, _
  ByVal mode As Long, _
  pclsidHandler As Any) As Long

Private Declare Function AVIFileRelease Lib "avifil32" ( _
  ByVal pfile As Long) As Long

Private Declare Function AVIFileInfo Lib "avifil32" _
  Alias "AVIFileInfoA" ( _
  ByVal pfile As Long, _
  pfi As AVIFileInfo, _
  ByVal lSize As Long) As Long

Private Declare Sub AVIFileInit Lib "avifil32" ()
Private Declare Sub AVIFileExit Lib "avifil32" ()

' AVI Info-Struktur
Private Type AVIFileInfo
  dwMaxBytesPerSec As Long
  dwFlags As Long
  dwCaps As Long
  dwStreams As Long
  dwSuggestedBufferSize As Long
  dwWidth As Long
  dwHeight As Long
  dwScale As Long
  dwRate As Long
  dwLength As Long
  dwEditCount As Long
  szFileType As String * 64
End Type

' Länge (Spieldauer) ermitteln
' (Rückgabewert erfolgt in Millisekunden)
Public Function AVI_GetLength(ByVal sFile As String) As Long
  Dim hFile As Long
  Dim AviInfo As AVIFileInfo
  Dim nLength As Long
    
  ' Fehlerbehandlung aktivieren
  On Error Resume Next
  
  ' Initialisieren
  AVIFileInit
  
  ' AVI öffnen (Handle erstellen)
  If AVIFileOpen(hFile, sFile, &H20, ByVal 0&) = 0 Then
    ' Infos lesen
    If AVIFileInfo(hFile, AviInfo, Len(AviInfo)) = 0 Then           <-------I THNK ITS THIS!!!
      nLength = AviInfo.dwLength                                               
    End If
    AVIFileRelease hFile
  End If
  
  ' Beenden
  AVIFileExit
  On Error Goto 0
  
  ' Rückgabewert
  AVI_GetLength = nLength
End Function
Edited by duketrapp
Link to comment
Share on other sites

i try find a solution get an avis length...

...i found this in vb script... can i convert the "get length" part in autoit comands?..

VB Code

Private Declare Function AVIFileOpen Lib "avifil32" _
  Alias "AVIFileOpenA" ( _
  ppfile As Long, _
  ByVal szFile As String, _
  ByVal mode As Long, _
  pclsidHandler As Any) As Long

Private Declare Function AVIFileRelease Lib "avifil32" ( _
  ByVal pfile As Long) As Long

Private Declare Function AVIFileInfo Lib "avifil32" _
  Alias "AVIFileInfoA" ( _
  ByVal pfile As Long, _
  pfi As AVIFileInfo, _
  ByVal lSize As Long) As Long

Private Declare Sub AVIFileInit Lib "avifil32" ()
Private Declare Sub AVIFileExit Lib "avifil32" ()

' AVI Info-Struktur
Private Type AVIFileInfo
  dwMaxBytesPerSec As Long
  dwFlags As Long
  dwCaps As Long
  dwStreams As Long
  dwSuggestedBufferSize As Long
  dwWidth As Long
  dwHeight As Long
  dwScale As Long
  dwRate As Long
  dwLength As Long
  dwEditCount As Long
  szFileType As String * 64
End Type

' Länge (Spieldauer) ermitteln
' (Rückgabewert erfolgt in Millisekunden)
Public Function AVI_GetLength(ByVal sFile As String) As Long
  Dim hFile As Long
  Dim AviInfo As AVIFileInfo
  Dim nLength As Long
    
  ' Fehlerbehandlung aktivieren
  On Error Resume Next
  
  ' Initialisieren
  AVIFileInit
  
  ' AVI öffnen (Handle erstellen)
  If AVIFileOpen(hFile, sFile, &H20, ByVal 0&) = 0 Then
    ' Infos lesen
    If AVIFileInfo(hFile, AviInfo, Len(AviInfo)) = 0 Then           <-------I THNK ITS THIS!!!
      nLength = AviInfo.dwLength                                               
    End If
    AVIFileRelease hFile
  End If
  
  ' Beenden
  AVIFileExit
  On Error Goto 0
  
  ' Rückgabewert
  AVI_GetLength = nLength
End Function
look up dllcall() and dllstructcreate() there are examples on the forum also. you should make sure you have that dll also. (can't call a function in a file you don't have right?)
Link to comment
Share on other sites

im not firm in dll handling.. just thought it would be possible to get this .avi info with a simple autoit phrase...

'simple' is subjective. the code you posted is calling a function in a dll (or so it appears to me) you CAN call the same dll through autoit, with the same values etc, and should get the same result. beta is required, and dllcall() / dllstructcreate() in the help file will help you.
Link to comment
Share on other sites

One way to do it would be to use Windows Media Player as an object and get the attributes for length.

Those attributes for video files are outlines here:

http://msdn.microsoft.com/library/default....mattributes.asp

Duration Attribute

The Duration attribute is the playing duration of the item, in seconds.

Remarks

This attribute is stored in both Media Library and the digital media file.

If you still need help when I get off work I'll write something up for you real fast. Edited by Simucal
AutoIt Scripts:Aimbot: Proof of Concept - PixelSearching Aimbot with several search/autoshoot/lock-on techniques.Sliding Toolbar - Add a nice Sliding Toolbar to your next script. Click the link to see an animation of it in action!FontInfo UDF - Get list of system fonts, or search to see if a particular font is installed.Get Extended Property UDF - Retrieve a files extended properties (e.g., video/image dimensions, file version, bitrate of song/video, etc)
Link to comment
Share on other sites

If you still need help ...

:oops: ... i realy dont have a clue on objects... :">

..but... i looked a bit and try this:

$oMedia = ObjGet("","MediaPlayer.MediaPlayer.1")
$oMediadur = $oMedia.currentMedia.duration

..and like i expected its not workin :) ... but i m right that the comand "player.currentMedia.duration" is what i need?...

..maybe i need this "read access to Media Library" or im just to noob to get the right spelling in writing the object code.. :( ..like i say... im new to this... but i tried :( ... script give me "Variable must be of type Object" error...

..btw... the videofile i need the length from is open when i try to use this object things... so i thnk i read that u dont need "ObjCreate" when the file is opened...but.. maybe im wrong :D

Edited by duketrapp
Link to comment
Share on other sites

As it turns out, there is a better way to do it.. it took a little bit of digging on my part.

The first method I mentioned would work, but you would have to first add the video to the media player collection (and I think you must do that manually).

So, after a little searching I came across some extended attributes. I think I might make a series of UDF's out of these. In any case, here you go:

$filepath = FileOpenDialog("Duration Test",@ScriptDir,"Videos (*.avi;*.mpg;*.mpeg;*.rm)")
ConsoleWrite($filepath&@CRLF)
$vid = StringTrimLeft($filepath,StringInStr($filepath,"\",0,-1))
$dir = StringTrimRight($filepath,(StringLen($filepath)-StringInStr($filepath,"\",0,-1)))
$ShellApp = ObjCreate("shell.application")
$oDir = $ShellApp.NameSpace($dir)
$oVid = $oDir.Parsename($vid)
$duration = $oDir.GetDetailsOf($oVid, 0x15)
msgbox(0,"Duration","Duration of Video: "&$duration)

Modify to do what you want with it.

Edited by Simucal
AutoIt Scripts:Aimbot: Proof of Concept - PixelSearching Aimbot with several search/autoshoot/lock-on techniques.Sliding Toolbar - Add a nice Sliding Toolbar to your next script. Click the link to see an animation of it in action!FontInfo UDF - Get list of system fonts, or search to see if a particular font is installed.Get Extended Property UDF - Retrieve a files extended properties (e.g., video/image dimensions, file version, bitrate of song/video, etc)
Link to comment
Share on other sites

$filepath = FileOpenDialog("Duration Test",@ScriptDir,"Videos (*.avi;*.mpg;*.mpeg;*.rm)")
ConsoleWrite($filepath&@CRLF)
$vid = StringTrimLeft($filepath,StringInStr($filepath,"\",0,-1))
$dir = StringTrimRight($filepath,(StringLen($filepath)-StringInStr($filepath,"\",0,-1)))
$ShellApp = ObjCreate("shell.application")
$oDir = $ShellApp.NameSpace($dir)
$oVid = $oDir.Parsename($vid)
$duration = $oDir.GetDetailsOf($oVid, 21)
msgbox(0,"Duration","Duration of Video: "&$duration)

Try that val.

Edit: Just tried it on a mpg and it didnt work. It will only work if the value is present when you right click properties on a video file, and select Summary (in advanced mode). If you dont see a duration there for your video then it wont show up. It shows up for most of my videos fine though.

Posted Image

Posted Image

Edited by Simucal
AutoIt Scripts:Aimbot: Proof of Concept - PixelSearching Aimbot with several search/autoshoot/lock-on techniques.Sliding Toolbar - Add a nice Sliding Toolbar to your next script. Click the link to see an animation of it in action!FontInfo UDF - Get list of system fonts, or search to see if a particular font is installed.Get Extended Property UDF - Retrieve a files extended properties (e.g., video/image dimensions, file version, bitrate of song/video, etc)
Link to comment
Share on other sites

  • 1 year later...

Sorry for bringing upp an old topic but id love to have this working.

Anyone have any idea why Simucal example does not work anymore?

UDF:Crypter a file encrypt / decrypt tool with no need to remember a password again. Based on Caesar cipher using entire ASCII Table.Script's: PixelSearch Helper, quick and simple way to create a PixelSeach.Chatserver - simplified, not so complicated multi-socket server.AutoIT - Firewall, simple example on howto create a firewall with AutoIt.
Link to comment
Share on other sites

Thanks :)

My secound quest is then to find a tool where i can get attributes from mkv,mpg,divx files.

Does anyone know of any tool where i can retrive extensive attributes from mkv,avi,mpg,divx files ?

Basicly only need to know a few parameters but i need them as correct as possible, Video Codec, Audio Codec, Audio Bitrate, Video Bitrate , Width, Height, Duration.

Edited by jokke
UDF:Crypter a file encrypt / decrypt tool with no need to remember a password again. Based on Caesar cipher using entire ASCII Table.Script's: PixelSearch Helper, quick and simple way to create a PixelSeach.Chatserver - simplified, not so complicated multi-socket server.AutoIT - Firewall, simple example on howto create a firewall with AutoIt.
Link to comment
Share on other sites

You could try this ...

#include "ExtProp.au3"

$file = "c:\video.wmv";change this with the location of the file

$w = _GetExtProperty($file,27)
$h = _GetExtProperty($file,28)
$d = _GetExtProperty($file,21)

MsgBox(32,"File Info","File : " & $file & @CRLF & @CRLF & "Width : " & $w & @CRLF & "Height : " & $h & @CRLF & "Duration : " & $d)
Link to comment
Share on other sites

_GetExtProperty works great on avi,wmv,mp4 files but it wont show any usable data from mkv,mpeg,divx files though.

Trying to figure out if GSpot has commandline parameters.

SOLUTION: Dirty but it works.

Download MPlayer (not windows media player) and then use these parameters:

$foo = Run(@ComSpec & ' /c mplayer.exe -vo null -ao null -frames 0 -identify '&FileGetShortName($file), @ScriptDir, @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD)
While 1
    $line = StdoutRead($foo)
    If @error Then ExitLoop
    
    
    MsgBox(0,"",$line)
WEnd
Edited by jokke
UDF:Crypter a file encrypt / decrypt tool with no need to remember a password again. Based on Caesar cipher using entire ASCII Table.Script's: PixelSearch Helper, quick and simple way to create a PixelSeach.Chatserver - simplified, not so complicated multi-socket server.AutoIT - Firewall, simple example on howto create a firewall with AutoIt.
Link to comment
Share on other sites

This will work for some info but I don't really like it because it's looping through all the files in a folder to find the one you want.

Func _FileGetDetails($File);; $File is the Full path and file name if the file to check.
   $objShell = ObjCreate("Shell.Application")
   $Path = StringLeft($File, StringInStr($File, "\", 0, -1) -1)
   $fName = StringMid($File, StringInStr($File, "\", 0, -1) +1)
   $objFolder = $objShell.Namespace($Path)
   For $Filename In $objFolder.Items
      If $objFolder.GetDetailsOf($Filename, 0) = $fName Then MsgBox(0, "TEST", "Duration : " & $objFolder.GetDetailsOf($Filename, 21))
   Next
EndFunc  ;<==> _FileGetDetails($File)

Here are the possibilities for the value in $objFolder.GetDetailsOf($Filename, value)

0 Name

1 Size

2 Type

3 Date Modified

4 Date Created

5 Date Accessed

6 Attributes

7 Status

8 Owner

9 Author

10 Title

11 Subject

12 Category

13 Pages

14 Comments

15 Copyright

16 Artist

17 Album Title

18 Year

19 Track Number

20 Genre

21 Duration

22 Bit Rate

23 Protected

24 Camera Model

25 Date Picture Taken

26 Dimensions

27, 28, 29 Not used

30 Company

31Description

32 File Version

33 Product Name

34 Product Version

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

Here is a slightly improved version of what I posted earlier

Where

$File is the Full path and file name if the file to check.

$Prop is the File property that you want from the list I gave

Func _FileGetDetails($File, $Prop = 0) 
   Dim $arrHeaders[35]
   $objShell = ObjCreate("Shell.Application")
   $Path = StringLeft($File, StringInStr($File, "\", 0, -1) -1)
   $fName = StringMid($File, StringInStr($File, "\", 0, -1) +1)
   $objFolder = $objShell.Namespace($Path)
   For $i = 0 to 34
    $arrHeaders[$i] = $objFolder.GetDetailsOf($objFolder.Items, $i)
   Next
   For $Filename In $objFolder.Items
      If $objFolder.GetDetailsOf($Filename, 0) = $fName Then
         MsgBox(0, $objFolder.GetDetailsOf($Filename, 0), $arrHeaders[$Prop] & " : " & $objFolder.GetDetailsOf($Filename, $Prop))
         ExitLoop
      EndIf
   Next
EndFunc;<==> _FileGetDetails($File)
Edited by GEOSoft

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

Hi GEOSoft and tnx,

I don't see how your code let me change the file attributes

Am I missing something

Eyal

It wasn't written to change anything only to get the information. Changing is a different story. And this is for file properties not attributes. For attributes all you need is FileSetAttrib() in the help file.

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...