From 5ce4a1ffc3ce8e56ec9906958c07f29a5cb9b7c1 Mon Sep 17 00:00:00 2001 From: Nikolaj Olsson Date: Sat, 7 Nov 2020 09:02:20 +0100 Subject: [PATCH] Add mpv log setting Default if false (off) --- Changelog.txt | 3 ++- libse/Settings.cs | 8 ++++++++ src/Logic/VideoPlayers/LibMpvDynamic.cs | 21 +++++++++++++++------ 3 files changed, 25 insertions(+), 7 deletions(-) diff --git a/Changelog.txt b/Changelog.txt index 42cb203f3..43a7028f6 100644 --- a/Changelog.txt +++ b/Changelog.txt @@ -3,7 +3,7 @@ 3.5.18 (xth November 2020) BETA * NEW: * Add "Measurement converter" - thx OmrSi - * Add waveform multi- track support - thx OmrSi + * Add waveform multi-audio-track support - thx OmrSi * Add import/export of shortcuts * Add "Matroska chapter support" - thx OmrSi * Add subtitle format XMP - thx Tore @@ -30,6 +30,7 @@ * Allow for .mpg/.mpeg transport stream file extension in "Batch convert" * Add some more EBU STL validation - thx Valentina * Improve Korean auto detect in PAC - thx andrewburnheimer + * Add MpvLogging setting * FIXED: * Fix crash in export image with font tag - thx Jake * Fix batch convert of Blu-ray sup file to VobSub - thx John diff --git a/libse/Settings.cs b/libse/Settings.cs index 97ecde339..e9dfa3bb4 100644 --- a/libse/Settings.cs +++ b/libse/Settings.cs @@ -1115,6 +1115,7 @@ $HorzAlign = Center public string MpvVideoOutputWindows { get; set; } public string MpvVideoOutputLinux { get; set; } public string MpvExtraOption { get; set; } + public bool MpvLogging { get; set; } public bool MpvHandlesPreviewText { get; set; } public string MpcHcLocation { get; set; } public string MkvMergeLocation { get; set; } @@ -3302,6 +3303,12 @@ $HorzAlign = Center settings.General.MpvExtraOption = subNode.InnerText.Trim(); } + subNode = node.SelectSingleNode("MpvLogging"); + if (subNode != null) + { + settings.General.MpvLogging = Convert.ToBoolean(subNode.InnerText.Trim()); + } + subNode = node.SelectSingleNode("MpvHandlesPreviewText"); if (subNode != null) { @@ -7712,6 +7719,7 @@ $HorzAlign = Center textWriter.WriteElementString("MpvVideoOutputWindows", settings.General.MpvVideoOutputWindows); textWriter.WriteElementString("MpvVideoOutputLinux", settings.General.MpvVideoOutputLinux); textWriter.WriteElementString("MpvExtraOption", settings.General.MpvExtraOption); + textWriter.WriteElementString("MpvLogging", settings.General.MpvLogging.ToString(CultureInfo.InvariantCulture)); textWriter.WriteElementString("MpvHandlesPreviewText", settings.General.MpvHandlesPreviewText.ToString(CultureInfo.InvariantCulture)); textWriter.WriteElementString("MpcHcLocation", settings.General.MpcHcLocation); textWriter.WriteElementString("MkvMergeLocation", settings.General.MkvMergeLocation); diff --git a/src/Logic/VideoPlayers/LibMpvDynamic.cs b/src/Logic/VideoPlayers/LibMpvDynamic.cs index 703c9e3dc..8ad1e1426 100644 --- a/src/Logic/VideoPlayers/LibMpvDynamic.cs +++ b/src/Logic/VideoPlayers/LibMpvDynamic.cs @@ -64,7 +64,7 @@ namespace Nikse.SubtitleEdit.Logic.VideoPlayers private IntPtr _mpvHandle; private Timer _videoLoadedTimer; private double? _pausePosition; // Hack to hold precise seeking when paused - private string _secondSubtitleFileName; + private string _secondSubtitleFileName; public override event EventHandler OnVideoLoaded; public override event EventHandler OnVideoEnded; @@ -359,9 +359,15 @@ namespace Nikse.SubtitleEdit.Logic.VideoPlayers { var lpBuffer = IntPtr.Zero; _mpvGetPropertyString(_mpvHandle, GetUtf8Bytes("aid"), MpvFormatString, ref lpBuffer); - int id = int.Parse(Marshal.PtrToStringAnsi(lpBuffer)); - int idx = _audioTrackIds.FindIndex(x => x.Key == id); - int number = AudioTracks.Count > 1 && idx != -1 ? idx : 0; + var numberString = Marshal.PtrToStringAnsi(lpBuffer); + if (string.IsNullOrEmpty(numberString)) + { + return 0; + } + + var id = int.Parse(numberString); + var idx = _audioTrackIds.FindIndex(x => x.Key == id); + var number = AudioTracks.Count > 1 && idx != -1 ? idx : 0; _mpvFree(lpBuffer); return number; } @@ -504,8 +510,11 @@ namespace Nikse.SubtitleEdit.Logic.VideoPlayers } _mpvHandle = _mpvCreate.Invoke(); - //var logFileName = Path.Combine(Configuration.DataDirectory, "mpv-log-" + Guid.NewGuid() + ".txt"); - //_mpvSetOptionString(_mpvHandle, GetUtf8Bytes("log-file"), GetUtf8Bytes(logFileName)); + if (Configuration.Settings.General.MpvLogging) + { + var logFileName = Path.Combine(Configuration.DataDirectory, "mpv-log-" + Guid.NewGuid() + ".txt"); + _mpvSetOptionString(_mpvHandle, GetUtf8Bytes("log-file"), GetUtf8Bytes(logFileName)); + } } else if (!Directory.Exists(videoFileName)) {