2020-05-08 11:07:51 +02:00
|
|
|
|
using System;
|
2020-05-12 21:28:50 +02:00
|
|
|
|
using FFMpegCore.Enums;
|
2019-03-03 00:33:00 +01:00
|
|
|
|
using FFMpegCore.Test.Resources;
|
2019-02-08 11:19:40 +01:00
|
|
|
|
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
|
|
|
|
using System.IO;
|
2020-12-07 00:47:47 +01:00
|
|
|
|
using System.Linq;
|
2020-12-06 00:33:55 +01:00
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using FFMpegCore.Pipes;
|
2019-02-08 11:19:40 +01:00
|
|
|
|
|
2019-03-03 00:33:00 +01:00
|
|
|
|
namespace FFMpegCore.Test
|
2019-02-08 11:19:40 +01:00
|
|
|
|
{
|
|
|
|
|
[TestClass]
|
2020-12-07 00:47:47 +01:00
|
|
|
|
public class AudioTest
|
2019-02-08 11:19:40 +01:00
|
|
|
|
{
|
|
|
|
|
[TestMethod]
|
|
|
|
|
public void Audio_Remove()
|
|
|
|
|
{
|
2020-12-07 00:47:47 +01:00
|
|
|
|
using var outputFile = new TemporaryFile("out.mp4");
|
|
|
|
|
|
|
|
|
|
FFMpeg.Mute(TestResources.Mp4Video, outputFile);
|
|
|
|
|
var analysis = FFProbe.Analyse(outputFile);
|
|
|
|
|
|
|
|
|
|
Assert.IsTrue(analysis.VideoStreams.Any());
|
|
|
|
|
Assert.IsTrue(!analysis.AudioStreams.Any());
|
2019-02-08 11:19:40 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[TestMethod]
|
|
|
|
|
public void Audio_Save()
|
|
|
|
|
{
|
2020-12-07 00:47:47 +01:00
|
|
|
|
using var outputFile = new TemporaryFile("out.mp3");
|
|
|
|
|
|
|
|
|
|
FFMpeg.ExtractAudio(TestResources.Mp4Video, outputFile);
|
|
|
|
|
var analysis = FFProbe.Analyse(outputFile);
|
|
|
|
|
|
|
|
|
|
Assert.IsTrue(!analysis.VideoStreams.Any());
|
|
|
|
|
Assert.IsTrue(analysis.AudioStreams.Any());
|
2019-02-08 11:19:40 +01:00
|
|
|
|
}
|
2020-12-06 00:33:55 +01:00
|
|
|
|
[TestMethod]
|
|
|
|
|
public async Task Audio_FromRaw()
|
|
|
|
|
{
|
2020-12-07 01:20:13 +01:00
|
|
|
|
await using var file = File.Open(TestResources.RawAudio, FileMode.Open);
|
2020-12-06 00:33:55 +01:00
|
|
|
|
var memoryStream = new MemoryStream();
|
|
|
|
|
await FFMpegArguments
|
|
|
|
|
.FromPipeInput(new StreamPipeSource(file), options => options.ForceFormat("s16le"))
|
2020-12-07 17:52:47 +01:00
|
|
|
|
.OutputToPipe(new StreamPipeSink(memoryStream), options => options.ForceFormat("mp3"))
|
2020-12-06 00:33:55 +01:00
|
|
|
|
.ProcessAsynchronously();
|
|
|
|
|
}
|
|
|
|
|
|
2019-02-08 11:19:40 +01:00
|
|
|
|
[TestMethod]
|
|
|
|
|
public void Audio_Add()
|
|
|
|
|
{
|
2020-12-07 00:47:47 +01:00
|
|
|
|
using var outputFile = new TemporaryFile("out.mp4");
|
|
|
|
|
|
|
|
|
|
var success = FFMpeg.ReplaceAudio(TestResources.Mp4WithoutAudio, TestResources.Mp3Audio, outputFile);
|
|
|
|
|
var videoAnalysis = FFProbe.Analyse(TestResources.Mp4WithoutAudio);
|
|
|
|
|
var audioAnalysis = FFProbe.Analyse(TestResources.Mp3Audio);
|
|
|
|
|
var outputAnalysis = FFProbe.Analyse(outputFile);
|
|
|
|
|
|
|
|
|
|
Assert.IsTrue(success);
|
|
|
|
|
Assert.AreEqual(Math.Max(videoAnalysis.Duration.TotalSeconds, audioAnalysis.Duration.TotalSeconds), outputAnalysis.Duration.TotalSeconds, 0.15);
|
|
|
|
|
Assert.IsTrue(File.Exists(outputFile));
|
2019-02-08 11:19:40 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[TestMethod]
|
|
|
|
|
public void Image_AddAudio()
|
|
|
|
|
{
|
2020-12-07 00:47:47 +01:00
|
|
|
|
using var outputFile = new TemporaryFile("out.mp4");
|
|
|
|
|
FFMpeg.PosterWithAudio(TestResources.PngImage, TestResources.Mp3Audio, outputFile);
|
|
|
|
|
var analysis = FFProbe.Analyse(TestResources.Mp3Audio);
|
|
|
|
|
Assert.IsTrue(analysis.Duration.TotalSeconds > 0);
|
|
|
|
|
Assert.IsTrue(File.Exists(outputFile));
|
2019-02-08 11:19:40 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|