Exemplo n.º 1
0
        private void ReadWaveFile(string targetFile, int delayInMilliseconds)
        {
            labelProgress.Text = Configuration.Settings.Language.AddWaveform.GeneratingPeakFile;
            Refresh();

            var waveFile = new WavePeakGenerator(targetFile);

            int sampleRate = Configuration.Settings.VideoControls.WaveformMinimumSampleRate; // Normally 128

            while (waveFile.Header.SampleRate % sampleRate != 0 && sampleRate < 5000)
            {
                sampleRate++;                                              // old sample-rate / new sample-rate must have rest = 0
            }
            waveFile.GeneratePeakSamples(sampleRate, delayInMilliseconds); // samples per second - SampleRate

            if (Configuration.Settings.VideoControls.GenerateSpectrogram)
            {
                labelProgress.Text = Configuration.Settings.Language.AddWaveform.GeneratingSpectrogram;
                Refresh();
                Directory.CreateDirectory(_spectrogramDirectory);
                SpectrogramBitmaps = waveFile.GenerateFourierData(256, _spectrogramDirectory, delayInMilliseconds); // image height = nfft / 2
            }
            WavePeak = waveFile;
            waveFile.Close();

            labelPleaseWait.Visible = false;
        }
Exemplo n.º 2
0
        private void MakeEmptyWaveFile()
        {
            labelProgress.Text = LanguageSettings.Current.AddWaveform.GeneratingPeakFile;
            Refresh();
            var videoInfo = UiUtil.GetVideoInfo(SourceVideoFileName);

            Peaks = WavePeakGenerator.GenerateEmptyPeaks(_peakWaveFileName, (int)videoInfo.TotalMilliseconds / 1000);
            labelPleaseWait.Visible = false;
        }
Exemplo n.º 3
0
 private void MakeWaveformAndSpectrogram(string videoFileName, string targetFile, int delayInMilliseconds)
 {
     using (var waveFile = new WavePeakGenerator(targetFile))
     {
         waveFile.GeneratePeaks(delayInMilliseconds, WavePeakGenerator.GetPeakWaveFileName(videoFileName));
         if (Configuration.Settings.VideoControls.GenerateSpectrogram)
         {
             waveFile.GenerateSpectrogram(delayInMilliseconds, WavePeakGenerator.SpectrogramDrawer.GetSpectrogramFolder(videoFileName));
         }
     }
 }
        private void GenerateWaveformAndSpectrogram(string targetFile, double delayInMilliseconds)
        {
            using (var waveFile = new WavePeakGenerator(targetFile))
            {
                // Generate and save peak file
                _statusText = Configuration.Settings.Language.AddWaveform.GeneratingPeakFile;
                Peaks       = waveFile.GeneratePeaks((int)Math.Round(delayInMilliseconds), _peakWaveFileName);

                if (Configuration.Settings.VideoControls.GenerateSpectrogram)
                {
                    _statusText = Configuration.Settings.Language.AddWaveform.GeneratingSpectrogram;
//                    Spectrogram = waveFile.GenerateSpectrogram(delayInMilliseconds, _spectrogramDirectory);
                }
            }
        }
        public AddWaveFormController(string sourceFileName, string peakWaveFileName)
            : base("AddWaveForm")
        {
            _sourceFileName   = sourceFileName;
            _peakWaveFileName = WavePeakGenerator.GetPeakWaveFileName(sourceFileName);
            _cancel           = false;
            _done             = false;
            _startTicks       = DateTime.Now.Ticks;
            _statusText       = string.Empty;
            _statusTextLast   = _statusText;
            (Window as AddWaveForm).SetSourceFile(sourceFileName);
            (Window as AddWaveForm).SetProgressText(_statusText);
            _progressTimer          = new System.Timers.Timer(250);
            _progressTimer.Elapsed += (object sender, System.Timers.ElapsedEventArgs e) =>
            {
                if (_done || _cancel)
                {
                    _progressTimer.Stop();
                    InvokeOnMainThread(() =>
                    {
                        DoCancel();
                        (Window as AddWaveForm).StopProgressBar();
                        System.Threading.Thread.Sleep(100);
                        Close();
                    });
                    return;
                }

                _statusText = FormatTime(TimeSpan.FromTicks(DateTime.Now.Ticks - _startTicks).TotalSeconds);
                if (_statusText != _statusTextLast)
                {
                    InvokeOnMainThread(() =>
                    {
                        if (_done || _cancel)
                        {
                            return;
                        }
                        (Window as AddWaveForm).SetProgressText(_statusText);
                    });
                    _statusTextLast = _statusText;
                }
            };
            _progressTimer.Start();
            StartAudioProcessing();
        }
