From c522cdaef30ab84ef579b6eb66a574843967daed Mon Sep 17 00:00:00 2001 From: Nikolaj Olsson Date: Sat, 28 Sep 2024 06:37:42 +0200 Subject: [PATCH] Add FramesRate to FfmpegMediaInfo --- src/libse/Common/FfmpegMediaInfo.cs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/libse/Common/FfmpegMediaInfo.cs b/src/libse/Common/FfmpegMediaInfo.cs index b2ea61e97..8bbab4e2d 100644 --- a/src/libse/Common/FfmpegMediaInfo.cs +++ b/src/libse/Common/FfmpegMediaInfo.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Diagnostics; +using System.Globalization; using System.IO; using System.Linq; using System.Text; @@ -14,9 +15,12 @@ namespace Nikse.SubtitleEdit.Core.Common public Dimension Dimension { get; set; } public TimeCode Duration { get; set; } + public decimal FramesRate { get; set; } private static readonly Regex ResolutionRegex = new Regex(@"\d\d+x\d\d+", RegexOptions.Compiled); private static readonly Regex DurationRegex = new Regex(@"Duration: \d+[:\.,]\d+[:\.,]\d+[:\.,]\d+", RegexOptions.Compiled); + private static readonly Regex Fps1Regex = new Regex(@" \d+\.\d+ fps", RegexOptions.Compiled); + private static readonly Regex Fps2Regex = new Regex(@" \d+ fps", RegexOptions.Compiled); private FfmpegMediaInfo() { @@ -58,6 +62,20 @@ namespace Nikse.SubtitleEdit.Core.Common { var info = new FfmpegMediaInfo(); + var fpsMatch = Fps1Regex.Match(log); + if (!fpsMatch.Success) + { + fpsMatch = Fps2Regex.Match(log); + } + if (fpsMatch.Success) + { + var fps = fpsMatch.Value.Trim().Split(' ')[0]; + if (double.TryParse(fps, NumberStyles.Any, CultureInfo.InvariantCulture, out var f)) + { + info.FramesRate = (decimal)f; + } + } + foreach (var line in log.SplitToLines()) { var s = line.Trim();