×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

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

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

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

(OP)
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: Accessing file properties

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.

RE: Accessing Media Files Extended Properties - .TS, .MPG, MP4 Files

Put a SUSPEND in your code, just after ? oItem.Name.

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

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads

RE: Accessing Media Files Extended Properties - .TS, .MPG, MP4 Files

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

RE: Accessing Media Files Extended Properties - .TS, .MPG, MP4 Files

(OP)
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.



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.



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') 

RE: Accessing Media Files Extended Properties - .TS, .MPG, MP4 Files

Try saving oItem.ExtendedProperty to a variable and see if IntelliSense will then kick in for the variable:

oEP = oItem.ExtendedProperty 
?oEP.
 

Tamar

RE: Accessing Media Files Extended Properties - .TS, .MPG, MP4 Files

(OP)
I get an error after the first line, oEP = oItem.ExtendedProperty.

OLE error code 0x8002000e: Invalid number of parameters.

RE: Accessing Media Files Extended Properties - .TS, .MPG, MP4 Files

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

Tamar

RE: Accessing Media Files Extended Properties - .TS, .MPG, MP4 Files

(OP)
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.

RE: Accessing Media Files Extended Properties - .TS, .MPG, MP4 Files

You need to use the Windows Media Player Object Model: https://docs.microsoft.com/en-us/windows/desktop/W...

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!

RE: Accessing Media Files Extended Properties - .TS, .MPG, MP4 Files

Following up Vernspace's suggestion, if you go here:

https://docs.microsoft.com/en-us/windows/desktop/w...

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

RE: Accessing Media Files Extended Properties - .TS, .MPG, MP4 Files

(OP)
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.

RE: Accessing Media Files Extended Properties - .TS, .MPG, MP4 Files

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.

RE: Accessing Media Files Extended Properties - .TS, .MPG, MP4 Files

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

RE: Accessing Media Files Extended Properties - .TS, .MPG, MP4 Files

(OP)
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.

RE: Accessing Media Files Extended Properties - .TS, .MPG, MP4 Files

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

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close