C# 使用ffmpeg.exe进行音频转换完整demo-asp.net转换代码

C# 使用ffmpeg.exe进行音频转换完整demo-asp.net转换代码

 

上一篇说了在winform下进行调用cmd.exe执行ffmpeg.exe进行音频转换完整demo.后来我又需要移植这个方式到asp.net中,但是asp.net和winform程序有很多不同。

需要修改WavConvertToAmr的方法,支持asp.net

1、WavConvertToAmr修改执行权限:如果在windows server中可能会遇到权限问题,需要配置IIS权限:

   先从IIS中找到你的网站,在右键--【属性】中看看使用的应用程序池是哪个,然后【在应用程序池】目录下找到它,右键---【属性】

 

IT分享

 

         找到【标识】选项卡,再找到【预定义账户】,在后边的下拉菜单中选择“本地系统”就可以了!

IT分享

 

 

         这样一来,你的网站就可以随心所欲的执行cmd命令了,其实不仅仅是执行cmd命令,简直是至高无上的权限!

         提醒一下,这样更改的是应用程序池权限,因此所有使用这个应用程序池的网站都有很高的权限,这是相当危险的,还须谨慎使用!!

这个方法存在危险,也通过设置执行的用户名和密码来设置:

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,必须一个字符一个字符的添加  !

2、在asp.net中调用方式:

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的下面

IT分享C# 使用ffmpeg.exe进行音频转换完整demo-asp.net转换代码

在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

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值