2017-06-12 65 views
0

我使用下面的命令在片切片實時流命令:ffmpeg的在C#中使用變量

ffmpeg -i InputStreamURL -acodec aac -strict -2 -vcodec libx264 -hls_wrap 100 -f hls -hls_time 20 /var/www/html/ts/1.m3u8 

,當我在命令提示符下執行此這是工作的罰款。現在我想使用C#這個命令的變量是這樣的:

private int cuttime; 
private int wrap; 


ffmpeg -i InputStreamURL -acodec aac -strict -2 -vcodec libx264 -hls_wrap wrap -f hls -hls_time cuttime /var/www/html/ts/1.m3u8 

我想這些變量與數據庫,並與HTML5一個前端接口連接。

如何將c#變量用於ffmpeg命令?

親切的問候

回答

1
// Create string where all variable arguments are replaced with {0}, {1}, and so on 
const string argumentsTemplate = "-i InputStreamURL -acodec aac -strict -2 -vcodec libx264 -hls_wrap {0} -f hls -hls_time {1} /var/www/html/ts/1.m3u8"; 

// String.Format replaces those {0}, {1} with actual values of variables 
// {0} with value of first parameter, {1} with value of second parameter, and so on 
var arguments = String.Format(argumentsTemplate, wrap, cuttime); 

// Start ffmpeg process with actual arguments 
Process.Start("ffmpeg", arguments); 
+0

謝謝這並獲得成功! – Fearcoder