在C#中读取WMV分辨率

时间:2010-06-18 20:49:08

标签: c# wmv

我正在尝试用C#读取WMV文件的图像大小 我尝试过使用这里描述的内容:
How do I get the duration of a video file using C#?
但唯一具有值的属性是持续时间
任何想法?
感谢。

3 个答案:

答案 0 :(得分:1)

我看到它完成的唯一方法是播放它并附加到开放事件:

    static WindowsMediaPlayerClass player;

    static void Main()
    {
        player = new WindowsMediaPlayerClass();  
        IWMPMedia mediaInfo = player.newMedia("test.wmv");
        player.OpenStateChange += new _WMPOCXEvents_OpenStateChangeEventHandler(player_OpenStateChange);
        player.currentMedia = mediaInfo;

        //...

        Console.WriteLine("Done.");
        Console.ReadKey();
    }

    private static void player_OpenStateChange(int state)
    {
        if (state == (int)WMPOpenState.wmposMediaOpen)
        {
            Console.WriteLine( "height = " + player.currentMedia.imageSourceHeight);
            Console.WriteLine( "width = " + player.currentMedia.imageSourceWidth);
        }
    }

在退出之前,您需要处理所有资源。

答案 1 :(得分:0)

您使用链接示例中的代码,但是您明确地执行了函数调用以获取heightwidth

示例:

using WMPLib; // this file is called Interop.WMPLib.dll

WindowsMediaPlayerClass wmp = new WindowsMediaPlayerClass();
IWMPMedia mediaInfo = wmp.newMedia("myfile.wmv"); 

long height, width;
mediaInfo.get_imageSourceHeight(height);
mediaInfo.get_imageSourceWidth(width);

答案 2 :(得分:0)

我更喜欢使用免费的NR​​eco.VideoInfo.dll。主要是因为我讨厌Windows Media Player。我发现WMP不可靠。

以下是下载链接:http://www.nrecosite.com/video_info_net.aspx它对其他内容也很有用。

var ffProbe = new NReco.VideoInfo.FFProbe();
var videoInfo = ffProbe.GetMediaInfo(pathToFile);
Int32 tmpHeight = videoInfo.Streams[0].Height;
Int32 tmpWidth = videoInfo.Streams[0].Width;