Results 1 to 12 of 12

Thread: [RESOLVED] Video Resolution with FileInfo

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Sep 2007
    Location
    St Charles, Mo
    Posts
    171

    Resolved [RESOLVED] Video Resolution with FileInfo

    I am using FileInfo to create a list of files in a directory. Is is possible to get video or image resolution as well using FileInfo. If not, what is the best way to pull that info down so I can include it in my csv file.

    Thanks

  2. #2
    Master Of Orion ForumAccount's Avatar
    Join Date
    Jan 2009
    Location
    Canada
    Posts
    2,802

    Re: Video Resolution with FileInfo

    You likely won't be able to do it with any managed code. What you'll have to do is find code/examples on extracting EXIF data from files.

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Sep 2007
    Location
    St Charles, Mo
    Posts
    171

    Re: Video Resolution with FileInfo

    I was not aware that video files such as mkv or mp4 had exif data. i thought that was reserved for jpgs while video data fell under extended properties. Would a regular exif reader be able to parse the vid files?

  4. #4
    Master Of Orion ForumAccount's Avatar
    Join Date
    Jan 2009
    Location
    Canada
    Posts
    2,802

    Re: Video Resolution with FileInfo

    Yeah I misread that for images. You are correct however, it would just be extended properties. Here is how you can do it:

    vb.net Code:
    1. Public Class Form1
    2.  
    3.     Private Sub Button1_Click(ByVal sender As System.Object, _
    4.                               ByVal e As System.EventArgs) _
    5.                               Handles Button1.Click
    6.         MessageBox.Show(Me.GetDimensions("C:\test\video.wmv"))
    7.     End Sub
    8.  
    9.     Public Function GetDimensions(ByVal path As String) As String
    10.         Dim shell = New Shell32.Shell()
    11.         Dim directory = IO.Path.GetDirectoryName(path)
    12.         If Not directory.Equals(String.Empty) Then
    13.             Dim fileName = IO.Path.GetFileName(path)
    14.             Dim folder = shell.NameSpace(directory)
    15.             For Each file As Shell32.FolderItem2 In folder.Items()
    16.                 If file.Name.Equals(fileName) Then
    17.                     Return TryCast(file.ExtendedProperty("Dimensions"), _
    18.                                    String)
    19.                 End If
    20.             Next
    21.         End If
    22.         Return Nothing
    23.     End Function
    24.  
    25. End Class

    For this code to run, you will need to add a reference to "Microsoft Shell Controls And Automation" which is under the COM tab. This code was derived from here. This was tested on XP SP3, so the property was "Dimensions", it might be something different for Windows 7. Could be FrameHeight and FrameWidth.

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Sep 2007
    Location
    St Charles, Mo
    Posts
    171

    Re: Video Resolution with FileInfo

    ForumAccount thanks for you input on this. I am running the code on a Vista box and it is rolling through but no results are being returned. I debug and everything seems to be fine up until this line.

    Code:
    Dim folder = shell.NameSpace(directory)
    The directory is good, D:/test, and the file name is solid. I hover over folder after it hits that line and it just shows {System.__ComObject} under parent and then message is shows "The method or operation is not implemented." The parent is interop.shell32 and stack trace shows " at Shell32.Folder.get_Parent()" There is something going on with opening the folder I am guess. The result of the function is nothing of course. I have added the COM reference as well. I clicked on the data entry under the parent in debug and under Item I see "Argument not specified for parameter 'key' of 'Public Default Property Item(key As Object) As Object'." Perhaps I am missing a parameter. Any thoughts.

    Thanks again.

  6. #6
    Master Of Orion ForumAccount's Avatar
    Join Date
    Jan 2009
    Location
    Canada
    Posts
    2,802

    Re: Video Resolution with FileInfo

    Quote Originally Posted by Spiffyguy View Post
    The directory is good, D:/test, and the file name is solid. I hover over folder after it hits that line and it just shows {System.__ComObject} under parent and then message is shows "The method or operation is not implemented." The parent is interop.shell32 and stack trace shows " at Shell32.Folder.get_Parent()" There is something going on with opening the folder I am guess. The result of the function is nothing of course. I have added the COM reference as well. I clicked on the data entry under the parent in debug and under Item I see "Argument not specified for parameter 'key' of 'Public Default Property Item(key As Object) As Object'." Perhaps I am missing a parameter. Any thoughts.

    Thanks again.
    Yes, I am seeing the same thing, however I don't think it is any cause for concern.

    See this code bank submission I just made.

  7. #7

    Thread Starter
    Addicted Member
    Join Date
    Sep 2007
    Location
    St Charles, Mo
    Posts
    171

    Re: Video Resolution with FileInfo

    That code bank submission looks a bit more contained than the function. However when I try to replicate it I have issues with this line.
    Code:
     Using file = New ShellFile("C:\Users\Public\Videos\Sample Videos\Wildlife.wmv")
    ShellFile is not listed in the intellisense so it says not declared. I have the COM reference for Microsoft Shell Controls and Automation and for giggles I imported Shell32 as well. One thing I noticed in my COM settings is when I make the reference to the Shell Controls and automation it gives me a DLL in my obj\release directory of Interop.Shell32.dll while in the list where you choose the COM to add it points to a dll that is straight Shell32.dll. Could that be an issue? I tried removing and readding but no change on the dll name. Sorry for the questions but I have not dealt with COM dlls before.

  8. #8
    Master Of Orion ForumAccount's Avatar
    Join Date
    Jan 2009
    Location
    Canada
    Posts
    2,802

    Re: Video Resolution with FileInfo

    Did you add the class that I wrote to the project? It is attached to the code bank submission.

  9. #9

    Thread Starter
    Addicted Member
    Join Date
    Sep 2007
    Location
    St Charles, Mo
    Posts
    171

    Re: Video Resolution with FileInfo

    I did not even see the attachment. It does work now. For some reason on Vista I get no data for the frame width and height but on a Win 7 box it shows up. I can't debug to see if I am getting same "error" info as I showed above, which is still there. Something I will have to keep working on. One last question I have is if there is a way to limit what properties it looks for instead of all of them? With the sheer number of properties Microsoft uses it slows down the data gather quite a bit. For some reason AVI files take extra long. If I am only have a few of the properties, it may cut down on the processing time.

    Thanks again.

  10. #10
    Master Of Orion ForumAccount's Avatar
    Join Date
    Jan 2009
    Location
    Canada
    Posts
    2,802

    Re: Video Resolution with FileInfo

    The FolderItem2 Interface has a ExtendedProperty function that you could use to search for only 1 or 2 properties. Another option is to only populate the name's of the values, and then when you want to get the value perform the code to get it. It would all be simple changes to the code that was written.

  11. #11

    Thread Starter
    Addicted Member
    Join Date
    Sep 2007
    Location
    St Charles, Mo
    Posts
    171

    Re: Video Resolution with FileInfo

    Thanks for the info. I played a little with the code and created a variable to pass to the collection portion. Looks like this.

    Code:
     Private Function GetCollection(ByVal ExtPropName As String) As ICollection
            Dim properties = New List(Of ExtendedProperty)()
            Dim shell = Me.Shell
            Dim directory = Me.Directory
            If Not String.IsNullOrEmpty(directory) Then
                Dim fileName = Me.FileName
                Dim folder = shell.NameSpace(directory)
                For Each item As Shell32.FolderItem2 In folder.Items()
                    If item.Name.Equals(fileName) Then
                        Dim index = 0
                        Dim name = String.Empty
                        Do
                            name = folder.GetDetailsOf(folder, index)
                            If name = ExtPropName Then
                                properties.Add(New ExtendedProperty(name, folder.GetDetailsOf(item, index)))
                            End If
                            If String.IsNullOrEmpty(name) Then
                                Return properties
                            End If
                            index += 1
                        Loop
                    End If
                Next
            End If
            Return Nothing
        End Function
    I just pass that value through and it works great, and faster than before, but ONLY on my win7 box. On the box I do development on, Vista 32bit, I get no results. Interestingly if I set the value to size or name it will return a value, just nothing further up the table of properties. Also when I view the properties of a file in Win Explorer I don't get the extended properties that I do on the Win 7 box. So I am thinking it is a Vista "Feature" that an issue with the code. Even adding those properties as a column in Win Explorer shows nothing. Not sure why. This is how I am making the call just in case someone else is wondering.

    Code:
    Dim FrameWidth As String = New ShellFile(filePath, "Frame width").ExtendedProperties("Frame width").Value
    Dim FrameHeight As String = New ShellFile(filePath, "Frame height").ExtendedProperties("Frame height").Value
    Thanks again

  12. #12
    New Member
    Join Date
    Jun 2016
    Posts
    4

    Re: [RESOLVED] Video Resolution with FileInfo

    Thanks for the blog it was very helpful

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width