|
-
Apr 4th, 2011, 10:57 AM
#1
Thread Starter
Addicted Member
[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
-
Apr 4th, 2011, 04:27 PM
#2
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.
-
Apr 4th, 2011, 06:34 PM
#3
Thread Starter
Addicted Member
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?
-
Apr 4th, 2011, 10:52 PM
#4
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:
Public Class Form1 Private Sub Button1_Click(ByVal sender As System.Object, _ ByVal e As System.EventArgs) _ Handles Button1.Click MessageBox.Show(Me.GetDimensions("C:\test\video.wmv")) End Sub Public Function GetDimensions(ByVal path As String) As String Dim shell = New Shell32.Shell() Dim directory = IO.Path.GetDirectoryName(path) If Not directory.Equals(String.Empty) Then Dim fileName = IO.Path.GetFileName(path) Dim folder = shell.NameSpace(directory) For Each file As Shell32.FolderItem2 In folder.Items() If file.Name.Equals(fileName) Then Return TryCast(file.ExtendedProperty("Dimensions"), _ String) End If Next End If Return Nothing End Function 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.
-
Apr 4th, 2011, 11:56 PM
#5
Thread Starter
Addicted Member
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.
-
Apr 5th, 2011, 10:49 AM
#6
Re: Video Resolution with FileInfo
 Originally Posted by Spiffyguy
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.
-
Apr 5th, 2011, 01:53 PM
#7
Thread Starter
Addicted Member
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.
-
Apr 5th, 2011, 03:49 PM
#8
Re: Video Resolution with FileInfo
Did you add the class that I wrote to the project? It is attached to the code bank submission.
-
Apr 5th, 2011, 10:04 PM
#9
Thread Starter
Addicted Member
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.
-
Apr 6th, 2011, 09:02 AM
#10
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.
-
Apr 6th, 2011, 08:52 PM
#11
Thread Starter
Addicted Member
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
-
Jun 27th, 2016, 04:41 AM
#12
New Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|