Use small preview mkv for ASSA style windows

This commit is contained in:
niksedk 2021-06-25 08:46:01 +02:00
parent 94966b9d7b
commit e9bc0f73b3
7 changed files with 69 additions and 77 deletions

View File

@ -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.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: ..\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 #ifdef localize
Source: {#bindir}\Languages\ar-EG.xml; DestDir: {app}\Languages; Flags: ignoreversion; Components: translations 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 Source: {#bindir}\Languages\bg-BG.xml; DestDir: {app}\Languages; Flags: ignoreversion; Components: translations
@ -619,6 +622,7 @@ begin
RemoveDir(ExpandConstant('{userappdata}\Subtitle Edit\Dictionaries')); RemoveDir(ExpandConstant('{userappdata}\Subtitle Edit\Dictionaries'));
DeleteFile(ExpandConstant('{userappdata}\Subtitle Edit\Ocr\Latin.db')); DeleteFile(ExpandConstant('{userappdata}\Subtitle Edit\Ocr\Latin.db'));
DeleteFile(ExpandConstant('{userappdata}\Subtitle Edit\Ocr\Latin.nocr')); DeleteFile(ExpandConstant('{userappdata}\Subtitle Edit\Ocr\Latin.nocr'));
DeleteFile(ExpandConstant('{userappdata}\Subtitle Edit\preview.mkv'));
DelTree(ExpandConstant('{userappdata}\Subtitle Edit\Ocr\*.*'), False, True, False); DelTree(ExpandConstant('{userappdata}\Subtitle Edit\Ocr\*.*'), False, True, False);
RemoveDir(ExpandConstant('{userappdata}\Subtitle Edit\Ocr')); RemoveDir(ExpandConstant('{userappdata}\Subtitle Edit\Ocr'));
DelTree(ExpandConstant('{userappdata}\Subtitle Edit\Plugins\*.*'), False, True, False); DelTree(ExpandConstant('{userappdata}\Subtitle Edit\Plugins\*.*'), False, True, False);

BIN
preview.mkv Normal file

Binary file not shown.

View File

@ -343,23 +343,8 @@ namespace Nikse.SubtitleEdit.Forms.Assa
private bool GeneratePreviewViaMpv() private bool GeneratePreviewViaMpv()
{ {
var fileName = Path.Combine(Configuration.DataDirectory, "preview.mp4"); var fileName = VideoPreviewGenerator.GetVideoPreviewFileName();
if (!File.Exists(fileName)) if (string.IsNullOrEmpty(fileName) || !LibMpvDynamic.IsInstalled)
{
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)
{ {
return false; return false;
} }
@ -377,26 +362,6 @@ namespace Nikse.SubtitleEdit.Forms.Assa
return true; 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) private void VideoLoaded(object sender, EventArgs e)
{ {
var format = new AdvancedSubStationAlpha(); var format = new AdvancedSubStationAlpha();
@ -407,8 +372,8 @@ namespace Nikse.SubtitleEdit.Forms.Assa
{ {
var p = new Paragraph(_subtitle.Paragraphs[indices[0]]) var p = new Paragraph(_subtitle.Paragraphs[indices[0]])
{ {
StartTime = { TotalMilliseconds = 0 }, StartTime = { TotalMilliseconds = 0 },
EndTime = { TotalMilliseconds = 1000 } EndTime = { TotalMilliseconds = 2000 }
}; };
p.Text = styleToApply + p.Text; p.Text = styleToApply + p.Text;
subtitle.Paragraphs.Add(p); subtitle.Paragraphs.Add(p);

View File

@ -216,7 +216,7 @@ namespace Nikse.SubtitleEdit.Forms.Assa
private bool GeneratePreviewViaMpv() private bool GeneratePreviewViaMpv()
{ {
var fileName = _videoFileName; // Path.Combine(Configuration.DataDirectory, "preview.mp4"); var fileName = _videoFileName;
if (!File.Exists(fileName)) if (!File.Exists(fileName))
{ {
var isFfmpegAvailable = !Configuration.IsRunningOnWindows || !string.IsNullOrEmpty(Configuration.Settings.General.FFmpegLocation) && File.Exists(Configuration.Settings.General.FFmpegLocation); var isFfmpegAvailable = !Configuration.IsRunningOnWindows || !string.IsNullOrEmpty(Configuration.Settings.General.FFmpegLocation) && File.Exists(Configuration.Settings.General.FFmpegLocation);

View File

@ -407,23 +407,8 @@ namespace Nikse.SubtitleEdit.Forms.Styles
private bool GeneratePreviewViaMpv() private bool GeneratePreviewViaMpv()
{ {
var fileName = Path.Combine(Configuration.DataDirectory, "preview.mp4"); var fileName = VideoPreviewGenerator.GetVideoPreviewFileName();
if (!File.Exists(fileName)) if (string.IsNullOrEmpty(fileName) || !LibMpvDynamic.IsInstalled)
{
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)
{ {
return false; return false;
} }
@ -441,26 +426,6 @@ namespace Nikse.SubtitleEdit.Forms.Styles
return true; 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) private void VideoStartLoaded(object sender, EventArgs e)
{ {
var format = new AdvancedSubStationAlpha(); var format = new AdvancedSubStationAlpha();

View File

@ -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
}
};
}
}
}

View File

@ -1240,6 +1240,7 @@
<Compile Include="Logic\VideoPlayers\MpcHC\NativeMethods.cs" /> <Compile Include="Logic\VideoPlayers\MpcHC\NativeMethods.cs" />
<Compile Include="Logic\VideoPlayers\QuartsPlayer.cs" /> <Compile Include="Logic\VideoPlayers\QuartsPlayer.cs" />
<Compile Include="Logic\VideoPlayers\VideoPlayer.cs" /> <Compile Include="Logic\VideoPlayers\VideoPlayer.cs" />
<Compile Include="Logic\VideoPreviewGenerator.cs" />
<Compile Include="Logic\WordSpellChecker.cs" /> <Compile Include="Logic\WordSpellChecker.cs" />
<Compile Include="Program.cs" /> <Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />