mirror of
https://github.com/rosenbjerg/FFMpegCore.git
synced 2024-11-14 02:04:14 +01:00
parent
f72a301d78
commit
5ee26d52ad
1 changed files with 9 additions and 2 deletions
|
@ -1,11 +1,13 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Text.RegularExpressions;
|
||||||
|
|
||||||
namespace FFMpegCore
|
namespace FFMpegCore
|
||||||
{
|
{
|
||||||
public class MediaAnalysis
|
public class MediaAnalysis
|
||||||
{
|
{
|
||||||
|
private static readonly Regex DurationRegex = new Regex("^(\\d{1,2}:\\d{1,2}:\\d{1,2}(.\\d{1,7})?)", RegexOptions.Compiled);
|
||||||
internal MediaAnalysis(string path, FFProbeAnalysis analysis)
|
internal MediaAnalysis(string path, FFProbeAnalysis analysis)
|
||||||
{
|
{
|
||||||
VideoStreams = analysis.Streams.Where(stream => stream.CodecType == "video").Select(ParseVideoStream).ToList();
|
VideoStreams = analysis.Streams.Where(stream => stream.CodecType == "video").Select(ParseVideoStream).ToList();
|
||||||
|
@ -54,7 +56,12 @@ private static TimeSpan ParseDuration(FFProbeStream ffProbeStream)
|
||||||
{
|
{
|
||||||
return ffProbeStream.Duration != null
|
return ffProbeStream.Duration != null
|
||||||
? TimeSpan.FromSeconds(ParseDoubleInvariant(ffProbeStream.Duration))
|
? TimeSpan.FromSeconds(ParseDoubleInvariant(ffProbeStream.Duration))
|
||||||
: TimeSpan.Parse(ffProbeStream.Tags?.Duration ?? "0");
|
: TimeSpan.Parse(TrimTimeSpan(ffProbeStream.Tags?.Duration) ?? "0");
|
||||||
|
}
|
||||||
|
private static string? TrimTimeSpan(string? durationTag)
|
||||||
|
{
|
||||||
|
var durationMatch = DurationRegex.Match(durationTag ?? "");
|
||||||
|
return durationMatch.Success ? durationMatch.Groups[1].Value : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private AudioStream ParseAudioStream(FFProbeStream stream)
|
private AudioStream ParseAudioStream(FFProbeStream stream)
|
||||||
|
@ -67,7 +74,7 @@ private AudioStream ParseAudioStream(FFProbeStream stream)
|
||||||
CodecLongName = stream.CodecLongName,
|
CodecLongName = stream.CodecLongName,
|
||||||
Channels = stream.Channels ?? default,
|
Channels = stream.Channels ?? default,
|
||||||
ChannelLayout = stream.ChannelLayout,
|
ChannelLayout = stream.ChannelLayout,
|
||||||
Duration = TimeSpan.FromSeconds(ParseDoubleInvariant(stream.Duration ?? stream.Tags?.Duration ?? "0")),
|
Duration = ParseDuration(stream),
|
||||||
SampleRateHz = !string.IsNullOrEmpty(stream.SampleRate) ? ParseIntInvariant(stream.SampleRate) : default,
|
SampleRateHz = !string.IsNullOrEmpty(stream.SampleRate) ? ParseIntInvariant(stream.SampleRate) : default,
|
||||||
Language = stream.Tags?.Language
|
Language = stream.Tags?.Language
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue