Try to improve detect of video info - thx Janjens :)

This commit is contained in:
niksedk 2021-10-03 09:45:08 +02:00
parent 0ed4b07c01
commit 349f5b00c6
4 changed files with 181 additions and 61 deletions

View File

@ -40,9 +40,9 @@ namespace Nikse.SubtitleEdit.Forms
{
this.components = new System.ComponentModel.Container();
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Main));
Nikse.SubtitleEdit.Core.Common.TimeCode timeCode4 = new Nikse.SubtitleEdit.Core.Common.TimeCode();
Nikse.SubtitleEdit.Core.Common.TimeCode timeCode5 = new Nikse.SubtitleEdit.Core.Common.TimeCode();
Nikse.SubtitleEdit.Core.Common.TimeCode timeCode6 = new Nikse.SubtitleEdit.Core.Common.TimeCode();
Nikse.SubtitleEdit.Core.Common.TimeCode timeCode1 = new Nikse.SubtitleEdit.Core.Common.TimeCode();
Nikse.SubtitleEdit.Core.Common.TimeCode timeCode2 = new Nikse.SubtitleEdit.Core.Common.TimeCode();
Nikse.SubtitleEdit.Core.Common.TimeCode timeCode3 = new Nikse.SubtitleEdit.Core.Common.TimeCode();
this.statusStrip1 = new System.Windows.Forms.StatusStrip();
this.labelStatus = new System.Windows.Forms.ToolStripStatusLabel();
this.toolStripSelected = new System.Windows.Forms.ToolStripStatusLabel();
@ -279,6 +279,9 @@ namespace Nikse.SubtitleEdit.Forms
this.toolStripMenuItemSetLanguage = new System.Windows.Forms.ToolStripMenuItem();
this.toolStripMenuItemWebVTT = new System.Windows.Forms.ToolStripMenuItem();
this.toolStripMenuItemPreview = new System.Windows.Forms.ToolStripMenuItem();
this.toolStripMenuItemInsertBefore = new System.Windows.Forms.ToolStripMenuItem();
this.toolStripMenuItemInsertAfter = new System.Windows.Forms.ToolStripMenuItem();
this.toolStripMenuItemInsertSubtitle = new System.Windows.Forms.ToolStripMenuItem();
this.toolStripMenuItemDelete = new System.Windows.Forms.ToolStripMenuItem();
this.toolStripMenuItemCopySourceText = new System.Windows.Forms.ToolStripMenuItem();
this.toolStripMenuItemColumn = new System.Windows.Forms.ToolStripMenuItem();
@ -552,9 +555,6 @@ namespace Nikse.SubtitleEdit.Forms
this.imageListPlayRate = new System.Windows.Forms.ImageList(this.components);
this.timerTextUndo = new System.Windows.Forms.Timer(this.components);
this.timerOriginalTextUndo = new System.Windows.Forms.Timer(this.components);
this.toolStripMenuItemInsertBefore = new System.Windows.Forms.ToolStripMenuItem();
this.toolStripMenuItemInsertAfter = new System.Windows.Forms.ToolStripMenuItem();
this.toolStripMenuItemInsertSubtitle = new System.Windows.Forms.ToolStripMenuItem();
this.statusStrip1.SuspendLayout();
this.toolStrip1.SuspendLayout();
this.menuStrip1.SuspendLayout();
@ -2545,7 +2545,7 @@ namespace Nikse.SubtitleEdit.Forms
this.toolStripMenuItemSelectedLines,
this.toolStripMenuItemGoogleMicrosoftTranslateSelLine});
this.contextMenuStripListView.Name = "contextMenuStripListView";
this.contextMenuStripListView.Size = new System.Drawing.Size(285, 798);
this.contextMenuStripListView.Size = new System.Drawing.Size(285, 776);
this.contextMenuStripListView.Closed += new System.Windows.Forms.ToolStripDropDownClosedEventHandler(this.MenuClosed);
this.contextMenuStripListView.Opening += new System.ComponentModel.CancelEventHandler(this.ContextMenuStripListViewOpening);
this.contextMenuStripListView.Opened += new System.EventHandler(this.MenuOpened);
@ -2638,6 +2638,27 @@ namespace Nikse.SubtitleEdit.Forms
this.toolStripMenuItemPreview.Text = "WebVTT browser preview";
this.toolStripMenuItemPreview.Click += new System.EventHandler(this.toolStripMenuItemPreview_Click);
//
// toolStripMenuItemInsertBefore
//
this.toolStripMenuItemInsertBefore.Name = "toolStripMenuItemInsertBefore";
this.toolStripMenuItemInsertBefore.Size = new System.Drawing.Size(284, 22);
this.toolStripMenuItemInsertBefore.Text = "Insert before";
this.toolStripMenuItemInsertBefore.Click += new System.EventHandler(this.ToolStripMenuItemInsertBeforeClick);
//
// toolStripMenuItemInsertAfter
//
this.toolStripMenuItemInsertAfter.Name = "toolStripMenuItemInsertAfter";
this.toolStripMenuItemInsertAfter.Size = new System.Drawing.Size(284, 22);
this.toolStripMenuItemInsertAfter.Text = "Insert after";
this.toolStripMenuItemInsertAfter.Click += new System.EventHandler(this.ToolStripMenuItemInsertAfterClick);
//
// toolStripMenuItemInsertSubtitle
//
this.toolStripMenuItemInsertSubtitle.Name = "toolStripMenuItemInsertSubtitle";
this.toolStripMenuItemInsertSubtitle.Size = new System.Drawing.Size(284, 22);
this.toolStripMenuItemInsertSubtitle.Text = "Insert subtitle file after this line...";
this.toolStripMenuItemInsertSubtitle.Click += new System.EventHandler(this.ToolStripMenuItemInsertSubtitleClick);
//
// toolStripMenuItemDelete
//
this.toolStripMenuItemDelete.Name = "toolStripMenuItemDelete";
@ -3565,14 +3586,14 @@ namespace Nikse.SubtitleEdit.Forms
this.timeUpDownVideoPosition.Name = "timeUpDownVideoPosition";
this.timeUpDownVideoPosition.Size = new System.Drawing.Size(111, 27);
this.timeUpDownVideoPosition.TabIndex = 12;
timeCode4.Hours = 0;
timeCode4.Milliseconds = 0;
timeCode4.Minutes = 0;
timeCode4.Seconds = 0;
timeCode4.TimeSpan = System.TimeSpan.Parse("00:00:00");
timeCode4.TotalMilliseconds = 0D;
timeCode4.TotalSeconds = 0D;
this.timeUpDownVideoPosition.TimeCode = timeCode4;
timeCode1.Hours = 0;
timeCode1.Milliseconds = 0;
timeCode1.Minutes = 0;
timeCode1.Seconds = 0;
timeCode1.TimeSpan = System.TimeSpan.Parse("00:00:00");
timeCode1.TotalMilliseconds = 0D;
timeCode1.TotalSeconds = 0D;
this.timeUpDownVideoPosition.TimeCode = timeCode1;
this.timeUpDownVideoPosition.UseVideoOffset = false;
//
// buttonGotoSub
@ -3805,14 +3826,14 @@ namespace Nikse.SubtitleEdit.Forms
this.timeUpDownVideoPositionAdjust.Name = "timeUpDownVideoPositionAdjust";
this.timeUpDownVideoPositionAdjust.Size = new System.Drawing.Size(111, 27);
this.timeUpDownVideoPositionAdjust.TabIndex = 13;
timeCode5.Hours = 0;
timeCode5.Milliseconds = 0;
timeCode5.Minutes = 0;
timeCode5.Seconds = 0;
timeCode5.TimeSpan = System.TimeSpan.Parse("00:00:00");
timeCode5.TotalMilliseconds = 0D;
timeCode5.TotalSeconds = 0D;
this.timeUpDownVideoPositionAdjust.TimeCode = timeCode5;
timeCode2.Hours = 0;
timeCode2.Milliseconds = 0;
timeCode2.Minutes = 0;
timeCode2.Seconds = 0;
timeCode2.TimeSpan = System.TimeSpan.Parse("00:00:00");
timeCode2.TotalMilliseconds = 0D;
timeCode2.TotalSeconds = 0D;
this.timeUpDownVideoPositionAdjust.TimeCode = timeCode2;
this.timeUpDownVideoPositionAdjust.UseVideoOffset = false;
//
// buttonAdjustSetEndTime
@ -5014,14 +5035,14 @@ namespace Nikse.SubtitleEdit.Forms
this.timeUpDownStartTime.Name = "timeUpDownStartTime";
this.timeUpDownStartTime.Size = new System.Drawing.Size(111, 27);
this.timeUpDownStartTime.TabIndex = 0;
timeCode6.Hours = 0;
timeCode6.Milliseconds = 0;
timeCode6.Minutes = 0;
timeCode6.Seconds = 0;
timeCode6.TimeSpan = System.TimeSpan.Parse("00:00:00");
timeCode6.TotalMilliseconds = 0D;
timeCode6.TotalSeconds = 0D;
this.timeUpDownStartTime.TimeCode = timeCode6;
timeCode3.Hours = 0;
timeCode3.Milliseconds = 0;
timeCode3.Minutes = 0;
timeCode3.Seconds = 0;
timeCode3.TimeSpan = System.TimeSpan.Parse("00:00:00");
timeCode3.TotalMilliseconds = 0D;
timeCode3.TotalSeconds = 0D;
this.timeUpDownStartTime.TimeCode = timeCode3;
this.timeUpDownStartTime.UseVideoOffset = false;
//
// numericUpDownDuration
@ -5376,27 +5397,6 @@ namespace Nikse.SubtitleEdit.Forms
this.timerOriginalTextUndo.Interval = 700;
this.timerOriginalTextUndo.Tick += new System.EventHandler(this.TimerOriginalTextUndoTick);
//
// toolStripMenuItemInsertBefore
//
this.toolStripMenuItemInsertBefore.Name = "toolStripMenuItemInsertBefore";
this.toolStripMenuItemInsertBefore.Size = new System.Drawing.Size(284, 22);
this.toolStripMenuItemInsertBefore.Text = "Insert before";
this.toolStripMenuItemInsertBefore.Click += new System.EventHandler(this.ToolStripMenuItemInsertBeforeClick);
//
// toolStripMenuItemInsertAfter
//
this.toolStripMenuItemInsertAfter.Name = "toolStripMenuItemInsertAfter";
this.toolStripMenuItemInsertAfter.Size = new System.Drawing.Size(284, 22);
this.toolStripMenuItemInsertAfter.Text = "Insert after";
this.toolStripMenuItemInsertAfter.Click += new System.EventHandler(this.ToolStripMenuItemInsertAfterClick);
//
// toolStripMenuItemInsertSubtitle
//
this.toolStripMenuItemInsertSubtitle.Name = "toolStripMenuItemInsertSubtitle";
this.toolStripMenuItemInsertSubtitle.Size = new System.Drawing.Size(284, 22);
this.toolStripMenuItemInsertSubtitle.Text = "Insert subtitle file after this line...";
this.toolStripMenuItemInsertSubtitle.Click += new System.EventHandler(this.ToolStripMenuItemInsertSubtitleClick);
//
// Main
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);