Exemplo n.º 6
0
        private void ReadWaveFile(string targetFile, int delayInMilliseconds)
        {
            labelProgress.Text = Configuration.Settings.Language.AddWaveform.GeneratingPeakFile;
            Refresh();

            using (var waveFile = new WavePeakGenerator(targetFile))
            {
                Peaks = waveFile.GeneratePeaks(delayInMilliseconds, _peakWaveFileName);

                if (Configuration.Settings.VideoControls.GenerateSpectrogram)
                {
                    labelProgress.Text = Configuration.Settings.Language.AddWaveform.GeneratingSpectrogram;
                    Refresh();
                    Spectrogram = waveFile.GenerateSpectrogram(delayInMilliseconds, _spectrogramDirectory);
                }
            }

            labelPleaseWait.Visible = false;
        }
Exemplo n.º 7
0
        private void MakeWaveformAndSpectrogram(string videoFileName, string targetFile, int delayInMilliseconds)
        {
            var waveFile = new WavePeakGenerator(targetFile);

            int sampleRate = Configuration.Settings.VideoControls.WaveformMinimumSampleRate; // Normally 128

            while (waveFile.Header.SampleRate % sampleRate != 0 && sampleRate < 5000)
            {
                sampleRate++;                                              // old sample-rate / new sample-rate must have rest = 0
            }
            waveFile.GeneratePeakSamples(sampleRate, delayInMilliseconds); // samples per second - SampleRate

            //if (Configuration.Settings.VideoControls.GenerateSpectrogram)
            //{
            //    //Directory.CreateDirectory(_spectrogramDirectory);
            //    //SpectrogramBitmaps = waveFile.GenerateFourierData(256, _spectrogramDirectory, delayInMilliseconds); // image height = nfft / 2
            //}
            waveFile.WritePeakSamples(Main.GetPeakWaveFileName(videoFileName));
            waveFile.Close();
        }
Exemplo n.º 8
0
        private void AddWaveform_Shown(object sender, EventArgs e)
        {
            Refresh();
            _numberOfAudioTracks = 0;
            var audioTrackNames      = new List <string>();
            var mkvAudioTrackNumbers = new Dictionary <int, int>();

            if (labelVideoFileName.Text.Length > 1 && File.Exists(labelVideoFileName.Text))
            {
                if (labelVideoFileName.Text.EndsWith(".mkv", StringComparison.OrdinalIgnoreCase))
                { // Choose for number of audio tracks in matroska files
                    MatroskaFile matroska = null;
                    try
                    {
                        matroska = new MatroskaFile(labelVideoFileName.Text);
                        if (matroska.IsValid)
                        {
                            foreach (var track in matroska.GetTracks())
                            {
                                if (track.IsAudio)
                                {
                                    _numberOfAudioTracks++;
                                    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);
                                }
                            }
                        }
                    }
                    finally
                    {
                        matroska?.Dispose();
                    }
                }
                else if (labelVideoFileName.Text.EndsWith(".mp4", StringComparison.OrdinalIgnoreCase) || labelVideoFileName.Text.EndsWith(".m4v", StringComparison.OrdinalIgnoreCase))
                { // Choose for number of audio tracks in mp4 files
                    try
                    {
                        var mp4    = new MP4Parser(labelVideoFileName.Text);
                        var tracks = mp4.GetAudioTracks();
                        int i      = 0;
                        foreach (var track in tracks)
                        {
                            i++;
                            if (track.Name != null && track.Mdia != null && track.Mdia.Mdhd != null && track.Mdia.Mdhd.LanguageString != null)
                            {
                                audioTrackNames.Add(i + ":  " + track.Name + " - " + track.Mdia.Mdhd.LanguageString);
                            }
                            else if (track.Name != null)
                            {
                                audioTrackNames.Add(i + ":  " + track.Name);
                            }
                            else
                            {
                                audioTrackNames.Add(i.ToString(CultureInfo.InvariantCulture));
                            }
                        }
                        _numberOfAudioTracks = tracks.Count;
                    }
                    catch
                    {
                        // ignored
                    }
                }

                // Choose audio track
                if (_numberOfAudioTracks > 1)
                {
                    using (var form = new ChooseAudioTrack(audioTrackNames, AudioTrackNumber))
                    {
                        if (form.ShowDialog(this) == DialogResult.OK)
                        {
                            if (AudioTrackNumber != form.SelectedTrack)
                            {
                                AudioTrackNumber = form.SelectedTrack;

                                var peakWaveFileName  = WavePeakGenerator.GetPeakWaveFileName(labelVideoFileName.Text, form.SelectedTrack);
                                var spectrogramFolder = WavePeakGenerator.SpectrogramDrawer.GetSpectrogramFolder(labelVideoFileName.Text, form.SelectedTrack);
                                if (File.Exists(peakWaveFileName))
                                {
                                    DialogResult = DialogResult.Cancel;
                                    return;
                                }

                                _peakWaveFileName     = peakWaveFileName;
                                _spectrogramDirectory = spectrogramFolder;
                            }
                        }
                        else
                        {
                            DialogResult = DialogResult.Cancel;
                            return;
                        }
                    }
                }

                // check for delay in matroska files
                if (labelVideoFileName.Text.EndsWith(".mkv", StringComparison.OrdinalIgnoreCase))
                {
                    MatroskaFile matroska = null;
                    try
                    {
                        matroska = new MatroskaFile(labelVideoFileName.Text);
                        if (matroska.IsValid)
                        {
                            _delayInMilliseconds = (int)matroska.GetAudioTrackDelayMilliseconds(mkvAudioTrackNumbers[AudioTrackNumber]);
                        }
                    }
                    catch (Exception exception)
                    {
                        SeLogger.Error(exception, $"Error getting delay from mkv: {labelVideoFileName.Text}");
                        _delayInMilliseconds = 0;
                    }
                    finally
                    {
                        matroska?.Dispose();
                    }
                }

                buttonRipWave_Click(null, null);
            }
            else if (_wavFileName != null)
            {
                FixWaveOnly();
            }
        }
