From d9b13cb1a76478fd1ec83a3b05812149fae17a99 Mon Sep 17 00:00:00 2001 From: LouisLam Date: Sat, 16 May 2020 20:36:47 +0800 Subject: [PATCH] fix drop frame rate --- Form1.Designer.cs | 3 ++- Form1.cs | 48 ++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 49 insertions(+), 2 deletions(-) diff --git a/Form1.Designer.cs b/Form1.Designer.cs index 6e4fed4..2f37c9c 100644 --- a/Form1.Designer.cs +++ b/Form1.Designer.cs @@ -109,7 +109,7 @@ this.dataGridView1.Name = "dataGridView1"; this.dataGridView1.ReadOnly = true; this.dataGridView1.RowTemplate.Height = 24; - this.dataGridView1.Size = new System.Drawing.Size(587, 141); + this.dataGridView1.Size = new System.Drawing.Size(586, 141); this.dataGridView1.TabIndex = 8; // // FilePath @@ -117,6 +117,7 @@ this.FilePath.HeaderText = "File Path"; this.FilePath.Name = "FilePath"; this.FilePath.ReadOnly = true; + this.FilePath.Width = 272; // // Status // diff --git a/Form1.cs b/Form1.cs index ab6ab30..4efa4a4 100644 --- a/Form1.cs +++ b/Form1.cs @@ -116,11 +116,24 @@ namespace CompressH265 { return; } + // Get FPS + var fps = GetFPS(inputFilename); + var fpsParam = ""; + + if (fps > 0) { + fpsParam = "-r " + fps; + } + + + + // Converting process.StartInfo.FileName = "ffmpeg.exe"; - process.StartInfo.Arguments = $"-i \"{inputFilename}\" -vcodec hevc -map_metadata 0 -vf yadif -crf 16 -preset medium \"{outputFilename}\""; + process.StartInfo.Arguments = $" -i \"{inputFilename}\" -vcodec hevc -map_metadata 0 -vf yadif -crf 20 -preset medium {fpsParam} \"{outputFilename}\""; process.StartInfo.UseShellExecute = false; process.StartInfo.CreateNoWindow = true; + MessageBox.Show(process.StartInfo.Arguments); + var rowID = nextTaskID++; var msgQueue = new Queue(); dataGridView1.Rows.Insert(rowID, shortName, "Preparing..."); @@ -166,6 +179,39 @@ namespace CompressH265 { processList.AddLast(process); } + private float GetFPS(string inputFilename) { + Process process = new Process(); + process.StartInfo.FileName = "ffmpeg.exe"; + process.StartInfo.Arguments = $"-i \"{inputFilename}\""; + process.StartInfo.UseShellExecute = false; + process.StartInfo.CreateNoWindow = true; + process.StartInfo.RedirectStandardError = true; + process.Start(); + process.WaitForExit(); + string err = process.StandardError.ReadToEnd(); + + var end = err.IndexOf(" fps,"); + + if (end < 0) { + return -1f; + } + + var start = end; + + while (true) { + if (err[start - 1] == ' ') { + break; + } + start--; + + if (start < 0) { + return -1; + } + } + + return float.Parse(err.Substring(start, end - start)); + } + private void button3_Click(object sender, EventArgs e) { ProcessStartInfo info = new ProcessStartInfo(); info.FileName = System.Reflection.Assembly.GetExecutingAssembly().Location;