mirror of
https://github.com/SubtitleEdit/subtitleedit.git
synced 2024-10-27 22:42:38 +01:00
Spectrogram loading cleanups.
This commit is contained in:
parent
ed7c351b19
commit
c8ed603f9b
@ -3,6 +3,7 @@ using System.Collections.Generic;
|
|||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using System.Xml;
|
using System.Xml;
|
||||||
@ -229,6 +230,105 @@ namespace Nikse.SubtitleEdit.Core
|
|||||||
HighestPeak = abs;
|
HighestPeak = abs;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static WavePeakData FromDisk(string peakFileName)
|
||||||
|
{
|
||||||
|
using (var peakGenerator = new WavePeakGenerator(peakFileName))
|
||||||
|
{
|
||||||
|
return peakGenerator.LoadPeaks();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public class SpectrogramData : IDisposable
|
||||||
|
{
|
||||||
|
private string _loadFromDirectory;
|
||||||
|
|
||||||
|
public SpectrogramData(int fftSize, int imageWidth, double sampleDuration, IList<Bitmap> images)
|
||||||
|
{
|
||||||
|
FftSize = fftSize;
|
||||||
|
ImageWidth = imageWidth;
|
||||||
|
SampleDuration = sampleDuration;
|
||||||
|
Images = images;
|
||||||
|
}
|
||||||
|
|
||||||
|
private SpectrogramData(string loadFromDirectory)
|
||||||
|
{
|
||||||
|
_loadFromDirectory = loadFromDirectory;
|
||||||
|
Images = new Bitmap[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
public int FftSize { get; private set; }
|
||||||
|
|
||||||
|
public int ImageWidth { get; private set; }
|
||||||
|
|
||||||
|
public double SampleDuration { get; private set; }
|
||||||
|
|
||||||
|
public IList<Bitmap> Images { get; private set; }
|
||||||
|
|
||||||
|
public bool IsLoaded
|
||||||
|
{
|
||||||
|
get { return _loadFromDirectory == null; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Load()
|
||||||
|
{
|
||||||
|
if (_loadFromDirectory == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
string directory = _loadFromDirectory;
|
||||||
|
_loadFromDirectory = null;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
string xmlInfoFileName = Path.Combine(directory, "Info.xml");
|
||||||
|
if (!File.Exists(xmlInfoFileName))
|
||||||
|
return;
|
||||||
|
var doc = new XmlDocument();
|
||||||
|
var culture = CultureInfo.InvariantCulture;
|
||||||
|
doc.Load(xmlInfoFileName);
|
||||||
|
FftSize = Convert.ToInt32(doc.DocumentElement.SelectSingleNode("NFFT").InnerText, culture);
|
||||||
|
ImageWidth = Convert.ToInt32(doc.DocumentElement.SelectSingleNode("ImageWidth").InnerText, culture);
|
||||||
|
SampleDuration = Convert.ToDouble(doc.DocumentElement.SelectSingleNode("SampleDuration").InnerText, culture);
|
||||||
|
|
||||||
|
var images = new List<Bitmap>();
|
||||||
|
var fileNames = Enumerable.Range(0, int.MaxValue)
|
||||||
|
.Select(n => Path.Combine(directory, n + ".gif"))
|
||||||
|
.TakeWhile(p => File.Exists(p));
|
||||||
|
foreach (string fileName in fileNames)
|
||||||
|
{
|
||||||
|
// important that this does not lock file (do NOT use Image.FromFile(fileName) or alike!!!)
|
||||||
|
using (var ms = new MemoryStream(File.ReadAllBytes(fileName)))
|
||||||
|
{
|
||||||
|
images.Add((Bitmap)Image.FromStream(ms));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Images = images;
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Dispose()
|
||||||
|
{
|
||||||
|
foreach (var image in Images)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
image.Dispose();
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Images = new Bitmap[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
public static SpectrogramData FromDisk(string spectrogramDirectory)
|
||||||
|
{
|
||||||
|
return new SpectrogramData(spectrogramDirectory);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public class WavePeakGenerator : IDisposable
|
public class WavePeakGenerator : IDisposable
|
||||||
@ -275,7 +375,7 @@ namespace Nikse.SubtitleEdit.Core
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="delayInMilliseconds">Delay in milliseconds (normally zero)</param>
|
/// <param name="delayInMilliseconds">Delay in milliseconds (normally zero)</param>
|
||||||
/// <param name="peakFileName">Path of the output file</param>
|
/// <param name="peakFileName">Path of the output file</param>
|
||||||
public void GeneratePeaks(int delayInMilliseconds, string peakFileName)
|
public WavePeakData GeneratePeaks(int delayInMilliseconds, string peakFileName)
|
||||||
{
|
{
|
||||||
int peaksPerSecond = Math.Min(Configuration.Settings.VideoControls.WaveformMinimumSampleRate, _header.SampleRate);
|
int peaksPerSecond = Math.Min(Configuration.Settings.VideoControls.WaveformMinimumSampleRate, _header.SampleRate);
|
||||||
|
|
||||||
@ -356,6 +456,8 @@ namespace Nikse.SubtitleEdit.Core
|
|||||||
stream.Write(buffer, 0, 4);
|
stream.Write(buffer, 0, 4);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return new WavePeakData(peaksPerSecond, peaks);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static WavePeak CalculatePeak(float[] chunk, int count)
|
private static WavePeak CalculatePeak(float[] chunk, int count)
|
||||||
@ -379,7 +481,7 @@ namespace Nikse.SubtitleEdit.Core
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Loads previously generated peaks from disk.
|
/// Loads previously generated peaks from disk.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public WavePeakData LoadPeaks()
|
internal WavePeakData LoadPeaks()
|
||||||
{
|
{
|
||||||
if (_header.BitsPerSample != 16)
|
if (_header.BitsPerSample != 16)
|
||||||
throw new Exception("Peaks file must be 16 bits per sample.");
|
throw new Exception("Peaks file must be 16 bits per sample.");
|
||||||
@ -543,7 +645,7 @@ namespace Nikse.SubtitleEdit.Core
|
|||||||
|
|
||||||
//////////////////////////////////////// SPECTRUM ///////////////////////////////////////////////////////////
|
//////////////////////////////////////// SPECTRUM ///////////////////////////////////////////////////////////
|
||||||
|
|
||||||
public List<Bitmap> GenerateSpectrogram(string spectrogramDirectory, int delayInMilliseconds)
|
public SpectrogramData GenerateSpectrogram(int delayInMilliseconds, string spectrogramDirectory)
|
||||||
{
|
{
|
||||||
const int fftSize = 256; // image height = fft size / 2
|
const int fftSize = 256; // image height = fft size / 2
|
||||||
const int imageWidth = 1024;
|
const int imageWidth = 1024;
|
||||||
@ -553,7 +655,7 @@ namespace Nikse.SubtitleEdit.Core
|
|||||||
// ignore negative delays for now (pretty sure it can't happen in mkv and some places pass in -1 by mistake)
|
// ignore negative delays for now (pretty sure it can't happen in mkv and some places pass in -1 by mistake)
|
||||||
delaySampleCount = Math.Max(delaySampleCount, 0);
|
delaySampleCount = Math.Max(delaySampleCount, 0);
|
||||||
|
|
||||||
var bitmaps = new List<Bitmap>();
|
var images = new List<Bitmap>();
|
||||||
var drawer = new SpectrogramDrawer(fftSize);
|
var drawer = new SpectrogramDrawer(fftSize);
|
||||||
var readSampleDataValue = GetSampleDataReader();
|
var readSampleDataValue = GetSampleDataReader();
|
||||||
Task saveImageTask = null;
|
Task saveImageTask = null;
|
||||||
@ -630,7 +732,7 @@ namespace Nikse.SubtitleEdit.Core
|
|||||||
|
|
||||||
// generate spectrogram for this chunk
|
// generate spectrogram for this chunk
|
||||||
Bitmap bmp = drawer.Draw(chunkSamples);
|
Bitmap bmp = drawer.Draw(chunkSamples);
|
||||||
bitmaps.Add(bmp);
|
images.Add(bmp);
|
||||||
|
|
||||||
// wait for previous image to finish saving
|
// wait for previous image to finish saving
|
||||||
if (saveImageTask != null)
|
if (saveImageTask != null)
|
||||||
@ -650,14 +752,15 @@ namespace Nikse.SubtitleEdit.Core
|
|||||||
|
|
||||||
var doc = new XmlDocument();
|
var doc = new XmlDocument();
|
||||||
var culture = CultureInfo.InvariantCulture;
|
var culture = CultureInfo.InvariantCulture;
|
||||||
|
double sampleDuration = (double)fftSize / _header.SampleRate;
|
||||||
doc.LoadXml("<SpectrogramInfo><SampleDuration/><NFFT/><ImageWidth/><SecondsPerImage/></SpectrogramInfo>");
|
doc.LoadXml("<SpectrogramInfo><SampleDuration/><NFFT/><ImageWidth/><SecondsPerImage/></SpectrogramInfo>");
|
||||||
doc.DocumentElement.SelectSingleNode("SampleDuration").InnerText = ((double)fftSize / _header.SampleRate).ToString(culture);
|
doc.DocumentElement.SelectSingleNode("SampleDuration").InnerText = sampleDuration.ToString(culture);
|
||||||
doc.DocumentElement.SelectSingleNode("NFFT").InnerText = fftSize.ToString(culture);
|
doc.DocumentElement.SelectSingleNode("NFFT").InnerText = fftSize.ToString(culture);
|
||||||
doc.DocumentElement.SelectSingleNode("ImageWidth").InnerText = imageWidth.ToString(culture);
|
doc.DocumentElement.SelectSingleNode("ImageWidth").InnerText = imageWidth.ToString(culture);
|
||||||
doc.DocumentElement.SelectSingleNode("SecondsPerImage").InnerText = ((double)chunkSampleCount / _header.SampleRate).ToString(culture); // currently unused; for backwards compatibility
|
doc.DocumentElement.SelectSingleNode("SecondsPerImage").InnerText = ((double)chunkSampleCount / _header.SampleRate).ToString(culture); // currently unused; for backwards compatibility
|
||||||
doc.Save(Path.Combine(spectrogramDirectory, "Info.xml"));
|
doc.Save(Path.Combine(spectrogramDirectory, "Info.xml"));
|
||||||
|
|
||||||
return bitmaps;
|
return new SpectrogramData(fftSize, imageWidth, sampleDuration, images);
|
||||||
}
|
}
|
||||||
|
|
||||||
private class SpectrogramDrawer
|
private class SpectrogramDrawer
|
||||||
|
@ -4,9 +4,8 @@ using System.Collections.Generic;
|
|||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
using System.Drawing.Drawing2D;
|
using System.Drawing.Drawing2D;
|
||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
using System.IO;
|
using System.Threading.Tasks;
|
||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
using System.Xml;
|
|
||||||
|
|
||||||
namespace Nikse.SubtitleEdit.Controls
|
namespace Nikse.SubtitleEdit.Controls
|
||||||
{
|
{
|
||||||
@ -83,12 +82,8 @@ namespace Nikse.SubtitleEdit.Controls
|
|||||||
private bool _noClear;
|
private bool _noClear;
|
||||||
private double _gapAtStart = -1;
|
private double _gapAtStart = -1;
|
||||||
|
|
||||||
private List<Bitmap> _spectrogramBitmaps = new List<Bitmap>();
|
private SpectrogramData _spectrogram;
|
||||||
private string _spectrogramDirectory;
|
|
||||||
private const int SpectrogramDisplayHeight = 128;
|
private const int SpectrogramDisplayHeight = 128;
|
||||||
private double _spectrogramSampleDuration;
|
|
||||||
private int _spectrogramImageWidth;
|
|
||||||
private int _spectrogramFftSize;
|
|
||||||
|
|
||||||
public delegate void ParagraphEventHandler(object sender, ParagraphEventArgs e);
|
public delegate void ParagraphEventHandler(object sender, ParagraphEventArgs e);
|
||||||
public event ParagraphEventHandler OnNewSelectionRightClicked;
|
public event ParagraphEventHandler OnNewSelectionRightClicked;
|
||||||
@ -107,7 +102,6 @@ namespace Nikse.SubtitleEdit.Controls
|
|||||||
|
|
||||||
private double _wholeParagraphMinMilliseconds;
|
private double _wholeParagraphMinMilliseconds;
|
||||||
private double _wholeParagraphMaxMilliseconds = double.MaxValue;
|
private double _wholeParagraphMaxMilliseconds = double.MaxValue;
|
||||||
private System.ComponentModel.BackgroundWorker _spectrogramBackgroundWorker;
|
|
||||||
public Keys InsertAtVideoPositionShortcut = Keys.None;
|
public Keys InsertAtVideoPositionShortcut = Keys.None;
|
||||||
public bool MouseWheelScrollUpIsForward = true;
|
public bool MouseWheelScrollUpIsForward = true;
|
||||||
|
|
||||||
@ -186,7 +180,7 @@ namespace Nikse.SubtitleEdit.Controls
|
|||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
return _spectrogramBitmaps != null && _spectrogramBitmaps.Count > 0;
|
return _spectrogram != null && _spectrogram.Images.Count > 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -208,7 +202,6 @@ namespace Nikse.SubtitleEdit.Controls
|
|||||||
}
|
}
|
||||||
|
|
||||||
public bool AllowOverlap { get; set; }
|
public bool AllowOverlap { get; set; }
|
||||||
private bool _tempShowSpectrogram;
|
|
||||||
|
|
||||||
private bool _showWaveform;
|
private bool _showWaveform;
|
||||||
public bool ShowWaveform
|
public bool ShowWaveform
|
||||||
@ -304,23 +297,12 @@ namespace Nikse.SubtitleEdit.Controls
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ResetSpectrogram()
|
public SpectrogramData Spectrogram
|
||||||
{
|
{
|
||||||
if (_spectrogramBitmaps != null)
|
set
|
||||||
{
|
{
|
||||||
for (int i = 0; i < _spectrogramBitmaps.Count; i++)
|
InitializeSpectrogram(value);
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
Bitmap bmp = _spectrogramBitmaps[i];
|
|
||||||
bmp.Dispose();
|
|
||||||
}
|
|
||||||
catch
|
|
||||||
{
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
_spectrogramBitmaps = new List<Bitmap>();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ClearSelection()
|
public void ClearSelection()
|
||||||
@ -1711,95 +1693,58 @@ namespace Nikse.SubtitleEdit.Controls
|
|||||||
|
|
||||||
/////////////////////////////////////////////////
|
/////////////////////////////////////////////////
|
||||||
|
|
||||||
public void InitializeSpectrogram(string spectrogramDirectory)
|
private void InitializeSpectrogram(SpectrogramData spectrogram)
|
||||||
{
|
{
|
||||||
_spectrogramBitmaps = new List<Bitmap>();
|
if (_spectrogram != null)
|
||||||
_tempShowSpectrogram = ShowSpectrogram;
|
|
||||||
ShowSpectrogram = false;
|
|
||||||
if (Directory.Exists(spectrogramDirectory))
|
|
||||||
{
|
{
|
||||||
_spectrogramDirectory = spectrogramDirectory;
|
_spectrogram.Dispose();
|
||||||
_spectrogramBackgroundWorker = new System.ComponentModel.BackgroundWorker();
|
_spectrogram = null;
|
||||||
_spectrogramBackgroundWorker.DoWork += LoadSpectrogramBitmapsAsync;
|
Invalidate();
|
||||||
_spectrogramBackgroundWorker.RunWorkerCompleted += LoadSpectrogramBitmapsCompleted;
|
|
||||||
_spectrogramBackgroundWorker.RunWorkerAsync();
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
private void LoadSpectrogramBitmapsCompleted(object sender, System.ComponentModel.RunWorkerCompletedEventArgs e)
|
if (spectrogram == null)
|
||||||
{
|
return;
|
||||||
LoadSpectrogramInfo(_spectrogramDirectory);
|
|
||||||
ShowSpectrogram = _tempShowSpectrogram;
|
|
||||||
if (_spectrogramBackgroundWorker != null)
|
|
||||||
_spectrogramBackgroundWorker.Dispose();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void LoadSpectrogramBitmapsAsync(object sender, System.ComponentModel.DoWorkEventArgs e)
|
if (spectrogram.IsLoaded)
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
{
|
||||||
for (var count = 0; ; count++)
|
InitializeSpectrogramInternal(spectrogram);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Task.Factory.StartNew(() =>
|
||||||
{
|
{
|
||||||
var fileName = Path.Combine(_spectrogramDirectory, count + ".gif");
|
spectrogram.Load();
|
||||||
|
BeginInvoke((Action)(() =>
|
||||||
// important that this does not lock file (do NOT use Image.FromFile(fileName) or alike!!!)
|
|
||||||
using (var ms = new MemoryStream(File.ReadAllBytes(fileName)))
|
|
||||||
{
|
{
|
||||||
_spectrogramBitmaps.Add((Bitmap)Image.FromStream(ms));
|
InitializeSpectrogramInternal(spectrogram);
|
||||||
}
|
}));
|
||||||
}
|
});
|
||||||
}
|
|
||||||
catch (FileNotFoundException)
|
|
||||||
{
|
|
||||||
// no more files
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void InitializeSpectrogram(List<Bitmap> spectrogramBitmaps, string spectrogramDirectory)
|
private void InitializeSpectrogramInternal(SpectrogramData spectrogram)
|
||||||
{
|
{
|
||||||
_spectrogramBitmaps = spectrogramBitmaps;
|
if (_spectrogram != null)
|
||||||
LoadSpectrogramInfo(spectrogramDirectory);
|
return;
|
||||||
}
|
|
||||||
|
|
||||||
private void LoadSpectrogramInfo(string spectrogramDirectory)
|
_spectrogram = spectrogram;
|
||||||
{
|
Invalidate();
|
||||||
try
|
|
||||||
{
|
|
||||||
var doc = new XmlDocument();
|
|
||||||
string xmlInfoFileName = Path.Combine(spectrogramDirectory, "Info.xml");
|
|
||||||
if (File.Exists(xmlInfoFileName))
|
|
||||||
{
|
|
||||||
doc.Load(xmlInfoFileName);
|
|
||||||
_spectrogramSampleDuration = Convert.ToDouble(doc.DocumentElement.SelectSingleNode("SampleDuration").InnerText, CultureInfo.InvariantCulture);
|
|
||||||
_spectrogramFftSize = Convert.ToInt32(doc.DocumentElement.SelectSingleNode("NFFT").InnerText, CultureInfo.InvariantCulture);
|
|
||||||
_spectrogramImageWidth = Convert.ToInt32(doc.DocumentElement.SelectSingleNode("ImageWidth").InnerText, CultureInfo.InvariantCulture);
|
|
||||||
ShowSpectrogram = true;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
ShowSpectrogram = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch
|
|
||||||
{
|
|
||||||
ShowSpectrogram = false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void DrawSpectrogram(Graphics graphics)
|
private void DrawSpectrogram(Graphics graphics)
|
||||||
{
|
{
|
||||||
int width = (int)Math.Round((EndPositionSeconds - StartPositionSeconds) / _spectrogramSampleDuration);
|
int width = (int)Math.Round((EndPositionSeconds - StartPositionSeconds) / _spectrogram.SampleDuration);
|
||||||
using (var bmpCombined = new Bitmap(width, _spectrogramFftSize / 2))
|
using (var bmpCombined = new Bitmap(width, _spectrogram.FftSize / 2))
|
||||||
using (var gfxCombined = Graphics.FromImage(bmpCombined))
|
using (var gfxCombined = Graphics.FromImage(bmpCombined))
|
||||||
{
|
{
|
||||||
int left = (int)Math.Round(StartPositionSeconds / _spectrogramSampleDuration);
|
int left = (int)Math.Round(StartPositionSeconds / _spectrogram.SampleDuration);
|
||||||
int offset = 0;
|
int offset = 0;
|
||||||
int imageIndex = left / _spectrogramImageWidth;
|
int imageIndex = left / _spectrogram.ImageWidth;
|
||||||
while (offset < width && imageIndex < _spectrogramBitmaps.Count)
|
while (offset < width && imageIndex < _spectrogram.Images.Count)
|
||||||
{
|
{
|
||||||
int x = (left + offset) % _spectrogramImageWidth;
|
int x = (left + offset) % _spectrogram.ImageWidth;
|
||||||
int w = Math.Min(_spectrogramImageWidth - x, width - offset);
|
int w = Math.Min(_spectrogram.ImageWidth - x, width - offset);
|
||||||
gfxCombined.DrawImage(_spectrogramBitmaps[imageIndex], offset, 0, new Rectangle(x, 0, w, bmpCombined.Height), GraphicsUnit.Pixel);
|
gfxCombined.DrawImage(_spectrogram.Images[imageIndex], offset, 0, new Rectangle(x, 0, w, bmpCombined.Height), GraphicsUnit.Pixel);
|
||||||
offset += w;
|
offset += w;
|
||||||
imageIndex++;
|
imageIndex++;
|
||||||
}
|
}
|
||||||
|
@ -18,7 +18,8 @@ namespace Nikse.SubtitleEdit.Forms
|
|||||||
private string _peakWaveFileName;
|
private string _peakWaveFileName;
|
||||||
private string _wavFileName;
|
private string _wavFileName;
|
||||||
private string _spectrogramDirectory;
|
private string _spectrogramDirectory;
|
||||||
public List<Bitmap> SpectrogramBitmaps { get; private set; }
|
public WavePeakData Peaks { get; private set; }
|
||||||
|
public SpectrogramData Spectrogram { get; private set; }
|
||||||
private string _encodeParamters;
|
private string _encodeParamters;
|
||||||
private const string RetryEncodeParameters = "acodec=s16l";
|
private const string RetryEncodeParameters = "acodec=s16l";
|
||||||
private int _audioTrackNumber = -1;
|
private int _audioTrackNumber = -1;
|
||||||
@ -236,13 +237,13 @@ namespace Nikse.SubtitleEdit.Forms
|
|||||||
|
|
||||||
using (var waveFile = new WavePeakGenerator(targetFile))
|
using (var waveFile = new WavePeakGenerator(targetFile))
|
||||||
{
|
{
|
||||||
waveFile.GeneratePeaks(delayInMilliseconds, _peakWaveFileName);
|
Peaks = waveFile.GeneratePeaks(delayInMilliseconds, _peakWaveFileName);
|
||||||
|
|
||||||
if (Configuration.Settings.VideoControls.GenerateSpectrogram)
|
if (Configuration.Settings.VideoControls.GenerateSpectrogram)
|
||||||
{
|
{
|
||||||
labelProgress.Text = Configuration.Settings.Language.AddWaveform.GeneratingSpectrogram;
|
labelProgress.Text = Configuration.Settings.Language.AddWaveform.GeneratingSpectrogram;
|
||||||
Refresh();
|
Refresh();
|
||||||
SpectrogramBitmaps = waveFile.GenerateSpectrogram(_spectrogramDirectory, delayInMilliseconds);
|
Spectrogram = waveFile.GenerateSpectrogram(delayInMilliseconds, _spectrogramDirectory);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -333,7 +333,7 @@ namespace Nikse.SubtitleEdit.Forms
|
|||||||
|
|
||||||
if (Configuration.Settings.VideoControls.GenerateSpectrogram)
|
if (Configuration.Settings.VideoControls.GenerateSpectrogram)
|
||||||
{
|
{
|
||||||
waveFile.GenerateSpectrogram(Main.GetSpectrogramFolder(videoFileName), delayInMilliseconds);
|
waveFile.GenerateSpectrogram(delayInMilliseconds, Main.GetSpectrogramFolder(videoFileName));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2552,8 +2552,7 @@ namespace Nikse.SubtitleEdit.Forms
|
|||||||
_videoAudioTrackNumber = -1;
|
_videoAudioTrackNumber = -1;
|
||||||
labelVideoInfo.Text = _languageGeneral.NoVideoLoaded;
|
labelVideoInfo.Text = _languageGeneral.NoVideoLoaded;
|
||||||
audioVisualizer.WavePeaks = null;
|
audioVisualizer.WavePeaks = null;
|
||||||
audioVisualizer.ResetSpectrogram();
|
audioVisualizer.Spectrogram = null;
|
||||||
audioVisualizer.Invalidate();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Configuration.Settings.General.ShowVideoPlayer || Configuration.Settings.General.ShowAudioVisualizer)
|
if (Configuration.Settings.General.ShowVideoPlayer || Configuration.Settings.General.ShowAudioVisualizer)
|
||||||
@ -2643,8 +2642,7 @@ namespace Nikse.SubtitleEdit.Forms
|
|||||||
_videoAudioTrackNumber = -1;
|
_videoAudioTrackNumber = -1;
|
||||||
labelVideoInfo.Text = _languageGeneral.NoVideoLoaded;
|
labelVideoInfo.Text = _languageGeneral.NoVideoLoaded;
|
||||||
audioVisualizer.WavePeaks = null;
|
audioVisualizer.WavePeaks = null;
|
||||||
audioVisualizer.ResetSpectrogram();
|
audioVisualizer.Spectrogram = null;
|
||||||
audioVisualizer.Invalidate();
|
|
||||||
|
|
||||||
Configuration.Settings.RecentFiles.Add(fileName, FirstVisibleIndex, FirstSelectedIndex, _videoFileName, _subtitleAlternateFileName);
|
Configuration.Settings.RecentFiles.Add(fileName, FirstVisibleIndex, FirstSelectedIndex, _videoFileName, _subtitleAlternateFileName);
|
||||||
Configuration.Settings.Save();
|
Configuration.Settings.Save();
|
||||||
@ -3301,8 +3299,7 @@ namespace Nikse.SubtitleEdit.Forms
|
|||||||
_videoAudioTrackNumber = -1;
|
_videoAudioTrackNumber = -1;
|
||||||
labelVideoInfo.Text = _languageGeneral.NoVideoLoaded;
|
labelVideoInfo.Text = _languageGeneral.NoVideoLoaded;
|
||||||
audioVisualizer.WavePeaks = null;
|
audioVisualizer.WavePeaks = null;
|
||||||
audioVisualizer.ResetSpectrogram();
|
audioVisualizer.Spectrogram = null;
|
||||||
audioVisualizer.Invalidate();
|
|
||||||
|
|
||||||
_sourceViewChange = false;
|
_sourceViewChange = false;
|
||||||
|
|
||||||
@ -12678,10 +12675,8 @@ namespace Nikse.SubtitleEdit.Forms
|
|||||||
string spectrogramFolder = GetSpectrogramFolder(fileName);
|
string spectrogramFolder = GetSpectrogramFolder(fileName);
|
||||||
if (File.Exists(peakWaveFileName))
|
if (File.Exists(peakWaveFileName))
|
||||||
{
|
{
|
||||||
using (var peakGenerator = new WavePeakGenerator(peakWaveFileName))
|
audioVisualizer.WavePeaks = WavePeakData.FromDisk(peakWaveFileName);
|
||||||
audioVisualizer.WavePeaks = peakGenerator.LoadPeaks();
|
audioVisualizer.Spectrogram = SpectrogramData.FromDisk(spectrogramFolder);
|
||||||
audioVisualizer.ResetSpectrogram();
|
|
||||||
audioVisualizer.InitializeSpectrogram(spectrogramFolder);
|
|
||||||
toolStripComboBoxWaveform_SelectedIndexChanged(null, null);
|
toolStripComboBoxWaveform_SelectedIndexChanged(null, null);
|
||||||
SetWaveformPosition(0, 0, 0);
|
SetWaveformPosition(0, 0, 0);
|
||||||
timerWaveform.Start();
|
timerWaveform.Start();
|
||||||
@ -13424,8 +13419,7 @@ namespace Nikse.SubtitleEdit.Forms
|
|||||||
if (audioVisualizer.WavePeaks != null)
|
if (audioVisualizer.WavePeaks != null)
|
||||||
{
|
{
|
||||||
audioVisualizer.WavePeaks = null;
|
audioVisualizer.WavePeaks = null;
|
||||||
audioVisualizer.ResetSpectrogram();
|
audioVisualizer.Spectrogram = null;
|
||||||
audioVisualizer.Invalidate();
|
|
||||||
}
|
}
|
||||||
openFileDialog1.InitialDirectory = Path.GetDirectoryName(openFileDialog1.FileName);
|
openFileDialog1.InitialDirectory = Path.GetDirectoryName(openFileDialog1.FileName);
|
||||||
if (!panelVideoPlayer.Visible)
|
if (!panelVideoPlayer.Visible)
|
||||||
@ -14825,10 +14819,8 @@ namespace Nikse.SubtitleEdit.Forms
|
|||||||
}
|
}
|
||||||
if (addWaveform.ShowDialog() == DialogResult.OK)
|
if (addWaveform.ShowDialog() == DialogResult.OK)
|
||||||
{
|
{
|
||||||
using (var peakGenerator = new WavePeakGenerator(peakWaveFileName))
|
audioVisualizer.WavePeaks = addWaveform.Peaks;
|
||||||
audioVisualizer.WavePeaks = peakGenerator.LoadPeaks();
|
audioVisualizer.Spectrogram = addWaveform.Spectrogram;
|
||||||
if (addWaveform.SpectrogramBitmaps != null)
|
|
||||||
audioVisualizer.InitializeSpectrogram(addWaveform.SpectrogramBitmaps, spectrogramFolder);
|
|
||||||
timerWaveform.Start();
|
timerWaveform.Start();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -15199,17 +15191,20 @@ namespace Nikse.SubtitleEdit.Forms
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (_videoFileName == null)
|
if (_videoFileName == null)
|
||||||
|
{
|
||||||
OpenVideo(fileName);
|
OpenVideo(fileName);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
using (var addWaveform = new AddWaveform())
|
using (var addWaveform = new AddWaveform())
|
||||||
{
|
{
|
||||||
string spectrogramFolder = GetSpectrogramFolder(_videoFileName);
|
|
||||||
string peakWaveFileName = GetPeakWaveFileName(_videoFileName);
|
string peakWaveFileName = GetPeakWaveFileName(_videoFileName);
|
||||||
|
string spectrogramFolder = GetSpectrogramFolder(_videoFileName);
|
||||||
addWaveform.InitializeViaWaveFile(fileName, peakWaveFileName, spectrogramFolder);
|
addWaveform.InitializeViaWaveFile(fileName, peakWaveFileName, spectrogramFolder);
|
||||||
if (addWaveform.ShowDialog() == DialogResult.OK)
|
if (addWaveform.ShowDialog() == DialogResult.OK)
|
||||||
{
|
{
|
||||||
using (var peakGenerator = new WavePeakGenerator(peakWaveFileName))
|
audioVisualizer.WavePeaks = addWaveform.Peaks;
|
||||||
audioVisualizer.WavePeaks = peakGenerator.LoadPeaks();
|
audioVisualizer.Spectrogram = addWaveform.Spectrogram;
|
||||||
timerWaveform.Start();
|
timerWaveform.Start();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -16494,8 +16489,7 @@ namespace Nikse.SubtitleEdit.Forms
|
|||||||
_videoAudioTrackNumber = -1;
|
_videoAudioTrackNumber = -1;
|
||||||
labelVideoInfo.Text = _languageGeneral.NoVideoLoaded;
|
labelVideoInfo.Text = _languageGeneral.NoVideoLoaded;
|
||||||
audioVisualizer.WavePeaks = null;
|
audioVisualizer.WavePeaks = null;
|
||||||
audioVisualizer.ResetSpectrogram();
|
audioVisualizer.Spectrogram = null;
|
||||||
audioVisualizer.Invalidate();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ToolStripMenuItemVideoDropDownOpening(object sender, EventArgs e)
|
private void ToolStripMenuItemVideoDropDownOpening(object sender, EventArgs e)
|
||||||
|
Loading…
Reference in New Issue
Block a user