C# 使用ffmpeg.exe進行音頻轉換完整demo-asp.net轉碼

來源:互聯網
上載者:User

標籤:

上一篇說了在winform下進行調用cmd.exe執行ffmpeg.exe進行音頻轉換完整demo.後來我又需要移植這個方式到asp.net中,但是asp.net和winform程式有很多不同。

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

1、WavConvertToAmr修改執行許可權:如果在windows server中可能會遇到許可權問題,需要配置IIS許可權:

   先從IIS中找到你的網站,在右鍵--【屬性】中看看使用的應用程式集區是哪個,然後【在應用程式集區】目錄下找到它,右鍵---【屬性】

 

 

         找到【標識】選項卡,再找到【預定義賬戶】,在後邊的下拉式功能表中選擇“本地系統”就可以了!

 

 

         這樣一來,你的網站就可以隨心所欲的執行cmd命令了,其實不僅僅是執行cmd命令,簡直是至高無上的許可權!

         提醒一下,這樣更改的是應用程式集區許可權,因此所有使用這個應用程式集區的網站都有很高的許可權,這是相當危險的,還須謹慎使用!!

這個方法存在危險,也通過設定執行的使用者名稱和密碼來設定:

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;            }        }

注意:構造使用者密碼,假定密碼為123,必須一個字元一個字元的添加  !

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

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);            }

將ffmpeg.exe放在網站的目錄ffmpeg的下面

在asp.net要注意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# 使用ffmpeg.exe進行音頻轉換完整demo-asp.net轉碼

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.