FFMpegCore/FFMpegCore.Test/AudioTest.cs

82 lines
2.5 KiB
C#
Raw Normal View History

2020-05-08 11:07:51 +02:00
using System;
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;
2019-03-03 00:33:00 +01:00
namespace FFMpegCore.Test
2019-02-08 11:19:40 +01:00
{
[TestClass]
public class AudioTest : BaseTest
{
[TestMethod]
public void Audio_Remove()
{
var output = Input.OutputLocation(VideoType.Mp4);
try
{
2020-05-08 11:07:51 +02:00
FFMpeg.Mute(Input.FullName, output);
Assert.IsTrue(File.Exists(output));
2019-02-08 11:19:40 +01:00
}
finally
{
2020-05-08 11:07:51 +02:00
if (File.Exists(output)) File.Delete(output);
2019-02-08 11:19:40 +01:00
}
}
[TestMethod]
public void Audio_Save()
{
var output = Input.OutputLocation(AudioType.Mp3);
try
{
2020-05-08 11:07:51 +02:00
FFMpeg.ExtractAudio(Input.FullName, output);
Assert.IsTrue(File.Exists(output));
2019-02-08 11:19:40 +01:00
}
finally
{
2020-05-08 11:07:51 +02:00
if (File.Exists(output)) File.Delete(output);
2019-02-08 11:19:40 +01:00
}
}
[TestMethod]
public void Audio_Add()
{
var output = Input.OutputLocation(VideoType.Mp4);
try
{
2020-05-08 11:07:51 +02:00
var success = FFMpeg.ReplaceAudio(VideoLibrary.LocalVideoNoAudio.FullName, VideoLibrary.LocalAudio.FullName, output);
Assert.IsTrue(success);
var audioAnalysis = FFProbe.Analyse(VideoLibrary.LocalVideoNoAudio.FullName);
var videoAnalysis = FFProbe.Analyse(VideoLibrary.LocalAudio.FullName);
var outputAnalysis = FFProbe.Analyse(output);
Assert.AreEqual(Math.Max(videoAnalysis.Duration.TotalSeconds, audioAnalysis.Duration.TotalSeconds), outputAnalysis.Duration.TotalSeconds, 0.15);
Assert.IsTrue(File.Exists(output));
2019-02-08 11:19:40 +01:00
}
finally
{
2020-05-08 11:07:51 +02:00
if (File.Exists(output)) File.Delete(output);
2019-02-08 11:19:40 +01:00
}
}
[TestMethod]
public void Image_AddAudio()
{
var output = Input.OutputLocation(VideoType.Mp4);
try
{
2020-05-08 11:07:51 +02:00
FFMpeg.PosterWithAudio(VideoLibrary.LocalCover.FullName, VideoLibrary.LocalAudio.FullName, output);
var analysis = FFProbe.Analyse(VideoLibrary.LocalAudio.FullName);
Assert.IsTrue(analysis.Duration.TotalSeconds > 0);
Assert.IsTrue(File.Exists(output));
2019-02-08 11:19:40 +01:00
}
finally
{
2020-05-08 11:07:51 +02:00
if (File.Exists(output)) File.Delete(output);
2019-02-08 11:19:40 +01:00
}
}
}
}