2013-05-22 11 views
10

Mam dziwne wymagania. Użytkownik może przesłać swoje wideo w dowolnym formacie (lub w ograniczonym formacie). Musimy je przechowywać i konwertować na format .mp4, abyśmy mogli zagrać w tę stronę.Prześlij wideo i przekonwertuj do .mp4 online w .net

To samo wymaganie również w przypadku plików audio.

Mam wpisane hasło, ale nie mogę uzyskać odpowiedniego pomysłu. Każda pomoc lub sugestie .... ??

Dzięki z góry

+0

nie wiem, czy to pomoże, ale jest konwerter Internecie - może przeglądać źródła? http://video.online-convert.com/convert-to-mp4 –

+0

jaki język .net używasz asp/c sharp? –

+0

możesz sprawdzić https://code.google.com/p/ffmpeg-sharp/ –

Odpowiedz

9

można konwertować pliki niemal każdy film/user audio MP4/MP3 z FFMpeg command line utility. Z .NET można nazwać użyciem biblioteki otoki jak Video Converter for .NET (to jedno jest dobre, bo wszystko jest pakowane do jednej DLL):

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

Zauważ, że konwersja wideo wymaga znacznych zasobów procesora; dobrze jest uruchomić go w tle.

+0

To zgłasza wyjątek "Wystąpił wyjątek typu" System.ComponentModel.Win32Exception "w pliku NReco.VideoConverter.dll, ale nie było obsługiwane kodem użytkownika Informacje dodatkowe: Określony plik wykonywalny nie jest ważna aplikacja dla tej platformy OS. " – haroonxml

8

Your Answer

Wymień FLV do .mp4 dostaniesz odpowiedź

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, na co jest druga konwersja – meda