2013-05-22 14 views
10

私は奇妙な要求があります。ユーザーは、任意の形式(または限られた形式)の動画をアップロードできます。それらを保存して.mp4フォーマットに変換する必要がありますので、私たちのサイトでそれを再生することができます。ビデオをアップロードし、ネットで.mp4に変換してください。

オーディオファイルも同様です。

私はグーグルではありますが、適切なアイデアは得られません。任意の助けや提案....?事前

+0

これが役立つ場合、私は知りませんが、オンラインコンバータはありますでしょう.MP4するのFLVを交換してください - 多分ソースを表示? http://video.online-convert.com/convert-to-mp4 –

+0

.net language asp/c sharpを使用していますか? –

+0

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

答えて

9

にあなたはほぼすべてのビデオ/オーディオのユーザーファイルがFFMpeg command line utilityとのmp4/mp3に変換することができます

感謝。 .NETから、(すべてが1つのDLLに詰め込まれているので、この1つがいいです)Video Converter for .NETのようなラッパーライブラリを使用して呼び出すことができます。ビデオ変換は、大量のCPUリソースを必要とすることが

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

注意。それをバックグラウンドで実行することをお勧めします。

+0

NReco.VideoConverter.dllでは 'System.ComponentModel.Win32Exception'という型の例外が発生しましたが、ユーザーコードで処理されませんでした。 追加情報:指定された実行可能ファイルはありませんこのOSプラットフォームのための有効なアプリケーションです。 – haroonxml

8

Your Answer

あなたはあなたの答え

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第2回目の変換は何ですか – meda

関連する問題