שתף באמצעות


Read Video File Properties

Question

Tuesday, November 5, 2013 3:02 AM

Is there any way I can read the properties of a video file (of any format),

such as title, length, year, genre, comments, etc., and write them to a

textbox within a userform?

Thanks in advance!

All replies (15)

Tuesday, November 5, 2013 3:51 AM ✅Answered | 1 vote

This should do it. If you don't know how to add this ref with visual studio then ask. Also if you note in the code the number 27 is referencing, I believe, the 27th entry in the extended attributes of the video file which happens to be video duration. I can't remember how many extended attributes there are. But there's a bunch of them and you could probably search the net for how many and what each mean on the net using google for a specific video file format or maybe any video file format uses the same attribute to list its info. But if you replace 27 with 1 or 10 or 12 you'll see different things appear if they contain info. Sometimes they don't cause that attribute was not used by that video file.

'Add reference browse C:\Windows\System32\Shell32.Dll

Public Class Form1

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        TextBox1.Text = "C:\Users\John\Desktop"
        TextBox2.Text = "Pegasus.wmv"
    End Sub

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Testsub()
    End Sub

    Private Sub Testsub()
        If TextBox1.TextLength > 0 AndAlso TextBox2.TextLength > 0 Then
            Dim objShell As Object
            Dim objFolder As Object
            Dim strDimensions As Object
            objShell = CreateObject("Shell.Application")
            objFolder = objShell.Namespace("C:\Users\John\Desktop") ' path to the foldercontaining the file
            strDimensions = objFolder.GetDetailsOf(objFolder.ParseName(TextBox2.Text), 27) ' Filename
            Label3.Text = "Video duration is " & strDimensions.ToString
        End If
    End Sub

End Class

Please BEWARE that I have NO EXPERIENCE and NO EXPERTISE and probably onset of DEMENTIA which may affect my answers! Also, I've been told by an expert, that when you post an image it clutters up the thread and mysteriously, over time, the link to the image will somehow become "unstable" or something to that effect. :) I can only surmise that is due to Global Warming of the threads.


Tuesday, November 5, 2013 3:10 AM

Please use FileInfo class and its properties (Name,Length……)

For Account Validation, please follow "Verify Account+Number" at http://social.msdn.microsoft.com/Forums/en-us/home?forum=reportabug

For ASP.NET Question, please ask at http://forums.asp.net

For other questions, you can find a specific forum and then ask at http://stackexchange.com/sites

Click and Donate at http://www.freerice.com


Tuesday, November 5, 2013 3:21 AM

I am fairly new to this, so I did not know of that class yet.

I appreciate the quick response.

Thank you sir!


Tuesday, November 5, 2013 3:29 AM

FileInfo fi = new FileInfo("Path & FileName.ExtensionName");

fi.Length/(1024*1024);  //Get the MB size

fi.CreationTime;  //Get CreationTime

……

For more properties: http://msdn.microsoft.com/en-us/library/system.io.fileinfo_properties(v=vs.80).aspx

For Account Validation, please follow "Verify Account+Number" at http://social.msdn.microsoft.com/Forums/en-us/home?forum=reportabug

For ASP.NET Question, please ask at http://forums.asp.net

For other questions, you can find a specific forum and then ask at http://stackexchange.com/sites

Click and Donate at http://www.freerice.com


Tuesday, November 5, 2013 4:01 AM

This is what appeared when I changed 27 to 1. Although the text is preceded by the words "video duration is" cause I told the Label to add that first though it is inaccurate for what is appearing. Then in the second image is what appeared when I changed 1 to 10 it displayed my P/C's name and my user name. Also perhaps this can be used with audio files too as I remember providing code for someone that did this with audio files and maybe I just changed the file to be used to a video file and it worked for that too but I don't remember cause it was a long time ago.

Please BEWARE that I have NO EXPERIENCE and NO EXPERTISE and probably onset of DEMENTIA which may affect my answers! Also, I've been told by an expert, that when you post an image it clutters up the thread and mysteriously, over time, the link to the image will somehow become "unstable" or something to that effect. :) I can only surmise that is due to Global Warming of the threads.


Tuesday, November 5, 2013 4:08 AM

This link is for Attributes for Video Files and I suppose goes from 1 to however many there are maybe. And on the left of the page is a link for attributes for audio files.

