diff --git a/installer/Subtitle_Edit_installer.iss b/installer/Subtitle_Edit_installer.iss
index 32798a19c..d319fa967 100644
--- a/installer/Subtitle_Edit_installer.iss
+++ b/installer/Subtitle_Edit_installer.iss
@@ -236,6 +236,9 @@ Source: ..\Dictionaries\en_US.dic; DestDir: {userappdata}\Subtit
Source: ..\Ocr\Latin.db; DestDir: {userappdata}\Subtitle Edit\Ocr; Flags: ignoreversion uninsneveruninstall onlyifdoesntexist; Components: main
Source: ..\Ocr\Latin.nocr; DestDir: {userappdata}\Subtitle Edit\Ocr; Flags: ignoreversion uninsneveruninstall onlyifdoesntexist; Components: main
+Source: ..\preview.mkv; DestDir: {userappdata}\Subtitle Edit; Flags: ignoreversion uninsneveruninstall onlyifdoesntexist; Components: main
+
+
#ifdef localize
Source: {#bindir}\Languages\ar-EG.xml; DestDir: {app}\Languages; Flags: ignoreversion; Components: translations
Source: {#bindir}\Languages\bg-BG.xml; DestDir: {app}\Languages; Flags: ignoreversion; Components: translations
@@ -619,6 +622,7 @@ begin
RemoveDir(ExpandConstant('{userappdata}\Subtitle Edit\Dictionaries'));
DeleteFile(ExpandConstant('{userappdata}\Subtitle Edit\Ocr\Latin.db'));
DeleteFile(ExpandConstant('{userappdata}\Subtitle Edit\Ocr\Latin.nocr'));
+ DeleteFile(ExpandConstant('{userappdata}\Subtitle Edit\preview.mkv'));
DelTree(ExpandConstant('{userappdata}\Subtitle Edit\Ocr\*.*'), False, True, False);
RemoveDir(ExpandConstant('{userappdata}\Subtitle Edit\Ocr'));
DelTree(ExpandConstant('{userappdata}\Subtitle Edit\Plugins\*.*'), False, True, False);
diff --git a/preview.mkv b/preview.mkv
new file mode 100644
index 000000000..f363db1cc
Binary files /dev/null and b/preview.mkv differ
diff --git a/src/ui/Forms/Assa/ApplyCustomStyles.cs b/src/ui/Forms/Assa/ApplyCustomStyles.cs
index 509e90b11..a969d4433 100644
--- a/src/ui/Forms/Assa/ApplyCustomStyles.cs
+++ b/src/ui/Forms/Assa/ApplyCustomStyles.cs
@@ -343,23 +343,8 @@ namespace Nikse.SubtitleEdit.Forms.Assa
private bool GeneratePreviewViaMpv()
{
- var fileName = Path.Combine(Configuration.DataDirectory, "preview.mp4");
- if (!File.Exists(fileName))
- {
- var isFfmpegAvailable = !Configuration.IsRunningOnWindows || !string.IsNullOrEmpty(Configuration.Settings.General.FFmpegLocation) && File.Exists(Configuration.Settings.General.FFmpegLocation);
- if (!isFfmpegAvailable)
- {
- return false;
- }
-
- using (var p = GetFFmpegProcess(fileName))
- {
- p.Start();
- p.WaitForExit();
- }
- }
-
- if (!LibMpvDynamic.IsInstalled)
+ var fileName = VideoPreviewGenerator.GetVideoPreviewFileName();
+ if (string.IsNullOrEmpty(fileName) || !LibMpvDynamic.IsInstalled)
{
return false;
}
@@ -377,26 +362,6 @@ namespace Nikse.SubtitleEdit.Forms.Assa
return true;
}
- public static Process GetFFmpegProcess(string outputFileName)
- {
- var ffmpegLocation = Configuration.Settings.General.FFmpegLocation;
- if (!Configuration.IsRunningOnWindows && (string.IsNullOrEmpty(ffmpegLocation) || !File.Exists(ffmpegLocation)))
- {
- ffmpegLocation = "ffmpeg";
- }
-
- return new Process
- {
- StartInfo =
- {
- FileName = ffmpegLocation,
- Arguments = $"-t 1 -f lavfi -i color=c=blue:s=720x480 -c:v libx264 -tune stillimage -pix_fmt yuv420p \"{outputFileName}\"",
- UseShellExecute = false,
- CreateNoWindow = true
- }
- };
- }
-
private void VideoLoaded(object sender, EventArgs e)
{
var format = new AdvancedSubStationAlpha();
@@ -407,8 +372,8 @@ namespace Nikse.SubtitleEdit.Forms.Assa
{
var p = new Paragraph(_subtitle.Paragraphs[indices[0]])
{
- StartTime = { TotalMilliseconds = 0 },
- EndTime = { TotalMilliseconds = 1000 }
+ StartTime = { TotalMilliseconds = 0 },
+ EndTime = { TotalMilliseconds = 2000 }
};
p.Text = styleToApply + p.Text;
subtitle.Paragraphs.Add(p);
diff --git a/src/ui/Forms/Assa/SetPosition.cs b/src/ui/Forms/Assa/SetPosition.cs
index 2764741c2..1c3c4009e 100644
--- a/src/ui/Forms/Assa/SetPosition.cs
+++ b/src/ui/Forms/Assa/SetPosition.cs
@@ -216,7 +216,7 @@ namespace Nikse.SubtitleEdit.Forms.Assa
private bool GeneratePreviewViaMpv()
{
- var fileName = _videoFileName; // Path.Combine(Configuration.DataDirectory, "preview.mp4");
+ var fileName = _videoFileName;
if (!File.Exists(fileName))
{
var isFfmpegAvailable = !Configuration.IsRunningOnWindows || !string.IsNullOrEmpty(Configuration.Settings.General.FFmpegLocation) && File.Exists(Configuration.Settings.General.FFmpegLocation);
diff --git a/src/ui/Forms/Styles/SubStationAlphaStyles.cs b/src/ui/Forms/Styles/SubStationAlphaStyles.cs
index 7669adfa1..fc4bf9a37 100644
--- a/src/ui/Forms/Styles/SubStationAlphaStyles.cs
+++ b/src/ui/Forms/Styles/SubStationAlphaStyles.cs
@@ -407,23 +407,8 @@ namespace Nikse.SubtitleEdit.Forms.Styles
private bool GeneratePreviewViaMpv()
{
- var fileName = Path.Combine(Configuration.DataDirectory, "preview.mp4");
- if (!File.Exists(fileName))
- {
- var isFfmpegAvailable = !Configuration.IsRunningOnWindows || !string.IsNullOrEmpty(Configuration.Settings.General.FFmpegLocation) && File.Exists(Configuration.Settings.General.FFmpegLocation);
- if (!isFfmpegAvailable)
- {
- return false;
- }
-
- using (var p = GetFFmpegProcess(fileName))
- {
- p.Start();
- p.WaitForExit();
- }
- }
-
- if (!LibMpvDynamic.IsInstalled)
+ var fileName = VideoPreviewGenerator.GetVideoPreviewFileName();
+ if (string.IsNullOrEmpty(fileName) || !LibMpvDynamic.IsInstalled)
{
return false;
}
@@ -441,26 +426,6 @@ namespace Nikse.SubtitleEdit.Forms.Styles
return true;
}
- public static Process GetFFmpegProcess(string outputFileName)
- {
- var ffmpegLocation = Configuration.Settings.General.FFmpegLocation;
- if (!Configuration.IsRunningOnWindows && (string.IsNullOrEmpty(ffmpegLocation) || !File.Exists(ffmpegLocation)))
- {
- ffmpegLocation = "ffmpeg";
- }
-
- return new Process
- {
- StartInfo =
- {
- FileName = ffmpegLocation,
- Arguments = $"-t 1 -f lavfi -i color=c=blue:s=720x480 -c:v libx264 -tune stillimage -pix_fmt yuv420p \"{outputFileName}\"",
- UseShellExecute = false,
- CreateNoWindow = true
- }
- };
- }
-
private void VideoStartLoaded(object sender, EventArgs e)
{
var format = new AdvancedSubStationAlpha();
diff --git a/src/ui/Logic/VideoPreviewGenerator.cs b/src/ui/Logic/VideoPreviewGenerator.cs
new file mode 100644
index 000000000..55dd7430a
--- /dev/null
+++ b/src/ui/Logic/VideoPreviewGenerator.cs
@@ -0,0 +1,57 @@
+using System;
+using System.Diagnostics;
+using System.Drawing.Imaging;
+using System.IO;
+using Nikse.SubtitleEdit.Core.Common;
+
+namespace Nikse.SubtitleEdit.Logic
+{
+ public class VideoPreviewGenerator
+ {
+ public static string GetVideoPreviewFileName()
+ {
+ var previewFileName = Path.Combine(Configuration.DataDirectory, "preview.mkv");
+ if (File.Exists(previewFileName))
+ {
+ return previewFileName;
+ }
+
+ try
+ {
+ const int rectangleSize = 9;
+ var backgroundImage = TextDesigner.MakeBackgroundImage(720, 480, rectangleSize, Configuration.Settings.General.UseDarkTheme);
+ var tempImageFileName = Path.Combine(Path.GetTempPath(), Guid.NewGuid() + ".png");
+ backgroundImage.Save(tempImageFileName, ImageFormat.Png);
+ var processMakeVideo = GetFFmpegProcess(tempImageFileName, previewFileName, backgroundImage.Width, backgroundImage.Height);
+ processMakeVideo.Start();
+ processMakeVideo.WaitForExit();
+ }
+ catch
+ {
+ return null;
+ }
+
+ return File.Exists(previewFileName) ? previewFileName : null;
+ }
+
+ private static Process GetFFmpegProcess(string imageFileName, string outputFileName, int videoWidth, int videoHeight)
+ {
+ var ffmpegLocation = Configuration.Settings.General.FFmpegLocation;
+ if (!Configuration.IsRunningOnWindows && (string.IsNullOrEmpty(ffmpegLocation) || !File.Exists(ffmpegLocation)))
+ {
+ ffmpegLocation = "ffmpeg";
+ }
+
+ return new Process
+ {
+ StartInfo =
+ {
+ FileName = ffmpegLocation,
+ Arguments = $"-t 3 -loop 1 -i \"{imageFileName}\" -c:v libx264 -tune stillimage -shortest -s {videoWidth}x{videoHeight} \"{outputFileName}\"",
+ UseShellExecute = false,
+ CreateNoWindow = true
+ }
+ };
+ }
+ }
+}
diff --git a/src/ui/SubtitleEdit.csproj b/src/ui/SubtitleEdit.csproj
index 8c3254136..7d3dfdc0e 100644
--- a/src/ui/SubtitleEdit.csproj
+++ b/src/ui/SubtitleEdit.csproj
@@ -1240,6 +1240,7 @@
+