Ejemplo n.º 1
0
        private void AudioWaveformDragDrop(object sender, DragEventArgs e)
        {
            var files = (string[])e.Data.GetData(DataFormats.FileDrop);
            if (files.Length != 1)
            {
                MessageBox.Show(_language.DropOnlyOneFile);
                return;
            }

            string fileName = files[0];
            string ext = Path.GetExtension(fileName).ToLowerInvariant();
            if (ext != ".wav" || !WavePeakGenerator.IsFileValidForVisualizer(fileName))
            {
                if (audioVisualizer.WavePeaks == null && (Utilities.GetMovieFileExtensions().Contains(ext) || ext == ".wav" || ext == ".mp3" || ext == ".mka" || ext == ".m4a" || ext == ".wma"))
                {
                    _videoFileName = fileName;
                    AudioWaveform_Click(null, null);
                    OpenVideo(_videoFileName);
                    return;
                }
                try
                {
                    var fi = new FileInfo(fileName);
                    if (fi.Length < 1024 * 500)
                    {
                        var lines = new List<string>(File.ReadAllLines(fileName));
                        foreach (SubtitleFormat format in SubtitleFormat.AllSubtitleFormats)
                        {
                            if (format.IsMine(lines, fileName))
                            {
                                OpenSubtitle(fileName, null);
                                return;
                            }
                        }
                    }
                }
                catch
                {
                }
            }

            if (ext != ".wav")
            {
                MessageBox.Show(".wav only!");
                return;
            }

            if (_videoFileName == null)
            {
                OpenVideo(fileName);
                return;
            }

            using (var addWaveform = new AddWaveform())
            {
                string peakWaveFileName = WavePeakGenerator.GetPeakWaveFileName(_videoFileName);
                string spectrogramFolder = Nikse.SubtitleEdit.Core.WavePeakGenerator.SpectrogramDrawer.GetSpectrogramFolder(_videoFileName);
                addWaveform.InitializeViaWaveFile(fileName, peakWaveFileName, spectrogramFolder);
                if (addWaveform.ShowDialog() == DialogResult.OK)
                {
                    audioVisualizer.WavePeaks = addWaveform.Peaks;
                    audioVisualizer.Spectrogram = addWaveform.Spectrogram;
                    timerWaveform.Start();
                }
            }
        }
Ejemplo n.º 2
0
        private void AudioWaveform_Click(object sender, EventArgs e)
        {
            if (audioVisualizer.WavePeaks == null)
            {
                if (string.IsNullOrEmpty(_videoFileName))
                {
                    buttonOpenVideo_Click(sender, e);
                    if (string.IsNullOrEmpty(_videoFileName))
                        return;
                }
                mediaPlayer.Pause();
                using (var addWaveform = new AddWaveform())
                {
                    var peakWaveFileName = WavePeakGenerator.GetPeakWaveFileName(_videoFileName);
                    var spectrogramFolder = Nikse.SubtitleEdit.Core.WavePeakGenerator.SpectrogramDrawer.GetSpectrogramFolder(_videoFileName);

                    if (WavePeakGenerator.IsFileValidForVisualizer(_videoFileName))
                    {
                        addWaveform.InitializeViaWaveFile(_videoFileName, peakWaveFileName, spectrogramFolder);
                    }
                    else
                    {
                        addWaveform.Initialize(_videoFileName, peakWaveFileName, spectrogramFolder, _videoAudioTrackNumber);
                    }
                    if (addWaveform.ShowDialog() == DialogResult.OK)
                    {
                        audioVisualizer.WavePeaks = addWaveform.Peaks;
                        audioVisualizer.Spectrogram = addWaveform.Spectrogram;
                        timerWaveform.Start();
                    }
                }
            }
        }
