Пример #1
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));
         }
     }
 }
        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();
        }
Пример #3
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();
            }
        }
Пример #4
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;
                }
            }
        }