mirror of
https://github.com/SubtitleEdit/subtitleedit.git
synced 2024-11-22 19:22:53 +01:00
Fix issue with frames - thx Jose /darnn :)
Fix#3929
This commit is contained in:
parent
408060754d
commit
3fad7e2703
@ -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);
|
||||
|
55
src/Test/Core/SubtitleFormatTest.cs
Normal file
55
src/Test/Core/SubtitleFormatTest.cs
Normal 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);
|
||||
}
|
||||
}
|
||||
}
|
@ -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" />
|
||||
|
Loading…
Reference in New Issue
Block a user