Jump to content

Getting an extended file property


Recommended Posts

Hi there - I've been working on an application and am just completely stumped.

I am working with a very large amount of GIF files and I need to determine which of them are animated.

What I have been doing until now is using imagemagick to analyze each GIF and returns an output file with the number of frames which I then parse to see # of frames. However, this whole process of dropping to DOS, running a program and then parsing the output file - and running this process 3-4 times a second, has my PC at 90-100% and just isn't working out so well.

I then realized that when I right-click on a GIF file and check the properties (in XP), Windows itself knows what the Frame Count is. Since windows knows that it's a multiple frame GIF file, I should be able to extract that information somehow, correct?

I am aware of the _GetExtProperty function, and unfortunately that function (or more accurately the API calls that it makes) do not carry the "Frame Count" variable (for XP, at any rate).

I did some more searching and I did find a VB forum where someone used the "ExtendedProperty" method which does contain "Frame Count" (based on their example anyways). I have been completely unsuccessful in getting this to work in AutoIt, though.

I was able to get it to run, but the values it returns for all properties is "0", which clearly is not correct.

Can anyone with a bit more experience point me in the right direction? Or is there a different (but efficent) way to get the frame count of an animated GIF file?

Here is the VB example using "ExtendedProperty" method:

Include the Reference for "Microsoft Shell Controls And Automation" (C:\WINDOWS\System32\Shell32.dll")

Then try this code.. It's not perfect as it doesn't seem to pick up everything in the summary window, just the occassional thing, but have a play with it..


Sub FileInformaiton()
Dim wsh As Shell
Dim fld As Shell32.Folder
Dim fle As Shell32.ShellFolderItem
Dim i As Long
Set wsh = New Shell
Set fld = wsh.BrowseForFolder(0, "Find Media", 0)
For i = 0 To fld.Items.Count - 1
Set fle = fld.Items.Item(i)
'verb 0 is always the default action on the file, so run it if you want by uncommenting the next line
'fle.Verbs.Item(0).DoIt
'at this point you will need to specify the extendedpropery you want, this will differ from file type to file type
'Bitmap files
Select Case fle.Type
Case "Bitmap Image"
Debug.Print "Name:" & fle.Name & " Path:" & fle.Path & " Size:" & fle.Size & " Modified:" & fle.ModifyDate
Debug.Print "Width:" & fle.ExtendedProperty("Width")
Debug.Print "Height:" & fle.ExtendedProperty("Height")
Debug.Print "Horizontal Resolution:" & fle.ExtendedProperty("Horizontal Resolution")
Debug.Print "Vertical Resolution:" & fle.ExtendedProperty("Vertical Resolution")
Debug.Print "Bit Depth:" & fle.ExtendedProperty("Bit Depth")
Debug.Print "Frame Count:" & fle.ExtendedProperty("Frame Count")
Case "Video Clip"
Debug.Print "Name:" & fle.Name & " Path:" & fle.Path & " Size:" & fle.Size & " Modified:" & fle.ModifyDate
Debug.Print "Width:" & fle.ExtendedProperty("Width")
Debug.Print "Height:" & fle.ExtendedProperty("Height")
Debug.Print "Duration:" & fle.ExtendedProperty("Duration")
Debug.Print "Bit Rate:" & fle.ExtendedProperty("BitRate")
Debug.Print "Audio Sample Size:" & fle.ExtendedProperty("AudioSampleSize")
Debug.Print "Audio Format:" & fle.ExtendedProperty("AudioFormat")
Debug.Print "Frame Rate:" & fle.ExtendedProperty("FrameRate")
Debug.Print "Data Rate:" & fle.ExtendedProperty("DataRate")
Debug.Print "Video Sample Size:" & fle.ExtendedProperty("VideoSampleSize")
Debug.Print "Video Compression:" & fle.ExtendedProperty("VideoCompression")
Case Else
Debug.Print "Name:" & fle.Name & " Path:" & fle.Path & " Size:" & fle.Size & " Modified:" & fle.ModifyDate
Debug.Print "File Type is currently unsupported by this code:" & fle.Type
End Select
Next i
Set fle = Nothing
Set fld = Nothing
Set wsh = Nothing
End Sub

And here is what I tried to write, but the results returned are all '0'.

$oShellApp = ObjCreate ("Shell.Application")
        
        $folder = $oShellApp.namespace("C:\temp")
        
        $file = $folder.ParseName("anim.gif")
        
        $name = $file.Name

        $width = $file.ExtendedProperty("Width")
        MsgBox(),"",$name)
        MsgBox(0,"",$width)

