C # using Ffmpeg.exe for audio conversion full demo-asp.net conversion code

Source: Internet
Author: User
Tags servervariables

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>        privatestringCmd(stringc)        {            try            {                System.Diagnostics.Process process = newSystem.Diagnostics.Process();                process.StartInfo.FileName = "cmd.exe";                process.StartInfo.UseShellExecute = false;                               process.StartInfo.CreateNoWindow = true;                process.StartInfo.UserName = "user";                //构造用户密码,假定密码为123,必须一个字符一个字符的添加                  System.Security.SecureString password = newSystem.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;//截取输出流                           stringoutStr = process.StandardOutput.ReadToEnd();                  process.Close();                          returnoutStr;            }            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    protectedvoidButton1_Click(objectsender, EventArgs e)    {        stringfileName = "d:\\2222.amr";        stringtargetFileName = "d:\\2222.mp3";        WavConvertAmr.WavConvertToAmr toamr = newWavConvertAmr.WavConvertToAmr();        stringremsg = 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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.