2016-10-03 50 views
0
 string strParam;   
     string Path_FFMPEG = @"C:\Windows\system32\cmd.exe"; 
     string WorkingDirectory = @"C:\Users\Braintech\documents\visual studio 2013\Projects\convertVideo\convertVideo";    
     string command1 = "ffmpeg -i video1.mp4 -c copy -bsf:v h264_mp4toannexb -f mpegts intermediate1.ts"; 
     string command2 = "ffmpeg -i video2.mp4 -c copy -bsf:v h264_mp4toannexb -f mpegts intermediate1.ts"; 
     string command3 = "ffmpeg -i" + "concat:intermediate1.ts|intermediate2.ts" + " -c copy -bsf:a aac_adtstoasc Output.mp4"; 
     string Command = @"" + command1 + " & " + command2 + " & " + command3 + " ";  

     strParam = "ffmpeg -f concat -i " + file + " -c copy " + strResult; 

     process(Path_FFMPEG, Command, WorkingDirectory); 
    public static void process(string Path_FFMPEG, string Command, string WorkingDirectory) 
    { 
     try 
     {   

      Process ffmpeg = new Process(); 
      ProcessStartInfo ffmpeg_StartInfo = new ProcessStartInfo(Path_FFMPEG, Command); 
      ffmpeg_StartInfo.WorkingDirectory = WorkingDirectory;    
      ffmpeg_StartInfo.UseShellExecute = false; 
      ffmpeg_StartInfo.RedirectStandardError = true; 
      ffmpeg_StartInfo.RedirectStandardOutput = true; 
      ffmpeg.StartInfo = ffmpeg_StartInfo; 
      ffmpeg_StartInfo.CreateNoWindow = true; 
      ffmpeg.EnableRaisingEvents = true; 
      ffmpeg.Start(); 
      ffmpeg.WaitForExit(30000);    
      ffmpeg.Close(); 
      ffmpeg.Dispose(); 
      ffmpeg = null; 
     } 
     catch (Exception ex) 
     { 

     } 
    } 

我試圖用ffmpeg合併兩個視頻。但它是手動工作,但無法執行使用C#code.it工程時,我手動在cmd上運行該命令。但是當我試圖運行使用C#它不起作用。請幫助某人。 在此先感謝。使用ffmpeg連接兩個視頻。

回答

1

基本上,不要嘗試將其加載到數組中。對於大文件,您應該有一個File()方法的過載範圍,該方法需要一個路徑或Stream,並知道該怎麼做。例如:

return File("/TestVideo/Wildlife.wmv", "video/x-ms-wmv"); 

或:

return File(videoPath, "video/x-ms-wmv"); 

然而,視頻確實是一個特殊的情況下,可能從更專業的處理中受益。

+0

我得回到它扮演Android應用視頻沒有擊中的視頻網址。所以我想在api中發送字節數組,並在視頻和播放中在客戶端進行轉換。 –

+0

@SunilKumar將視頻加載到字節數組是一個可怕的想法,永遠不會工作;這不是你應該如何處理大文件。因此,無論您需要流媒體API('FileResult'知道這裏要做什麼),或者您需要多個小的請求(可怕的)。 –

+0

@sunilKumar文件結果不在api控制器中運行 –

0

返回byte數組實際上是一個NO-GO。
因此,不要將整個視頻作爲byte數組返回,爲什麼不把它保存在某處(例如Web API),如果它尚未保存爲文件,並將視頻URI作爲響應發回?

您要使用的視頻播放器肯定知道如何處理該URI。

另一種選擇是在您的Web API中啓用206 PARTIAL CONTENT支持,並在您的視頻播放器中使用Web API的URI。

看到這裏https://stackoverflow.com/a/33634614/2528907

+0

其實我不想在安全的原因發送視頻的網址在響應。我只是想發送字節數組或任何其他合適的解決方案,通過這些解決方案我可以在響應中發送who; e視頻,並且它將使用android應用程序播放,而不會觸及服務器視頻網址。 –

+0

那麼,實際上,如果這是您的問題,您的用戶也可以找出發送字節數組的端點。 「PARTIAL CONTENT」選項如何? – GeorgeChond

+0

我使用部分內容,但對於大型視頻,它也不起作用,它會使請求崩潰。 –

相關問題