Please BEWARE that I have NO EXPERIENCE and NO EXPERTISE and probably onset of DEMENTIA which may affect my answers! Also, I've been told by an expert, that when you post an image it clutters up the thread and mysteriously, over time, the link to the image will somehow become "unstable" or something to that effect. :) I can only surmise that is due to Global Warming of the threads.


Tuesday, November 5, 2013 4:15 AM

I used this code to list 100 attributes and only about 12 or so were used by that particular video file and most came up blank. But it will let you see which attribute displays what information.

Try
    For i = 1 To 100
        RichTextBox1.AppendText(i.ToString & " .. " & objFolder.GetDetailsOf(objFolder.ParseName(TextBox2.Text), i) & vbCrLf)
    Next
Catch ex As Exception
End Try

Please BEWARE that I have NO EXPERIENCE and NO EXPERTISE and probably onset of DEMENTIA which may affect my answers! Also, I've been told by an expert, that when you post an image it clutters up the thread and mysteriously, over time, the link to the image will somehow become "unstable" or something to that effect. :) I can only surmise that is due to Global Warming of the threads.


Tuesday, November 5, 2013 4:22 AM

It works with audio files too. This is from an MP3 file which must be using the name of artist attributes too or something since it displayed Billy Idol. Also I changed the range from 1 to 400 attributes and received entries in between the 100 to 200 range too so you may want to check that. And on the video file the 280 to 286 range.

19 .. Unrated
20 .. Billy Idol
21 .. Hot In The City
195 .. Chrysalis Records

280 .. {33564D57-0000-0010-8000-00AA00389B71}
281 ..
282 .. ‎24000kbps
283 .. 1080
284 .. ‎29 frames/second
285 .. 1440
286 .. ‎24192kbps

Please BEWARE that I have NO EXPERIENCE and NO EXPERTISE and probably onset of DEMENTIA which may affect my answers! Also, I've been told by an expert, that when you post an image it clutters up the thread and mysteriously, over time, the link to the image will somehow become "unstable" or something to that effect. :) I can only surmise that is due to Global Warming of the threads.


Wednesday, November 6, 2013 1:18 AM

I followed your every step and it's all working good.

Except instead of saying "00:03:14", it says "length"

and does so for all of the attributes I've tried.


Wednesday, November 6, 2013 1:46 AM

I followed your every step and it's all working good.

Except instead of saying "00:03:14", it says "length"

and does so for all of the attributes I've tried.

Well is that only in one video file? I have different video files that say different things depending on what whoever created them or what app created them maybe decided to place as an attribute for it. Maybe you could pull the video up in Windows Live Movie Maker (after making a copy of the original) and see if that can add an attribute where you want it although I don't remember if WLMM can save a video to different formats or even open any video format. If you play the video in Windows Media Player does WMP show the length in time? I figure it gets that info from an attribute but maybe it checks the video file extension and checks the file size and figures it out from there.

Please BEWARE that I have NO EXPERIENCE and NO EXPERTISE and probably onset of DEMENTIA which may affect my answers! Also, I've been told by an expert, that when you post an image it clutters up the thread and mysteriously, over time, the link to the image will somehow become "unstable" or something to that effect. :) I can only surmise that is due to Global Warming of the threads.


Wednesday, November 6, 2013 2:45 AM

I've tried multiple .avi and .wmv files including an original sample video.  Windows Media Player recognizes the length as well as other attributes of both types of formats, although I can only edit .wmv properties and not the .avis.


Wednesday, November 6, 2013 2:54 AM

I even tried it with a few wma files with the same result


Wednesday, November 6, 2013 4:10 AM

I even tried it with a few wma files with the same result

Well go to this link and download the Drop .avi file and see what you get. I'll post the results I get here in a few minutes when I re-edit this post and add it in here.

This is all the attributes I received from that file;