Ejemplo n.º 3
0
        private void buttonRipWave_Click(object sender, EventArgs e)
        {
            if (listViewInputFiles.Items.Count == 0)
            {
                MessageBox.Show(Configuration.Settings.Language.BatchConvert.NothingToConvert);
                return;
            }
            _converting                = true;
            buttonRipWave.Enabled      = false;
            progressBar1.Style         = ProgressBarStyle.Blocks;
            progressBar1.Maximum       = listViewInputFiles.Items.Count;
            progressBar1.Value         = 0;
            progressBar1.Visible       = progressBar1.Maximum > 2;
            buttonInputBrowse.Enabled  = false;
            buttonSearchFolder.Enabled = false;
            _abort = false;
            listViewInputFiles.BeginUpdate();
            foreach (ListViewItem item in listViewInputFiles.Items)
            {
                item.SubItems[3].Text = "-";
            }
            listViewInputFiles.EndUpdate();
            Refresh();
            int index = 0;

            while (index < listViewInputFiles.Items.Count && _abort == false)
            {
                var item = listViewInputFiles.Items[index];
                item.SubItems[3].Text = Configuration.Settings.Language.AddWaveformBatch.ExtractingAudio;
                string fileName = item.Text;
                try
                {
                    string  targetFile = Path.Combine(Path.GetTempPath(), Guid.NewGuid() + ".wav");
                    Process process;
                    try
                    {
                        string encoderName;
                        process        = AddWaveform.GetCommandLineProcess(fileName, -1, targetFile, Configuration.Settings.General.VlcWaveTranscodeSettings, out encoderName);
                        labelInfo.Text = encoderName;
                    }
                    catch (DllNotFoundException)
                    {
                        if (MessageBox.Show(Configuration.Settings.Language.AddWaveform.VlcMediaPlayerNotFound + Environment.NewLine +
                                            Environment.NewLine +
                                            Configuration.Settings.Language.AddWaveform.GoToVlcMediaPlayerHomePage,
                                            Configuration.Settings.Language.AddWaveform.VlcMediaPlayerNotFoundTitle, MessageBoxButtons.YesNo) == DialogResult.Yes)
                        {
                            Process.Start("http://www.videolan.org/");
                        }
                        buttonRipWave.Enabled = true;
                        return;
                    }

                    process.Start();
                    while (!process.HasExited && !_abort)
                    {
                        Application.DoEvents();
                    }


                    // check for delay in matroska files
                    var audioTrackNames      = new List <string>();
                    var mkvAudioTrackNumbers = new Dictionary <int, int>();
                    if (fileName.ToLower().EndsWith(".mkv", StringComparison.OrdinalIgnoreCase))
                    {
                        MatroskaFile matroska = null;
                        try
                        {
                            matroska = new MatroskaFile(fileName);

                            if (matroska.IsValid)
                            {
                                foreach (var track in matroska.GetTracks())
                                {
                                    if (track.IsAudio)
                                    {
                                        if (track.CodecId != null && track.Language != null)
                                        {
                                            audioTrackNames.Add("#" + track.TrackNumber + ": " + track.CodecId.Replace("\0", string.Empty) + " - " + track.Language.Replace("\0", string.Empty));
                                        }
                                        else
                                        {
                                            audioTrackNames.Add("#" + track.TrackNumber);
                                        }
                                        mkvAudioTrackNumbers.Add(mkvAudioTrackNumbers.Count, track.TrackNumber);
                                    }
                                }
                                if (mkvAudioTrackNumbers.Count > 0)
                                {
                                    _delayInMilliseconds = (int)matroska.GetTrackStartTime(mkvAudioTrackNumbers[0]);
                                }
                            }
                        }
                        catch
                        {
                            _delayInMilliseconds = 0;
                        }
                        finally
                        {
                            if (matroska != null)
                            {
                                matroska.Dispose();
                            }
                        }
                    }

                    item.SubItems[3].Text = Configuration.Settings.Language.AddWaveformBatch.Calculating;
                    MakeWaveformAndSpectrogram(fileName, targetFile, _delayInMilliseconds);

                    // cleanup
                    try
                    {
                        File.Delete(targetFile);
                    }
                    catch
                    {
                        // don't show error about unsuccessful delete
                    }

                    IncrementAndShowProgress();

                    item.SubItems[3].Text = Configuration.Settings.Language.AddWaveformBatch.Done;
                }
                catch
                {
                    IncrementAndShowProgress();
                    item.SubItems[3].Text = "ERROR";
                }
                index++;
            }
            _converting          = false;
            labelProgress.Text   = string.Empty;
            labelInfo.Text       = string.Empty;
            progressBar1.Visible = false;
            TaskbarList.SetProgressState(Handle, TaskbarButtonProgressFlags.NoProgress);
            buttonRipWave.Enabled      = true;
            buttonInputBrowse.Enabled  = true;
            buttonSearchFolder.Enabled = true;
        }
