Fix issue with frames - thx Jose /darnn :)

Fix#3929
This commit is contained in:
Nikolaj Olsson 2020-01-20 07:31:58 +01:00
parent 408060754d
commit 3fad7e2703
3 changed files with 57 additions and 1 deletions

View File

@ -395,7 +395,7 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
public static int MillisecondsToFramesMaxFrameRate(double milliseconds)
{
int frames = (int)Math.Round(milliseconds / TimeCode.BaseUnit / GetFrameForCalculation(Configuration.Settings.General.CurrentFrameRate));
int frames = (int)Math.Round(milliseconds / (TimeCode.BaseUnit / GetFrameForCalculation(Configuration.Settings.General.CurrentFrameRate)));
if (frames >= Configuration.Settings.General.CurrentFrameRate)
{
frames = (int)(Configuration.Settings.General.CurrentFrameRate - 0.01);

View File

@ -0,0 +1,55 @@
using Nikse.SubtitleEdit.Core;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Nikse.SubtitleEdit.Core.SubtitleFormats;
namespace Test.Core
{
[TestClass]
public class SubtitleFormatTest
{
[TestMethod]
public void MillisecondsToFrames()
{
Configuration.Settings.General.CurrentFrameRate = 23.976;
var fr = SubtitleFormat.MillisecondsToFrames(100);
Assert.AreEqual(2, fr);
fr = SubtitleFormat.MillisecondsToFrames(999);
Assert.AreEqual(24, fr);
Configuration.Settings.General.CurrentFrameRate = 30;
fr = SubtitleFormat.MillisecondsToFrames(100);
Assert.AreEqual(3, fr);
fr = SubtitleFormat.MillisecondsToFrames(999);
Assert.AreEqual(30, fr);
fr = SubtitleFormat.MillisecondsToFrames(2000);
Assert.AreEqual(60, fr);
}
[TestMethod]
public void MillisecondsToFramesMaxFrameRate()
{
Configuration.Settings.General.CurrentFrameRate = 30;
var fr = SubtitleFormat.MillisecondsToFramesMaxFrameRate(100);
Assert.AreEqual(3, fr);
fr = SubtitleFormat.MillisecondsToFramesMaxFrameRate(1000);
Assert.AreEqual(29, fr);
fr = SubtitleFormat.MillisecondsToFramesMaxFrameRate(2000);
Assert.AreEqual(29, fr);
}
[TestMethod]
public void FramesToMilliseconds()
{
Configuration.Settings.General.CurrentFrameRate = 30;
var fr = SubtitleFormat.FramesToMilliseconds(1);
Assert.AreEqual(33, fr);
fr = SubtitleFormat.FramesToMilliseconds(30);
Assert.AreEqual(1000, fr);
fr = SubtitleFormat.FramesToMillisecondsMax999(30);
Assert.AreEqual(999, fr);
}
}
}

View File

@ -52,6 +52,7 @@
<Compile Include="Core\PlainTextImporterTest.cs" />
<Compile Include="Core\StringExtensionsTest.cs" />
<Compile Include="Core\NikseBitmapTest.cs" />
<Compile Include="Core\SubtitleFormatTest.cs" />
<Compile Include="Core\SubtitleTest.cs" />
<Compile Include="Core\RichTextToPlainTextTest.cs" />
<Compile Include="Logic\BridgeGapsTest.cs" />