Skip to content

Commit

Permalink
Special version using images from a folder instead of extracting them…
Browse files Browse the repository at this point in the history
… from a video

Images are sorted by name. Most features should work as expected.
  • Loading branch information
mlaily committed May 1, 2021
1 parent 7475c96 commit 9efb4e3
Show file tree
Hide file tree
Showing 14 changed files with 114 additions and 325 deletions.
2 changes: 1 addition & 1 deletion MovieBarCodeGenerator.Tests/DebugTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public void Generate_All_Barcode_Settings_Combinations()
{
Assert.Inconclusive("Uncomment me to run the test");

var ffmpegWrapper = new FfmpegWrapper(FfmpegExecutablePath);
var ffmpegWrapper = new ImageProvider();
var streamProcessor = new ImageStreamProcessor();

var allGenerators = new List<IBarGenerator>();
Expand Down
13 changes: 1 addition & 12 deletions MovieBarCodeGenerator.Tests/VideoProcessingTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,17 +50,6 @@ public void TestFileCanBeCreated()
Assert.IsTrue(File.Exists(TestVideoFileName));
}

[Test]
public void FfmpegWrapper_GetMediaDuration_Returns_Correct_Value()
{
CreateTestVideoIfNecessary();
var ffmpegWrapper = new FfmpegWrapper(FfmpegExecutablePath);

var duration = ffmpegWrapper.GetMediaDuration(TestVideoFileName, CancellationToken.None);

Assert.AreEqual(TimeSpan.FromSeconds(TestVideoDuration), duration);
}

[Test]
[TestCase(1)]
[TestCase(2)]
Expand All @@ -70,7 +59,7 @@ public void FfmpegWrapper_GetMediaDuration_Returns_Correct_Value()
public async Task FfmpegWrapper_GetImagesFromMedia_Returns_Expected_Values(int requestedFrameCount)
{
CreateTestVideoIfNecessary();
var ffmpegWrapper = new FfmpegWrapper(FfmpegExecutablePath);
var ffmpegWrapper = new ImageProvider();

var images = ffmpegWrapper.GetImagesFromMedia(
TestVideoFileName,
Expand Down
5 changes: 2 additions & 3 deletions MovieBarCodeGenerator/CLI/CLIBatchProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ namespace MovieBarCodeGenerator.CLI
public class CLIBatchProcessor
{
private BarCodeParametersValidator _barCodeParametersValidator = new BarCodeParametersValidator();
private FfmpegWrapper _ffmpegWrapper = new FfmpegWrapper("ffmpeg.exe");
private ImageProvider _imageProvider = new ImageProvider();
private ImageStreamProcessor _imageProcessor = new ImageStreamProcessor();

public void Process(string[] args)
Expand Down Expand Up @@ -168,7 +168,6 @@ private void DealWithOneInputFile(RawArguments arguments)
rawBarWidth: arguments.RawBarWidth,
rawImageWidth: arguments.RawWidth,
rawImageHeight: arguments.RawHeight,
useInputHeightForOutput: arguments.UseInputHeight,
// Choosing whether to overwrite or not is done after validating parameters, not here
shouldOverwriteOutputPaths: x => { existingOutputs = x; return true; },
generators);
Expand All @@ -191,7 +190,7 @@ private void DealWithOneInputFile(RawArguments arguments)
{
result = _imageProcessor.CreateBarCodes(
parameters,
_ffmpegWrapper,
_imageProvider,
CancellationToken.None,
null,
x => Console.WriteLine(x));
Expand Down
16 changes: 6 additions & 10 deletions MovieBarCodeGenerator/Core/BarCodeParametersValidator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ public BarCodeParameters GetValidatedParameters(
string rawBarWidth,
string rawImageWidth,
string rawImageHeight,
bool useInputHeightForOutput,
Func<IReadOnlyCollection<string>, bool> shouldOverwriteOutputPaths,
IEnumerable<IBarGenerator> barGenerators)
{
Expand Down Expand Up @@ -84,16 +83,13 @@ public BarCodeParameters GetValidatedParameters(
}

int? imageHeight = null;
if (!useInputHeightForOutput)
if (int.TryParse(rawImageHeight, out var nonNullableImageHeight) && nonNullableImageHeight > 0)
{
if (int.TryParse(rawImageHeight, out var nonNullableImageHeight) && nonNullableImageHeight > 0)
{
imageHeight = nonNullableImageHeight;
}
else
{
throw new ParameterValidationException("Invalid output height.");
}
imageHeight = nonNullableImageHeight;
}
else
{
throw new ParameterValidationException("Invalid output height.");
}

return new BarCodeParameters
Expand Down
116 changes: 0 additions & 116 deletions MovieBarCodeGenerator/Core/BitmapStream.cs

This file was deleted.

145 changes: 0 additions & 145 deletions MovieBarCodeGenerator/Core/FfmpegWrapper.cs

This file was deleted.

3 changes: 2 additions & 1 deletion MovieBarCodeGenerator/Core/GdiBarGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
Expand Down Expand Up @@ -89,7 +90,7 @@ public GdiBarGenerator(
public string DisplayName => _displayName ?? Name;
public string FileNameSuffix { get; }

public Image GetBar(BitmapStream source, int barWidth, int barHeight)
public Image GetBar(FileStream source, int barWidth, int barHeight)
{
var sourceImage = Image.FromStream(source, true, false);
var useSaneDefaults = ScalingMode == ScalingMode.Sane;
Expand Down
Loading

0 comments on commit 9efb4e3

Please sign in to comment.