Fixed two issues regarding new mpv - thx aaaxx :)

This commit is contained in:
Nikolaj Olsson 2016-02-28 10:58:19 +01:00
parent 703a799da7
commit a83ca22973
11 changed files with 190 additions and 69 deletions

View File

@ -1745,6 +1745,11 @@ can edit in same subtitle file (collaboration)</Information>
<Miscellaneous>Misc.</Miscellaneous>
<UseDoNotBreakAfterList>Use do-not-break-after list (for auto-br)</UseDoNotBreakAfterList>
</Settings>
<SettingsMpv>
<Title>Settings for mpv</Title>
<DownloadMpv>Download mpv dll</DownloadMpv>
<DownloadMpvFailed>Unable to download mpv - please re-try later!</DownloadMpvFailed>
</SettingsMpv>
<SetVideoOffset>
<Title>Set video offset</Title>
<Description>Set video offset (subtitles should not follow real video time, but e.g. +10 hours)</Description>

View File

@ -79,6 +79,7 @@ namespace Nikse.SubtitleEdit.Core
public LanguageStructure.SetMinimumDisplayTimeBetweenParagraphs SetMinimumDisplayTimeBetweenParagraphs;
public LanguageStructure.SetSyncPoint SetSyncPoint;
public LanguageStructure.Settings Settings;
public LanguageStructure.SettingsMpv SettingsMpv;
public LanguageStructure.SetVideoOffset SetVideoOffset;
public LanguageStructure.ShowEarlierLater ShowEarlierLater;
public LanguageStructure.ShowHistory ShowHistory;
@ -2023,6 +2024,13 @@ can edit in same subtitle file (collaboration)",
UseDoNotBreakAfterList = "Use do-not-break-after list (for auto-br)",
};
SettingsMpv = new LanguageStructure.SettingsMpv
{
Title = "Settings for mpv",
DownloadMpv = "Download mpv dll",
DownloadMpvFailed = "Unable to download mpv - please re-try later!",
};
SetVideoOffset = new LanguageStructure.SetVideoOffset
{
Title = "Set video offset",

View File

@ -4687,6 +4687,15 @@ namespace Nikse.SubtitleEdit.Core
case "Settings/UseDoNotBreakAfterList":
language.Settings.UseDoNotBreakAfterList = reader.Value;
break;
case "SettingsMpv/Title":
language.SettingsMpv.Title = reader.Value;
break;
case "SettingsMpv/DownloadMpv":
language.SettingsMpv.DownloadMpv = reader.Value;
break;
case "SettingsMpv/DownloadMpvFailed":
language.SettingsMpv.DownloadMpvFailed = reader.Value;
break;
case "SetVideoOffset/Title":
language.SetVideoOffset.Title = reader.Value;
break;

View File

@ -1905,6 +1905,12 @@
public string UseDoNotBreakAfterList { get; set; }
}
public class SettingsMpv
{
public string Title { get; set; }
public string DownloadMpv { get; set; }
public string DownloadMpvFailed { get; set; }
}
public class SetVideoOffset
{
public string Title { get; set; }

View File

@ -534,6 +534,7 @@ namespace Nikse.SubtitleEdit.Core
public string VlcWaveTranscodeSettings { get; set; }
public string VlcLocation { get; set; }
public string VlcLocationRelative { get; set; }
public string MpvVideoOutput { get; set; }
public string MpcHcLocation { get; set; }
public bool UseFFmpegForWaveExtraction { get; set; }
public string FFmpegLocation { get; set; }
@ -626,6 +627,7 @@ namespace Nikse.SubtitleEdit.Core
OpenSubtitleExtraExtensions = "*.mp4;*.m4v;*.mkv;*.ts"; // matroska/mp4/m4v files (can contain subtitles)
ListViewColumnsRememberSize = true;
VlcWaveTranscodeSettings = "acodec=s16l"; // "acodec=s16l,channels=1,ab=64,samplerate=8000";
MpvVideoOutput = "vdpau"; // mpv "vo" option
UseTimeFormatHHMMSSFF = false;
ClearStatusBarAfterSeconds = 10;
MoveVideo100Or500MsPlaySmallSample = false;
@ -1483,6 +1485,9 @@ namespace Nikse.SubtitleEdit.Core
subNode = node.SelectSingleNode("VlcLocationRelative");
if (subNode != null)
settings.General.VlcLocationRelative = subNode.InnerText.Trim();
subNode = node.SelectSingleNode("MpvVideoOutput");
if (subNode != null)
settings.General.MpvVideoOutput = subNode.InnerText.Trim();
subNode = node.SelectSingleNode("MpcHcLocation");
if (subNode != null)
settings.General.MpcHcLocation = subNode.InnerText.Trim();
@ -2838,6 +2843,7 @@ namespace Nikse.SubtitleEdit.Core
textWriter.WriteElementString("VlcWaveTranscodeSettings", settings.General.VlcWaveTranscodeSettings);
textWriter.WriteElementString("VlcLocation", settings.General.VlcLocation);
textWriter.WriteElementString("VlcLocationRelative", settings.General.VlcLocationRelative);
textWriter.WriteElementString("MpvVideoOutput", settings.General.MpvVideoOutput);
textWriter.WriteElementString("MpcHcLocation", settings.General.MpcHcLocation);
textWriter.WriteElementString("UseFFmpegForWaveExtraction", settings.General.UseFFmpegForWaveExtraction.ToString(CultureInfo.InvariantCulture));
textWriter.WriteElementString("FFmpegLocation", settings.General.FFmpegLocation);

View File

@ -12811,10 +12811,10 @@ namespace Nikse.SubtitleEdit.Forms
toolStripComboBoxFrameRate.Text = string.Format("{0:0.###}", _videoInfo.FramesPerSecond);
UiUtil.InitializeVideoPlayerAndContainer(fileName, _videoInfo, mediaPlayer, VideoLoaded, VideoEnded);
mediaPlayer.Volume = 0;
mediaPlayer.ShowFullscreenButton = Configuration.Settings.General.VideoPlayerShowFullscreenButton;
mediaPlayer.OnButtonClicked -= MediaPlayer_OnButtonClicked;
mediaPlayer.OnButtonClicked += MediaPlayer_OnButtonClicked;
mediaPlayer.Volume = 0;
if (_videoInfo.VideoCodec != null)
labelVideoInfo.Text = Path.GetFileName(fileName) + " " + _videoInfo.Width + "x" + _videoInfo.Height + " " + _videoInfo.VideoCodec.Trim();

View File

@ -147,6 +147,7 @@
this.comboBoxlVideoPlayerPreviewFontSize = new System.Windows.Forms.ComboBox();
this.checkBoxVideoPlayerShowStopButton = new System.Windows.Forms.CheckBox();
this.groupBoxVideoEngine = new System.Windows.Forms.GroupBox();
this.buttonMpvSettings = new System.Windows.Forms.Button();
this.labelPlatform = new System.Windows.Forms.Label();
this.buttonVlcPathBrowse = new System.Windows.Forms.Button();
this.textBoxVlcPath = new System.Windows.Forms.TextBox();
@ -304,6 +305,7 @@
this.colorDialogSSAStyle = new System.Windows.Forms.ColorDialog();
this.labelStatus = new System.Windows.Forms.Label();
this.openFileDialogFFmpeg = new System.Windows.Forms.OpenFileDialog();
this.labelMpvSettings = new System.Windows.Forms.Label();
this.tabControlSettings.SuspendLayout();
this.tabPageGenerel.SuspendLayout();
this.groupBoxMiscellaneous.SuspendLayout();
@ -1734,6 +1736,8 @@
//
// groupBoxVideoEngine
//
this.groupBoxVideoEngine.Controls.Add(this.labelMpvSettings);
this.groupBoxVideoEngine.Controls.Add(this.buttonMpvSettings);
this.groupBoxVideoEngine.Controls.Add(this.labelPlatform);
this.groupBoxVideoEngine.Controls.Add(this.buttonVlcPathBrowse);
this.groupBoxVideoEngine.Controls.Add(this.textBoxVlcPath);
@ -1753,6 +1757,16 @@
this.groupBoxVideoEngine.TabStop = false;
this.groupBoxVideoEngine.Text = "Video engine";
//
// buttonMpvSettings
//
this.buttonMpvSettings.Location = new System.Drawing.Point(466, 87);
this.buttonMpvSettings.Name = "buttonMpvSettings";
this.buttonMpvSettings.Size = new System.Drawing.Size(29, 21);
this.buttonMpvSettings.TabIndex = 29;
this.buttonMpvSettings.Text = "...";
this.buttonMpvSettings.UseVisualStyleBackColor = true;
this.buttonMpvSettings.Click += new System.EventHandler(this.buttonMpvSettings_Click);
//
// labelPlatform
//
this.labelPlatform.Font = new System.Drawing.Font("Tahoma", 6.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
@ -3579,6 +3593,17 @@
//
this.openFileDialogFFmpeg.FileName = "openFileDialog1";
//
// labelMpvSettings
//
this.labelMpvSettings.AutoSize = true;
this.labelMpvSettings.Font = new System.Drawing.Font("Tahoma", 6.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.labelMpvSettings.ForeColor = System.Drawing.Color.Gray;
this.labelMpvSettings.Location = new System.Drawing.Point(501, 93);
this.labelMpvSettings.Name = "labelMpvSettings";
this.labelMpvSettings.Size = new System.Drawing.Size(33, 11);
this.labelMpvSettings.TabIndex = 30;
this.labelMpvSettings.Text = "--vo=?";
//
// Settings
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
@ -3973,5 +3998,7 @@
private System.Windows.Forms.Button buttonSsaColor;
private System.Windows.Forms.CheckBox checkBoxSsaFontBold;
private System.Windows.Forms.CheckBox checkBoxFceSkipStep1;
private System.Windows.Forms.Button buttonMpvSettings;
private System.Windows.Forms.Label labelMpvSettings;
}
}

View File

@ -134,12 +134,11 @@ namespace Nikse.SubtitleEdit.Forms
if (!LibVlcDynamic.IsInstalled)
radioButtonVideoPlayerVLC.Enabled = false;
if (!LibMpvDynamic.IsInstalled)
radioButtonVideoPlayerMPV.Enabled = false;
if (!UiUtil.IsQuartsDllInstalled)
radioButtonVideoPlayerDirectShow.Enabled = false;
if (Logic.VideoPlayers.MpcHC.MpcHc.GetMpcHcFileName() == null)
radioButtonVideoPlayerMpcHc.Enabled = false;
RefreshMpvSettings();
textBoxVlcPath.Text = gs.VlcLocation;
textBoxVlcPath.Left = labelVideoPlayerVLC.Left + labelVideoPlayerVLC.Width + 5;
@ -337,6 +336,8 @@ namespace Nikse.SubtitleEdit.Forms
radioButtonVideoPlayerMPV.Text = language.MpvPlayer;
labelVideoPlayerMPlayer.Text = language.MpvPlayerDescription;
buttonMpvSettings.Left = labelVideoPlayerMPlayer.Left + labelVideoPlayerMPlayer.Width + 5;
labelMpvSettings.Left = buttonMpvSettings.Left + buttonMpvSettings.Width + 5;
radioButtonVideoPlayerVLC.Text = language.VlcMediaPlayer;
labelVideoPlayerVLC.Text = language.VlcMediaPlayerDescription;
gs.VlcLocation = textBoxVlcPath.Text;
@ -2632,5 +2633,19 @@ namespace Nikse.SubtitleEdit.Forms
UpdateSsaExample();
}
private void buttonMpvSettings_Click(object sender, EventArgs e)
{
using (var form = new SettingsMpv())
{
form.ShowDialog(this);
RefreshMpvSettings();
}
}
private void RefreshMpvSettings()
{
radioButtonVideoPlayerMPV.Enabled = LibMpvDynamic.IsInstalled;
labelMpvSettings.Text = "--vo=" + Configuration.Settings.General.MpvVideoOutput;
}
}
}