And finally, if you want to try this with an animated GIF, here's the GIF I was using (and I had it in c:\temp.)

Also - MSDN info about "ExtendedProperty"

Thanks for any help you may be able to provide. I'm at wit's end!

Link to comment
Share on other sites

So, I've been searching for a solution for you for a little while and this is what I came up with for right now:

First off you, will need the WIA Image Acquisition DLL. I have attached it to this post, but you can also get it here: http://www.microsoft.com/downloads/details...&DisplayLang=en

Once you have downloaded the attached DLL, open up a command prompt and navigate to the folder that the DLL is in. Once there, run this command:

regsvr32 wiaaut.dll

After that, you can use the WIA as an object in your scripts. It has a TON of image properties you can get from images. If you go to that link I gave you, you can see some of the available properties.

Here is an example script you would run to see if your Gif was animated:

$oImage = ObjCreate("WIA.ImageFile")
$s_Path = FileOpenDialog("Select Gif Image", @ScriptDir, "Gif Images (*.gif)")
$oImage.LoadFile($s_Path)

If $oImage.IsAnimated Then
    MsgBox(0, "Image Info", "This is an animated image.")
Else
    MsgBox(0, "Image Info", "This is not an animated image.")
Endif

In the mean time, I'll work on making a revised version of _GetExtendedProperty and see if I cant get some things like Frame Count, etc without the use of a DLL. There are still alot of properties I would like to be able to retrieve from files that I presently can not.

Enjoy,

Simucal

wiaaut.dll

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

According to that VBScript website, this should work (but it does not):

$sPath = FileOpenDialog("Select Gif Image", @DesktopDir, "Gif Images (*.gif)")
$sFile = StringTrimLeft($sPath, StringInStr($sPath, "\", 0, -1))
$sDir = StringTrimRight($sPath, (StringLen($sPath) - StringInStr($sPath, "\", 0, -1)))
$oShell = ObjCreate ("Shell.Application")
$oFolder = $oShell.Namespace($sDir)
$oFile = $oFolder.ParseName($sFile)
$sFrameCount = $oFile.ExtendedProperty('Frame Count')
ConsoleWrite("Frame Count: "&$sFrameCount)

So, I'm going to have to dig a little deeper.

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

Oh! Thank you SO much.. I haven't tried it out yet, I will give it a shot later this evening or tomorrow. I knew there had to be a way seeing as how Windows can, by default, display this information about the file.

BTW, your Extended Properties function has been extremely useful in some other items I've worked on - thanks for all your work on that! I've been slowly dabbling in the world of DLLs and Objects/Methods and it's a bit overwhelming at times. The most I've been able to do so far is pull an XML file and extract information from it - and even then I don't feel I'm doing it as efficiently as it probably could be. Definitely a learning experience.

Thanks again.

Link to comment
Share on other sites

Sounds good, let me know if you get everything to work.

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

Works beautifully! Thanks so much!

However - for future reference, where did you find the extended documentation? The link itself didn't really have any instructions that I could find - and while there was a .chm file included with the download, I couldn't find any reference to the "IsAnimated" property. Where did you find this info?

Thanks again!

Link to comment
Share on other sites

Works beautifully! Thanks so much!

However - for future reference, where did you find the extended documentation? The link itself didn't really have any instructions that I could find - and while there was a .chm file included with the download, I couldn't find any reference to the "IsAnimated" property. Where did you find this info?

Thanks again!

In the helpfile, if you switch to index.. and type in "IsAnimated" it should come up. I found the reference to it on some vbs website but I cant seem to find it at the moment.

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

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...