2013-05-22 33 views
10

Ho uno strano requisito. L'utente può caricare i propri video di qualsiasi formato (o un formato limitato). Dobbiamo memorizzarli e convertirli in formato .mp4 in modo che possiamo riprodurli sul nostro sito.Carica qualsiasi video e converti in .mp4 online in .net

Stesso requisito anche per i file audio.

Ho cercato su Google ma non riesco a ottenere alcuna idea adeguata. Qualsiasi aiuto o suggerimento .... ??

Grazie in anticipo

+0

non so se questo aiuterà, ma non c'è un convertitore online - forse vista la fonte? http://video.online-convert.com/convert-to-mp4 –

+0

quale lingua .net usi asp/c sharp? –

+0

potresti voler controllare https://code.google.com/p/ffmpeg-sharp/ –

risposta

9

È possibile convertire i file praticamente qualsiasi video/audio per utente MP4/MP3 con FFMpeg command line utility. Da .NET che può essere chiamato con libreria wrapper come Video Converter for .NET (questo è bello perché tutto è confezionato in una DLL):

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

Nota che la conversione video richiede notevoli risorse di CPU; è una buona idea eseguirlo in background.

+0

Questo genera un'eccezione "Un'eccezione di tipo 'System.ComponentModel.Win32Exception' si è verificata in NReco.VideoConverter.dll ma non è stata gestita nel codice utente Ulteriori informazioni: l'eseguibile specificato non è un'applicazione valida per questa piattaforma del sistema operativo. " – haroonxml

8

Your Answer

Si prega di sostituire .flv per .mp4 avrete la vostra risposta

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 qual è la seconda conversione per – meda

Problemi correlati