Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Features: Progress #98

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions MediaToolkit src/MediaToolkit.Test/Features/ArgumentsFeature.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
using System;
using System.Collections.Generic;
using MediaToolkit.Util;
using NUnit.Framework;

namespace MediaToolkit.Test.Features
{
/*
* The FFmpeg library supports a huge range of arguments and the current implementation
* of CommandBuilder isn't really designed to allow clients to take full advantage of
* FFmpegs capabilities. So... about time we changed things up a little.
*
*
*
* ******/


[TestFixture]
public class ArgumentsFeature
{
[Test]
public void BuildArgument()
{
string expectedOutput = @"-ss 20 -i ""test.mp4"" -vframes 1 ""test.jpg""";

string inputFilePath = @"test.mp4";
string outputFilePath = @"test.jpg";
TimeSpan timespan = TimeSpan.FromSeconds(20);

IArgument argument = new GetThumbnailArgument(inputFilePath, outputFilePath, timespan);
argument.ComposeArgument();

Assert.That(argument.Argument.ToString() == expectedOutput, "{0} != {1}".FormatInvariant(argument.Argument, expectedOutput));
}


}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using System;
using System.Text;
using MediaToolkit.Util;

namespace MediaToolkit.Test.Features
{
public class GetThumbnailArgument : IArgument
{
public GetThumbnailArgument(string inputFilePath, string outputFilePath, TimeSpan seekPosition)
{
this.Argument = new StringBuilder();
InputFilePath = inputFilePath;
OutputFilePath = outputFilePath;
SeekPosition = seekPosition;
}

public string InputFilePath { get; private set; }
public string OutputFilePath { get; private set; }
public TimeSpan SeekPosition { get; private set; }


public void ComposeArgument()
{
this.Argument.Append("-ss {0} ".FormatInvariant(this.SeekPosition.TotalSeconds));
this.Argument.Append("-i \"{0}\" ".FormatInvariant(this.InputFilePath));
this.Argument.Append("-vframes {0} ".FormatInvariant(1));
this.Argument.Append("\"{0}\"".FormatInvariant(this.OutputFilePath));
}

public StringBuilder Argument { get; private set; }
}
}
11 changes: 11 additions & 0 deletions MediaToolkit src/MediaToolkit.Test/Features/IArgument.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using System.Text;

namespace MediaToolkit.Test.Features
{
public interface IArgument
{
StringBuilder Argument { get; }

void ComposeArgument();
}
}
12 changes: 12 additions & 0 deletions MediaToolkit src/MediaToolkit.Test/Features/IMediaProcessor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
namespace MediaToolkit.Test.Features
{
/*
* This will eventually replace the "Engine" class
*/

public interface IMediaProcessor<TArgument> where TArgument : IArgument
{


}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using System;
using System.Linq;
using MediaToolkit.Features;
using MediaToolkit.Util;
using NUnit.Framework;

namespace MediaToolkit.Test.Features
{
[TestFixture]
public class MetadataTestsAndFeatures
{
[Test]
public void Init()
{
MetadataProvider provider = new MetadataProvider();
var meta = provider.GetMetadata(
@"../../TestVideo/BigBunny.m4v");

meta.MetadataIndex.Select(kvp => "{0}:{1}".FormatInvariant(kvp.Key, kvp.Value) )
.ToList()
.ForEach(Console.WriteLine);
}


}
}
5 changes: 5 additions & 0 deletions MediaToolkit src/MediaToolkit.Test/MediaToolkit.Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@
</ItemGroup>
<ItemGroup>
<Compile Include="ConvertTest.cs" />
<Compile Include="Features\ArgumentsFeature.cs" />
<Compile Include="Features\GetThumbnailArgument.cs" />
<Compile Include="Features\IArgument.cs" />
<Compile Include="Features\IMediaProcessor.cs" />
<Compile Include="Features\MetadataTestsAndFeatures.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Util\RegexEngineTest.cs" />
</ItemGroup>
Expand Down
25 changes: 1 addition & 24 deletions MediaToolkit src/MediaToolkit/EngineBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
using System.Configuration;
using System.Diagnostics;
using System.IO;
using System.IO.Compression;
using System.Reflection;
using System.Threading;

using MediaToolkit.Properties;
Expand Down Expand Up @@ -86,7 +84,7 @@ private void EnsureFFmpegFileExists()
{
if (!File.Exists(this.FFmpegFilePath))
{
UnpackFFmpegExecutable(this.FFmpegFilePath);
Document.Decompress(Resources.FFmpegManifestResourceName, this.FFmpegFilePath);
}
}

Expand All @@ -111,27 +109,6 @@ private static void KillFFmpegProcesses()
}
}

///-------------------------------------------------------------------------------------------------
/// <summary> Unpack ffmpeg executable. </summary>
/// <exception cref="Exception"> Thrown when an exception error condition occurs. </exception>
private static void UnpackFFmpegExecutable(string path)
{
Stream compressedFFmpegStream = Assembly.GetExecutingAssembly()
.GetManifestResourceStream(Resources.FFmpegManifestResourceName);

if (compressedFFmpegStream == null)
{
throw new Exception(Resources.Exceptions_Null_FFmpeg_Gzip_Stream);
}

using (FileStream fileStream = new FileStream(path, FileMode.Create))
using (GZipStream compressedStream = new GZipStream(compressedFFmpegStream, CompressionMode.Decompress))
{
compressedStream.CopyTo(fileStream);
}
}



