asp.net for audio conversion. AMR turn. mp3 Tutorial (using FFmpeg conversion method)

Source: Internet
Author: User
Tags split

Objective

The previous article has shared with you the asp.net use of the seven-cow conversion method will be. Amr mp3 method, at that time also said that there is another way to use the FFmpeg conversion method, the following article will give you a detailed description of this method. This method is much simpler than the first.

FFmpeg's name comes from the MPEG video coding standard, the front "FF" represents "Fast Forward", and FFmpeg is a set of open source computer programs that can be used to record, convert, and transform digital audio and video into streams. It is easy to convert multiple video formats to each other.

FFmpeg conversion method

First, you have to download a "Ffmpeg.exe" plugin and put it in your project, as shown in the following figure:

The file is called in the program to help convert the audio format!

Code on:

The code is as follows Copy Code
Usingsystem;
usingsystem.threading;
Usingsystem.io;
Usingsystem.diagnostics;
usingsystem.security;
Publicpartialclasscowala_201512Chritmas_amrtest:System.Web.UI.Page
{
Protectedvoidpage_load (Objectsender, EventArgs e)
{
if (! IsPostBack)
{
Changedplay.visible =false;
}
}
Protectedvoidffmpeg_click (Objectsender, EventArgs e)
{
if (amrfileup.hasfile)
{
Stringkey = Amrfileup.filename;
Stringsavepath = Server.MapPath ("~/upload/amr/") + key;
Amrfileup.saveas (Savepath);
Stringmp3savepth = Server.MapPath ("~/upload/mp3/") + key. Split ('. ') [0]. ToString () + ". mp3";
if (!string. IsNullOrEmpty (CONVERTTOMP3 (Savepath, mp3savepth))
{
Changedplay.visible =true;
CHANGEDPLAY.ATTRIBUTES.ADD ("src", "upload/mp3/" + key. Split ('. ') [0]. ToString () + ". mp3");
Response.Write ("<script>alert") (' Convert success! ');</script> ");
}
}
}
PUBLICSTRINGCONVERTTOMP3 (Stringpathbefore,stringpathlater)
{
STRINGC = Server.MapPath ("/ffmpeg/") +@ "ffmpeg.exe-i" + Pathbefore + "" + pathlater;
Stringstr = Runcmd (c);
RETURNSTR;
}
<summary>
Execute cmd command
</summary>
Privatestringruncmd (STRINGC)
{
Try
{
ProcessStartInfo Info =newprocessstartinfo ("cmd.exe");
Info. Redirectstandardoutput =false;
Info. UseShellExecute =false;
Process p = Process.Start (info);
P.startinfo.useshellexecute =false;
P.startinfo.redirectstandardinput =true;
P.startinfo.redirectstandardoutput =true;
P.startinfo.redirectstandarderror =true;
P.start ();
P.standardinput.writeline (c);
P.standardinput.autoflush =true;
Thread.Sleep (1000);
P.standardinput.writeline ("Exit");
p.WaitForExit ();
Stringoutstr = P.standardoutput.readtoend ();
P.close ();
RETURNOUTSTR;
}
catch (Exception ex)
{
Return "error" + ex. message;
}
}
}

Next to the effect of the picture:

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.