Search code examples
c#mp4taglib-sharp

How to read the file rating from an mp4 file?


As the title says, can I read/write windows explorer compatible file rating data to and from mp4 video files?

It seems that windows explorer adds (a tag?) named "WM/SharedUserRating" with the corresponding data. This tag seems to be part of the ASF file format/tag format.

But I am unable to open an MP4 file as ASF (object guid exception) and the MP4 tag data extracted by taglib doesn't show the rating...?


Solution

  • If you are on Windows 10, you can use the Windows RT API. Add the Nuget package Microsoft.Windows.SDK.Contracts to your application and then you can access the rating using StorageFile:

    using Windows.Storage;
    using Windows.Storage.FileProperties;
    
    var f = await StorageFile.GetFileFromPathAsync(@"D:\ProjectsNoBackup\VideoStuff\12-Lead Ecg H.264 480P30.mp4");
    var v = await f.Properties.GetVideoPropertiesAsync();
    

    Then v.Rating is a UInt32 value where 0=0, 1=1, 2=25, 3=50, 4=75 and 5=99 (per @Michael).