///-------------------------------------------------------------------------------------------------
/// <summary>
Expand Down
9 changes: 9 additions & 0 deletions MediaToolkit src/MediaToolkit/Features/IMetadata.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using System.Collections.Generic;

namespace MediaToolkit.Features
{
public interface IMetadata
{
Dictionary<string, string> MetadataIndex { get; set; }
}
}
9 changes: 9 additions & 0 deletions MediaToolkit src/MediaToolkit/Features/IMetadataProvider.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using System;

namespace MediaToolkit.Features
{
public interface IMetadataProvider : IDisposable
{
IMetadata GetMetadata(string filename);
}
}
9 changes: 9 additions & 0 deletions MediaToolkit src/MediaToolkit/Features/Metadata.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using System.Collections.Generic;

namespace MediaToolkit.Features
{
public class Metadata : IMetadata
{
public Dictionary<string, string> MetadataIndex { get; set; }
}
}
70 changes: 70 additions & 0 deletions MediaToolkit src/MediaToolkit/Features/MetadataProvider.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using MediaToolkit.Util;

namespace MediaToolkit.Features
{
public class MetadataProvider : IMetadataProvider
{
const string DefaultExiftoolPath = "/MediaToolkit/exiftool.exe";

public MetadataProvider()
{
Document.Decompress("MediaToolkit.Resources.Exiftool.exe.gz", DefaultExiftoolPath);

this.isDisposed = false;
this.exiftoolProcess = new Process();
}

private bool isDisposed;

private readonly Process exiftoolProcess;

protected virtual void Dispose(bool isDisposing)
{
if (!isDisposing) return;
if (this.isDisposed) return;

this.isDisposed = true;
this.exiftoolProcess.Dispose();
GC.SuppressFinalize(this);
}

public void Dispose()
{
this.Dispose(true);
}

public IMetadata GetMetadata(string filename)
{
exiftoolProcess.StartInfo = new ProcessStartInfo
{
Arguments = "\"{0}\"".FormatInvariant(filename),
FileName = DefaultExiftoolPath,
CreateNoWindow = true,
RedirectStandardInput = false,
RedirectStandardOutput = true,
RedirectStandardError = true,
UseShellExecute = false,
WindowStyle = ProcessWindowStyle.Hidden
};

Dictionary<string, string> metadataIndex = new Dictionary<string, string>();

exiftoolProcess.OutputDataReceived += (sender, args) =>
{
if (args.Data.Contains("ExifTool Version Number")) return;

var keyValue = args.Data.Split(':');
metadataIndex.Add(keyValue[0], keyValue[1]);
};

exiftoolProcess.Start();
exiftoolProcess.BeginOutputReadLine();
exiftoolProcess.WaitForExit();

return new Metadata {MetadataIndex = metadataIndex};
}
}
}
12 changes: 9 additions & 3 deletions MediaToolkit src/MediaToolkit/MediaToolkit.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
Expand All @@ -9,7 +9,7 @@
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>MediaToolkit</RootNamespace>
<AssemblyName>MediaToolkit</AssemblyName>
<TargetFrameworkVersion>v2.0</TargetFrameworkVersion>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<TargetFrameworkProfile />
<PrimaryVersionType>AssemblyVersionAttribute</PrimaryVersionType>
Expand Down Expand Up @@ -64,6 +64,10 @@
<Compile Include="Engine.cs" />
<Compile Include="EngineBase.cs" />
<Compile Include="EngineParameters.cs" />
<Compile Include="Features\IMetadata.cs" />
<Compile Include="Features\IMetadataProvider.cs" />
<Compile Include="Features\Metadata.cs" />
<Compile Include="Features\MetadataProvider.cs" />
<Compile Include="FFmpegTask.cs" />
<Compile Include="Model\Metadata.cs" />
<Compile Include="Options\ConversionOptions.cs" />
Expand All @@ -86,8 +90,10 @@
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
<SubType>Designer</SubType>
</EmbeddedResource>
<EmbeddedResource Include="Resources\Exiftool.exe.gz" />
<EmbeddedResource Include="Resources\FFmpeg.exe.gz" />
</ItemGroup>
<ItemGroup />
<Import Project="$(MSBuildToolsPath)\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.
Expand All @@ -96,4 +102,4 @@
<Target Name="AfterBuild">
</Target>
-->
</Project>
</Project>
4 changes: 2 additions & 2 deletions MediaToolkit src/MediaToolkit/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
[assembly: AssemblyCompany("Aydin")]
[assembly: AssemblyCopyright("Copyright © 2014")]
[assembly: AssemblyDescription("A .NET wrapper for FFmpeg, to convert & process all types of media.")]
[assembly: AssemblyFileVersion("1.1.0.0")]
[assembly: AssemblyFileVersion("1.1.0.1")]
[assembly: AssemblyProduct("MediaToolkit")]
[assembly: AssemblyTitle("MediaToolkit")]
[assembly: AssemblyVersion("1.1.0.0")]
[assembly: AssemblyVersion("1.1.0.1")]
[assembly: ComVisible(false)]
[assembly: Guid("e03e0a90-f6c1-4d13-8649-d61783abeff3")]

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading