mirror of
https://github.com/rosenbjerg/FFMpegCore.git
synced 2024-11-10 08:34:12 +01:00
parent
399da85257
commit
263645f83b
3 changed files with 17 additions and 21 deletions
|
@ -25,20 +25,22 @@ public async Task Audio_FromStream_Duration()
|
||||||
Assert.IsTrue(fileAnalysis.Duration == streamAnalysis.Duration);
|
Assert.IsTrue(fileAnalysis.Duration == streamAnalysis.Duration);
|
||||||
}
|
}
|
||||||
|
|
||||||
[TestMethod]
|
[DataTestMethod]
|
||||||
public void MediaAnalysis_ParseDuration()
|
[DataRow("0:00:03.008000", 0, 0, 0, 3, 8)]
|
||||||
|
[DataRow("05:12:59.177", 0, 5, 12, 59, 177)]
|
||||||
|
[DataRow("149:07:50.911750", 6, 5, 7, 50, 911750)]
|
||||||
|
[DataRow("00:00:00.83", 0, 0, 0, 0, 830)]
|
||||||
|
public void MediaAnalysis_ParseDuration(string duration, int expectedDays, int expectedHours, int expectedMinutes, int expectedSeconds, int expectedMilliseconds)
|
||||||
{
|
{
|
||||||
var durationHHMMSS = new FFProbeStream { Duration = "05:12:59.177" };
|
var ffprobeStream = new FFProbeStream { Duration = duration };
|
||||||
var longDuration = new FFProbeStream { Duration = "149:07:50.911750" };
|
|
||||||
var shortDuration = new FFProbeStream { Duration = "00:00:00.83" };
|
|
||||||
|
|
||||||
var testdurationHHMMSS = MediaAnalysis.ParseDuration(durationHHMMSS);
|
var parsedDuration = MediaAnalysisUtils.ParseDuration(ffprobeStream);
|
||||||
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.AreEqual(parsedDuration.Days, expectedDays);
|
||||||
Assert.IsTrue(testlongDuration.Days == 6 && testlongDuration.Hours == 5 && testlongDuration.Minutes == 7 && testlongDuration.Seconds == 50 && testlongDuration.Milliseconds == 911);
|
Assert.AreEqual(parsedDuration.Hours, expectedHours);
|
||||||
Assert.IsTrue(testdurationHHMMSS.Days == 0 && testshortDuration.Hours == 0 && testshortDuration.Minutes == 0 && testshortDuration.Seconds == 0 && testshortDuration.Milliseconds == 830);
|
Assert.AreEqual(parsedDuration.Minutes, expectedMinutes);
|
||||||
|
Assert.AreEqual(parsedDuration.Seconds, expectedSeconds);
|
||||||
|
Assert.AreEqual(parsedDuration.Milliseconds, expectedMilliseconds);
|
||||||
}
|
}
|
||||||
|
|
||||||
[TestMethod]
|
[TestMethod]
|
||||||
|
|
|
@ -163,8 +163,8 @@ public static bool Convert(
|
||||||
var source = FFProbe.Analyse(input);
|
var source = FFProbe.Analyse(input);
|
||||||
FFMpegHelper.ConversionSizeExceptionCheck(source);
|
FFMpegHelper.ConversionSizeExceptionCheck(source);
|
||||||
|
|
||||||
var scale = VideoSize.Original == size ? 1 : (double)source.PrimaryVideoStream.Height / (int)size;
|
var scale = VideoSize.Original == size ? 1 : (double)source.PrimaryVideoStream!.Height / (int)size;
|
||||||
var outputSize = new Size((int)(source.PrimaryVideoStream.Width / scale), (int)(source.PrimaryVideoStream.Height / scale));
|
var outputSize = new Size((int)(source.PrimaryVideoStream!.Width / scale), (int)(source.PrimaryVideoStream.Height / scale));
|
||||||
|
|
||||||
if (outputSize.Width % 2 != 0)
|
if (outputSize.Width % 2 != 0)
|
||||||
outputSize.Width += 1;
|
outputSize.Width += 1;
|
||||||
|
|
|
@ -18,7 +18,7 @@ private MediaFormat ParseFormat(Format analysisFormat)
|
||||||
{
|
{
|
||||||
return new MediaFormat
|
return new MediaFormat
|
||||||
{
|
{
|
||||||
Duration = ParseDuration(analysisFormat.Duration),
|
Duration = MediaAnalysisUtils.ParseDuration(analysisFormat.Duration),
|
||||||
FormatName = analysisFormat.FormatName,
|
FormatName = analysisFormat.FormatName,
|
||||||
FormatLongName = analysisFormat.FormatLongName,
|
FormatLongName = analysisFormat.FormatLongName,
|
||||||
StreamCount = analysisFormat.NbStreams,
|
StreamCount = analysisFormat.NbStreams,
|
||||||
|
@ -89,7 +89,7 @@ private AudioStream ParseAudioStream(FFProbeStream stream)
|
||||||
|
|
||||||
public static class MediaAnalysisUtils
|
public static class MediaAnalysisUtils
|
||||||
{
|
{
|
||||||
private static readonly Regex DurationRegex = new Regex("^(\\d{1,5}:\\d{1,2}:\\d{1,2}(.\\d{1,7})?)", RegexOptions.Compiled);
|
private static readonly Regex DurationRegex = new Regex(@"^(\d+):(\d{1,2}):(\d{1,2})\.(\d{1,3})", RegexOptions.Compiled);
|
||||||
|
|
||||||
public static double DivideRatio((double, double) ratio) => ratio.Item1 / ratio.Item2;
|
public static double DivideRatio((double, double) ratio) => ratio.Item1 / ratio.Item2;
|
||||||
|
|
||||||
|
@ -150,11 +150,5 @@ public static TimeSpan ParseDuration(FFProbeStream ffProbeStream)
|
||||||
{
|
{
|
||||||
return ParseDuration(ffProbeStream.Duration);
|
return ParseDuration(ffProbeStream.Duration);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static string? TrimTimeSpan(string? durationTag)
|
|
||||||
{
|
|
||||||
var durationMatch = DurationRegex.Match(durationTag ?? "");
|
|
||||||
return durationMatch.Success ? durationMatch.Groups[1].Value : null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in a new issue