diff --git a/SimpleFFmpegGUI.Core/FileSystemUtility.cs b/SimpleFFmpegGUI.Core/FileSystemUtility.cs index 6ac5c4f..b121b72 100644 --- a/SimpleFFmpegGUI.Core/FileSystemUtility.cs +++ b/SimpleFFmpegGUI.Core/FileSystemUtility.cs @@ -1,4 +1,6 @@ -using SimpleFFmpegGUI.Model; +using FzLib.IO; +using SimpleFFmpegGUI.FFmpegLib; +using SimpleFFmpegGUI.Model; using System; using System.Collections.Generic; using System.IO; @@ -11,18 +13,10 @@ public static class FileSystemUtility { private const string TempDirKey = "TempDir"; - public static string GetTempDir() - { - using var db = FFmpegDbContext.GetNew(); - var value = db.Configs.FirstOrDefault(p => p.Key == TempDirKey)?.Value; - if (value == null) - { - string str = Guid.NewGuid().ToString(); - value = Path.Combine(Path.GetTempPath(), str); - Directory.CreateDirectory(value); - } - return value; - } + /// + /// 不合法的文件名字符集合 + /// + private static HashSet invalidFileNameChars = Path.GetInvalidFileNameChars().ToHashSet(); public static string GetSequence(string sampleFilePath) { @@ -61,5 +55,73 @@ public static string GetSequence(string sampleFilePath) } return null; } + + public static string GetTempDir() + { + using var db = FFmpegDbContext.GetNew(); + var value = db.Configs.FirstOrDefault(p => p.Key == TempDirKey)?.Value; + if (value == null) + { + string str = Guid.NewGuid().ToString(); + value = Path.Combine(Path.GetTempPath(), str); + Directory.CreateDirectory(value); + } + return value; + } + + /// + /// 生成输出路径 + /// + /// + /// + /// + public static string GenerateOutputPath(TaskInfo task) + { + string output = task.Output.Trim(); + var a = task.Arguments; + if (string.IsNullOrEmpty(output)) + { + if (task.Inputs.Count == 0) + { + throw new Exception("没有指定输出路径,且输入文件为空"); + } + output = task.Inputs[0].FilePath; + } + + //删除非法字符 + string dir = Path.GetDirectoryName(output); + string filename = Path.GetFileName(output); + if (filename.Any(p => invalidFileNameChars.Contains(p))) + { + foreach (var c in invalidFileNameChars) + { + filename = filename.Replace(c.ToString(), ""); + } + output = Path.Combine(dir, filename); + } + + + //修改扩展名 + if (!string.IsNullOrEmpty(a?.Format)) + { + VideoFormat format = VideoFormat.Formats.Where(p => p.Name == a.Format || p.Extension == a.Format).FirstOrDefault(); + if (format != null) + { + string name = Path.GetFileNameWithoutExtension(output); + string extension = format.Extension; + output = Path.Combine(dir, name + "." + extension); + } + } + + //获取非重复文件名 + task.RealOutput = FileSystem.GetNoDuplicateFile(output); + + //创建目录 + if (!new FileInfo(task.RealOutput).Directory.Exists) + { + new FileInfo(task.RealOutput).Directory.Create(); + } + return task.RealOutput; + } } } \ No newline at end of file diff --git a/SimpleFFmpegGUI.Core/Manager/FFmpegManager.cs b/SimpleFFmpegGUI.Core/Manager/FFmpegManager.cs index 5deac6a..ff2f4c1 100644 --- a/SimpleFFmpegGUI.Core/Manager/FFmpegManager.cs +++ b/SimpleFFmpegGUI.Core/Manager/FFmpegManager.cs @@ -15,6 +15,7 @@ using System.Text.RegularExpressions; using System.Threading; using Task = System.Threading.Tasks.Task; +using static SimpleFFmpegGUI.FileSystemUtility; namespace SimpleFFmpegGUI.Manager { @@ -50,10 +51,6 @@ public class FFmpegManager : INotifyPropertyChanged /// private static readonly Regex rVMAF = new Regex(@"VMAF score: [0-9\.]+", RegexOptions.Compiled); - /// - /// 不合法的文件名字符集合 - /// - private static HashSet invalidFileNameChars = Path.GetInvalidFileNameChars().ToHashSet(); /// /// 当前任务 @@ -135,6 +132,7 @@ public bool Paused /// FFmpeg进程 /// private FFmpegProcess Process { get; set; } + /// /// 测试输出参数是否合法 /// @@ -223,7 +221,7 @@ public async Task RunAsync() string tempDir = FileSystemUtility.GetTempDir(); await (task.Type switch { - TaskType.Code => RunCodeProcessAsync(tempDir, cancel.Token), + TaskType.Code => RunCodeProcessAsync(cancel.Token), TaskType.Combine => RunCombineProcessAsync(cancel.Token), TaskType.Compare => RunCompareProcessAsync(cancel.Token), TaskType.Custom => RunCustomProcessAsync(cancel.Token), @@ -271,58 +269,6 @@ public void Suspend() ProcessExtension.SuspendProcess(Process.Id); StatusChanged?.Invoke(this, EventArgs.Empty); } - /// - /// 生成输出路径 - /// - /// - /// - /// - private static string GenerateOutputPath(TaskInfo task) - { - string output = task.Output.Trim(); - var a = task.Arguments; - if (string.IsNullOrEmpty(output)) - { - if (task.Inputs.Count == 0) - { - throw new Exception("没有指定输出路径,且输入文件为空"); - } - output = task.Inputs[0].FilePath; - } - - //删除非法字符 - string dir = Path.GetDirectoryName(output); - string filename = Path.GetFileName(output); - if (filename.Any(p => invalidFileNameChars.Contains(p))) - { - foreach (var c in invalidFileNameChars) - { - filename = filename.Replace(c.ToString(), ""); - } - output = Path.Combine(dir, filename); - } - - - //修改扩展名 - if (!string.IsNullOrEmpty(a?.Format)) - { - VideoFormat format = VideoFormat.Formats.Where(p => p.Name == a.Format || p.Extension == a.Format).FirstOrDefault(); - if (format != null) - { - string name = Path.GetFileNameWithoutExtension(output); - string extension = format.Extension; - output = Path.Combine(dir, name + "." + extension); - } - } - - //获取非重复文件名 - task.RealOutput = FileSystem.GetNoDuplicateFile(output); - if (!new FileInfo(task.RealOutput).Directory.Exists) - { - new FileInfo(task.RealOutput).Directory.Create(); - } - return task.RealOutput; - } /// /// 获取视频的长度 @@ -456,14 +402,23 @@ private async Task RunAsync(string arguments, string desc, CancellationToken can /// /// /// - private async Task RunCodeProcessAsync(string tempDir, CancellationToken cancellationToken) + private async Task RunCodeProcessAsync(CancellationToken cancellationToken) { - string message = null; if (task.Inputs.Count != 1) { throw new ArgumentException("普通编码,输入文件必须为1个"); } + //处理图像序列名 + if (task.Inputs.Count == 1 && task.Inputs[0].Image2) + { + string seq = GetSequence(task.Inputs[0].FilePath); + if (seq != null) + { + task.Inputs[0].FilePath = seq; + } + } GenerateOutputPath(task); + string message; if (task.Arguments.Video == null || !task.Arguments.Video.TwoPass) { Progress = GetProgress(); diff --git a/SimpleFFmpegGUI.Host/ConsoleLogger.cs b/SimpleFFmpegGUI.Host/ConsoleLogger.cs index d2fe9bf..c12f576 100644 --- a/SimpleFFmpegGUI.Host/ConsoleLogger.cs +++ b/SimpleFFmpegGUI.Host/ConsoleLogger.cs @@ -15,9 +15,11 @@ public static void StartListen() { if (instance == null) { - new ConsoleLogger(); + instance = new ConsoleLogger(); } } + + private string lastLogContent = null; private void Logger_Log(object sender, LogEventArgs e) { ConsoleColor defaultColor = Console.ForegroundColor; @@ -40,6 +42,12 @@ private void Logger_Log(object sender, LogEventArgs e) _ => e.Log.Type.ToString().PadLeft(2) }; string time = e.Log.Time.ToString("yyyy-MM-dd HH:mm:ss"); + + if (lastLogContent != null && lastLogContent.StartsWith("frame=") && e.Log.Message.StartsWith("frame=")) + { + ClearLine(); + } + Console.Write(time); Console.Write(" \t"); Console.ForegroundColor = color; @@ -48,6 +56,15 @@ private void Logger_Log(object sender, LogEventArgs e) Console.Write(" \t"); Console.Write(e.Log.Message); Console.WriteLine(); + + + lastLogContent = e.Log.Message; + } + static void ClearLine() + { + Console.SetCursorPosition(0, Console.CursorTop); + Console.Write(new string(' ', Console.WindowWidth)); + Console.SetCursorPosition(0, Console.CursorTop - 1); } } } \ No newline at end of file diff --git a/SimpleFFmpegGUI.Web/src/components/StatusBar.vue b/SimpleFFmpegGUI.Web/src/components/StatusBar.vue index d04859f..ef735a7 100644 --- a/SimpleFFmpegGUI.Web/src/components/StatusBar.vue +++ b/SimpleFFmpegGUI.Web/src/components/StatusBar.vue @@ -52,6 +52,20 @@ + + { + // if (this.status.isPaused) { + // //this.walkingProgress=0; + // //return; + // } + // console.log(this.walkingProgress); + // if (delay > 0) { + // delay--; + // if (delay == 0) { + // this.walkingProgress = 0; + // } + // return; + // } + // if (this.walkingProgress >= 100) { + // delay = 10; + // } else { + // this.walkingProgress++; + // } + // }, 50); return; }); }, @@ -211,6 +261,10 @@ export default Vue.component("status-bar", {