Mp4 fix + unit test

This commit is contained in:
niksedk 2014-10-05 00:10:23 +02:00
parent d5af0383b4
commit cdbc5f083d
4 changed files with 36 additions and 5 deletions

View File

@ -106,9 +106,11 @@ namespace Nikse.SubtitleEdit.Logic.Mp4
public MP4Parser(string fileName)
{
FileName = fileName;
var fs = new FileStream(FileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
ParseMp4(fs);
fs.Close();
using (var fs = new FileStream(FileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
{
ParseMp4(fs);
fs.Close();
}
}
public MP4Parser(FileStream fs)
@ -129,8 +131,8 @@ namespace Nikse.SubtitleEdit.Logic.Mp4
if (Size < 8)
return;
if (Name == "moov" && Moov != null)
Moov = new Moov(fs, Position);
if (Name == "moov" && Moov == null)
Moov = new Moov(fs, Position); // only scan first "moov" element
count++;
if (count > 100)

Binary file not shown.

View File

@ -0,0 +1,23 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.IO;
namespace Test.Logic.Mp4
{
[TestClass]
[DeploymentItem("Files")]
public class Mp4Test
{
[TestMethod]
public void Mp4Test1()
{
string fileName = Path.Combine(Directory.GetCurrentDirectory(), "sample_MP4_SRT.mp4");
var parser = new Nikse.SubtitleEdit.Logic.Mp4.MP4Parser(fileName);
var tracks = parser.GetSubtitleTracks();
Assert.IsTrue(tracks.Count == 1);
Assert.IsTrue(tracks[0].Mdia.Minf.Stbl.EndTimeCodes.Count == 2);
}
}
}

View File

@ -49,6 +49,7 @@
<Compile Include="Logic\Dictionaries\NamesListTest.cs" />
<Compile Include="Core\HtmlUtilTest.cs" />
<Compile Include="Logic\Dictionaries\OcrFixReplaceListTest.cs" />
<Compile Include="Logic\Mp4\Mp4Test.cs" />
<Compile Include="Logic\TransportStream\TransportStreamTest.cs" />
<Compile Include="Logic\TarFileTest.cs" />
<Compile Include="Logic\VideoFormats\MatroskaTest.cs" />
@ -90,6 +91,11 @@
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>
<ItemGroup>
<Content Include="Files\sample_MP4_SRT.mp4">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.