2011-05-27 7 views
2

Je veux créer une vignette d'un fichier vidéo téléchargé dans mon application pour cela J'ai utilisé ffmpeg. Le code est le suivant:créer une vignette à partir de la vidéo dans asp.net

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

mais il lance une exception:

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

Si quelqu'un a une idée alors s'il vous plaît le faire savoir.

Répondre

0

Je suggère d'utiliser la bibliothèque "DexterLib" pour ce faire. J'ai utilisé cette bibliothèque pour générer des miniatures de clips vidéo dans un environnement hébergé, et cela fonctionne comme un charme.

Voici ce dont vous avez besoin.

  1. Ajoutez une référence à la bibliothèque "DexterLib" à votre projet.

  2. Ajouter une référence aux bibliothèques suivantes:

    using System.Drawing.Imaging; 
    using System.Runtime.InteropServices; 
    using DexterLib; 
    
  3. Utilisez le code suivant pour saisir une image et générer une vignette:

    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 
    } 
    

La méthode "WriteBitmapBits" prend dans "Stream Time, Width, Height et FileName" pour votre vidéo dans cet ordre comme paramètre d'entrée que vous utilisez ensuite pour enregistrer la vignette au format JPG. Faites-moi savoir si vous avez d'autres questions. Si vous voulez le voir en action, vous pouvez jeter un oeil à un Open Source Project Portal J'ai ici:

http://digioznetportal.svn.sourceforge.net/viewvc/digioznetportal/digioznetportal_1.1/DigiOz%20.NET%20Portal%201.1/trunk/

Cliquez sur le lien « Télécharger GNU Tarball » pour télécharger l'ensemble du code source, puis prendre un regardez les "controls/VideoUpload.ascx.cs" et parcourez ce code pour voir comment cela fonctionne.

J'espère que cela aide.

Merci, Pete

+0

expliqueriez-vous ce que sont 'lsServerPath',' 'lsFBitmapName' et lsFJpegName' comment voulez-vous défini urls et les chemins? –

Questions connexes