Add burn-in video preview - thx Masina86 :)

Fix #7024
This commit is contained in:
niksedk 2023-07-01 18:17:29 +02:00
parent 344511f4e9
commit a1c9984283
5 changed files with 337 additions and 0 deletions

View File

@ -11,6 +11,8 @@ using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Windows.Forms;
using Nikse.SubtitleEdit.Logic.VideoPlayers;
using Nikse.SubtitleEdit.Forms.BinaryEdit;
namespace Nikse.SubtitleEdit.Forms
{
@ -1217,6 +1219,21 @@ namespace Nikse.SubtitleEdit.Forms
{
buttonPreview.Enabled = false;
labelPreviewPleaseWait.Visible = true;
if (LibMpvDynamic.IsInstalled && Configuration.Settings.General.VideoPlayer == "MPV")
{
var temp = new Subtitle(_assaSubtitle);
var subFileName = GetAssaFileName(_inputVideoFileName);
FileUtil.WriteAllText(subFileName, new AdvancedSubStationAlpha().ToText(temp, null), new TextEncoding(Encoding.UTF8, "UTF8"));
using (var form = new PreviewVideo(_inputVideoFileName, subFileName, _assaSubtitle))
{
form.ShowDialog(this);
}
return;
}
Cursor = Cursors.WaitCursor;
// generate blank video

88
src/ui/Forms/PreviewVideo.Designer.cs generated Normal file
View File

@ -0,0 +1,88 @@
namespace Nikse.SubtitleEdit.Forms
{
partial class PreviewVideo
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
this.videoPlayerContainer1 = new Nikse.SubtitleEdit.Controls.VideoPlayerContainer();
this.timerSubtitleOnVideo = new System.Windows.Forms.Timer(this.components);
this.SuspendLayout();
//
// videoPlayerContainer1
//
this.videoPlayerContainer1.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(18)))), ((int)(((byte)(18)))), ((int)(((byte)(18)))));
this.videoPlayerContainer1.Chapters = null;
this.videoPlayerContainer1.CurrentPosition = 0D;
this.videoPlayerContainer1.Dock = System.Windows.Forms.DockStyle.Fill;
this.videoPlayerContainer1.FontSizeFactor = 1F;
this.videoPlayerContainer1.LastParagraph = null;
this.videoPlayerContainer1.Location = new System.Drawing.Point(0, 0);
this.videoPlayerContainer1.Name = "videoPlayerContainer1";
this.videoPlayerContainer1.ShowFullscreenButton = true;
this.videoPlayerContainer1.ShowMuteButton = true;
this.videoPlayerContainer1.ShowStopButton = true;
this.videoPlayerContainer1.Size = new System.Drawing.Size(800, 450);
this.videoPlayerContainer1.SubtitleText = "";
this.videoPlayerContainer1.TabIndex = 17;
this.videoPlayerContainer1.TextRightToLeft = System.Windows.Forms.RightToLeft.No;
this.videoPlayerContainer1.UsingFrontCenterAudioChannelOnly = false;
this.videoPlayerContainer1.VideoHeight = 0;
this.videoPlayerContainer1.VideoPlayer = null;
this.videoPlayerContainer1.VideoWidth = 0;
this.videoPlayerContainer1.Volume = 0D;
//
// timerSubtitleOnVideo
//
this.timerSubtitleOnVideo.Interval = 25;
this.timerSubtitleOnVideo.Tick += new System.EventHandler(this.timerSubtitleOnVideo_Tick);
//
// PreviewVideo
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(800, 450);
this.Controls.Add(this.videoPlayerContainer1);
this.KeyPreview = true;
this.Name = "PreviewVideo";
this.ShowIcon = false;
this.ShowInTaskbar = false;
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
this.Text = "PreviewVideo";
this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.PreviewVideo_FormClosing);
this.Shown += new System.EventHandler(this.PreviewVideo_Shown);
this.KeyDown += new System.Windows.Forms.KeyEventHandler(this.PreviewVideo_KeyDown);
this.ResumeLayout(false);
}
#endregion
private Controls.VideoPlayerContainer videoPlayerContainer1;
private System.Windows.Forms.Timer timerSubtitleOnVideo;
}
}

