在asp.net视频缩略图创建 [英] create thumbnail from video in asp.net

查看:320
本文介绍了在asp.net视频缩略图创建的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的应用程序创建一个上传视频文件的缩略图为了这个,我已经使用的ffmpeg 。在code是如下:

I want to create thumbnail of an uploaded video file in my application for this I have used ffmpeg. The code is as follows:

 string thumbpath, thumbname;
        string thumbargs;
        string thumbre;
        thumbpath = Server.MapPath("~/thumbnails/");
        thumbname = thumbpath + "Test" + ".png";
        string f = Server.MapPath("~/testvideo.wmv");
        thumbargs = "-i " + f + " -vcodec png -vframes 1 -ss 00:00:07 -s 150x150 " + thumbname;
        Process thumbproc = new Process();
        thumbproc = new Process();
        thumbproc.StartInfo.FileName = Server.MapPath("~\\ffmpeg\\ffmpeg.exe");
        thumbproc.StartInfo.Arguments = thumbargs;
        thumbproc.StartInfo.UseShellExecute = false;
        thumbproc.StartInfo.CreateNoWindow = false;
        thumbproc.StartInfo.RedirectStandardOutput = false;
        try
        {
            thumbproc.Start();
        }
        catch (Exception ex)
        {
            Response.Write(ex.Message);
        }
        thumbproc.WaitForExit();
        thumbproc.Close();

但它抛出一个异常:

but it's throwing an exception :

MainModule = 'thumbproc.MainModule'
threw an exception of type 'System.ComponentModel.Win32Exception'

如果有人有一个想法,那么请让知道。

If some one has an idea then please let know.

推荐答案

我建议您使用DexterLib库来做到这一点。我已经使用这个库生成托管环境下的视频剪辑的缩略图,以及它的工作原理就像一个魅力。

I suggest using "DexterLib" library to do this. I have used this library to generate thumbnails of video clips in hosted environment, and it works like a charm.

下面是你需要的。


  1. 要DexterLib库的引用添加到项目中。

  1. Add a reference to "DexterLib" library to your project.

引用添加到下列库:

using System.Drawing.Imaging;
using System.Runtime.InteropServices;
using DexterLib;


  • 使用以下code抢到了框架和生成缩略图:

  • Use the following code to grab a frame and generate a thumbnail:

    try
    {
        MediaDetClass loMD = new MediaDetClass();
        loMD.Filename = lsServerPath;
        loMD.CurrentStream = 0;
        loMD.WriteBitmapBits(0, 150, 150, lsFBitmapName);
    
        System.Drawing.Image loImg = System.Drawing.Image.FromFile(lsFBitmapName);
        loImg.Save(lsFJpegName, ImageFormat.Jpeg);
        loImg.Dispose();
        System.IO.File.Delete(lsFBitmapName);
    }
    catch (Exception loEx)
    {
        // Means media not supported
    }
    


  • 在WriteBitmapBits方法需要在数据流时间,宽度,高度和文件名中的顺序作为输入参数,然后您再使用保存缩略图为JPG视频。让我知道,如果您有任何其他问题。如果你想看到它在行动你可以看看一个开放源码的门户网站项目我这里有:

    The "WriteBitmapBits" method takes in the "Stream Time, Width, Height and FileName" for your video in that order as input parameter which you then use to save the thumbnail as JPG. Let me know if you have any additional questions. If you want to see it in action you can take a look at an Open Source Portal Project I have here:

    <一个href=\"http://digioznetportal.svn.sourceforge.net/viewvc/digioznetportal/digioznetportal_1.1/DigiOz%20.NET%20Portal%201.1/trunk/\" rel=\"nofollow\">http://digioznetportal.svn.sourceforge.net/viewvc/digioznetportal/digioznetportal_1.1/DigiOz%20.NET%20Portal%201.1/trunk/

    点击下载GNU的tarball链接下载整个源$ C ​​$ C,再看看在控制/ VideoUpload.ascx.cs,并通过code步骤来看看它是如何工作的。

    Click on "Download GNU Tarball" link to download the whole source code, then take a look at the "controls/VideoUpload.ascx.cs" and step through that code to see how it works.

    我希望这有助于。

    谢谢,
    皮特

    这篇关于在asp.net视频缩略图创建的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