mirror of
https://github.com/rosenbjerg/FFMpegCore.git
synced 2024-11-14 02:04:14 +01:00
Merge pull request #57 from max619/fix/invariant_culture_parsing
Fix FormatException in Media Analysis
Former-commit-id: 52444d439e
This commit is contained in:
commit
209b8d8dd6
1 changed files with 13 additions and 8 deletions
|
@ -35,8 +35,8 @@ private VideoStream ParseVideoStream(Stream stream)
|
||||||
{
|
{
|
||||||
Index = stream.Index,
|
Index = stream.Index,
|
||||||
AvgFrameRate = DivideRatio(ParseRatioDouble(stream.AvgFrameRate, '/')),
|
AvgFrameRate = DivideRatio(ParseRatioDouble(stream.AvgFrameRate, '/')),
|
||||||
BitRate = !string.IsNullOrEmpty(stream.BitRate) ? int.Parse(stream.BitRate) : default,
|
BitRate = !string.IsNullOrEmpty(stream.BitRate) ? ParseIntInvariant(stream.BitRate) : default,
|
||||||
BitsPerRawSample = !string.IsNullOrEmpty(stream.BitsPerRawSample) ? int.Parse(stream.BitsPerRawSample) : default,
|
BitsPerRawSample = !string.IsNullOrEmpty(stream.BitsPerRawSample) ? ParseIntInvariant(stream.BitsPerRawSample) : default,
|
||||||
CodecName = stream.CodecName,
|
CodecName = stream.CodecName,
|
||||||
CodecLongName = stream.CodecLongName,
|
CodecLongName = stream.CodecLongName,
|
||||||
DisplayAspectRatio = ParseRatioInt(stream.DisplayAspectRatio, ':'),
|
DisplayAspectRatio = ParseRatioInt(stream.DisplayAspectRatio, ':'),
|
||||||
|
@ -52,7 +52,7 @@ private VideoStream ParseVideoStream(Stream stream)
|
||||||
private static TimeSpan ParseDuration(Stream stream)
|
private static TimeSpan ParseDuration(Stream stream)
|
||||||
{
|
{
|
||||||
return stream.Duration != null
|
return stream.Duration != null
|
||||||
? TimeSpan.FromSeconds(double.Parse(stream.Duration))
|
? TimeSpan.FromSeconds(ParseDoubleInvariant(stream.Duration))
|
||||||
: TimeSpan.Parse(stream.Tags.Duration ?? "0");
|
: TimeSpan.Parse(stream.Tags.Duration ?? "0");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -61,13 +61,13 @@ private AudioStream ParseAudioStream(Stream stream)
|
||||||
return new AudioStream
|
return new AudioStream
|
||||||
{
|
{
|
||||||
Index = stream.Index,
|
Index = stream.Index,
|
||||||
BitRate = !string.IsNullOrEmpty(stream.BitRate) ? int.Parse(stream.BitRate) : default,
|
BitRate = !string.IsNullOrEmpty(stream.BitRate) ? ParseIntInvariant(stream.BitRate) : default,
|
||||||
CodecName = stream.CodecName,
|
CodecName = stream.CodecName,
|
||||||
CodecLongName = stream.CodecLongName,
|
CodecLongName = stream.CodecLongName,
|
||||||
Channels = stream.Channels ?? default,
|
Channels = stream.Channels ?? default,
|
||||||
ChannelLayout = stream.ChannelLayout,
|
ChannelLayout = stream.ChannelLayout,
|
||||||
Duration = TimeSpan.FromSeconds(double.Parse(stream.Duration ?? stream.Tags.Duration ?? "0")),
|
Duration = TimeSpan.FromSeconds(ParseDoubleInvariant(stream.Duration ?? stream.Tags.Duration ?? "0")),
|
||||||
SampleRateHz = !string.IsNullOrEmpty(stream.SampleRate) ? int.Parse(stream.SampleRate) : default
|
SampleRateHz = !string.IsNullOrEmpty(stream.SampleRate) ? ParseIntInvariant(stream.SampleRate) : default
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -76,13 +76,18 @@ private static (int, int) ParseRatioInt(string input, char separator)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrEmpty(input)) return (0, 0);
|
if (string.IsNullOrEmpty(input)) return (0, 0);
|
||||||
var ratio = input.Split(separator);
|
var ratio = input.Split(separator);
|
||||||
return (int.Parse(ratio[0]), int.Parse(ratio[1]));
|
return (ParseIntInvariant(ratio[0]), ParseIntInvariant(ratio[1]));
|
||||||
}
|
}
|
||||||
private static (double, double) ParseRatioDouble(string input, char separator)
|
private static (double, double) ParseRatioDouble(string input, char separator)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrEmpty(input)) return (0, 0);
|
if (string.IsNullOrEmpty(input)) return (0, 0);
|
||||||
var ratio = input.Split(separator);
|
var ratio = input.Split(separator);
|
||||||
return (ratio.Length > 0 ? double.Parse(ratio[0]) : 0, ratio.Length > 1 ? double.Parse(ratio[1]) : 0);
|
return (ratio.Length > 0 ? ParseDoubleInvariant(ratio[0]) : 0, ratio.Length > 1 ? ParseDoubleInvariant(ratio[1]) : 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static double ParseDoubleInvariant(string line) =>
|
||||||
|
double.Parse(line, System.Globalization.NumberStyles.Any, System.Globalization.CultureInfo.InvariantCulture);
|
||||||
|
private static int ParseIntInvariant(string line) =>
|
||||||
|
int.Parse(line, System.Globalization.NumberStyles.Any, System.Globalization.CultureInfo.InvariantCulture);
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in a new issue