Skip to content

Commit e9bc0f7

Browse files
committed
Use small preview mkv for ASSA style windows
1 parent 94966b9 commit e9bc0f7

7 files changed

+69
-77
lines changed

installer/Subtitle_Edit_installer.iss

+4
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,9 @@ Source: ..\Dictionaries\en_US.dic; DestDir: {userappdata}\Subtit
236236
Source: ..\Ocr\Latin.db; DestDir: {userappdata}\Subtitle Edit\Ocr; Flags: ignoreversion uninsneveruninstall onlyifdoesntexist; Components: main
237237
Source: ..\Ocr\Latin.nocr; DestDir: {userappdata}\Subtitle Edit\Ocr; Flags: ignoreversion uninsneveruninstall onlyifdoesntexist; Components: main
238238

239+
Source: ..\preview.mkv; DestDir: {userappdata}\Subtitle Edit; Flags: ignoreversion uninsneveruninstall onlyifdoesntexist; Components: main
240+
241+
239242
#ifdef localize
240243
Source: {#bindir}\Languages\ar-EG.xml; DestDir: {app}\Languages; Flags: ignoreversion; Components: translations
241244
Source: {#bindir}\Languages\bg-BG.xml; DestDir: {app}\Languages; Flags: ignoreversion; Components: translations
@@ -619,6 +622,7 @@ begin
619622
RemoveDir(ExpandConstant('{userappdata}\Subtitle Edit\Dictionaries'));
620623
DeleteFile(ExpandConstant('{userappdata}\Subtitle Edit\Ocr\Latin.db'));
621624
DeleteFile(ExpandConstant('{userappdata}\Subtitle Edit\Ocr\Latin.nocr'));
625+
DeleteFile(ExpandConstant('{userappdata}\Subtitle Edit\preview.mkv'));
622626
DelTree(ExpandConstant('{userappdata}\Subtitle Edit\Ocr\*.*'), False, True, False);
623627
RemoveDir(ExpandConstant('{userappdata}\Subtitle Edit\Ocr'));
624628
DelTree(ExpandConstant('{userappdata}\Subtitle Edit\Plugins\*.*'), False, True, False);

preview.mkv

34.9 KB
Binary file not shown.

src/ui/Forms/Assa/ApplyCustomStyles.cs

+4-39
Original file line numberDiff line numberDiff line change
@@ -343,23 +343,8 @@ private void buttonTogglePreview_Click(object sender, EventArgs e)
343343

344344
private bool GeneratePreviewViaMpv()
345345
{
346-
var fileName = Path.Combine(Configuration.DataDirectory, "preview.mp4");
347-
if (!File.Exists(fileName))
348-
{
349-
var isFfmpegAvailable = !Configuration.IsRunningOnWindows || !string.IsNullOrEmpty(Configuration.Settings.General.FFmpegLocation) && File.Exists(Configuration.Settings.General.FFmpegLocation);
350-
if (!isFfmpegAvailable)
351-
{
352-
return false;
353-
}
354-
355-
using (var p = GetFFmpegProcess(fileName))
356-
{
357-
p.Start();
358-
p.WaitForExit();
359-
}
360-
}
361-
362-
if (!LibMpvDynamic.IsInstalled)
346+
var fileName = VideoPreviewGenerator.GetVideoPreviewFileName();
347+
if (string.IsNullOrEmpty(fileName) || !LibMpvDynamic.IsInstalled)
363348
{
364349
return false;
365350
}
@@ -377,26 +362,6 @@ private bool GeneratePreviewViaMpv()
377362
return true;
378363
}
379364

380-
public static Process GetFFmpegProcess(string outputFileName)
381-
{
382-
var ffmpegLocation = Configuration.Settings.General.FFmpegLocation;
383-
if (!Configuration.IsRunningOnWindows && (string.IsNullOrEmpty(ffmpegLocation) || !File.Exists(ffmpegLocation)))
384-
{
385-
ffmpegLocation = "ffmpeg";
386-
}
387-
388-
return new Process
389-
{
390-
StartInfo =
391-
{
392-
FileName = ffmpegLocation,
393-
Arguments = $"-t 1 -f lavfi -i color=c=blue:s=720x480 -c:v libx264 -tune stillimage -pix_fmt yuv420p \"{outputFileName}\"",
394-
UseShellExecute = false,
395-
CreateNoWindow = true
396-
}
397-
};
398-
}
399-
400365
private void VideoLoaded(object sender, EventArgs e)
401366
{
402367
var format = new AdvancedSubStationAlpha();
@@ -407,8 +372,8 @@ private void VideoLoaded(object sender, EventArgs e)
407372
{
408373
var p = new Paragraph(_subtitle.Paragraphs[indices[0]])
409374
{
410-
StartTime = { TotalMilliseconds = 0 },
411-
EndTime = { TotalMilliseconds = 1000 }
375+
StartTime = { TotalMilliseconds = 0 },
376+
EndTime = { TotalMilliseconds = 2000 }
412377
};
413378
p.Text = styleToApply + p.Text;
414379
subtitle.Paragraphs.Add(p);

src/ui/Forms/Assa/SetPosition.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ private void buttonCancel_Click(object sender, EventArgs e)
216216

217217
private bool GeneratePreviewViaMpv()
218218
{
219-
var fileName = _videoFileName; // Path.Combine(Configuration.DataDirectory, "preview.mp4");
219+
var fileName = _videoFileName;
220220
if (!File.Exists(fileName))
221221
{
222222
var isFfmpegAvailable = !Configuration.IsRunningOnWindows || !string.IsNullOrEmpty(Configuration.Settings.General.FFmpegLocation) && File.Exists(Configuration.Settings.General.FFmpegLocation);

src/ui/Forms/Styles/SubStationAlphaStyles.cs

+2-37
Original file line numberDiff line numberDiff line change
@@ -407,23 +407,8 @@ private List<string> GetFontNames(byte[] fontBytes)
407407

408408
private bool GeneratePreviewViaMpv()
409409
{
410-
var fileName = Path.Combine(Configuration.DataDirectory, "preview.mp4");
411-
if (!File.Exists(fileName))
412-
{
413-
var isFfmpegAvailable = !Configuration.IsRunningOnWindows || !string.IsNullOrEmpty(Configuration.Settings.General.FFmpegLocation) && File.Exists(Configuration.Settings.General.FFmpegLocation);
414-
if (!isFfmpegAvailable)
415-
{
416-
return false;
417-
}
418-
419-
using (var p = GetFFmpegProcess(fileName))
420-
{
421-
p.Start();
422-
p.WaitForExit();
423-
}
424-
}
425-
426-
if (!LibMpvDynamic.IsInstalled)
410+
var fileName = VideoPreviewGenerator.GetVideoPreviewFileName();
411+
if (string.IsNullOrEmpty(fileName) || !LibMpvDynamic.IsInstalled)
427412
{
428413
return false;
429414
}
@@ -441,26 +426,6 @@ private bool GeneratePreviewViaMpv()
441426
return true;
442427
}
443428

444-
public static Process GetFFmpegProcess(string outputFileName)
445-
{
446-
var ffmpegLocation = Configuration.Settings.General.FFmpegLocation;
447-
if (!Configuration.IsRunningOnWindows && (string.IsNullOrEmpty(ffmpegLocation) || !File.Exists(ffmpegLocation)))
448-
{
449-
ffmpegLocation = "ffmpeg";
450-
}
451-
452-
return new Process
453-
{
454-
StartInfo =
455-
{
456-
FileName = ffmpegLocation,
457-
Arguments = $"-t 1 -f lavfi -i color=c=blue:s=720x480 -c:v libx264 -tune stillimage -pix_fmt yuv420p \"{outputFileName}\"",
458-
UseShellExecute = false,
459-
CreateNoWindow = true
460-
}
461-
};
462-
}
463-
464429
private void VideoStartLoaded(object sender, EventArgs e)
465430
{
466431
var format = new AdvancedSubStationAlpha();

src/ui/Logic/VideoPreviewGenerator.cs

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
using System;
2+
using System.Diagnostics;
3+
using System.Drawing.Imaging;
4+
using System.IO;
5+
using Nikse.SubtitleEdit.Core.Common;
6+
7+
namespace Nikse.SubtitleEdit.Logic
8+
{
9+
public class VideoPreviewGenerator
10+
{
11+
public static string GetVideoPreviewFileName()
12+
{
13+
var previewFileName = Path.Combine(Configuration.DataDirectory, "preview.mkv");
14+
if (File.Exists(previewFileName))
15+
{
16+
return previewFileName;
17+
}
18+
19+
try
20+
{
21+
const int rectangleSize = 9;
22+
var backgroundImage = TextDesigner.MakeBackgroundImage(720, 480, rectangleSize, Configuration.Settings.General.UseDarkTheme);
23+
var tempImageFileName = Path.Combine(Path.GetTempPath(), Guid.NewGuid() + ".png");
24+
backgroundImage.Save(tempImageFileName, ImageFormat.Png);
25+
var processMakeVideo = GetFFmpegProcess(tempImageFileName, previewFileName, backgroundImage.Width, backgroundImage.Height);
26+
processMakeVideo.Start();
27+
processMakeVideo.WaitForExit();
28+
}
29+
catch
30+
{
31+
return null;
32+
}
33+
34+
return File.Exists(previewFileName) ? previewFileName : null;
35+
}
36+
37+
private static Process GetFFmpegProcess(string imageFileName, string outputFileName, int videoWidth, int videoHeight)
38+
{
39+
var ffmpegLocation = Configuration.Settings.General.FFmpegLocation;
40+
if (!Configuration.IsRunningOnWindows && (string.IsNullOrEmpty(ffmpegLocation) || !File.Exists(ffmpegLocation)))
41+
{
42+
ffmpegLocation = "ffmpeg";
43+
}
44+
45+
return new Process
46+
{
47+
StartInfo =
48+
{
49+
FileName = ffmpegLocation,
50+
Arguments = $"-t 3 -loop 1 -i \"{imageFileName}\" -c:v libx264 -tune stillimage -shortest -s {videoWidth}x{videoHeight} \"{outputFileName}\"",
51+
UseShellExecute = false,
52+
CreateNoWindow = true
53+
}
54+
};
55+
}
56+
}
57+
}

src/ui/SubtitleEdit.csproj

+1
Original file line numberDiff line numberDiff line change
@@ -1240,6 +1240,7 @@
12401240
<Compile Include="Logic\VideoPlayers\MpcHC\NativeMethods.cs" />
12411241
<Compile Include="Logic\VideoPlayers\QuartsPlayer.cs" />
12421242
<Compile Include="Logic\VideoPlayers\VideoPlayer.cs" />
1243+
<Compile Include="Logic\VideoPreviewGenerator.cs" />
12431244
<Compile Include="Logic\WordSpellChecker.cs" />
12441245
<Compile Include="Program.cs" />
12451246
<Compile Include="Properties\AssemblyInfo.cs" />

0 commit comments

Comments
 (0)