csharp 使用ASP.Net转换带有FFMPEG的视频
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了csharp 使用ASP.Net转换带有FFMPEG的视频相关的知识,希望对你有一定的参考价值。
public static string ConvertVideo(string file, string convertedExtension)
{
string result = string.Empty;
string input = string.Empty;
string output = string.Empty;
try
{
string ffmpegFilePath = "~/video/ffmpeg/ffmpeg.exe"; // path of ffmpeg.exe - please replace it for your options.
FileInfo fi = new FileInfo(HttpContext.Current.Server.MapPath(file));
string filename = Path.GetFileNameWithoutExtension(fi.Name);
string extension = Path.GetExtension(fi.Name);
input = HttpContext.Current.Server.MapPath(file);
output = HttpContext.Current.Server.MapPath("/video/" + filename + convertedExtension);
var processInfo = new ProcessStartInfo(HttpContext.Current.Server.MapPath(ffmpegFilePath), " -i \"" + input + "\" -ar 22050 \"" + output + "\"")
{
UseShellExecute = false,
CreateNoWindow = true,
RedirectStandardOutput = true,
RedirectStandardError = true
};
try
{
Process process = System.Diagnostics.Process.Start(processInfo);
result = process.StandardError.ReadToEnd();
process.WaitForExit();
process.Close();
}
catch (Exception)
{
result = string.Empty;
}
}
catch (Exception ex)
{
string error = ex.Message;
}
return result;
}
以上是关于csharp 使用ASP.Net转换带有FFMPEG的视频的主要内容,如果未能解决你的问题,请参考以下文章