2

我正在尝试在 C# 中读取 WMV 文件的图像大小。
我尝试使用此处描述的内容:
如何使用 C# 获取视频文件的持续时间?
但唯一具有值的属性是 Duration。

有任何想法吗 ?
谢谢。

4

3 回答 3

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);
        }
    }

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

于 2010-08-10T00:31:38.250 回答
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);
于 2010-06-18T20:53:04.950 回答
0

我更喜欢使用免费的 NReco.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;
于 2016-07-01T20:44:54.643 回答