From 6a3ddce7dd158fdd37dad0e73289dbb14802cd03 Mon Sep 17 00:00:00 2001 From: Nikolaj Olsson Date: Sun, 28 Apr 2024 19:09:20 +0200 Subject: [PATCH] Add video res to ffmpeg info --- src/libse/Common/FfmpegMediaInfo.cs | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/src/libse/Common/FfmpegMediaInfo.cs b/src/libse/Common/FfmpegMediaInfo.cs index 1ded83ab0..c6bfe1050 100644 --- a/src/libse/Common/FfmpegMediaInfo.cs +++ b/src/libse/Common/FfmpegMediaInfo.cs @@ -4,12 +4,17 @@ using System.Diagnostics; using System.IO; using System.Linq; using System.Text; +using System.Text.RegularExpressions; namespace Nikse.SubtitleEdit.Core.Common { public class FfmpegMediaInfo { public List Tracks { get; set; } + public int VideoWidth { get; set; } + public int VideoHeight { get; set; } + + private static readonly Regex ResolutionRegex = new Regex(@"\d\d+x\d\d+", RegexOptions.Compiled); private FfmpegMediaInfo() { @@ -19,7 +24,7 @@ namespace Nikse.SubtitleEdit.Core.Common public static FfmpegMediaInfo Parse(string videoFileName) { if (string.IsNullOrEmpty(Configuration.Settings.General.FFmpegLocation) || - !File.Exists(Configuration.Settings.General.FFmpegLocation)) + !File.Exists(Configuration.Settings.General.FFmpegLocation)) { return new FfmpegMediaInfo(); } @@ -56,6 +61,20 @@ namespace Nikse.SubtitleEdit.Core.Common var s = line.Trim(); if (s.StartsWith("Stream #", StringComparison.Ordinal)) { + var resolutionMatch = ResolutionRegex.Match(s); + if (resolutionMatch.Success) + { + var parts = resolutionMatch.Value.Split('x'); + if (info.VideoWidth == 0 && + parts.Length == 2 && + int.TryParse(parts[0], out var w) && + int.TryParse(parts[0], out var h)) + { + info.VideoWidth = w; + info.VideoHeight = h; + } + } + var arr = s.Replace(": ", "¤").Split('¤'); if (arr.Length == 3) { @@ -123,7 +142,7 @@ namespace Nikse.SubtitleEdit.Core.Common StartInfo = { FileName = ffmpegLocation, - Arguments = $"-i \"{inputFileName}\" - hide_banner", + Arguments = $"-i \"{inputFileName}\" -hide_banner", UseShellExecute = false, CreateNoWindow = true }