Beispiel #1
0
        private void convertButton_Click(object sender, EventArgs e)
        {
            MediaFoundationReader foundationReader = new MediaFoundationReader(OFD.FileName);
            SaveFileDialog        SFD = new SaveFileDialog();

            SFD.Title = "Save here your file";
            if (mp3RadioButton.Checked)
            {
                SFD.Filter = "MP3|*.mp3";
                SFD.ShowDialog();
                MediaFoundationEncoder.EncodeToMp3(foundationReader, SFD.FileName);
            }
            if (aacRadioButton.Checked)
            {
                SFD.Filter = "AAC|*.aac";
                SFD.ShowDialog();
                MediaFoundationEncoder.EncodeToAac(foundationReader, SFD.FileName);
            }
            if (wmaRadioButton.Checked)
            {
                SFD.Filter = "WMA|*.wma";
                SFD.ShowDialog();
                MediaFoundationEncoder.EncodeToWma(foundationReader, SFD.FileName);
            }
        }
Beispiel #2
0
        public Task Convert(string Inputfile, string OutputFile)
        {
            StopWatch w = new StopWatch();

            if (!Initialized)
            {
                Initialized = true;
                MediaFoundationApi.Startup();
            }
            return(new Task(delegate()
            {
                FileInfo inf = new FileInfo(OutputFile);
                AudioFileReader FileR = new AudioFileReader(Inputfile);
                string l = inf.Extension.ToLower();
                if (l.EndsWith("mp3"))
                {
                    MediaFoundationEncoder.EncodeToMp3(FileR, OutputFile, Bitrate);
                }
                else if (l.EndsWith("wma"))
                {
                    MediaFoundationEncoder.EncodeToWma(FileR, OutputFile, Bitrate);
                }
                else if (l.EndsWith("aac"))
                {
                    MediaFoundationEncoder.EncodeToAac(FileR, OutputFile, Bitrate);
                }
                else
                {
                    throw new NotSupportedException("Format not supported");
                }
                w.PrintDur("MediaProvider");
            }));
        }
 /// <summary>
 /// Convert WAV to WMA
 /// </summary>
 /// <param name="waveFileName"></param>
 /// <param name="mp3FileName"></param>
 /// <param name="bitRate"></param>
 public void WaveToWMA(string waveFileName, string wmaFileName, int bitRate = 44100)
 {
     using (MediaFoundationReader reader = new MediaFoundationReader(waveFileName))
     {
         MediaFoundationEncoder.EncodeToWma(reader, wmaFileName, bitRate);
     }
 }
        private void Convert()
        {
            var reader = new MediaFoundationReader(fileSource.FullName);

            switch (type)
            {
            case ConvertType.ToMP3:
                MediaFoundationEncoder.EncodeToMp3(reader, desPath);
                break;

            case ConvertType.ToAAC:
                MediaFoundationEncoder.EncodeToAac(reader, desPath);
                break;

            case ConvertType.ToWMA:
                MediaFoundationEncoder.EncodeToWma(reader, desPath);
                break;

            case ConvertType.ToWAV:
                WaveFileWriter.CreateWaveFile(desPath, reader);
                break;

            default:
                break;
            }
            MsgBox.Show("Convert Completed!!!", "Notification", MsgBox.Buttons.OK);
        }
 public void Encode(Stream source, string outputPath, SongTags tags, byte[] reusedBuffer)
 {
     using (var reader = new WaveFileReader(source))
     {
         MediaFoundationEncoder.EncodeToWma(
             reader,
             outputPath
             );
     }
 }
Beispiel #6
0
        public Record()
        {
            List <IMFActivate> devices = new List <IMFActivate>();

            foreach (var i in MediaFoundationApi.EnumDeviceSources())
            {
                devices.Add(i);
            }
            MediaFoundationCapturer capturer = new MediaFoundationCapturer(devices[0]);
            WaveInProvider          waveIn   = new WaveInProvider(capturer);

            capturer.StartRecording();
            Thread.Sleep(5000);
            capturer.StopRecording();
            MediaFoundationEncoder.EncodeToWma(waveIn, @"C:\record.mp3");
        }