Ejemplo n.º 4
0
        private void AudioWaveform_Click(object sender, EventArgs e)
        {
            if (this.audioVisualizer.WavePeaks == null)
            {
                if (string.IsNullOrEmpty(this.VideoFileName))
                {
                    this.buttonOpenVideo_Click(sender, e);
                    if (string.IsNullOrEmpty(this.VideoFileName))
                    {
                        return;
                    }
                }

                this.mediaPlayer.Pause();
                using (var addWaveform = new AddWaveform())
                {
                    var peakWaveFileName = GetPeakWaveFileName(this.VideoFileName);
                    var spectrogramFolder = GetSpectrogramFolder(this.VideoFileName);
                    addWaveform.Initialize(this.VideoFileName, spectrogramFolder, this._videoAudioTrackNumber);
                    if (addWaveform.ShowDialog() == DialogResult.OK)
                    {
                        addWaveform.WavePeak.WritePeakSamples(peakWaveFileName);
                        var audioPeakWave = new WavePeakGenerator(peakWaveFileName);
                        audioPeakWave.GenerateAllSamples();
                        audioPeakWave.Close();
                        this.audioVisualizer.WavePeaks = audioPeakWave;
                        if (addWaveform.SpectrogramBitmaps != null)
                        {
                            this.audioVisualizer.InitializeSpectrogram(addWaveform.SpectrogramBitmaps, spectrogramFolder);
                        }

                        this.timerWaveform.Start();
                    }
                }
            }
        }
Ejemplo n.º 5
0
        private void AudioWaveformDragDrop(object sender, DragEventArgs e)
        {
            var files = (string[])e.Data.GetData(DataFormats.FileDrop);
            if (files.Length != 1)
            {
                MessageBox.Show(this._language.DropOnlyOneFile);
                return;
            }

            string fileName = files[0];
            string ext = Path.GetExtension(fileName).ToLowerInvariant();
            if (ext != ".wav")
            {
                if (this.audioVisualizer.WavePeaks == null && (Utilities.GetMovieFileExtensions().Contains(ext) || ext == ".mp3"))
                {
                    this.VideoFileName = fileName;
                    this.AudioWaveform_Click(null, null);
                    this.OpenVideo(this.VideoFileName);
                    return;
                }

                try
                {
                    var fi = new FileInfo(fileName);
                    if (fi.Length < 1024 * 500)
                    {
                        var lines = new List<string>(File.ReadAllLines(fileName));
                        foreach (SubtitleFormat format in SubtitleFormat.AllSubtitleFormats)
                        {
                            if (format.IsMine(lines, fileName))
                            {
                                this.OpenSubtitle(fileName, null);
                                return;
                            }
                        }
                    }
                }
                catch
                {
                }
            }

            if (string.IsNullOrEmpty(this.VideoFileName))
            {
                this.buttonOpenVideo_Click(null, null);
            }

            if (this.VideoFileName == null)
            {
                return;
            }

            if (ext != ".wav")
            {
                MessageBox.Show(".wav only!");
                return;
            }

            using (var addWaveform = new AddWaveform())
            {
                string spectrogramFolder = GetSpectrogramFolder(this.VideoFileName);
                addWaveform.InitializeViaWaveFile(fileName, spectrogramFolder);
                if (addWaveform.ShowDialog() == DialogResult.OK)
                {
                    string peakWaveFileName = GetPeakWaveFileName(this.VideoFileName);
                    addWaveform.WavePeak.WritePeakSamples(peakWaveFileName);
                    var audioPeakWave = new WavePeakGenerator(peakWaveFileName);
                    audioPeakWave.GenerateAllSamples();
                    this.audioVisualizer.WavePeaks = audioPeakWave;
                    this.timerWaveform.Start();
                }
            }
        }
