2021-03-05 18:06:40 +01:00
|
|
|
|
using System;
|
|
|
|
|
using System.IO;
|
2020-05-08 11:07:51 +02:00
|
|
|
|
using System.Threading.Tasks;
|
2020-03-01 12:55:57 +01:00
|
|
|
|
using FFMpegCore.Test.Resources;
|
|
|
|
|
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
|
|
|
|
|
|
|
|
|
namespace FFMpegCore.Test
|
|
|
|
|
{
|
|
|
|
|
[TestClass]
|
|
|
|
|
public class FFProbeTests
|
|
|
|
|
{
|
|
|
|
|
[TestMethod]
|
|
|
|
|
public void Probe_TooLongOutput()
|
|
|
|
|
{
|
2020-12-07 00:47:47 +01:00
|
|
|
|
Assert.ThrowsException<System.Text.Json.JsonException>(() => FFProbe.Analyse(TestResources.Mp4Video, 5));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[TestMethod]
|
|
|
|
|
public async Task Audio_FromStream_Duration()
|
|
|
|
|
{
|
2020-12-07 21:00:43 +01:00
|
|
|
|
var fileAnalysis = await FFProbe.AnalyseAsync(TestResources.WebmVideo);
|
|
|
|
|
await using var inputStream = File.OpenRead(TestResources.WebmVideo);
|
2020-12-07 00:47:47 +01:00
|
|
|
|
var streamAnalysis = await FFProbe.AnalyseAsync(inputStream);
|
|
|
|
|
Assert.IsTrue(fileAnalysis.Duration == streamAnalysis.Duration);
|
2020-03-01 12:55:57 +01:00
|
|
|
|
}
|
2021-02-07 01:50:12 +01:00
|
|
|
|
|
|
|
|
|
[TestMethod]
|
|
|
|
|
public void MediaAnalysis_ParseDuration()
|
|
|
|
|
{
|
|
|
|
|
var durationHHMMSS = new FFProbeStream { Duration = "05:12:59.177" };
|
|
|
|
|
var longDuration = new FFProbeStream { Duration = "149:07:50.911750" };
|
|
|
|
|
var shortDuration = new FFProbeStream { Duration = "00:00:00.83" };
|
|
|
|
|
|
|
|
|
|
var testdurationHHMMSS = MediaAnalysis.ParseDuration(durationHHMMSS);
|
|
|
|
|
var testlongDuration = MediaAnalysis.ParseDuration(longDuration);
|
|
|
|
|
var testshortDuration = MediaAnalysis.ParseDuration(shortDuration);
|
|
|
|
|
|
|
|
|
|
Assert.IsTrue(testdurationHHMMSS.Days == 0 && testdurationHHMMSS.Hours == 5 && testdurationHHMMSS.Minutes == 12 && testdurationHHMMSS.Seconds == 59 && testdurationHHMMSS.Milliseconds == 177);
|
|
|
|
|
Assert.IsTrue(testlongDuration.Days == 6 && testlongDuration.Hours == 5 && testlongDuration.Minutes == 7 && testlongDuration.Seconds == 50 && testlongDuration.Milliseconds == 911);
|
|
|
|
|
Assert.IsTrue(testdurationHHMMSS.Days == 0 && testshortDuration.Hours == 0 && testshortDuration.Minutes == 0 && testshortDuration.Seconds == 0 && testshortDuration.Milliseconds == 830);
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-05 18:06:40 +01:00
|
|
|
|
[TestMethod]
|
|
|
|
|
public async Task Uri_Duration()
|
|
|
|
|
{
|
|
|
|
|
var fileAnalysis = await FFProbe.AnalyseAsync(new Uri("https://github.com/rosenbjerg/FFMpegCore/raw/master/FFMpegCore.Test/Resources/input_3sec.webm"));
|
|
|
|
|
Assert.IsNotNull(fileAnalysis);
|
|
|
|
|
}
|
2020-03-01 12:55:57 +01:00
|
|
|
|
|
|
|
|
|
[TestMethod]
|
|
|
|
|
public void Probe_Success()
|
|
|
|
|
{
|
2020-12-07 00:47:47 +01:00
|
|
|
|
var info = FFProbe.Analyse(TestResources.Mp4Video);
|
2020-10-25 17:11:52 +01:00
|
|
|
|
Assert.AreEqual(3, info.Duration.Seconds);
|
2020-05-09 17:53:03 +02:00
|
|
|
|
|
2021-03-05 18:06:40 +01:00
|
|
|
|
Assert.AreEqual("5.1", info.PrimaryAudioStream!.ChannelLayout);
|
2020-05-09 17:53:03 +02:00
|
|
|
|
Assert.AreEqual(6, info.PrimaryAudioStream.Channels);
|
|
|
|
|
Assert.AreEqual("AAC (Advanced Audio Coding)", info.PrimaryAudioStream.CodecLongName);
|
|
|
|
|
Assert.AreEqual("aac", info.PrimaryAudioStream.CodecName);
|
2020-07-06 23:33:50 +02:00
|
|
|
|
Assert.AreEqual("LC", info.PrimaryAudioStream.Profile);
|
2020-10-25 17:11:52 +01:00
|
|
|
|
Assert.AreEqual(377351, info.PrimaryAudioStream.BitRate);
|
2020-05-09 17:53:03 +02:00
|
|
|
|
Assert.AreEqual(48000, info.PrimaryAudioStream.SampleRateHz);
|
|
|
|
|
|
2021-03-05 18:06:40 +01:00
|
|
|
|
Assert.AreEqual(1471810, info.PrimaryVideoStream!.BitRate);
|
2020-05-09 17:53:03 +02:00
|
|
|
|
Assert.AreEqual(16, info.PrimaryVideoStream.DisplayAspectRatio.Width);
|
|
|
|
|
Assert.AreEqual(9, info.PrimaryVideoStream.DisplayAspectRatio.Height);
|
|
|
|
|
Assert.AreEqual("yuv420p", info.PrimaryVideoStream.PixelFormat);
|
|
|
|
|
Assert.AreEqual(1280, info.PrimaryVideoStream.Width);
|
|
|
|
|
Assert.AreEqual(720, info.PrimaryVideoStream.Height);
|
|
|
|
|
Assert.AreEqual(25, info.PrimaryVideoStream.AvgFrameRate);
|
|
|
|
|
Assert.AreEqual(25, info.PrimaryVideoStream.FrameRate);
|
|
|
|
|
Assert.AreEqual("H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10", info.PrimaryVideoStream.CodecLongName);
|
|
|
|
|
Assert.AreEqual("h264", info.PrimaryVideoStream.CodecName);
|
|
|
|
|
Assert.AreEqual(8, info.PrimaryVideoStream.BitsPerRawSample);
|
|
|
|
|
Assert.AreEqual("Main", info.PrimaryVideoStream.Profile);
|
|
|
|
|
}
|
|
|
|
|
|
2020-10-25 17:42:50 +01:00
|
|
|
|
[TestMethod, Timeout(10000)]
|
2020-05-09 17:53:03 +02:00
|
|
|
|
public async Task Probe_Async_Success()
|
|
|
|
|
{
|
2020-12-07 00:47:47 +01:00
|
|
|
|
var info = await FFProbe.AnalyseAsync(TestResources.Mp4Video);
|
2020-10-25 17:11:52 +01:00
|
|
|
|
Assert.AreEqual(3, info.Duration.Seconds);
|
2020-03-01 12:55:57 +01:00
|
|
|
|
}
|
2020-05-12 21:28:50 +02:00
|
|
|
|
|
2020-05-10 12:07:28 +02:00
|
|
|
|
[TestMethod, Timeout(10000)]
|
2020-04-28 14:21:48 +02:00
|
|
|
|
public void Probe_Success_FromStream()
|
|
|
|
|
{
|
2020-12-07 00:47:47 +01:00
|
|
|
|
using var stream = File.OpenRead(TestResources.WebmVideo);
|
2020-05-08 11:07:51 +02:00
|
|
|
|
var info = FFProbe.Analyse(stream);
|
2020-10-25 17:11:52 +01:00
|
|
|
|
Assert.AreEqual(3, info.Duration.Seconds);
|
2020-04-28 14:21:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
2020-10-25 17:42:50 +01:00
|
|
|
|
[TestMethod, Timeout(10000)]
|
2020-05-08 11:07:51 +02:00
|
|
|
|
public async Task Probe_Success_FromStream_Async()
|
2020-04-28 14:21:48 +02:00
|
|
|
|
{
|
2020-12-07 00:47:47 +01:00
|
|
|
|
await using var stream = File.OpenRead(TestResources.WebmVideo);
|
2020-05-08 11:07:51 +02:00
|
|
|
|
var info = await FFProbe.AnalyseAsync(stream);
|
2020-10-25 17:11:52 +01:00
|
|
|
|
Assert.AreEqual(3, info.Duration.Seconds);
|
2020-04-28 14:21:48 +02:00
|
|
|
|
}
|
2020-03-01 12:55:57 +01:00
|
|
|
|
}
|
|
|
|
|
}
|