View File

@ -1,6 +1,6 @@
namespace Nikse.SubtitleEdit.Forms
{
partial class SettingsMpv
sealed partial class SettingsMpv
{
/// <summary>
/// Required designer variable.
@ -29,7 +29,7 @@
private void InitializeComponent()
{
this.buttonDownload = new System.Windows.Forms.Button();
this.comboBox1 = new System.Windows.Forms.ComboBox();
this.comboBoxVideoOutput = new System.Windows.Forms.ComboBox();
this.label1 = new System.Windows.Forms.Label();
this.buttonOK = new System.Windows.Forms.Button();
this.buttonCancel = new System.Windows.Forms.Button();
@ -40,33 +40,34 @@
//
this.buttonDownload.Location = new System.Drawing.Point(12, 24);
this.buttonDownload.Name = "buttonDownload";
this.buttonDownload.Size = new System.Drawing.Size(159, 23);
this.buttonDownload.Size = new System.Drawing.Size(186, 23);
this.buttonDownload.TabIndex = 0;
this.buttonDownload.Text = "Download mpv dll";
this.buttonDownload.UseVisualStyleBackColor = true;
this.buttonDownload.Click += new System.EventHandler((sender, e) => this.buttonDownload_Click(sender, e));
this.buttonDownload.Click += new System.EventHandler(this.buttonDownload_Click_1);
//
// comboBox1
// comboBoxVideoOutput
//
this.comboBox1.FormattingEnabled = true;
this.comboBox1.Items.AddRange(new object[] {
this.comboBoxVideoOutput.FormattingEnabled = true;
this.comboBoxVideoOutput.Items.AddRange(new object[] {
"direct3d_shaders",
"direct3d ",
"sdl",
"vaapi"});
this.comboBox1.Location = new System.Drawing.Point(12, 109);
this.comboBox1.Name = "comboBox1";
this.comboBox1.Size = new System.Drawing.Size(186, 21);
this.comboBox1.TabIndex = 1;
"vaapi",
"vdpau"});
this.comboBoxVideoOutput.Location = new System.Drawing.Point(12, 109);
this.comboBoxVideoOutput.Name = "comboBoxVideoOutput";
this.comboBoxVideoOutput.Size = new System.Drawing.Size(186, 21);
this.comboBoxVideoOutput.TabIndex = 1;
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(12, 93);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(66, 13);
this.label1.Size = new System.Drawing.Size(67, 13);
this.label1.TabIndex = 2;
this.label1.Text = "Video option";
this.label1.Text = "Video output";
//
// buttonOK
//
@ -78,6 +79,7 @@
this.buttonOK.TabIndex = 4;
this.buttonOK.Text = "&OK";
this.buttonOK.UseVisualStyleBackColor = true;
this.buttonOK.Click += new System.EventHandler(this.buttonOK_Click);
//
// buttonCancel
//
@ -90,6 +92,7 @@
this.buttonCancel.TabIndex = 5;
this.buttonCancel.Text = "C&ancel";
this.buttonCancel.UseVisualStyleBackColor = true;
this.buttonCancel.Click += new System.EventHandler(this.buttonCancel_Click);
//
// labelPleaseWait
//
@ -109,7 +112,7 @@
this.Controls.Add(this.buttonOK);
this.Controls.Add(this.buttonCancel);
this.Controls.Add(this.label1);
this.Controls.Add(this.comboBox1);
this.Controls.Add(this.comboBoxVideoOutput);
this.Controls.Add(this.buttonDownload);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
this.KeyPreview = true;
@ -119,7 +122,7 @@
this.ShowIcon = false;
this.ShowInTaskbar = false;
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
this.Text = "SettingsMpv";
this.Text = "Settings for mpv";
this.ResumeLayout(false);
this.PerformLayout();
@ -128,7 +131,7 @@
#endregion
private System.Windows.Forms.Button buttonDownload;
private System.Windows.Forms.ComboBox comboBox1;
private System.Windows.Forms.ComboBox comboBoxVideoOutput;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Button buttonOK;
private System.Windows.Forms.Button buttonCancel;

View File

@ -7,14 +7,55 @@ using Nikse.SubtitleEdit.Core;
namespace Nikse.SubtitleEdit.Forms
{
public partial class SettingsMpv : Form
public sealed partial class SettingsMpv : Form
{
public SettingsMpv()
{
InitializeComponent();
labelPleaseWait.Text = string.Empty;
comboBoxVideoOutput.Text = Configuration.Settings.General.MpvVideoOutput;
buttonCancel.Text = Configuration.Settings.Language.General.Cancel;
buttonOK.Text = Configuration.Settings.Language.General.Ok;
Text = Configuration.Settings.Language.SettingsMpv.Title;
buttonDownload.Text = Configuration.Settings.Language.SettingsMpv.DownloadMpv;
}
private void buttonDownload_Click(object sender, EventArgs e)
private void wc_DownloadDataCompleted(object sender, DownloadDataCompletedEventArgs e)
{
if (e.Error != null )
{
MessageBox.Show(Configuration.Settings.Language.SettingsMpv.DownloadMpvFailed);
labelPleaseWait.Text = string.Empty;
buttonOK.Enabled = true;
buttonDownload.Enabled = true;
Cursor = Cursors.Default;
return;
}
string dictionaryFolder = Configuration.DataDirectory;
using (var ms = new MemoryStream(e.Result))
using (ZipExtractor zip = ZipExtractor.Open(ms))
{
List<ZipExtractor.ZipFileEntry> dir = zip.ReadCentralDir();
foreach (ZipExtractor.ZipFileEntry entry in dir)
{
if (entry.FilenameInZip.EndsWith(".dll", StringComparison.OrdinalIgnoreCase))
{
string fileName = Path.GetFileName(entry.FilenameInZip);
string path = Path.Combine(dictionaryFolder, fileName);
zip.ExtractFile(entry, path);
}
}
}
Cursor = Cursors.Default;
labelPleaseWait.Text = string.Empty;
buttonOK.Enabled = true;
buttonDownload.Enabled = true;
MessageBox.Show("mpv downloaded OK");
}
private void buttonDownload_Click_1(object sender, EventArgs e)
{
try
{
@ -45,41 +86,17 @@ namespace Nikse.SubtitleEdit.Forms
}
}
private void wc_DownloadDataCompleted(object sender, DownloadDataCompletedEventArgs e)
private void buttonOK_Click(object sender, EventArgs e)
{
if (e.Error != null )
{
MessageBox.Show("Unable to download mpv - please re-try later!");
labelPleaseWait.Text = string.Empty;
buttonOK.Enabled = true;
buttonDownload.Enabled = true;
Cursor = Cursors.Default;
return;
if (!string.IsNullOrWhiteSpace(comboBoxVideoOutput.Text))
Configuration.Settings.General.MpvVideoOutput = comboBoxVideoOutput.Text;
DialogResult = DialogResult.OK;
}
string dictionaryFolder = Utilities.DictionaryFolder;
using (var ms = new MemoryStream(e.Result))
using (ZipExtractor zip = ZipExtractor.Open(ms))
private void buttonCancel_Click(object sender, EventArgs e)
{
List<ZipExtractor.ZipFileEntry> dir = zip.ReadCentralDir();
foreach (ZipExtractor.ZipFileEntry entry in dir)
{
if (entry.FilenameInZip.EndsWith(".dll", StringComparison.OrdinalIgnoreCase))
{
string fileName = Path.GetFileName(entry.FilenameInZip);
string path = Path.Combine(dictionaryFolder, fileName);
zip.ExtractFile(entry, path);
DialogResult = DialogResult.Cancel;
}
}
}
Cursor = Cursors.Default;
labelPleaseWait.Text = string.Empty;
buttonOK.Enabled = true;
buttonDownload.Enabled = true;
MessageBox.Show("mpv downloaded OK");
}
}
}

View File

@ -55,6 +55,11 @@ namespace Nikse.SubtitleEdit.Logic.VideoPlayers
private IntPtr _libMpvDll;
private IntPtr _mpvHandle;
private Timer _videoLoadedTimer;
private Timer _videoEndedTimer;
public override event EventHandler OnVideoLoaded;
public override event EventHandler OnVideoEnded;
private object GetDllType(Type type, string name)
{
@ -312,7 +317,12 @@ namespace Nikse.SubtitleEdit.Logic.VideoPlayers
if (!string.IsNullOrEmpty(videoFileName))
{
_mpvInitialize.Invoke(_mpvHandle);
_mpvSetOptionString(_mpvHandle, Encoding.UTF8.GetBytes("vo\0"), Encoding.UTF8.GetBytes("direct3d_shaders\0")); // "direct3d" for compabality with old systems
string videoOutput = "direct3d_shaders";
if (string.IsNullOrWhiteSpace(Configuration.Settings.General.MpvVideoOutput))
videoOutput = Configuration.Settings.General.MpvVideoOutput;
_mpvSetOptionString(_mpvHandle, Encoding.UTF8.GetBytes("vo\0"), Encoding.UTF8.GetBytes(videoOutput + "\0")); // "direct3d_shaders" is default, "direct3d" could be used for compabality with old systems
_mpvSetOptionString(_mpvHandle, Encoding.UTF8.GetBytes("keep-open\0"), Encoding.UTF8.GetBytes("always\0")); // don't auto close video
_mpvSetOptionString(_mpvHandle, Encoding.UTF8.GetBytes("no-sub\0"), Encoding.UTF8.GetBytes("\0")); // don't load subtitles
if (ownerControl != null)
@ -323,37 +333,52 @@ namespace Nikse.SubtitleEdit.Logic.VideoPlayers
}
_mpvCommand(_mpvHandle, new[] { "loadfile", videoFileName, null });
_videoLoadedTimer = new Timer { Interval = 50 };
_videoLoadedTimer.Tick += VideoLoadedTimer_Tick;
_videoLoadedTimer.Start();
}
}
private void VideoLoadedTimer_Tick(object sender, EventArgs e)
{
_videoLoadedTimer.Stop();
const int mpvEventFileLoaded = 8;
int l = 0;
while (l < 10000)
{
Application.DoEvents();
try
{
var eventIdHandle = _mpvWaitEvent(_mpvHandle, 0);
var eventId = Convert.ToInt64(Marshal.PtrToStructure(eventIdHandle, typeof(int)));
if (eventId == mpvEventFileLoaded)
{
Application.DoEvents();
if (onVideoLoaded != null)
onVideoLoaded.Invoke(this, null);
Application.DoEvents();
Pause();
return;
break;
}
l++;
}
catch
{
return;
}
}
Application.DoEvents();
if (OnVideoLoaded != null)
OnVideoLoaded.Invoke(this, null);
Application.DoEvents();
Pause();
}
private void VideoEndedTimer_Tick(object sender, EventArgs e)
{
}
public override void DisposeVideoPlayer()
{
Dispose();
}
public override event EventHandler OnVideoLoaded;
public override event EventHandler OnVideoEnded;
private void ReleaseUnmangedResources()
{
try