View File

@ -0,0 +1,100 @@
using Nikse.SubtitleEdit.Logic;
using Nikse.SubtitleEdit.Logic.VideoPlayers;
using System;
using System.IO;
using System.Windows.Forms;
using Nikse.SubtitleEdit.Core.Common;
namespace Nikse.SubtitleEdit.Forms
{
public partial class PreviewVideo : Form
{
private string _videoFileName;
private readonly string _subtitleFileName;
private readonly Subtitle _subtitle;
public PreviewVideo(string videoFileName, string subtitleFileName, Subtitle subtitle)
{
UiUtil.PreInitialize(this);
InitializeComponent();
UiUtil.FixFonts(this);
_videoFileName = videoFileName;
_subtitleFileName = subtitleFileName;
_subtitle = subtitle;
}
private void PreviewVideo_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Escape)
{
DialogResult = DialogResult.Cancel;
}
}
private void PreviewVideo_FormClosing(object sender, FormClosingEventArgs e)
{
CloseVideo();
}
private void CloseVideo()
{
timerSubtitleOnVideo.Stop();
Application.DoEvents();
if (videoPlayerContainer1.VideoPlayer != null)
{
videoPlayerContainer1.Pause();
videoPlayerContainer1.VideoPlayer.DisposeVideoPlayer();
videoPlayerContainer1.VideoPlayer = null;
}
Application.DoEvents();
_videoFileName = null;
videoPlayerContainer1.Visible = false;
}
private void PreviewVideo_Shown(object sender, EventArgs e)
{
var videoInfo = UiUtil.GetVideoInfo(_videoFileName);
UiUtil.InitializeVideoPlayerAndContainer(_videoFileName, videoInfo, videoPlayerContainer1, VideoStartLoaded, VideoStartEnded);
Text = $"{LanguageSettings.Current.General.Preview} - {videoInfo.Width}x{videoInfo.Height}, {Path.GetFileName(_videoFileName)}";
}
private void VideoStartEnded(object sender, EventArgs e)
{
videoPlayerContainer1.Pause();
if (videoPlayerContainer1.VideoPlayer is LibMpvDynamic libmpv)
{
libmpv.RemoveSubtitle();
}
}
private void VideoStartLoaded(object sender, EventArgs e)
{
videoPlayerContainer1.Pause();
timerSubtitleOnVideo.Start();
if (videoPlayerContainer1.VideoPlayer is LibMpvDynamic libmpv)
{
libmpv.LoadSubtitle(_subtitleFileName);
}
if (_subtitle?.Paragraphs.Count > 0)
{
videoPlayerContainer1.CurrentPosition = _subtitle.Paragraphs[0].StartTime.TotalSeconds + 0.1;
}
}
private void timerSubtitleOnVideo_Tick(object sender, EventArgs e)
{
if (videoPlayerContainer1 == null || videoPlayerContainer1.IsPaused)
{
return;
}
if (!videoPlayerContainer1.IsPaused)
{
videoPlayerContainer1.RefreshProgressBar();
}
}
}
}

View File

@ -0,0 +1,123 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<metadata name="timerSubtitleOnVideo.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
</root>

View File

@ -385,6 +385,12 @@
<Compile Include="Forms\GetVideoPosition.Designer.cs">
<DependentUpon>GetVideoPosition.cs</DependentUpon>
</Compile>
<Compile Include="Forms\PreviewVideo.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="Forms\PreviewVideo.Designer.cs">
<DependentUpon>PreviewVideo.cs</DependentUpon>
</Compile>
<Compile Include="Forms\ShotChangesList.cs">
<SubType>Form</SubType>
</Compile>
@ -1665,6 +1671,9 @@
<EmbeddedResource Include="Forms\Options\WordLists.resx">
<DependentUpon>WordLists.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Forms\PreviewVideo.resx">
<DependentUpon>PreviewVideo.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Forms\ShotChangesList.resx">
<DependentUpon>ShotChangesList.cs</DependentUpon>
</EmbeddedResource>