开发者

How to parse out information of WMV file in C#

I wan开发者_开发知识库t to get information of ASF file as bitrate, metadata, language...I have read ASF Specification and know a ASF file has parts : Header Object, Data Object, Index Object. At frist, I think ASF file's binary file and i try to solve by CLASS and FUNCTION in C# as : FileStream, BinaryReader :

String path = @"E:\KhoaLuanTN\Streaming video server\video\encoder_ad.wmv";
        FileStream filer = File.OpenRead(path);
        BinaryReader br = new BinaryReader(filer);         
        byte [] file = br.ReadBytes(100);

Then, I try to convert into String :

 textBox1.Text = Encoding.ASCII.GetString ( file );

But it doesn't display as I expect. It displays a nonsensical string: 0&?u?f? ??. So please show me how to convert information in a ASF file into String.


You can check out AsfMojo on codeplex. It offers a simple API to extract all of the information you are interested in:

Sample code

using (AsfFile asfFile = new AsfFile(sampleFileName))
{
    //Get bitrate
    uint asfBitRate = asfFile.PacketConfiguration.AsfBitRate;
    Console.WriteLine("Bitrate: " + asfBitRate);

    //Get language
    var languageObject = (AsfLanguageListObject)asfFile.GetAsfObjectByType(AsfGuid.ASF_Language_List_Object).FirstOrDefault();
    if (languageObject != null)
    {
        foreach (string language in languageObject.Languages)
            Console.WriteLine("Language: " + language);
    }

    //Get Metadata
    var metadataObject = (AsfMetadataObject)asfFile.GetAsfObjectByType(AsfGuid.ASF_Metadata_Object).FirstOrDefault();
    if (metadataObject != null)
    {
        foreach (var item in metadataObject.DescriptionRecords)
            Console.WriteLine(string.Format("{0}: {1} (stream #{2})", item.Name, item.Value, item.StreamNumber));
    }
}


Sample Output

This creates the following output for my sample file:

Bitrate: 455932
Language: en-us
IsVBR: False (stream #1)
DeviceConformanceTemplate: L2 (stream #1)
IsVBR: False (stream #2)
DeviceConformanceTemplate: MP@ML (stream #2)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