The previous article said under WinForm call Cmd.exe perform Ffmpeg.exe for audio conversion complete demo. Later I need to migrate this way to ASP. NET, but the ASP. NET and WinForm programs are quite different.
You need to modify the Wavconverttoamr method to support ASP.
1. Wavconverttoamr Modify Execute Permissions: If you may experience permissions issues in Windows Server, you need to configure IIS permissions:
Find your site from IIS first, and in the right--properties, see which application pool you are using, and then locate it in the application pool directory, right----the properties
Find the "Identification" tab, then find "pre-defined account" and select "Local System" in the drop-down menu.
In this way, your website can execute the cmd command at will, in fact not only executes the cmd command, simply is the supreme authority!
As a reminder, this changes the application pool permissions, so all sites that use this application pool have very high permissions, which is quite dangerous and must be used with caution!!
This method is dangerous and is set by setting the user name and password to execute:
123456789101112131415161718192021222324252627282930313233343536373839404142 |
/// <summary>
/// 执行Cmd命令
/// </summary>
private
string
Cmd(
string
c)
{
try
{
System.Diagnostics.Process process =
new
System.Diagnostics.Process();
process.StartInfo.FileName =
"cmd.exe"
;
process.StartInfo.UseShellExecute =
false
;
process.StartInfo.CreateNoWindow =
true
;
process.StartInfo.UserName =
"user"
;
//构造用户密码,假定密码为123,必须一个字符一个字符的添加
System.Security.SecureString password =
new
System.Security.SecureString();
password.AppendChar(
‘p‘
);
password.AppendChar(
‘a‘
);
password.AppendChar(
‘s‘
);
password.AppendChar(
‘s‘
);
process.StartInfo.Password = password;
process.StartInfo.RedirectStandardInput =
true
;
process.StartInfo.RedirectStandardOutput =
true
;
process.StartInfo.RedirectStandardError =
true
;
process.Start();
process.StandardInput.WriteLine(c);
process.StandardInput.AutoFlush =
true
;
Thread.Sleep(1000);
process.StandardInput.WriteLine(
"exit"
);
process.WaitForExit();
//StreamReader reader = process.StandardOutput;//截取输出流
string
outStr = process.StandardOutput.ReadToEnd();
process.Close();
return
outStr;
}
catch (Exception ex)
{
return
"error"
+ex.Message;
}
}
|
Note: To construct a user password, assume that the password is 123, you must add one character to a character!
2. How to call in asp:
12345678 |
protected
void
Button1_Click(
object
sender, EventArgs e)
{
string
fileName =
"d:\\2222.amr"
;
string
targetFileName =
"d:\\2222.mp3"
;
WavConvertAmr.WavConvertToAmr toamr =
new
WavConvertAmr.WavConvertToAmr();
string
remsg = toamr.ConvertToAmr(Server.MapPath(
"./ffmpeg/"
), fileName, targetFileName);
}
|
Place Ffmpeg.exe under the directory FFmpeg of the website
In ASP. Note the path to the FFMEPG:
12345678910111213 |
./当前目录
/网站主目录
../上层目录
~/网站虚拟目录
如果当前的网站目录为E:\wwwroot 应用程序虚拟目录为E:\wwwroot\company 浏览的页面路径为E:\wwwroot\company\news\show.asp
在show.asp页面中使用
Server.MapPath(
"./"
) 返回路径为:E:\wwwroot\company\news
Server.MapPath(
"/"
) 返回路径为:E:\wwwroot
Server.MapPath(
"../"
) 返回路径为:E:\wwwroot\company
Server.MapPath(
"~/"
) 返回路径为:E:\wwwroot\company
server.MapPath(request.ServerVariables(
"Path_Info"
))
Request.ServerVariables(
"Path_Translated"
)
上面两种方式返回路径为 D:\wwwroot\company\news\show.asp
|
C # using Ffmpeg.exe for audio conversion full demo-asp.net conversion code