|
|
Comments and Discussions
|
|
 |

|
Thank you for the great code firstly. And do you have any suggestion for me to access the metadata of different types of file?
For example, if I want to access Bitrate of a *.mp4 or *.avi file, the SDK seems not allow me to do this. The return of GetFieldByName will be incorrect. So I am very grateful if you can provide some ideas, thank you so much!
|
|
|
|

|
First off, I'm glad you found the article helpful. But this article is VERY old, and there are no doubt newer libraries and SDK's out there. Many of these may have the functionality you need. I would do an internet search for the functionality you want, to find something newer and more robust. Good luck!
|
|
|
|

|
Thank you so much for your help! I will also do other research for this issue. Once I have new findings, I will share it on this thread. Look forword to hearing good news from you.
Sincerely.
|
|
|
|

|
And does someone know how to get video resolution (frame width and height) that will work on Macintosh?
|
|
|
|

|
Can I use some kind of a ffmpeg mono wrapper to convert videos?
modified on Wednesday, September 21, 2011 6:09 AM
|
|
|
|

|
Hi,
great! You can also use it for mp3s.
I found that GetFieldByName does not close the handle on the file in some times. I put the MetaDataEditor.Close() in a "finally" block and it seems that the problem disappeared?
Someone here to explain what is happening?
|
|
|
|

|
Dear Kris,
I am a student from Hungary and I read your code about titled "Accessing WMF metadata with C#". I think this is a very very good application that you was writing, but I have a problem: I don't programming with C# and I only have Visual Basic 2005 or 2008. Shall you programming this application with VB, because I need this program as a plug-in for my exam.
Yours faithfully,
Peter Farago
Student, From Hungary
08 January, 2010.
|
|
|
|

|
Peter,
The functionality in VB will be the same as in C#. Just translate what's happening in C# into VB. (A student should be able to see code in one language, and be able to translate it to another - especially code that is very straight-forward, as this one is.) I bet that if you looked closely at the code, you'd be able to see what it's doing, and then write it in VB. Just take it step by step.
|
|
|
|

|
Iam able to read properties like title, author etc but iam not able to read WM/Codec attribute.It returns null in size parameter of GetAttributebyName().
can any one help me
Thanks in advance..
|
|
|
|

|
This code works great on XP. I play a .wma file using an embedded WMP11 player and change the meta data at will. Now on Vista it's a whole new ball game. I can only set the meta data when the .wma file is not playing (or even referenced by the WMP11 player). Any idea on how to "fix" this for Vista?
Thanks for the great code.
|
|
|
|

|
*sigh* Sorry - I don't have any idea. I haven't had to target anything for Vista yet, so I don't know what the tricks are. If you figure it out, do reply, so that others can benefit from your experience. Good luck!
|
|
|
|

|
I am executing the following line:
string rating = MetaDataReader.GetFieldByName("C:\\Users\\himanp\\M3Shared\\z.wma", "Rating");
After execution, the value of the above string is "ERROR: Exception from HRESULT: 0xC00D07F0"
Your article mentions - "Be sure that the file you're interrogating has the field you are asking for. If it doesn't, the query will return an error: Exception from HRESULT: 0xC00D07F0 or Exception from HRESULT: 0xC00D001D."
I have checked that and the rating field is definitely present in my file z.wma.
Any suggestions?
|
|
|
|

|
I tried with a different audio file. This the string returned by the method was:
"ERROR: Exception from HRESULT: 0xC00D07F0"
(While in my code, the error code mentioned is "0xC00D001D")
|
|
|
|

|
What version of WMV is your file? This SDK is for an older version than what is out currently. Don't know what else it could be.
|
|
|
|

|
For Bitrate we tryed with below code.
result = MetadataEdit.SetAttrib("The Trooper.wmv", wStreamNum, "Bitrate", wAttribType, "2011");
Got error like "Value does not fall within the expected range."
Please help me in this.
|
|
|
|

|
Verify that wAttribType has the correct value (should be 0 for a DWord).
Verify that wStreamNum has the correct value - different attributes are available for different streams, so make sure the stream you are using has the bitrate attribute. Those are the 1st things I'd verify. Good luck.
|
|
|
|

|
I tried with correct input value, still not able to get or set the value of following attributes
Bitrate, Rating, Frame width, Frame height
Can you help me in this?
|
|
|
|

|
What type of media file is this? What version of the SDK? I don't know what else to check, because I didn't do anything with setting values, only reading them. Good luck.
|
|
|
|

|
Hi,
How can we make use of SDK functions to Set and Edit Metadata like 'Title' and 'Author'.if any body has got any idea on this issue please feel free to share it.
Regards,
Ani
|
|
|
|

|
Hi,
Although simple attributes seems to be read. Attributes like Framerate,Aspectratio does not get read?
What is the way to read them?
Regards
Jeesh Nair
|
|
|
|