Beispiel #7
0
        /// <summary>
        /// Transcodes the source audio to the target format and quality.
        /// </summary>
        /// <param name="formatType">Format to convert this audio to.</param>
        /// <param name="quality">Quality of the processed output audio. For streaming formats, it can be one of the following: Low (96 kbps), Medium (128 kbps), Best (192 kbps).  For WAV formats, it can be one of the following: Low (11kHz ADPCM), Medium (22kHz ADPCM), Best (44kHz PCM)</param>
        /// <param name="targetFileName">Name of the file containing the processed source audio. Must be null for Wav and Adpcm. Must not be null for streaming compressed formats.</param>
        public void ConvertFormat(ConversionFormat formatType, ConversionQuality quality, string targetFileName)
        {
            if (disposed)
            {
                throw new ObjectDisposedException("AudioContent");
            }

            switch (formatType)
            {
            case ConversionFormat.Adpcm:
                ConvertWav(new AdpcmWaveFormat(QualityToSampleRate(quality), format.ChannelCount));
                break;

            case ConversionFormat.Pcm:
                ConvertWav(new WaveFormat(QualityToSampleRate(quality), format.ChannelCount));
                break;

            case ConversionFormat.WindowsMedia:
#if WINDOWS
                reader.Position = 0;
                MediaFoundationEncoder.EncodeToWma(reader, targetFileName, QualityToBitRate(quality));
                break;
#else
                throw new NotSupportedException("WindowsMedia encoding supported on Windows only");
#endif

            case ConversionFormat.Xma:
                throw new NotSupportedException("XMA is not a supported encoding format. It is specific to the Xbox 360.");

            case ConversionFormat.ImaAdpcm:
                ConvertWav(new ImaAdpcmWaveFormat(QualityToSampleRate(quality), format.ChannelCount, 4));
                break;

            case ConversionFormat.Aac:
#if WINDOWS
                reader.Position = 0;
                MediaFoundationEncoder.EncodeToAac(reader, targetFileName, QualityToBitRate(quality));
                break;
#else
                throw new NotImplementedException();
#endif

            case ConversionFormat.Vorbis:
                throw new NotImplementedException("Vorbis is not yet implemented as an encoding format.");
            }
        }
        /// <summary>
        /// Transcodes the source audio to the target format and quality.
        /// </summary>
        /// <param name="formatType">Format to convert this audio to.</param>
        /// <param name="quality">Quality of the processed output audio. For streaming formats, it can be one of the following: Low (96 kbps), Medium (128 kbps), Best (192 kbps).  For WAV formats, it can be one of the following: Low (11kHz ADPCM), Medium (22kHz ADPCM), Best (44kHz PCM)</param>
        /// <param name="targetFileName">Name of the file containing the processed source audio. Must be null for Wav and Adpcm. Must not be null for streaming compressed formats.</param>
        public void ConvertFormat(ConversionFormat formatType, ConversionQuality quality, string targetFileName)
        {
            if (disposed)
            {
                throw new ObjectDisposedException("AudioContent");
            }


            switch (formatType)
            {
            case ConversionFormat.Adpcm:
#if WINDOWS
                ConvertWav(new AdpcmWaveFormat(QualityToSampleRate(quality), format.ChannelCount));
#else
                throw new NotSupportedException("Adpcm encoding supported on Windows only");
#endif
                break;

            case ConversionFormat.Pcm:
#if WINDOWS
                ConvertWav(new WaveFormat(QualityToSampleRate(quality), format.ChannelCount));
#elif LINUX
                // TODO Do the conversion for Linux platform
#else
                targetFileName = Guid.NewGuid().ToString() + ".wav";
                if (!ConvertAudio.Convert(fileName, targetFileName, AudioFormatType.LinearPCM, MonoMac.AudioToolbox.AudioFileType.WAVE, quality))
                {
                    throw new InvalidDataException("Failed to convert to PCM");
                }
                Read(targetFileName);
                if (File.Exists(targetFileName))
                {
                    File.Delete(targetFileName);
                }
#endif
                break;

            case ConversionFormat.WindowsMedia:
#if WINDOWS
                reader.Position = 0;
                MediaFoundationEncoder.EncodeToWma(reader, targetFileName, QualityToBitRate(quality));
                break;
#else
                throw new NotSupportedException("WindowsMedia encoding supported on Windows only");
#endif

            case ConversionFormat.Xma:
                throw new NotSupportedException("XMA is not a supported encoding format. It is specific to the Xbox 360.");

            case ConversionFormat.ImaAdpcm:
#if WINDOWS
                ConvertWav(new ImaAdpcmWaveFormat(QualityToSampleRate(quality), format.ChannelCount, 4));
#else
                throw new NotImplementedException("ImaAdpcm has not been implemented on this platform");
#endif
                break;

            case ConversionFormat.Aac:
#if WINDOWS
                reader.Position = 0;
                var mediaType = SelectMediaType(AudioSubtypes.MFAudioFormat_AAC, reader.WaveFormat, QualityToBitRate(quality));
                if (mediaType == null)
                {
                    throw new InvalidDataException("Cound not find a suitable mediaType to convert to.");
                }
                using (var encoder = new MediaFoundationEncoder(mediaType)) {
                    encoder.Encode(targetFileName, reader);
                }
#elif LINUX
                // TODO: Code for Linux convertion
#else
                if (!ConvertAudio.Convert(fileName, targetFileName, AudioFormatType.MPEG4AAC, MonoMac.AudioToolbox.AudioFileType.MPEG4, quality))
                {
                    throw new InvalidDataException("Failed to convert to AAC");
                }
#endif
                break;

            case ConversionFormat.Vorbis:
                throw new NotImplementedException("Vorbis is not yet implemented as an encoding format.");
            }
        }
