From 081d5503dcd88595855d7df4feac0e7c2920a42e Mon Sep 17 00:00:00 2001 From: SwareJonge Date: Sun, 28 Jan 2024 01:16:56 +0100 Subject: [PATCH 1/3] Recording framerate fix --- InputDisplay/Config/Config.cs | 2 +- InputDisplay/Core/Animator.cs | 5 ++--- InputDisplay/Entities/Timer.cs | 8 +++++--- InputDisplay/Forms/MainForm.cs | 2 +- InputDisplay/Forms/OptionTabs.cs | 4 +++- InputDisplay/Forms/RecordForm.cs | 11 ++++++----- 6 files changed, 18 insertions(+), 14 deletions(-) diff --git a/InputDisplay/Config/Config.cs b/InputDisplay/Config/Config.cs index c029a28..b46684b 100644 --- a/InputDisplay/Config/Config.cs +++ b/InputDisplay/Config/Config.cs @@ -123,6 +123,6 @@ static public int Outline } } - static public int PlaybackSpeed { get; set; } = 60; + static public double PlaybackSpeed { get; set; } = 60/1.001; } } diff --git a/InputDisplay/Core/Animator.cs b/InputDisplay/Core/Animator.cs index bfe75a6..081720d 100644 --- a/InputDisplay/Core/Animator.cs +++ b/InputDisplay/Core/Animator.cs @@ -55,7 +55,7 @@ public void SwitchController(string controller) public bool Update() { - int roundedFrame = (int) Math.Floor(this.CurrentFrame); + int roundedFrame = (int)Math.Floor(this.CurrentFrame); //end of inputs reached if (roundedFrame >= this.GhostReader.TotalFrames) @@ -76,7 +76,6 @@ public bool Update() if (roundedFrame >= this.GhostReader.Trick_inputs[this.TrickIndex].endFrame) { this.TrickIndex += 1; - } (bool accelerator, bool drift, bool item) actions = this.GhostReader.Face_inputs[this.FaceIndex].values; @@ -85,7 +84,7 @@ public bool Update() this.Controller.Update(actions.accelerator, actions.drift, actions.item, coords, trick); - this.CurrentFrame += (double) Config.PlaybackSpeed / this.Fps; + this.CurrentFrame += Config.PlaybackSpeed / this.Fps; return true; } diff --git a/InputDisplay/Entities/Timer.cs b/InputDisplay/Entities/Timer.cs index 92f4296..fd888d0 100644 --- a/InputDisplay/Entities/Timer.cs +++ b/InputDisplay/Entities/Timer.cs @@ -25,9 +25,11 @@ public void Draw(ref Graphics g, double currentFrame) SolidBrush blackBrush = new SolidBrush(Color.Black); g.FillRectangle(blackBrush, new Rectangle(new Point(this.Coords.X, this.Coords.Y), this.Size)); - - int actualFrame = (int)Math.Floor(currentFrame) - 240; - double seconds = actualFrame * (1.0 / 60.0); + // TODO: with a timescale of 16.667ms the final time is quite far off the end time + // however having the correct timescale (1/(60.1.001)) also results in weird stuff + // Leaving it like this because when having the "correct" scale, time starts at -4.004 which seems weird + // Perhaps it'd be better to render the frame number instead + double seconds = ((currentFrame) - 240) * (1.0 / 60); SolidBrush whiteBrush = new SolidBrush(Color.White); g.DrawString(seconds.ToString("0.000", CultureInfo.CreateSpecificCulture("en-CA")), drawFont, whiteBrush, this.Coords.X, this.Coords.Y + 5, new StringFormat()); } diff --git a/InputDisplay/Forms/MainForm.cs b/InputDisplay/Forms/MainForm.cs index a8987d4..dcdbf7e 100644 --- a/InputDisplay/Forms/MainForm.cs +++ b/InputDisplay/Forms/MainForm.cs @@ -28,7 +28,7 @@ public MainForm() { InitializeComponent(); VariableSetup(); - this.Animator = new Animator(62.5, this.pictureBox1.ClientSize.Width, this.pictureBox1.ClientSize.Height); + this.Animator = new Animator(60/1.001, this.pictureBox1.ClientSize.Width, this.pictureBox1.ClientSize.Height); this.AllowDrop = true; this.DragEnter += new DragEventHandler(Form1_DragEnter); this.DragDrop += new DragEventHandler(Form1_DragDrop); diff --git a/InputDisplay/Forms/OptionTabs.cs b/InputDisplay/Forms/OptionTabs.cs index 9ce47cb..9229fef 100644 --- a/InputDisplay/Forms/OptionTabs.cs +++ b/InputDisplay/Forms/OptionTabs.cs @@ -61,7 +61,9 @@ private void NumericUpDown1_ValueChanged(object sender, EventArgs e) private void NumericUpDown2_ValueChanged(object sender, EventArgs e) { - Config.PlaybackSpeed = (int)this.numericUpDown2.Value; + // The original playback speed is 59.94(60/1.001) fps + // do this weird calculation to properly allow up to 3x speed + Config.PlaybackSpeed = 60 * ((double)this.numericUpDown2.Value / 1.001 / 100); } private void NumericUpDown4_ValueChanged(object sender, EventArgs e) diff --git a/InputDisplay/Forms/RecordForm.cs b/InputDisplay/Forms/RecordForm.cs index 12b16f8..6563c84 100644 --- a/InputDisplay/Forms/RecordForm.cs +++ b/InputDisplay/Forms/RecordForm.cs @@ -49,12 +49,13 @@ public RecordForm(MainForm mainForm, Animator animator, bool alhpaChannel, strin this.label2.Visible = false; this.progressBar1.Visible = false; - if (Config.PlaybackSpeed == 60) + if (Config.PlaybackSpeed == (60/1.001)) { this.PrepareRecording(); - } else + } + else { - this.label1.Text = String.Format("The current playback speed is set to {0} (regular speed is 60)\nAre you sure you want to continue?", Config.PlaybackSpeed); + this.label1.Text = String.Format("The current playback speed is set to {0} (regular speed is 100)\nAre you sure you want to continue?", Config.PlaybackSpeed); } } @@ -151,7 +152,7 @@ private void Render(object sender, DoWorkEventArgs e) // Prepare the animator and write all the frames to the temp directory this.Animator.Clear(); int frameNr = 0; - int totalFrames = (int)((double)Math.Ceiling((double)((60.0 / Config.PlaybackSpeed) * this.Animator.Fps)) * this.Animator.GetGhostInfo().Item4); + int totalFrames = (int)(Math.Ceiling((((60/1.001) / Config.PlaybackSpeed) * this.Animator.Fps)) * this.Animator.GetGhostInfo().Item4); while (this.Animator.Update()) { // Check for cancel request @@ -171,7 +172,7 @@ private void Render(object sender, DoWorkEventArgs e) Process proc = new Process(); proc.StartInfo.FileName = "ffmpeg\\ffmpeg"; this.FileName = String.Format("{0}.{1}", DateTime.Now.ToString("yy-MM-dd-hh-mm-ss"), this.FileFormat); - proc.StartInfo.Arguments = String.Format("-framerate 62.5 -i temp\\%d.png -vcodec {0} {1}", codec, this.FileName); + proc.StartInfo.Arguments = String.Format("-r \"60000/1001\" -i temp\\%d.png -vcodec {0} {1}", codec, this.FileName); proc.StartInfo.RedirectStandardError = true; proc.StartInfo.UseShellExecute = false; proc.StartInfo.CreateNoWindow = true; From c55ea6ad2cca7dc946c82715c612be15085cd226 Mon Sep 17 00:00:00 2001 From: SwareJonge Date: Sun, 28 Jan 2024 13:24:18 +0100 Subject: [PATCH 2/3] use percentage for playback speed --- InputDisplay/Forms/MainForm.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/InputDisplay/Forms/MainForm.cs b/InputDisplay/Forms/MainForm.cs index dcdbf7e..18c66ea 100644 --- a/InputDisplay/Forms/MainForm.cs +++ b/InputDisplay/Forms/MainForm.cs @@ -561,7 +561,7 @@ private void InitializeComponent() this.numericUpDown2.Size = new System.Drawing.Size(44, 20); this.numericUpDown2.TabIndex = 11; this.numericUpDown2.Value = new decimal(new int[] { - 60, + 100, 0, 0, 0}); From 1cc6358e58bb78469025582011d60590b5108309 Mon Sep 17 00:00:00 2001 From: SwareJonge Date: Sun, 28 Jan 2024 15:08:16 +0100 Subject: [PATCH 3/3] revert some changes --- InputDisplay/Forms/MainForm.cs | 7 ++----- InputDisplay/Forms/RecordForm.cs | 2 ++ 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/InputDisplay/Forms/MainForm.cs b/InputDisplay/Forms/MainForm.cs index 18c66ea..6d34bd5 100644 --- a/InputDisplay/Forms/MainForm.cs +++ b/InputDisplay/Forms/MainForm.cs @@ -20,15 +20,14 @@ public partial class MainForm : Form private CheatDetector CheatDetector; private bool GhostLoaded = false; private bool Animate = false; - - private Stopwatch stopWatch = new Stopwatch(); private AccurateTimer timer; public MainForm() { InitializeComponent(); VariableSetup(); - this.Animator = new Animator(60/1.001, this.pictureBox1.ClientSize.Width, this.pictureBox1.ClientSize.Height); + // Set the framerate of the animator to 62.5fps, this may seem weird but a frame lasts exactly 16ms this way + this.Animator = new Animator(62.5, this.pictureBox1.ClientSize.Width, this.pictureBox1.ClientSize.Height); this.AllowDrop = true; this.DragEnter += new DragEventHandler(Form1_DragEnter); this.DragDrop += new DragEventHandler(Form1_DragDrop); @@ -959,10 +958,8 @@ private void Form1_FormClosing(object sender, FormClosingEventArgs e) private void TimerCallback() { - this.stopWatch.Stop(); this.AdvanceAnimator(); this.pictureBox1.Invalidate(); - this.stopWatch.Restart(); return; } diff --git a/InputDisplay/Forms/RecordForm.cs b/InputDisplay/Forms/RecordForm.cs index 6563c84..a04d1ce 100644 --- a/InputDisplay/Forms/RecordForm.cs +++ b/InputDisplay/Forms/RecordForm.cs @@ -49,6 +49,8 @@ public RecordForm(MainForm mainForm, Animator animator, bool alhpaChannel, strin this.label2.Visible = false; this.progressBar1.Visible = false; + Animator.Fps = (60 / 1.001); // Set the framerate of the animator to 59.94fps, this matches the framerate of the game + if (Config.PlaybackSpeed == (60/1.001)) { this.PrepareRecording();