AsfMojo - asp.net MVC / Extract Frame from WMV C# Cache

做~自己de王妃 提交于 2019-12-24 02:59:15

问题


I am using AsfMojo (in a handler) in my MVC application to extract a bmp from WMV file, it works great on my localhost IIS7, however the image does not show when I publish the application to our hosting service.

the view script:

 <img id="Image1" alt="image"  src="ImageHandler.ashx?img=CT0001.wmv" height="512" width="512" />

The handler script:

       string videoname = System.Web.HttpContext.Current.Server.MapPath("Video/" + sImageFileName);
            if(File.Exists(videoname)) 
                {
                Bitmap bmp = AsfImage.FromFile(videoname).AtOffset(timeOffset);
                bmp.Save(objMemoryStream, ImageFormat.Png);
                byte[] imageContent = new byte[objMemoryStream.Length];
                objMemoryStream.Position = 0;
                objMemoryStream.Read(imageContent, 0, (int)objMemoryStream.Length);
                context.Response.ContentType = "image/jpeg";
                context.Response.BinaryWrite(imageContent);
                context.Response.Cache.SetExpires(DateTime.Now.AddMinutes(5));
                context.Response.Cache.SetMaxAge(TimeSpan.FromMinutes(5));

Here is the error message when I tried to display the image in a new window using Chrome:

Source Error: 

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace: 


[ArgumentNullException: Value cannot be null.
Parameter name: image]
   System.Drawing.Graphics.DrawImage(Image image, Int32 x, Int32 y, Int32 width, Int32 height) +1133063
   DirectshowTest.ImageHandler.ProcessRequest(HttpContext context) in E:\..\projects\DirectshowTest\DirectshowTest\ImageHandler.ashx.cs:40
   System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +341
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +69

I suspect becasue of the size of the wmv file, the handler script does not wait until it reads all frames in the file in this line:

 Bitmap bmp = AsfImage.FromFile(videoname).AtOffset(timeOffset);

I tried to cache the contnet response without any luck. Is there a way to check if the file has completely read before generating the image.

I would appreciate your suggestions, thanks in advance.

来源:https://stackoverflow.com/questions/14395238/asfmojo-asp-net-mvc-extract-frame-from-wmv-c-sharp-cache

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!