Add test for the new audio pipe

This commit is contained in:
Julien Loir 2021-05-25 16:14:40 +02:00
parent 717b404b7f
commit acd462a527
2 changed files with 157 additions and 3 deletions

View file

@ -1,10 +1,13 @@
using System;
using FFMpegCore.Enums;
using FFMpegCore.Exceptions;
using FFMpegCore.Pipes;
using FFMpegCore.Test.Resources;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using FFMpegCore.Pipes;
namespace FFMpegCore.Test
{
@ -69,5 +72,155 @@ public void Image_AddAudio()
Assert.IsTrue(analysis.Duration.TotalSeconds > 0);
Assert.IsTrue(File.Exists(outputFile));
}
[TestMethod, Timeout(10000)]
public void Audio_ToAAC_Args_Pipe()
{
using var outputFile = new TemporaryFile($"out{VideoType.Mp4.Extension}");
var samples = new List<IAudioSample>
{
new PcmAudioSampleWrapper(new byte[] { 0, 0 }),
new PcmAudioSampleWrapper(new byte[] { 0, 0 }),
};
var audioSamplesSource = new RawAudioPipeSource(samples)
{
Channels = 2,
Format = "s8",
SampleRate = 8000,
};
var success = FFMpegArguments
.FromPipeInput(audioSamplesSource)
.OutputToFile(outputFile, false, opt => opt
.WithAudioCodec(AudioCodec.Aac))
.ProcessSynchronously();
Assert.IsTrue(success);
}
[TestMethod, Timeout(10000)]
public void Audio_ToLibVorbis_Args_Pipe()
{
using var outputFile = new TemporaryFile($"out{VideoType.Mp4.Extension}");
var samples = new List<IAudioSample>
{
new PcmAudioSampleWrapper(new byte[] { 0, 0 }),
new PcmAudioSampleWrapper(new byte[] { 0, 0 }),
};
var audioSamplesSource = new RawAudioPipeSource(samples)
{
Channels = 2,
Format = "s8",
SampleRate = 8000,
};
var success = FFMpegArguments
.FromPipeInput(audioSamplesSource)
.OutputToFile(outputFile, false, opt => opt
.WithAudioCodec(AudioCodec.LibVorbis))
.ProcessSynchronously();
Assert.IsTrue(success);
}
[TestMethod, Timeout(10000)]
public async Task Audio_ToAAC_Args_Pipe_Async()
{
using var outputFile = new TemporaryFile($"out{VideoType.Mp4.Extension}");
var samples = new List<IAudioSample>
{
new PcmAudioSampleWrapper(new byte[] { 0, 0 }),
new PcmAudioSampleWrapper(new byte[] { 0, 0 }),
};
var audioSamplesSource = new RawAudioPipeSource(samples)
{
Channels = 2,
Format = "s8",
SampleRate = 8000,
};
var success = await FFMpegArguments
.FromPipeInput(audioSamplesSource)
.OutputToFile(outputFile, false, opt => opt
.WithAudioCodec(AudioCodec.Aac))
.ProcessAsynchronously();
Assert.IsTrue(success);
}
[TestMethod, Timeout(10000)]
public void Audio_ToAAC_Args_Pipe_ValidDefaultConfiguration()
{
using var outputFile = new TemporaryFile($"out{VideoType.Mp4.Extension}");
var samples = new List<IAudioSample>
{
new PcmAudioSampleWrapper(new byte[] { 0, 0 }),
new PcmAudioSampleWrapper(new byte[] { 0, 0 }),
};
var audioSamplesSource = new RawAudioPipeSource(samples);
var success = FFMpegArguments
.FromPipeInput(audioSamplesSource)
.OutputToFile(outputFile, false, opt => opt
.WithAudioCodec(AudioCodec.Aac))
.ProcessSynchronously();
Assert.IsTrue(success);
}
[TestMethod, Timeout(10000)]
public void Audio_ToAAC_Args_Pipe_InvalidChannels()
{
using var outputFile = new TemporaryFile($"out{VideoType.Mp4.Extension}");
var audioSamplesSource = new RawAudioPipeSource(new List<IAudioSample>())
{
Channels = 0,
};
var ex = Assert.ThrowsException<FFMpegException>(() => FFMpegArguments
.FromPipeInput(audioSamplesSource)
.OutputToFile(outputFile, false, opt => opt
.WithAudioCodec(AudioCodec.Aac))
.ProcessSynchronously());
}
[TestMethod, Timeout(10000)]
public void Audio_ToAAC_Args_Pipe_InvalidFormat()
{
using var outputFile = new TemporaryFile($"out{VideoType.Mp4.Extension}");
var audioSamplesSource = new RawAudioPipeSource(new List<IAudioSample>())
{
Format = "s8le",
};
var ex = Assert.ThrowsException<FFMpegException>(() => FFMpegArguments
.FromPipeInput(audioSamplesSource)
.OutputToFile(outputFile, false, opt => opt
.WithAudioCodec(AudioCodec.Aac))
.ProcessSynchronously());
}
[TestMethod, Timeout(10000)]
public void Audio_ToAAC_Args_Pipe_InvalidSampleRate()
{
using var outputFile = new TemporaryFile($"out{VideoType.Mp4.Extension}");
var audioSamplesSource = new RawAudioPipeSource(new List<IAudioSample>())
{
SampleRate = 0,
};
var ex = Assert.ThrowsException<FFMpegException>(() => FFMpegArguments
.FromPipeInput(audioSamplesSource)
.OutputToFile(outputFile, false, opt => opt
.WithAudioCodec(AudioCodec.Aac))
.ProcessSynchronously());
}
}
}

View file

@ -6,7 +6,8 @@
namespace FFMpegCore.Pipes
{
/// <summary>
/// Implementation of <see cref="IPipeSource"/> for a raw audio stream that is gathered from <see cref="IEnumerator{IAudioFrame}"/>
/// Implementation of <see cref="IPipeSource"/> for a raw audio stream that is gathered from <see cref="IEnumerator{IAudioFrame}"/>.
/// It is the user's responbility to make sure the enumerated samples match the configuration provided to this pipe.
/// </summary>
public class RawAudioPipeSource : IPipeSource
{