//public CSAudioConverter.AudioConverter audioConverter1 = new CSAudioConverter.AudioConverter(); public void ConvertAudio(string path) { //string FILE = "the-file-you-want-to-process.webm"; //FFmpeg - i "${FILE}" - vn - ab 128k - ar 44100 - y "${FILE%.webm}.mp3"; //FFmpeg //string inputVideoPath = Path.Combine(path); //string outputPathMp4 = Path.Combine(path+ ".mp3"); //IMediaInfo info = await FFmpeg.GetMediaInfo(inputVideoPath); //IStream audioStream = info.AudioStreams.FirstOrDefault() // ?.SetChannels(2); //return FFmpeg.Conversions.New() // .AddStream(videoStream, audioStream) // .SetOutput(outputPathMp4); //string output = path + ".mp3"; //FFmpeg.Conversions.FromSnippet.ExtractAudio(path, output).Start(); ////FFmpeg.Conversions.FromSnippet.ExtractAudio(path, path + ".mp3"); //string output = path+ ".mp3"; //var conversion = FFmpeg.Conversions.FromSnippet.ExtractAudio(path, output); //conversion.Start(); //data.UserName = "******"; //data.UserKey = "d1200cee3a2f9f7aeddb37f9ea398592"; //data.Format = CSAudioConverter.Format.MP3; //Options.Core.SourceFile sourceFile = new Options.Core.SourceFile(path); //data.sourceFile; //data.Convert(); //https://www.codeproject.com/Articles/8544/Aumplib-C-Namespace-And-Classes-For-Audio-Conversi CSAudioConverter.AudioConverter audioConverter1 = new CSAudioConverter.AudioConverter(); audioConverter1.UserName = "******"; audioConverter1.UserKey = "d1200cee3a2f9f7aeddb37f9ea398592"; audioConverter1.Format = CSAudioConverter.Format.MP3; Options.Core.SourceFile sourceFile = new Options.Core.SourceFile(path); audioConverter1.Convert(); }
/// <summary> /// Convert, join and cut the source audio file(s). /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void cmdConvert_Click(object sender, EventArgs e) { //Check if already running: if (audioConverter1.OperationState == CSAudioConverter.OperationState.Running) { MessageBox.Show("Already running."); return; } //Check if there is source multimedia file to process: if (txtSourceMediaFile1.Text == "") { MessageBox.Show("Please select the SourceMediaFile1 to convert"); return; } #region DecodeModeExplain /* * Set the mode of the decoder, this can be the LocalCodecs which * will use the codecs that installed on the system, or FFMpeg * which will use the FFMpeg libraries. If you decide to use the * FFMpeg libraries, please make sure the FFMpeg folder with dll * files is existed under the output directory of the project: */ #endregion audioConverter1.DecodeMode = (CSAudioConverter.DecodeMode)Enum.Parse(typeof(CSAudioConverter.DecodeMode), cboDecodeMode.Text); //Set the destination path and properties: SetDestinationFileName(); //Set the destination file: audioConverter1.DestinatioFile = lblDestinationFile.Text; //[Optional: Default is MP3] //Set the destination audio format, this can be AAC, APE, MP2, MP3, OGG, PCM WAV, ACM WAV and WMA: audioConverter1.Format = (CSAudioConverter.Format)Enum.Parse(typeof(CSAudioConverter.Format), cboDestinationFormat.Text); #region MoreOptionalProperties //If the destination format is ACM (WAV) set the ACM tag and format. if (cboDestinationFormat.Text == "ACM") { //Set the ACM tag and format: //[Optional: Default is WAV] audioConverter1.ACMTag = cboACMTags.Text; //[Optional: Default is 44100, 16, Stereo] audioConverter1.ACMFormat = cboACMFormats.Text; } //[Optional: Default is 192] //Set the bitrate of the destination: audioConverter1.Bitrate = (CSAudioConverter.Bitrate)Enum.Parse(typeof(CSAudioConverter.Bitrate), cboBitrate.Text); //Or set by value //audioConverter1.BitrateVal = 192; //[Optional: Default is 44100] //Set the sample rate of the destination (from 8000 to 48000): audioConverter1.Samplerate = (CSAudioConverter.Samplerate)Enum.Parse(typeof(CSAudioConverter.Samplerate), cboSamplerate.Text); //Or set by value //audioConverter1.SamplerateVal = 48000; //[Optional: Default is 16] //Set the bit-depth of the destination file (8, 16, 24, 32): audioConverter1.Bits = (CSAudioConverter.Bits)Enum.Parse(typeof(CSAudioConverter.Bits), cboBits.Text); //[Optional: Default is 2] //Set the number of the channels of the destination file (1 or 2): audioConverter1.Channels = (CSAudioConverter.Channels)Enum.Parse(typeof(CSAudioConverter.Channels), cboChannels.Text); #endregion //Add one or more source multimedia files to the SourceFiles list. //If you will add more then one source multimedia file to the list, //the control will join them all into one multimedia file: //First clear the SourceFiles list: audioConverter1.SourceFiles.Clear(); //Set the time length to converter: TimeSpan from_time = new TimeSpan(timeFrom1.Value.Hour, timeFrom1.Value.Minute, timeFrom1.Value.Second); TimeSpan to_time = new TimeSpan(timeTo1.Value.Hour, timeTo1.Value.Minute, timeTo1.Value.Second); //Add the file to the SourceFiles list: Options.Core.SourceFile sourceFile = new Options.Core.SourceFile(txtSourceMediaFile1.Text, from_time, to_time); audioConverter1.SourceFiles.Add(sourceFile); #region ExamplesOfAddingFiles //If you want to convert all the file you can add source file without the from_time and the to_time: //audioConverter1.SourceFiles.Add(new Options.Core.SourceFile(txtSourceMediaFile1.Text)); //This will also convert all the file: //audioConverter1.SourceFiles.Add(new Options.Core.SourceFile(txtSourceMediaFile1.Text, 0, 0)); //This will convert from the from_time to the end of the file: //audioConverter1.SourceFiles.Add(new Options.Core.SourceFile(txtSourceMediaFile1.Text, from_time, 0)); #endregion // Add the second multimedia file (for joining): if (txtSourceMediaFile2.Text != "") { //Set the time length to converter of the second multimedia file: from_time = new TimeSpan(timeFrom2.Value.Hour, timeFrom2.Value.Minute, timeFrom2.Value.Second); to_time = new TimeSpan(timeTo2.Value.Hour, timeTo2.Value.Minute, timeTo2.Value.Second); //Add the second file to the SourceFiles list: audioConverter1.SourceFiles.Add(new Options.Core.SourceFile(txtSourceMediaFile2.Text, from_time, to_time)); } //Add more multimedia files to join as adding the second multimedia file... //Run the process: audioConverter1.Convert(); //Disable the buttons controls until the process has ended: cmdConvert.Enabled = false; }