|
First off, thanks for a great article! I've written a simple display window that reads *.wma file attributes and displays them to a window. It works fine, but the performance is pretty slow when the number of files gets close to 1000. The bottle neck seems to be in the GetFieldByName() routine. Have you done anything with increasing the performance of this otherwise great code?
Thanks,
John
|
|
|
|

|
John,
Glad you found the article useful. Unfortunately, I haven't done any more work with the code (I got moved to another project). The GetFieldByName() method uses calls to the SDK methods, which could be the cause of the slow-down. I'd be interested in hearing from you if you do find a way to increase the performance. Then I can update the sample, and give you the credit for the improvement.
Kris
|
|
|
|

|
You named your project completely wrong: WMF (vector based gfx: windows meta FILE) and WMV (VIDEO) are completly different things.
-- modified at 7:16 Wednesday 28th February, 2007
|
|
|
|

|
Gee, I guess I called it WMF because that's what Microsoft called it. It's the "WMF wrapper" class by them, in their code and on their website.
|
|
|
|

|
Microsoft has the sometimes annoying habit of recycling product names, code names, and acronyms. WMF in this case stands for Windows Media Format and while it does in fact cover WMV (Video), this article and the associated SDK also equally applies to WMA (Audio).
|
|
|
|

|
Hi,
I am adding some metadata into wmv file. My data is a string data of size>64k. SO I have to use IWMHeaderInfo3 got it.
But I am getting the error "The parameter is incorrect."
Please help me ! ! !
Following is my code (in c#)
///
///
///
public static void AddMetaData()
{
try
{
// Create a WMEncoder object.
WMEncoder Encoder = new WMEncoder();
IWMMetadataEditor metadataEditor = null;
try
{
//create encoder object
Qlikkit.WMFSDKWrapper.Functions.WMCreateEditor(out metadataEditor);
}
catch(Exception ex)
{
string str = ex.Message;
}
// open wmv file
try
{
String videoFileName = Model.CApplicationData.userVideoDataPath + @"\" + Utils.Constants.VIDEO_NO_AUDIO_NAME;
metadataEditor.Open(videoFileName);
}
catch(System.Runtime.InteropServices.COMException ex)
{
string mystr = ex.Message;
string mystr2 = ex.StackTrace;
}
// get the IWMHeaderInfo3 interface
IWMHeaderInfo3 headerInfo = metadataEditor as IWMHeaderInfo3;
// this code is just for testing
// get attribute count
ushort Outindex2= 0;
headerInfo.GetAttributeCount(0,out Outindex2);
// end of testing code
int metadataSize =100;
char [] mm = new byte[metadataSize];
for(int jj=0; jj<metadataSize; jj++)
{
mm[jj]= 'H';
}
System.IntPtr myptr = new IntPtr();
myptr = Marshal.AllocHGlobal(metadataSize);
// copy then data to pinter
Marshal.Copy(mm,0,myptr,metadataSize);
ushort Outindex3= 0;
Qlikkit.WMFSDKWrapper.WMT_ATTR_DATATYPE attrDataType2 = new Qlikkit.WMFSDKWrapper.WMT_ATTR_DATATYPE();
attrDataType2 = Qlikkit.WMFSDKWrapper.WMT_ATTR_DATATYPE.WMT_TYPE_STRING;
try
{
// add attribute
headerInfo.AddAttribute(
(ushort)0,
"Mydataww",
out Outindex3,
attrDataType2,
(ushort)0,
//myDataptr,
myptr,
(uint)metadataSize
);
}
catch(Exception ex2)
{
// TODO: Handle exceptions.
string str = ex2.Message;
}
// close the metadata editor
metadataEditor.Close();
//[in] WORD containing the stream number of the stream to which the attribute applies. Setting this value to zero indicates an attribute that applies to the entire file.
//Pointer to a wide-character null-terminated string containing the name of the attribute. Attribute names are limited to 1024 wide characters
//Pointer to a WORD. On successful completion of the method, this value is set to the index assigned to the new attribute
//Type of data used for the new attribute. For more information about the types of data supported, see WMT_ATTR_DATATYPE
//WORD containing the language index of the language to be associated with the new attribute. This is the index of the language in the language list for the file. Setting this value to zero indicates that the default language will be used. A default language is created and set according to the regional settings on the computer running your application
//myDataptr,//Pointer to an array of bytes containing the attribute value.
//DWORD containing the length of the attribute value, in bytes
}
catch (Exception ex)
{
// TODO: Handle exceptions.
string str = ex.Message;
}
}
Thanks in advance and regard,
Hemant.
|
|
|
|

|
Hemant,
I'm very sorry, but I'm leaving town today and will be unable to help you until I return to my computer on 27 November.
I will look into this when I return, if you haven't solved it by then.
Again, I'm sorry I can't help you right now,
Kris
|
|
|
|

|
Hi, I'm trying to read the duration attribute of the file and it's returning what looks like unicode characters " 嫊"
Any ideas? The file is valid, it has a valid duration attribute as far as I can see through explorer and WMP, other attributes (such as "Author") are reading ok.
WMVMetaDataReader wmv = new WMVMetaDataReader();
wmv.GetFieldByName(this.FileAbsolutePath, "Duration");
Many thanks,
Sam
|
|
|
|

|
If you are working file files encoded in Asia, there seems to be a problem with the way the ConvertAttrToString method is handling the data from the file. This is a method written by the Microsoft folks who created the WMF wrapper class. Maybe they didn't account for something different in Asian-based files. The only suggestion I have is to see my reply in the first post (Weird characters), and try to catch exactly where the odd characters are coming from, and then attempt to handle them on an individual basis.
Sounds like the MS folks need to update their WMF wrapper!
Kris
|
|
|
|

|
I have the same problem. And I do NOT use asian characters in my wmv files. I think there's something wrong with your code. I hope someone can fix this.
It's really stupid. I just learned C# because on the web there are almost only sites concerning c# and not c++. (If I was searching for something I instantly got an solution for C# but after an hour of search I still got nothing valuable for my C++ project) And in c++ I know how to do this (get duration of wmv files). But why has Microsoft not yet released a new SDK for C#?
|
|
|
|

|
My code is based on the Microsoft SDK - all the obtaining of properties is their code. I just pared down the code that calls those methods, to make it easier to use & understand. I suspect it is the MS code that has problems with certain (as of this point unknown) files. The C# SDK is certainly due for a facelift!
There is a entire C++ section to the MS Windows Media SDK. Did it not meet your needs? Also, did you see this: http://msdn2.microsoft.com/en-us/library/bb231964.aspx
In your searches for code, are you including "C++" in the keywords? Maybe you're just looking for something obscure, but I find a lot of C++ on the web. There is an entire section here in CodeProject.
Some other sites you might find helpful are:
http://csourcesearch.net/
http://www.koders.com/
http://archive.devx.com/sourcebank/
http://www.codase.com/
Good luck with your project!
Kris
|
|
|
|

|
I have just stepped through this code with VS 2008 using a tag of @"WM/TrackNumber". This particular tag does not return a string (as a byte array), it returns a 4 byte array and it is index 0 that appears to hold the track number as a byte value (e.g. track number 2 returns byte values of 2,0,0,0). This results in odd characters being returned due to the bytes being interpreted as Unicode characters. I can only assume that tags that return odd characters are not returned as strings. When I use "Title" everything works fine.
|
|
|
|

|
Problem solved. There's a much easier way retrieving this file information by accessing wmlib through a .net component.
|
|
|
|

|
On some asian music files, when I retrieve the album metadata information, I get a whole bunch of \0 characters at the end of the name.
For example, I would get: "Baby VoxSpecial\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
In Windows Media Player, these characters don't show up.
Do you have any idea why these characters are showing up? Is it running off the string? Or is it because there are asian characters and it is not handling it properly? How can I remove these?
|
|
|
|

|
I'm not sure why you'd be getting that back. It could indeed be some special characters. I suspect it probably has to do with how it's converting the name attribute to a string, in the ConvertAttrToString method. You could try stepping through a run and watching some of the values as they are processed. You should be able to detect the \0 when it's converted. If it is happening there, you could just filter out the bad characters before they're added to the return value. For instance in the 3 loops like this:
for (int i = 0; i < pbValue.Length - 2; i += 2)
{
Value += Convert.ToString(BitConverter.ToChar(pbValue, i));
}
you could examine the results of the Convert.ToString call and if it's a bad value, don't add it to the Value string.
Do let me know what you find out.
Kris
|
|
|
|

|
I stepped through the code and was able to find where it was putting in \0 characters. I couldn't figure out why some of the titles would be returning this. Maybe the WMF layer got confused and returned the wrong string length, thus all the extra \0 characters. To get rid of the \0, I modified the code as follows:
for (int i = 0; i < pbValue.Length - 2; i += 2)
{
if (pbValue[i] == 0 && pbValue[i + 1] == 0)
break; // Got a bad length in, since we are seeing \0's in the string!!
Value += Convert.ToString(BitConverter.ToChar(pbValue, i));
}
Though this is good enough for now, it would be nice though to know why I was getting the extra \0. I suspect it is a bad string length being returned.
|
|
|
|

|
Yes, I suspect something odd with the way the ConvertAttrToString method is handling the data from the file. This is a method written by the Microsoft folks who created the WMF wrapper class. Maybe they didn't account for something different in Asian-based files.
It would be nice to be able to contact them and talk to them about this problem - they might not be aware of it. But I do not know how to contact them.
Glad we came up with a work-around, at least!
Kris
|
|
|
|
 |
|
|
General News Suggestion Question Bug Answer Joke Rant Admin
|
An article on how to use C# and the Windows Media Format SDK to read metadata in Windows Media Format files.
| Type | Article |
| Licence | |
| First Posted | 21 Jun 2006 |
| Views | 78,707 |
| Bookmarked | 43 times |
|
|