Ejemplo n.º 6
0
        private void buttonRipWave_Click(object sender, EventArgs e)
        {
            if (listViewInputFiles.Items.Count == 0)
            {
                MessageBox.Show(LanguageSettings.Current.BatchConvert.NothingToConvert);
                return;
            }

            _converting                = true;
            buttonRipWave.Enabled      = false;
            progressBar1.Style         = ProgressBarStyle.Blocks;
            progressBar1.Maximum       = listViewInputFiles.Items.Count;
            progressBar1.Value         = 0;
            progressBar1.Visible       = progressBar1.Maximum > 2;
            buttonInputBrowse.Enabled  = false;
            buttonSearchFolder.Enabled = false;
            _abort = false;
            listViewInputFiles.BeginUpdate();
            foreach (ListViewItem item in listViewInputFiles.Items)
            {
                item.SubItems[3].Text = "-";
            }

            listViewInputFiles.EndUpdate();
            Refresh();
            var index = 0;

            while (index < listViewInputFiles.Items.Count && _abort == false)
            {
                var item = listViewInputFiles.Items[index];

                void UpdateStatus(string status)
                {
                    item.SubItems[3].Text = status;
                    Refresh();
                }

                UpdateStatus(LanguageSettings.Current.AddWaveformBatch.ExtractingAudio);
                var fileName = item.Text;
                try
                {
                    var     targetFile = Path.Combine(Path.GetTempPath(), Guid.NewGuid() + ".wav");
                    Process process;
                    try
                    {
                        process        = AddWaveform.GetCommandLineProcess(fileName, -1, targetFile, Configuration.Settings.General.VlcWaveTranscodeSettings, out var encoderName);
                        labelInfo.Text = encoderName;
                    }
                    catch (DllNotFoundException)
                    {
                        var isFfmpegAvailable = !string.IsNullOrEmpty(Configuration.Settings.General.FFmpegLocation) && File.Exists(Configuration.Settings.General.FFmpegLocation);
                        if (isFfmpegAvailable)
                        {
                            Configuration.Settings.General.UseFFmpegForWaveExtraction = true;
                            process        = AddWaveform.GetCommandLineProcess(fileName, -1, targetFile, Configuration.Settings.General.VlcWaveTranscodeSettings, out var encoderName);
                            labelInfo.Text = encoderName;
                        }
                        else
                        {
                            if (MessageBox.Show(LanguageSettings.Current.AddWaveform.FfmpegNotFound, "Subtitle Edit", MessageBoxButtons.YesNoCancel) != DialogResult.Yes)
                            {
                                buttonRipWave.Enabled = true;
                                return;
                            }

                            using (var form = new DownloadFfmpeg())
                            {
                                if (form.ShowDialog(this) == DialogResult.OK && !string.IsNullOrEmpty(form.FFmpegPath))
                                {
                                    Configuration.Settings.General.FFmpegLocation             = form.FFmpegPath;
                                    Configuration.Settings.General.UseFFmpegForWaveExtraction = true;
                                    process        = AddWaveform.GetCommandLineProcess(fileName, -1, targetFile, Configuration.Settings.General.VlcWaveTranscodeSettings, out var encoderName);
                                    labelInfo.Text = encoderName;
                                }
                                else
                                {
                                    buttonRipWave.Enabled = true;
                                    return;
                                }
                            }
                        }
                    }

                    process.Start();
                    while (!process.HasExited && !_abort)
                    {
                        Application.DoEvents();
                    }

                    // check for delay in matroska files
                    var audioTrackNames      = new List <string>();
                    var mkvAudioTrackNumbers = new Dictionary <int, int>();
                    if (fileName.ToLowerInvariant().EndsWith(".mkv", StringComparison.OrdinalIgnoreCase))
                    {
                        try
                        {
                            using (var matroska = new MatroskaFile(fileName))
                            {
                                if (matroska.IsValid)
                                {
                                    foreach (var track in matroska.GetTracks())
                                    {
                                        if (track.IsAudio)
                                        {
                                            if (track.CodecId != null && track.Language != null)
                                            {
                                                audioTrackNames.Add("#" + track.TrackNumber + ": " + track.CodecId.Replace("\0", string.Empty) + " - " + track.Language.Replace("\0", string.Empty));
                                            }
                                            else
                                            {
                                                audioTrackNames.Add("#" + track.TrackNumber);
                                            }

                                            mkvAudioTrackNumbers.Add(mkvAudioTrackNumbers.Count, track.TrackNumber);
                                        }
                                    }
                                    if (mkvAudioTrackNumbers.Count > 0)
                                    {
                                        _delayInMilliseconds = (int)matroska.GetAudioTrackDelayMilliseconds(mkvAudioTrackNumbers[0]);
                                    }
                                }
                            }
                        }
                        catch (Exception exception)
                        {
                            SeLogger.Error(exception, $"Error getting delay from mkv: {fileName}");
                            _delayInMilliseconds = 0;
                        }
                    }

                    UpdateStatus(LanguageSettings.Current.AddWaveformBatch.Calculating);
                    MakeWaveformAndSpectrogram(fileName, targetFile, _delayInMilliseconds);

                    if (checkBoxGenerateSceneChanges.Visible && checkBoxGenerateSceneChanges.Checked)
                    {
                        GenerateSceneChanges(fileName);
                    }

                    // cleanup
                    try
                    {
                        File.Delete(targetFile);
                    }
                    catch
                    {
                        // don't show error about unsuccessful delete
                    }

                    IncrementAndShowProgress();

                    UpdateStatus(LanguageSettings.Current.AddWaveformBatch.Done);
                }
                catch
                {
                    IncrementAndShowProgress();

                    UpdateStatus(LanguageSettings.Current.AddWaveformBatch.Error);
                }
                index++;
            }
            _converting          = false;
            labelProgress.Text   = string.Empty;
            labelInfo.Text       = string.Empty;
            progressBar1.Visible = false;
            TaskbarList.SetProgressState(Owner.Handle, TaskbarButtonProgressFlags.NoProgress);
            buttonRipWave.Enabled      = true;
            buttonInputBrowse.Enabled  = true;
            buttonSearchFolder.Enabled = true;
        }