Add FramesRate to FfmpegMediaInfo

This commit is contained in:
Nikolaj Olsson 2024-09-28 06:37:42 +02:00
parent 0dcb118064
commit c522cdaef3

View File

@ -1,6 +1,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
using System.Globalization;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
@ -14,9 +15,12 @@ namespace Nikse.SubtitleEdit.Core.Common
public Dimension Dimension { get; set; } public Dimension Dimension { get; set; }
public TimeCode Duration { 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 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 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() private FfmpegMediaInfo()
{ {
@ -58,6 +62,20 @@ namespace Nikse.SubtitleEdit.Core.Common
{ {
var info = new FfmpegMediaInfo(); 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()) foreach (var line in log.SplitToLines())
{ {
var s = line.Trim(); var s = line.Trim();