View File

@ -538,7 +538,7 @@
<data name="toolStripButtonAssaDraw.Image" type="System.Drawing.Bitmap, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>
iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8
YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAIvSURBVFhH1ZZNSxtRFIaH4qYFXUiFolGr7sSNHyD6H/wZ
YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAIvSURBVFhH1ZZNSxtRFIaH4qYFXUiloFGr7sSNHyD6H/wZ
dVNsbGx+hgtJYiYhGxdC/Igbf0QXCgrd2C7bKNguKnRVQpi+5+SeeDs5JnNnVPSBh5k7k3vfd27CEO/Z
4ft+UCqVnDRTk1Mul4M43FsJWohZnY8uSFRAtjGXy7GMFnSXIFaB9tN2QwsMC5wL2OEeTjv0zU1CC7UF
TgXoVy6o4ZZttGAROBVoNps8SQvUZK5/6OEkiFxAtp62WAtT3eYpejgJ3AuEQ3rIaOEkiF1A8PK31zQZ
@ -547,7 +547,7 @@
Z82l6NBCxM5ZRg0XhXw+T+FfzHTGLnD9KeNWwqyrhtrunG20Phf6bo8QTgUOJsfdd0GeXgvUJBqNxn8B
FE7upVIvpUA9nc6a292RAq6Y6d7+RGpLCtC4nvlwHmsXXMT/w19mavvpDyZHL8wlz7lAEuynF+of0+6/
hThIOPtm6K/t4xcIKQUerIQWars/MfY4BcxQRQr8zDq+mHpxhBdOlAJX6+8XHmQXJNwfHV7BcAAOwtdw
yBxp3A9vX0xra8sYJ6YPvoIUMAKn4AychYtwyRzn4DSk+8OQPk/zXsCnguf9A/y4fDo5isePAAAAAElF
yBxp3A9vX0xra8sYJ6YPvoIUMAKn4AychYtwyRzn4DSk+8OQPk/zXsCnguf9A+3ofDbQynoiAAAAAElF
TkSuQmCC
</value>
</data>
@ -682,9 +682,6 @@
<metadata name="toolStripWaveControls.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>652, 56</value>
</metadata>
<metadata name="toolStripWaveControls.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>652, 56</value>
</metadata>
<data name="toolStripButtonWaveformZoomOut.Image" type="System.Drawing.Bitmap, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>
iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8
@ -777,12 +774,12 @@
<metadata name="imageListBookmarks.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>981, 56</value>
</metadata>
<metadata name="contextMenuStripTextBoxSourceView.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>193, 17</value>
</metadata>
<metadata name="contextMenuStripTextBoxListView.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>668, 17</value>
</metadata>
<metadata name="contextMenuStripTextBoxSourceView.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>193, 17</value>
</metadata>
<metadata name="contextMenuStripEmpty.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 95</value>
</metadata>
@ -794,7 +791,7 @@
AAEAAAD/////AQAAAAAAAAAMAgAAAFdTeXN0ZW0uV2luZG93cy5Gb3JtcywgVmVyc2lvbj00LjAuMC4w
LCBDdWx0dXJlPW5ldXRyYWwsIFB1YmxpY0tleVRva2VuPWI3N2E1YzU2MTkzNGUwODkFAQAAACZTeXN0
ZW0uV2luZG93cy5Gb3Jtcy5JbWFnZUxpc3RTdHJlYW1lcgEAAAAERGF0YQcCAgAAAAkDAAAADwMAAAD2
CAAAAk1TRnQBSQFMAgEBAgEAAewBKwHsASsBEAEAARABAAT/AQkBAAj/AUIBTQE2AQQGAAE2AQQCAAEo
CAAAAk1TRnQBSQFMAgEBAgEAAfQBKwH0ASsBEAEAARABAAT/AQkBAAj/AUIBTQE2AQQGAAE2AQQCAAEo
AwABQAMAARADAAEBAQABCAYAAQQYAAGAAgABgAMAAoABAAGAAwABgAEAAYABAAKAAgADwAEAAcAB3AHA
AQAB8AHKAaYBAAEzBQABMwEAATMBAAEzAQACMwIAAxYBAAMcAQADIgEAAykBAANVAQADTQEAA0IBAAM5
AQABgAF8Af8BAAJQAf8BAAGTAQAB1gEAAf8B7AHMAQABxgHWAe8BAAHWAucBAAGQAakBrQIAAf8BMwMA

