Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Accessing Media Files Extended Properties - .TS, .MPG, MP4 Files 1

Status
Not open for further replies.

JasonCannon

IS-IT--Management
Apr 11, 2013
30
0
0
US
I am trying access some extended properties for .TS, .MPG, & MP4 type media files. Length, Bit rate, Frame Rates, etc.

I could this thread that has been great is getting me in the right direction, but the Length extended property is only giving back NULL.

thread184-785890

This is my code so far. I can get the Name, but not much else in the Extended Properties.

Code:
oShell = CreateObject("Shell.Application")
cFolder = 'C:\Temp\HC'
oFolder = oShell.NameSpace(cFolder)
oItems = oFolder.Items
For each oItem in oItems
   IF (upper(JustExt( oItem.Name )) == 'TS')
      ? oItem.Name
      ? oItem.ExtendedProperty('Length')
   ENDIF 
NEXT

So, how do I find out the "names" for the extended properties? Not having much luck searching online.
 
Put a SUSPEND in your code, just after [tt]? oItem.Name[/tt].

oItem will then be visible form the command window. You could type [tt]? oItem.[/tt] (note the dot), and Intellisense will give you a list of its properties. One of those is ExtendedProperty. so you then type [tt]? oItem.ExtendedProperty.[/tt] and Intellisense will give you the available extended properties.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
But I wonder if that is really what you want. Your mention of MPGs and MP4s suggest you are looking for id3 tags - the sort you find in music, videos, ebooks, etc. I don't think Shell.Application will give you that.

If that's right, you might have to resort to low-level file access to read the tags from the physical files. There are many sources on-line that explain the format and layout of these tags. For example, the Wikipedia article on ID3.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Mike,

Thanks for that. Forgot about being able to do that. But it does not look like it is showing me the other available tags for ExtendedProperty. See attached image below.

ExtendedProperty_lpycx8.jpg


Pulling up the "properties" of my file, I have been trying the names given there. That is where I got "Length", but I have also tried "Duration". "Length" gives me NULL whereas "Duration" gives me an error.

Properties_sjmmhb.jpg


But this works, and gives me back "2008884", which leads me to believe that "Length" is in there, in the ExtendedProperty, somewhere.

Code:
? oItem.ExtendedProperty('Data rate')
 
Try saving oItem.ExtendedProperty to a variable and see if IntelliSense will then kick in for the variable:

[pre]
oEP = oItem.ExtendedProperty
?oEP.
[/pre]

Tamar
 
I get an error after the first line, oEP = oItem.ExtendedProperty.

OLE error code 0x8002000e: Invalid number of parameters.

 
Okay, so it's some kind of array, not a collection. Try using a numeric index and see if that works.

Tamar
 
You mean like …

? oItem.ExtendedProperty(1) and then (2), etc?

I did notice that ? oItem.ExtendedProperty( shows "ExtendedProperty(bstrPropName as String, pvRet as Varient @) as VOID" as a drop down note.

 
You need to use the Windows Media Player Object Model:
I'll give you a taste:

lcMediaFile = some media file (e.g. MP4, WMV, MOV, TS...)

loPlayer = CREATEOBJECT("WMPlayer.OCX.7")
loVideo = loPlayer.newMedia(lcMediaFile)
liBitRate = INT(VAL(loVideo.getItemInfo("Bitrate")))
liFrameRate = INT(VAL(loVideo.getItemInfo("FrameRate")))
lcResolution = loVideo.getItemInfo("WM/VideoWidth") + " x " + loVideo.getItemInfo("WM/VideoHeight")
lcDuration = loVideo.durationString

Note: This does not work with 4k videos on Windows 7 (WMP cannot play 4k videos on Windows 7). However, my tests show that *some* 4k videos are supported by WMP on Windows 10.

The rest is up to you after you study the extremely detailed Microsoft docs. Have fun!
 
Following up Vernspace's suggestion, if you go here:


you will see a list of all the possible values that you can pass to loVideo.getItemInfo().

For example, if you are interested in finding the attributes for audio files, go to the above page, then drill down into Audio Items. You will see a list of over 90 items, including for example Bitrate, Copyright, Is_Protected, Mediatype, RecordingTime, ReleaseDate, etc. There are similar lists for CD tracks, videos, playlists, etc.

I've just tried using these attributes for an MP3 file. They all appear to work.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Vernspace & Mike,

Thank you both so much. The lcDuration is exactly what I have been looking for.

But, how did you know to use those exact "language"? The ".newMedia(" in loVideo = loPlayer.newMedia(lcMediaFile) and the ".durationString" in lcDuration = loVideo.durationString?

Granted, I have not read all of both those links you all sent from Microsoft.com, but I was trying to work backwards and see if I could find the above verbiage by looking through those links, and so far, I can't.

I was able to get to the link Mike sent (Link) from the link Vernspace sent.

From there, I clicked on the "Video Items" link, since I am working with a video file.

On the "Video Item Attributes" page, in the list of attributes, the only one that appears to apply is "Duration Attribute". So, I go there.

And on this page, I do not see how to get the ".durationString" and it states that the duration is listed in seconds. When I run the code from Vernspace, the variable lcDuration gives the duration as "02:33". Now, this does match the Properties window above for my video file, but it is not in seconds.

So, I was hoping that I could find exactly where I could find out how to recreate the code Vernspace sent by this one example, and if I can, I just have to read those links more. But from what I have outlined above, I am not sure that is the case.

Again, I can't thank you all enough for the help.

Jason...


"..if you give a man a fish he is hungry again in an hour. If you teach him to catch a fish you do him a good turn." --Anne Isabella Thackeray Ritchie.
 
Jason, you now have the link which you can drill down to other links and drill down to even more links to learn every thing you need to know. You have been given a working sample. The rest is up to you. No free lunch.
 
Jason,

The DurationString property that you are referring to is not the same as the Duration attribute that you pass to oVideo.getItemInfo(). The former gives you a formatted string, in the format HH:MM:SS. The latter gives you a value in seconds.

Does that help at all?

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
I am just going to assume that "vernpace" did not read my last reply. It is hard to accept that someone that was at first so informative and helpful could so quickly become so patronizing and rude.

Now knowing to look for a different term, "property" rather than "attribute", is helpful. But I am then rather confused why your link was specifically to attributes.

No matter. I feel as I have "worn out my welcome" here and will move on.

Thanks,
Jason...

"..if you give a man a fish he is hungry again in an hour. If you teach him to catch a fish you do him a good turn."
-- Anne Isabella Thackeray Ritchie.
 
Jason, you have most definitely not worn out your welcome. You asked a sensible question - albeit one that was more difficult than many we get here. There's nothing wrong with that. On the contrary - it's good to have a challenge. But it does mean that it could take a little longer to get a useful reply. Please persevere a little longer.

Regarding the reason for my link being specifically to the list of attributes, I was trying to help you with the parameter that you pass to GetItemInfo(). Vernspace showed us how use can pass "Bitrate" and "Framerate" to that function. I was trying to point you to the other values that you can pass - of which Duration was one example.

Does that help at all?

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top