2013-05-22 2 views
10

Ich habe eine seltsame Anforderung. Der Nutzer kann sein Video in einem beliebigen Format (oder einem eingeschränkten Format) hochladen. Wir müssen sie speichern und in .mp4 Format konvertieren, damit wir das auf unserer Website spielen können.Laden Sie ein beliebiges Video und konvertieren Sie. MP4 online in. NET

Gleiche Anforderung auch für Audiodateien.

Ich habe gegoogelt, aber ich kann keine richtige Idee. Irgendwelche Hilfe oder Vorschläge .... ??

Vielen Dank im Voraus

+0

ich weiß nicht erhalten, wenn dies dazu beitragen wird, aber es ist ein Online-Konverter - vielleicht die Quelle anzeigen? http://video.online-convert.com/convert-to-mp4 –

+0

Welche .net Sprache verwenden Sie asp/cis? –

+0

Sie vielleicht überprüfen möchten https://code.google.com/p/ffmpeg-sharp/ –

Antwort

9

Sie fast alle Video/Audio-Dateien der Benutzer zu mp4/mp3 mit FFMpeg command line utility umwandeln kann. Von .NET kann es mit Wrapper-Bibliothek wie Video Converter for .NET aufgerufen werden (dies ist schön, weil alles in einen DLL verpackt):

(new NReco.VideoConverter.FFMpegConverter()).ConvertMedia(pathToVideoFile, pathToOutputMp4File, Formats.mp4) 

Beachten Sie, dass Video-Konvertierung erhebliche CPU-Ressourcen erfordert; Es ist eine gute Idee, es im Hintergrund auszuführen.

+0

Dies löst eine Ausnahme aus "Eine Ausnahme vom Typ 'System.ComponentModel.Win32Exception' in NReco.VideoConverter.dll aufgetreten ist, wurde aber nicht in Benutzercode behandelt Zusätzliche Informationen: Die angegebene ausführbare Datei ist nicht eine gültige Anwendung für diese Betriebssystemplattform. " – haroonxml

8

Your Answer

bitte ersetzen .flv Mp4 Sie Ihre Antwort

private bool ReturnVideo(string fileName) 
    { 
     string html = string.Empty; 
     //rename if file already exists 

     int j = 0; 
     string AppPath; 
     string inputPath; 
     string outputPath; 
     string imgpath; 
     AppPath = Request.PhysicalApplicationPath; 
     //Get the application path 
     inputPath = AppPath + "OriginalVideo"; 
     //Path of the original file 
     outputPath = AppPath + "ConvertVideo"; 
     //Path of the converted file 
     imgpath = AppPath + "Thumbs"; 
     //Path of the preview file 
     string filepath = Server.MapPath("~/OriginalVideo/" + fileName); 
     while (File.Exists(filepath)) 
     { 
      j = j + 1; 
      int dotPos = fileName.LastIndexOf("."); 
      string namewithoutext = fileName.Substring(0, dotPos); 
      string ext = fileName.Substring(dotPos + 1); 
      fileName = namewithoutext + j + "." + ext; 
      filepath = Server.MapPath("~/OriginalVideo/" + fileName); 
     } 
     try 
     { 
      this.fileuploadImageVideo.SaveAs(filepath); 
     } 
     catch 
     { 
      return false; 
     } 
     string outPutFile; 
     outPutFile = "~/OriginalVideo/" + fileName; 
     int i = this.fileuploadImageVideo.PostedFile.ContentLength; 
     System.IO.FileInfo a = new System.IO.FileInfo(Server.MapPath(outPutFile)); 
     while (a.Exists == false) 
     { 

     } 
     long b = a.Length; 
     while (i != b) 
     { 

     } 


     string cmd = " -i \"" + inputPath + "\\" + fileName + "\" \"" + outputPath + "\\" + fileName.Remove(fileName.IndexOf(".")) + ".flv" + "\""; 
     ConvertNow(cmd); 
     string imgargs = " -i \"" + outputPath + "\\" + fileName.Remove(fileName.IndexOf(".")) + ".flv" + "\" -f image2 -ss 1 -vframes 1 -s 280x200 -an \"" + imgpath + "\\" + fileName.Remove(fileName.IndexOf(".")) + ".jpg" + "\""; 
     ConvertNow(imgargs); 


     return true; 
    } 
    private void ConvertNow(string cmd) 
    { 
     string exepath; 
     string AppPath = Request.PhysicalApplicationPath; 
     //Get the application path 
     exepath = AppPath + "ffmpeg.exe"; 
     System.Diagnostics.Process proc = new System.Diagnostics.Process(); 
     proc.StartInfo.FileName = exepath; 
     //Path of exe that will be executed, only for "filebuffer" it will be "flvtool2.exe" 
     proc.StartInfo.Arguments = cmd; 
     //The command which will be executed 
     proc.StartInfo.UseShellExecute = false; 
     proc.StartInfo.CreateNoWindow = true; 
     proc.StartInfo.RedirectStandardOutput = false; 
     proc.Start(); 

     while (proc.HasExited == false) 
     { 

     } 
    } 
    protected void btn_Submit_Click(object sender, EventArgs e) 
    { 
     ReturnVideo(this.fileuploadImageVideo.FileName.ToString()); 
    } 
+0

@ Tejas was ist die zweite Konvertierung für – meda

Verwandte Themen