1 .. 660 KB
2 .. AVI File
3 .. 1/2/2013 9:07 PM
4 .. 1/2/2013 9:07 PM
5 .. 1/2/2013 9:07 PM
6 .. A
9 .. Video
10 .. Acer\John
11 .. Video
19 .. Unrated
27 .. 00:00:06
29 .. No
53 .. ACER (this computer)
155 .. drop
173 .. No
176 .. Desktop
177 .. C:\Users\John\Desktop
178 .. Desktop (C:\Users\John)
180 .. C:\Users\John\Desktop\drop.avi
182 .. AVI File
188 .. Unresolved
268 .. Guest
269 .. Shared
280 .. {31345649-0000-0010-8000-00AA00389B71}
282 .. ‎1030kbps
283 .. 240
284 .. ‎30 frames/second
285 .. 256
286 .. ‎1030kbps

Please BEWARE that I have NO EXPERIENCE and NO EXPERTISE and probably onset of DEMENTIA which may affect my answers! Also, I've been told by an expert, that when you post an image it clutters up the thread and mysteriously, over time, the link to the image will somehow become "unstable" or something to that effect. :) I can only surmise that is due to Global Warming of the threads.


Friday, November 8, 2013 2:16 AM

These are my results for drop.avi in a new project (after adding the shell32.dll reference of course.)

1 .. Size
2 .. Item type
3 .. Date modified
4 .. Date created
5 .. Date accessed
6 .. Attributes
9 .. Perceived type
10 .. Owner
11 .. Kind
19 .. Rating
27 .. Length
29 .. Protected
53 .. Computer
155 .. Filename
173 .. Shared
176 .. Folder name
177 .. Folder path
178 .. Folder
180 .. Path
182 .. Type
188 .. Link status
268 .. Shared with
269 .. Sharing status
280 .. Video compression
282 .. Data rate
283 .. Frame height
284 .. Frame rate


Friday, November 8, 2013 3:53 AM

These are my results for drop.avi in a new project (after adding the shell32.dll reference of course.)

1 .. Size
2 .. Item type
3 .. Date modified
4 .. Date created
5 .. Date accessed
6 .. Attributes
9 .. Perceived type
10 .. Owner
11 .. Kind
19 .. Rating
27 .. Length
29 .. Protected
53 .. Computer
155 .. Filename
173 .. Shared
176 .. Folder name
177 .. Folder path
178 .. Folder
180 .. Path
182 .. Type
188 .. Link status
268 .. Shared with
269 .. Sharing status
280 .. Video compression
282 .. Data rate
283 .. Frame height
284 .. Frame rate

The bad thing is that something not right is happening. And I have no idea what. I'm using Win 7 64 bit laptop with Visual Studio 2012 compiling for any cpu and .Net 4.5 I believe.

On the other hand if I was you I would save a copy of each of those parameters, as many as there are, so that you can know for each extended attribute what the parameter means. So when you get it working and it returns information like I have you will know for parameter 280 that means video compression.

So what's the possibility you could add reference to the shell32.dll by browsing to C:\System\Windows\SysWOW64 instead and clicking on the shell32.dll and maybe it will change how your code is working? Windows came up with this magical weird thing where when you click on a file in the System32 folder you are actually redirected to the SysWOW64 folder for the file and vice versa if you click on a file in the SysWOW64 folder you are redirected to the System32 folder for the actual file. I think on 64 bit PC's all the 64bit .dlls are actually in the System32 folder and all the 32bit .dlls are actually in the SysWOW64 folder or something and this redirection, although I've read about it before but don't remember actually how it works, could be an issue. Also if you're on a 32 bit PC perhaps instead of compiling for any CPU maybe you should compile for just an X86 CPU and see if that changes anything.

So if you click on Visual Studios project tab and open the projects properties that is where you set compiling for any CPU or X86 or X64 CPU and once you change that you must build your project again. That is also where you determine what rev of .Net framework you want to compile to. In case you were compiling to .Net 4.5 and wanted to put your app on an XP machine you would have to lower your compilation to .Net 4.0 since that is the highest rev of .Net an XP machine can have installed on it I think. But anyhow look into those things and see what happens. I know to launch the Windows on screen Keyboard I have to compile my app that does it to X64 CPU for it to work and for 32bit PC's it has to be compiled to X86 CPU.

Please BEWARE that I have NO EXPERIENCE and NO EXPERTISE and probably onset of DEMENTIA which may affect my answers! Also, I've been told by an expert, that when you post an image it clutters up the thread and mysteriously, over time, the link to the image will somehow become "unstable" or something to that effect. :) I can only surmise that is due to Global Warming of the threads.