Exemplo n.º 9
0
        private void buttonSave_Click(object sender, EventArgs e)
        {
            var model = new SeJobModel
            {
                Version            = "1.0",
                JobId              = textBoxJobId.Text,
                JobName            = textBoxJobName.Text.Trim(),
                Message            = textBoxJobDescription.Text.Trim(),
                SubtitleFileFormat = _subtitleFormat.Name,
                SubtitleFileName   = textBoxSubtitleFileName.Text.Trim(),
                SubtitleContent    = _subtitle.ToText(_subtitleFormat),
                VideoStreamingUrl  = textBoxVideoUrl.Text.Trim(),
            };

            if (!string.IsNullOrEmpty(_videoFileName))
            {
                model.VideoHash = Path.GetFileNameWithoutExtension(WavePeakGenerator.GetPeakWaveFileName(_videoFileName));
                if (!string.IsNullOrEmpty(model.VideoStreamingUrl))
                {
                    model.VideoHash = MovieHasher.GenerateHashFromString(model.VideoStreamingUrl);
                }
            }

            if (checkBoxOriginal.Checked && _subtitleOriginal?.Paragraphs.Count > 0)
            {
                model.SubtitleFileNameOriginal = _subtitleOriginal.FileName;
                model.SubtitleContentOriginal  = _subtitleOriginal.ToText(_subtitleFormat);
            }

            if (checkBoxIncludeWaveform.Checked && _waveform?.PeakMins.Count > 0)
            {
                model.Waveform = _waveform;
            }

            if (checkBoxIncludeShotChanges.Checked && _shotChanges?.Count > 0)
            {
                model.ShotChanges = _shotChanges;
            }

            if (checkBoxIncludeBookmarks.Checked)
            {
                model.Bookmarks = new List <SeJobBookmark>();
                foreach (var p in _subtitle?.Paragraphs.Where(p => !string.IsNullOrEmpty(p.Bookmark)))
                {
                    model.Bookmarks.Add(new SeJobBookmark
                    {
                        Idx = _subtitle.GetIndex(p),
                        Txt = p.Bookmark,
                    });
                }
            }

            if (checkBoxIncludeRules.Checked)
            {
                model.Rules = new SeJobRules
                {
                    MaxNumberOfLines                    = (int)numericUpDownMaxNumberOfLines.Value,
                    SubtitleLineMaximumLength           = (int)numericUpDownSubtitleLineMaximumLength.Value,
                    SubtitleMaximumCharactersPerSeconds = numericUpDownMaxCharsSec.Value,
                    SubtitleMinimumDisplayMilliseconds  = (int)numericUpDownDurationMin.Value,
                    SubtitleMaximumDisplayMilliseconds  = (int)numericUpDownDurationMax.Value,
                    MinimumMillisecondsBetweenLines     = (int)numericUpDownMinGapMs.Value,
                    SubtitleMaximumWordsPerMinute       = numericUpDownMaxWordsMin.Value,
                    SubtitleOptimalCharactersPerSeconds = numericUpDownOptimalCharsSec.Value,
                };
            }

            using (var saveDialog = new SaveFileDialog {
                FileName = Path.GetFileNameWithoutExtension(model.SubtitleFileName), Filter = "se-job|*.se-job"
            })
            {
                if (saveDialog.ShowDialog() == DialogResult.OK)
                {
                    File.WriteAllBytes(saveDialog.FileName, SeJobHandler.SaveSeJob(model));
                    DialogResult = DialogResult.OK;
                }
            }
        }
