Пример #1
0
        public static void GetMp3(IList <string> files)
        {
            if (!ffmpegPresent() || !ffprobePresent())
            {
                return;
            }
            if (files == null)
            {
                throw new ArgumentNullException("files");
            }
            try {
                foreach (string path in files)
                {
                    // Checks
                    if (!File.Exists(path))
                    {
                        MessageBox.Show("Le fichier demandé n'existe pas !\r\n" + path);
                        continue;
                    }
                    if (!MediaInfo.Check(path, null, true, true))
                    {
                        continue;
                    }

                    // Processing
                    using (SaveFileDialog sfd = new SaveFileDialog()) {
                        sfd.Title      = "Sortie : " + Path.GetFileName(path);
                        sfd.Filter     = "Fichier de sortie mp3|*.mp3";
                        sfd.DefaultExt = "mp3";
                        if (sfd.ShowDialog() != DialogResult.OK)
                        {
                            return;
                        }

                        LogWindow lw = new LogWindow();
                        lw.Show();
                        using (Process p = new Process()) {
                            ProcessStartInfo psi = new ProcessStartInfo(Common.ffmpeg, CommandLineBuilder.ExtractMp3(path, sfd.FileName, BitrateMp3.Standard, SamplingRate.AudioCD));
                            psi.UseShellExecute       = false;
                            psi.CreateNoWindow        = true;
                            psi.RedirectStandardError = true;
                            p.StartInfo = psi;
                            p.Start();
                            string line;
                            while ((line = p.StandardError.ReadLine()) != null)
                            {
                                lw.Log(line);
                                Application.DoEvents();
                            }
                            p.WaitForExit();
                        }
                        lw.Log("\r\n---------------------------------------------\r\nFin de l'opération\r\n---------------------------------------------");
                        lw.CanBeClosed = true;
                    }
                }
            } catch (Exception ex) {
                MessageBox.Show(ex.Message);
                MessageBox.Show(ex.StackTrace);
            }
        }