上一篇说了在winform下进行调用cmd.exe执行ffmpeg.exe进行音频转换完整demo.后来我又须要移植这个方式到asp.net中,可是asp.net和winform程序有不少不一样。html
须要修改WavConvertToAmr的方法,支持asp.netc#
一、WavConvertToAmr修改执行权限:若是在windows server中可能会遇到权限问题,须要配置IIS权限:windows
先从IIS中找到你的网站,在右键--【属性】中看看使用的应用程序池是哪一个,而后【在应用程序池】目录下找到它,右键---【属性】asp.net
找到【标识】选项卡,再找到【预约义帐户】,在后边的下拉菜单中选择“本地系统”就能够了!网站
这样一来,你的网站就能够为所欲为的执行cmd命令了,其实不单单是执行cmd命令,简直是至高无上的权限!spa
提醒一下,这样更改的是应用程序池权限,所以全部使用这个应用程序池的网站都有很高的权限,这是至关危险的,还须谨慎使用!!.net
这个方法存在危险,也经过设置执行的用户名和密码来设置:code
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
/// <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;
}
}
|
注意:构造用户密码,假定密码为123,必须一个字符一个字符的添加 !orm
二、在asp.net中调用方式:server
1
2
3
4
5
6
7
8
|
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);
}
|
将ffmpeg.exe放在网站的目录ffmpeg的下面
在asp.net要注意ffmepg的路径:
1
2
3
4
5
6
7
8
9
10
11
12
13
|
./当前目录
/网站主目录
../上层目录
~/网站虚拟目录
若是当前的网站目录为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
|
转载网址:
http://www. suxxxxxxxxchso.com/projecteactual/csharp-ffmpeg-demo-mp3-amr-mp4-asp.net.html