View File

@ -47,6 +47,12 @@ namespace Nikse.SubtitleEdit.Logic
return info;
}
info = TryReadVideoInfoViaLibMpv(fileName);
if (info.Success)
{
return info;
}
return new VideoInfo { VideoCodec = "Unknown" };
}
@ -55,6 +61,11 @@ namespace Nikse.SubtitleEdit.Logic
return QuartsPlayer.GetVideoInfo(fileName);
}
private static VideoInfo TryReadVideoInfoViaLibMpv(string fileName)
{
return LibMpvDynamic.GetVideoInfo(fileName);
}
private static long _lastShowSubTicks = DateTime.UtcNow.Ticks;
private static int _lastShowSubHash;

View File

@ -45,6 +45,7 @@ namespace Nikse.SubtitleEdit.Logic.VideoPlayers
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
private delegate int MpvGetPropertyDouble(IntPtr mpvHandle, byte[] name, int format, ref double data);
private MpvGetPropertyDouble _mpvGetPropertyDouble;
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
@ -327,6 +328,83 @@ namespace Nikse.SubtitleEdit.Logic.VideoPlayers
}
}
public int VideoWidth
{
get
{
if (_mpvHandle == IntPtr.Zero)
{
return 0;
}
int mpvFormatDouble = 5;
double d = 0;
_mpvGetPropertyDouble(_mpvHandle, GetUtf8Bytes("width"), mpvFormatDouble, ref d);
return (int)d;
}
}
public int VideoHeight
{
get
{
if (_mpvHandle == IntPtr.Zero)
{
return 0;
}
int mpvFormatDouble = 5;
double d = 0;
_mpvGetPropertyDouble(_mpvHandle, GetUtf8Bytes("height"), mpvFormatDouble, ref d);
return (int)d;
}
}
public int VideoTotalFrames
{
get
{
if (_mpvHandle == IntPtr.Zero)
{
return 0;
}
int mpvFormatDouble = 5;
double d = 0;
_mpvGetPropertyDouble(_mpvHandle, GetUtf8Bytes("estimated-frame-count"), mpvFormatDouble, ref d);
return (int)d;
}
}
public double VideoFps
{
get
{
if (_mpvHandle == IntPtr.Zero)
{
return 0;
}
int mpvFormatDouble = 5;
double d = 0;
_mpvGetPropertyDouble(_mpvHandle, GetUtf8Bytes("container-fps"), mpvFormatDouble, ref d);
return d;
}
}
public string VideoCodec
{
get
{
if (_mpvHandle == IntPtr.Zero)
{
return string.Empty;
}
var lpBuffer = IntPtr.Zero;
_mpvGetPropertyString(_mpvHandle, GetUtf8Bytes("video-codec"), MpvFormatString, ref lpBuffer);
var codec = Marshal.PtrToStringAnsi(lpBuffer);
_mpvFree(lpBuffer);
return codec;
}
}
public override bool IsPlaying => !IsPaused;
private List<KeyValuePair<int, string>> _audioTrackIds;
@ -760,5 +838,39 @@ namespace Nikse.SubtitleEdit.Logic.VideoPlayers
_mpvSetOptionString(_mpvHandle, GetUtf8Bytes("contrast"), GetUtf8Bytes(_contrast.ToString(CultureInfo.InvariantCulture)));
return _contrast;
}
internal static VideoInfo GetVideoInfo(string fileName)
{
var info = new VideoInfo { Success = false };
try
{
var libmpv = new LibMpvDynamic();
libmpv.Initialize(null, fileName, null, null);
for (int i = 0; i < 10; i++)
{
System.Threading.Thread.Sleep(10);
Application.DoEvents();
}
info.Width = libmpv.VideoWidth;
info.Height = libmpv.VideoHeight;
info.TotalSeconds = libmpv.Duration;
info.TotalMilliseconds = info.TotalSeconds * 1000.0;
info.TotalFrames = libmpv.VideoTotalFrames;
info.VideoCodec = libmpv.VideoCodec;
info.FramesPerSecond = libmpv.VideoFps;
info.FileType = Path.GetExtension(fileName).TrimStart('.');
info.Success = true;
libmpv.HardDispose();
}
catch
{
// ignored
}
return info;
}
}
}