Asp.net ...amr .mp3 (using ffmpeg conversion method),. amrffmpeg

Source: Internet
Author: User

Asp.net ...amr .mp3 (using ffmpeg conversion method),. amrffmpeg

Preface

In the previous article, I learned how to use asp.netto convert .amrto using the seven-way conversion method. At that time, I also said that another method is to use the ffmpeg conversion method. The following article will introduce this method in detail. This method is much simpler than the first one!

The name of FFmpeg comes from the MPEG video encoding standard. The previous "FF" indicates "Fast Forward". FFmpeg is a set of functions that can be used to record and convert digital audios and videos, and can be converted into open-source computer programs of the stream. You can easily convert multiple video formats.

Ffmpeg Conversion Method

First, you have to download the javasffmpeg.exe plug-in and put it in your project, such:

This file will be called in the program to help convert the audio format!

Code:

Using System; using System. threading; using System. IO; using System. diagnostics; using System. security; public partial class cowala_201512Chritmas_amrtest: System. web. UI. page {protected void Page_Load (object sender, EventArgs e) {if (! IsPostBack) {changedPlay. visible = false ;}} protected void Ffmpeg_Click (object sender, EventArgs e) {if (AmrFileUp. hasFile) {string key = AmrFileUp. fileName; string savepath = Server. mapPath ("~ /Upload/amr/") + key; AmrFileUp. SaveAs (savepath); string mp3SavePth = 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 ('conversion successful! '); </Script> ") ;}} public string ConvertToMp3 (string pattern fore, string pathLater) {string c = Server. mapPath ("/ffmpeg/") + @ "ffmpeg.exe-I" + pathBefore + "" + pathLater; string str = RunCmd (c); return str ;} /// <summary> /// execute the Cmd command /// </summary> private string RunCmd (string c) {try {ProcessStartInfo info = new ProcessStartInfo ("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 (); string outStr = p. standardOutput. readToEnd (); p. close (); return outStr;} catch (Exception ex) {return "error" + ex. message ;}}}

Next, let's see:

Summary

Well, it's that simple. Don't trust your eyes. It's actually that simple! I hope the content in this article will be helpful for your study or work. If you have any questions, please leave a message.

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.