add user selectable delay setting to GifWriter

may not always function exactly as expected due to web browser shortcomings
This commit is contained in:
goyuken 2012-09-22 21:24:20 +00:00
parent e156b3f722
commit 911ebc38d1
4 changed files with 109 additions and 7 deletions

View File

@ -11,21 +11,55 @@ namespace BizHawk.MultiClient.AVOut
{
public class GifToken : IDisposable
{
private int _frameskip, _framedelay;
/// <summary>
/// how many frames to skip for each frame deposited
/// </summary>
public int frameskip { get; private set; }
public int frameskip
{
get { return _frameskip; }
private set
{
if (value < 0)
_frameskip = 0;
else if (value > 999)
_frameskip = 999;
else
_frameskip = value;
}
}
/// <summary>
/// how long to delay between each gif frame (units of 10ms, -1 = auto)
/// </summary>
public int framedelay
{
get { return _framedelay; }
private set
{
if (value < -1)
_framedelay = -1;
else if (value > 100)
_framedelay = 100;
else
_framedelay = value;
}
}
public void Dispose() { }
public GifToken(int frameskip)
public GifToken(int frameskip, int framedelay)
{
this.frameskip = frameskip;
this.framedelay = framedelay;
}
public static GifToken LoadFromConfig()
{
GifToken ret = new GifToken(0);
GifToken ret = new GifToken(0, 0);
ret.frameskip = Global.Config.GifWriterFrameskip;
ret.framedelay = Global.Config.GifWriterDelay;
return ret;
}
}
@ -143,7 +177,11 @@ namespace BizHawk.MultiClient.AVOut
{
if (token == null)
return;
int delay = (100 * fpsden * (token.frameskip + 1) + (fpsnum / 2)) / fpsnum;
int delay;
if (token.framedelay == -1)
delay = (100 * fpsden * (token.frameskip + 1) + (fpsnum / 2)) / fpsnum;
else
delay = token.framedelay;
Delay[0] = (byte)(delay & 0xff);
Delay[1] = (byte)(delay >> 8 & 0xff);
}

View File

@ -32,13 +32,18 @@
this.button2 = new System.Windows.Forms.Button();
this.numericUpDown1 = new System.Windows.Forms.NumericUpDown();
this.label1 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.numericUpDown2 = new System.Windows.Forms.NumericUpDown();
this.label3 = new System.Windows.Forms.Label();
((System.ComponentModel.ISupportInitialize)(this.numericUpDown1)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.numericUpDown2)).BeginInit();
this.SuspendLayout();
//
// button1
//
this.button1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.button1.DialogResult = System.Windows.Forms.DialogResult.OK;
this.button1.Location = new System.Drawing.Point(12, 51);
this.button1.Location = new System.Drawing.Point(12, 100);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(75, 23);
this.button1.TabIndex = 0;
@ -47,8 +52,9 @@
//
// button2
//
this.button2.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.button2.DialogResult = System.Windows.Forms.DialogResult.Cancel;
this.button2.Location = new System.Drawing.Point(93, 51);
this.button2.Location = new System.Drawing.Point(93, 100);
this.button2.Name = "button2";
this.button2.Size = new System.Drawing.Size(75, 23);
this.button2.TabIndex = 1;
@ -76,13 +82,47 @@
this.label1.TabIndex = 3;
this.label1.Text = "Number of frames to skip for each frame written:";
//
// label2
//
this.label2.AutoSize = true;
this.label2.Location = new System.Drawing.Point(12, 48);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(67, 13);
this.label2.TabIndex = 4;
this.label2.Text = "Frame delay:";
//
// numericUpDown2
//
this.numericUpDown2.Location = new System.Drawing.Point(12, 64);
this.numericUpDown2.Minimum = new decimal(new int[] {
1,
0,
0,
-2147483648});
this.numericUpDown2.Name = "numericUpDown2";
this.numericUpDown2.Size = new System.Drawing.Size(120, 20);
this.numericUpDown2.TabIndex = 5;
this.numericUpDown2.ValueChanged += new System.EventHandler(this.numericUpDown2_ValueChanged);
//
// label3
//
this.label3.AutoSize = true;
this.label3.Location = new System.Drawing.Point(138, 66);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(35, 13);
this.label3.TabIndex = 6;
this.label3.Text = "label3";
//
// GifWriterForm
//
this.AcceptButton = this.button1;
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.CancelButton = this.button2;
this.ClientSize = new System.Drawing.Size(269, 83);
this.ClientSize = new System.Drawing.Size(269, 135);
this.Controls.Add(this.label3);
this.Controls.Add(this.numericUpDown2);
this.Controls.Add(this.label2);
this.Controls.Add(this.label1);
this.Controls.Add(this.numericUpDown1);
this.Controls.Add(this.button2);
@ -90,6 +130,7 @@
this.Name = "GifWriterForm";
this.Text = "GifWriter Options";
((System.ComponentModel.ISupportInitialize)(this.numericUpDown1)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.numericUpDown2)).EndInit();
this.ResumeLayout(false);
this.PerformLayout();
@ -101,5 +142,8 @@
private System.Windows.Forms.Button button2;
private System.Windows.Forms.NumericUpDown numericUpDown1;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.NumericUpDown numericUpDown2;
private System.Windows.Forms.Label label3;
}
}

View File

@ -21,16 +21,35 @@ namespace BizHawk.MultiClient.AVOut
using (var dlg = new GifWriterForm())
{
dlg.numericUpDown1.Value = Global.Config.GifWriterFrameskip;
dlg.numericUpDown2.Value = Global.Config.GifWriterDelay;
dlg.numericUpDown2_ValueChanged(null, null);
var result = dlg.ShowDialog(parent);
if (result == DialogResult.OK)
{
Global.Config.GifWriterFrameskip = (int)dlg.numericUpDown1.Value;
Global.Config.GifWriterDelay = (int)dlg.numericUpDown2.Value;
return GifWriter.GifToken.LoadFromConfig();
}
else
return null;
}
}
private void numericUpDown2_ValueChanged(object sender, EventArgs e)
{
if (numericUpDown2.Value == -1)
{
label3.Text = "Auto";
}
else if (numericUpDown2.Value == 0)
{
label3.Text = "Fastest";
}
else
{
label3.Text = string.Format("{0} FPS", (int)((100 + numericUpDown2.Value / 2) / numericUpDown2.Value));
}
}
}
}

View File

@ -328,6 +328,7 @@ namespace BizHawk.MultiClient
public string FFmpegCustomCommand = "-c:a foo -c:v bar -f baz";
public string AVICodecToken = "";
public int GifWriterFrameskip = 3;
public int GifWriterDelay = -1;
// NESPPU Settings
public bool AutoLoadNESPPU = false;