Beispiel #9
0
 public void SaveToWMA(string path)
 {
     MediaFoundationApi.Startup();
     MediaFoundationEncoder.EncodeToWma(this.WaveData(), path);
 }
Beispiel #10
0
        private void WAVtoWMA()
        {
            sw.Reset();
            sw.Start();
            string plik;

            do
            {
                do
                {
                    plik = textBox1.Text;
                }while (!System.IO.File.Exists(plik));
            }while (!plik.EndsWith(".wav"));
            string plikwav     = plik.Replace(".wav", ".wma");
            string pliksciezka = plikwav;

            int    index    = plikwav.LastIndexOf("\\");
            string nazwawav = plikwav.Substring(index + 1, plikwav.Length - index - 1);

            index = plik.LastIndexOf("\\");
            string nazwamp3 = plik.Substring(index + 1, plik.Length - index - 1);

            string pokompresji = Path.GetFileNameWithoutExtension(plik) + "-encoded" + ".wma";

            using (var reader = new MediaFoundationReader(textBox1.Text))
            {
                MediaFoundationEncoder.EncodeToAac(reader, plikwav);
            }

            using (var reader2 = new MediaFoundationReader(plikwav))
            {
                MediaFoundationEncoder.EncodeToWma(reader2, pokompresji, 192000);
            }

            File.Delete(plikwav);

            FileInfo fileInfo = new FileInfo(pokompresji);

            if (fileInfo.Exists)
            {
                long   bytes     = 0;
                double kilobytes = 0;
                double megabytes = 0;

                bytes       = fileInfo.Length;
                kilobytes   = (double)bytes / 1024;
                megabytes   = kilobytes / 1024;
                y           = megabytes;
                label3.Text = "Po konwersji: " + Convert.ToString(Math.Round(megabytes, 3)) + " MB";
                string format1 = fileInfo.Extension;
                label4.Text = Path.GetFileNameWithoutExtension(pokompresji) + "  Typ pliku: " + format1;

                z            = (100 - ((100 * y) / x));
                wynik        = Convert.ToInt32(System.Math.Floor(z));
                label11.Text = "Stopień konwersji: " + wynik + "%";
            }
            sw.Stop();
            TimeSpan timeSpan = sw.Elapsed;

            czas.Text = String.Format("{0}h {1}m {2}s {3}ms", timeSpan.Hours, timeSpan.Minutes, timeSpan.Seconds, timeSpan.Milliseconds);
            MessageBox.Show("Konwersja zakończona. Plik zapisany w: " + plikwav + ".\nNaciśnij dowolny klawisz.");
            Console.In.ReadLine();
        }