Exemplo n.º 10
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();
                    }
                }
            }
        }
Exemplo n.º 11
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();
                }
            }
        }
Exemplo n.º 12
0
        private void ReadWaveFile(string targetFile, int delayInMilliseconds)
        {
            labelProgress.Text = Configuration.Settings.Language.AddWaveform.GeneratingPeakFile;
            Refresh();

            using (var waveFile = new WavePeakGenerator(targetFile))
            {
                Peaks = waveFile.GeneratePeaks(delayInMilliseconds, _peakWaveFileName);

                if (Configuration.Settings.VideoControls.GenerateSpectrogram)
                {
                    labelProgress.Text = Configuration.Settings.Language.AddWaveform.GeneratingSpectrogram;
                    Refresh();
                    Spectrogram = waveFile.GenerateSpectrogram(delayInMilliseconds, _spectrogramDirectory);
                }
            }

            labelPleaseWait.Visible = false;
        }
Exemplo n.º 13
0
        private bool IsFileValidForVisualizer(string fileName)
        {
            if (!fileName.EndsWith(".wav", StringComparison.OrdinalIgnoreCase))
                return false;

            using (var wpg = new WavePeakGenerator(fileName))
            {
                return wpg.IsSupported;
            }
        }
Exemplo n.º 14
0
        private void ReadWaveFile(string targetFile, int delayInMilliseconds)
        {
            labelProgress.Text = Configuration.Settings.Language.AddWaveform.GeneratingPeakFile;
            Refresh();

            var waveFile = new WavePeakGenerator(targetFile);

            int sampleRate = Configuration.Settings.VideoControls.WaveformMinimumSampleRate; // Normally 128
            while (waveFile.Header.SampleRate % sampleRate != 0 && sampleRate < 5000)
                sampleRate++; // old sample-rate / new sample-rate must have rest = 0

            waveFile.GeneratePeakSamples(sampleRate, delayInMilliseconds); // samples per second - SampleRate

            if (Configuration.Settings.VideoControls.GenerateSpectrogram)
            {
                labelProgress.Text = Configuration.Settings.Language.AddWaveform.GeneratingSpectrogram;
                Refresh();
                Directory.CreateDirectory(_spectrogramDirectory);
                SpectrogramBitmaps = waveFile.GenerateFourierData(256, _spectrogramDirectory, delayInMilliseconds); // image height = nfft / 2
            }
            WavePeak = waveFile;
            waveFile.Close();

            labelPleaseWait.Visible = false;
        }
Exemplo n.º 15
0
        private void MakeWaveformAndSpectrogram(string videoFileName, string targetFile, int delayInMilliseconds)
        {
            var waveFile = new WavePeakGenerator(targetFile);

            int sampleRate = Configuration.Settings.VideoControls.WaveformMinimumSampleRate; // Normally 128
            while (waveFile.Header.SampleRate % sampleRate != 0 && sampleRate < 5000)
                sampleRate++; // old sample-rate / new sample-rate must have rest = 0

            waveFile.GeneratePeakSamples(sampleRate, delayInMilliseconds); // samples per second - SampleRate

            //if (Configuration.Settings.VideoControls.GenerateSpectrogram)
            //{
            //    //Directory.CreateDirectory(_spectrogramDirectory);
            //    //SpectrogramBitmaps = waveFile.GenerateFourierData(256, _spectrogramDirectory, delayInMilliseconds); // image height = nfft / 2
            //}
            waveFile.WritePeakSamples(Main.GetPeakWaveFileName(videoFileName));
            waveFile.Close();
        }