fix drop frame rate

This commit is contained in:
LouisLam 2020-05-16 20:36:47 +08:00
parent 01bbdde60c
commit d9b13cb1a7
2 changed files with 49 additions and 2 deletions

3
Form1.Designer.cs generated
View File

@ -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
//

View File

@ -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<string>();
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;