如何从Windows Media Server 2008捕获实时流

时间:2010-05-22 06:16:20

标签: c# video-capture wms

我想从Windows媒体服务器捕获实时流到我的电脑上的文件系统 我已使用以下代码尝试使用自己的媒体服务器。但是当我检查了 out put file我发现了这个。

FileStream fs = null;

try
{
    HttpWebRequest req = (HttpWebRequest)WebRequest.Create("http://mywmsserver/test");
    CookieContainer ci = new CookieContainer(1000);
    req.Timeout = 60000;
    req.Method = "Get";
    req.KeepAlive = true;
    req.MaximumAutomaticRedirections = 99;
    req.UseDefaultCredentials = true;
    req.UserAgent = "Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.3) Gecko/20100401 Firefox/3.6.3";
    req.ReadWriteTimeout = 90000000;
    req.CookieContainer = ci;
    //req.MediaType = "video/x-ms-asf";

    req.AllowWriteStreamBuffering = true;

    HttpWebResponse resp = (HttpWebResponse)req.GetResponse();
    Stream resps = resp.GetResponseStream();


    fs = new FileStream("d:\\dump.wmv", FileMode.Create, FileAccess.ReadWrite);

    byte[] buffer = new byte[1024];
    int bytesRead = 0;
    while ((bytesRead = resps.Read(buffer, 0, buffer.Length)) > 0)
    {

        fs.Write(buffer, 0, bytesRead);
    }

}
catch (Exception ex)
{

}
finally
{
    if (fs != null)
        fs.Close();
}

1 个答案:

答案 0 :(得分:2)

我不确定这里是否有问题......但是......这段代码非常方便!!

我一直在寻找一种方法来从家庭安全应用程序的WiFi网络摄像头捕获ASF视频流......就这样做了。

您需要在C#代码的开头提供这些代码..然后编译并运行。

使用System.IO;
使用System.Web;
使用System.Net;

感谢您的帖子!