增加webp和avif动图格式

This commit is contained in:
ww-rm
2025-04-09 13:19:17 +08:00
parent 64cfe5fdd7
commit e35903f436
12 changed files with 258 additions and 20 deletions

View File

@@ -47,7 +47,7 @@
panel1.Location = new Point(0, 0);
panel1.Name = "panel1";
panel1.Padding = new Padding(50, 15, 50, 10);
panel1.Size = new Size(710, 698);
panel1.Size = new Size(793, 754);
panel1.TabIndex = 2;
//
// tableLayoutPanel1
@@ -65,7 +65,7 @@
tableLayoutPanel1.RowStyles.Add(new RowStyle());
tableLayoutPanel1.RowStyles.Add(new RowStyle(SizeType.Absolute, 20F));
tableLayoutPanel1.RowStyles.Add(new RowStyle(SizeType.Absolute, 20F));
tableLayoutPanel1.Size = new Size(610, 673);
tableLayoutPanel1.Size = new Size(693, 729);
tableLayoutPanel1.TabIndex = 0;
//
// propertyGrid_ExportArgs
@@ -74,7 +74,7 @@
propertyGrid_ExportArgs.Location = new Point(3, 3);
propertyGrid_ExportArgs.Name = "propertyGrid_ExportArgs";
propertyGrid_ExportArgs.PropertySort = PropertySort.Categorized;
propertyGrid_ExportArgs.Size = new Size(604, 594);
propertyGrid_ExportArgs.Size = new Size(687, 650);
propertyGrid_ExportArgs.TabIndex = 1;
propertyGrid_ExportArgs.ToolbarVisible = false;
//
@@ -88,18 +88,18 @@
tableLayoutPanel2.Controls.Add(button_Ok, 0, 0);
tableLayoutPanel2.Controls.Add(button_Cancel, 1, 0);
tableLayoutPanel2.Dock = DockStyle.Bottom;
tableLayoutPanel2.Location = new Point(3, 630);
tableLayoutPanel2.Location = new Point(3, 686);
tableLayoutPanel2.Margin = new Padding(3, 30, 3, 3);
tableLayoutPanel2.Name = "tableLayoutPanel2";
tableLayoutPanel2.RowCount = 1;
tableLayoutPanel2.RowStyles.Add(new RowStyle());
tableLayoutPanel2.Size = new Size(604, 40);
tableLayoutPanel2.Size = new Size(687, 40);
tableLayoutPanel2.TabIndex = 10;
//
// button_Ok
//
button_Ok.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
button_Ok.Location = new Point(160, 3);
button_Ok.Location = new Point(201, 3);
button_Ok.Margin = new Padding(3, 3, 30, 3);
button_Ok.Name = "button_Ok";
button_Ok.Size = new Size(112, 34);
@@ -111,7 +111,7 @@
// button_Cancel
//
button_Cancel.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
button_Cancel.Location = new Point(332, 3);
button_Cancel.Location = new Point(373, 3);
button_Cancel.Margin = new Padding(30, 3, 3, 3);
button_Cancel.Name = "button_Cancel";
button_Cancel.Size = new Size(112, 34);
@@ -126,9 +126,8 @@
AutoScaleDimensions = new SizeF(11F, 24F);
AutoScaleMode = AutoScaleMode.Font;
CancelButton = button_Cancel;
ClientSize = new Size(710, 698);
ClientSize = new Size(793, 754);
Controls.Add(panel1);
FormBorderStyle = FormBorderStyle.FixedDialog;
Icon = (Icon)resources.GetObject("$this.Icon");
MaximizeBox = false;
MinimizeBox = false;

View File

@@ -11,7 +11,7 @@ using System.Reflection;
namespace SpineViewer.Dialogs
{
public partial class ExportDialog: Form
public partial class ExportDialog : Form
{
private readonly ExporterWrapper wrapper;

View File

@@ -0,0 +1,55 @@
using FFMpegCore;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SpineViewer.Exporter
{
/// <summary>
/// MP4 导出参数
/// </summary>
public class AvifExporter : FFmpegVideoExporter
{
public AvifExporter()
{
FPS = 12;
}
public override string Format => "avif";
public override string Suffix => ".avif";
/// <summary>
/// 编码器
/// </summary>
public string Codec { get; set; } = "av1_nvenc";
/// <summary>
/// CRF
/// </summary>
public int CRF { get => crf; set => crf = Math.Clamp(value, 0, 63); }
private int crf = 23;
/// <summary>
/// 像素格式
/// </summary>
public string PixelFormat { get; set; } = "yuv420p";
/// <summary>
/// 循环次数, 0 无限循环, 取值范围 [0, 65535]
/// </summary>
public int Loop { get => loop; set => loop = Math.Clamp(value, 0, 65535); }
private int loop = 0;
public override string FileNameNoteSuffix => $"{Codec}_{CRF}_{PixelFormat}";
public override void SetOutputOptions(FFMpegArgumentOptions options)
{
base.SetOutputOptions(options);
options.WithVideoCodec(Codec).WithConstantRateFactor(CRF).WithCustomArgument($"-loop {Loop}");
}
}
}

View File

@@ -12,6 +12,11 @@ namespace SpineViewer.Exporter
/// </summary>
public class CustomExporter : FFmpegVideoExporter
{
public CustomExporter()
{
CustomArgument = "-c:v libx264 -crf 23 -pix_fmt yuv420p"; // 提供一个示例参数
}
public override string Format => CustomFormat;
public override string Suffix => CustomSuffix;

View File

@@ -35,6 +35,12 @@ namespace SpineViewer.Exporter
public byte AlphaThreshold { get => alphaThreshold; set => alphaThreshold = value; }
private byte alphaThreshold = 128;
/// <summary>
/// 循环次数, -1 不循环, 0 无限循环, 取值范围 [-1, 65535]
/// </summary>
public int Loop { get => loop; set => loop = Math.Clamp(value, -1, 65535); }
private int loop = 0;
public override string FileNameNoteSuffix => $"{MaxColors}_{AlphaThreshold}";
public override void SetOutputOptions(FFMpegArgumentOptions options)
@@ -43,7 +49,7 @@ namespace SpineViewer.Exporter
var v = $"[0:v] split [s0][s1]";
var s0 = $"[s0] palettegen=reserve_transparent=1:max_colors={MaxColors} [p]";
var s1 = $"[s1][p] paletteuse=dither=bayer:alpha_threshold={AlphaThreshold}";
var customArgs = $"-filter_complex \"{v};{s0};{s1}\"";
var customArgs = $"-filter_complex \"{v};{s0};{s1}\" -loop {Loop}";
options.WithCustomArgument(customArgs);
}
}

View File

@@ -0,0 +1,60 @@
using FFMpegCore;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SpineViewer.Exporter
{
/// <summary>
/// MP4 导出参数
/// </summary>
public class WebpExporter : FFmpegVideoExporter
{
public WebpExporter()
{
FPS = 12;
}
public override string Format => "webp";
public override string Suffix => ".webp";
/// <summary>
/// 编码器
/// </summary>
public string Codec { get; set; } = "libwebp";
/// <summary>
/// 是否无损
/// </summary>
public bool Lossless { get; set; } = false;
/// <summary>
/// 质量
/// </summary>
public int Quality { get => quality; set => quality = Math.Clamp(value, 0, 100); }
private int quality = 75;
/// <summary>
/// 像素格式
/// </summary>
public string PixelFormat { get; set; } = "yuva420p";
/// <summary>
/// 循环次数, 0 无限循环, 取值范围 [0, 65535]
/// </summary>
public int Loop { get => loop; set => loop = Math.Clamp(value, 0, 65535); }
private int loop = 0;
public override string FileNameNoteSuffix => $"{Codec}_{Quality}_{PixelFormat}";
public override void SetOutputOptions(FFMpegArgumentOptions options)
{
base.SetOutputOptions(options);
options.WithVideoCodec(Codec).WithCustomArgument($"-lossless {(Lossless ? 1 : 0)} -quality {Quality} -loop {Loop}");
}
}
}

View File

@@ -0,0 +1,44 @@
using SpineViewer.Exporter;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SpineViewer.PropertyGridWrappers.Exporter
{
public class AvifExporterWrapper(AvifExporter exporter) : FFmpegVideoExporterWrapper(exporter)
{
[Browsable(false)]
public override AvifExporter Exporter => (AvifExporter)base.Exporter;
/// <summary>
/// 编码器
/// </summary>
[StringEnumConverter.StandardValues("av1_nvenc", "av1_amf", "libaom-av1", Customizable = true)]
[TypeConverter(typeof(StringEnumConverter))]
[Category("[3] "), DisplayName(""), Description("-c:v, 使\n建议使用硬件加速, libaom-av1 ")]
public string Codec { get => Exporter.Codec; set => Exporter.Codec = value; }
/// <summary>
/// CRF
/// </summary>
[Category("[3] "), DisplayName("CRF"), Description("-crf, 0-63, 18-28, 23, ")]
public int CRF { get => Exporter.CRF; set => Exporter.CRF = value; }
/// <summary>
/// 像素格式
/// </summary>
[StringEnumConverter.StandardValues("yuv420p", "yuv422p", "yuv444p", Customizable = true)]
[TypeConverter(typeof(StringEnumConverter))]
[Category("[3] "), DisplayName(""), Description("-pix_fmt, 使")]
public string PixelFormat { get => Exporter.PixelFormat; set => Exporter.PixelFormat = value; }
/// <summary>
/// 循环次数
/// </summary>
[Category("[3] "), DisplayName(""), Description(", 0 , [0, 65535]")]
public int Loop { get => Exporter.Loop; set => Exporter.Loop = value; }
}
}

View File

@@ -13,16 +13,29 @@ namespace SpineViewer.PropertyGridWrappers.Exporter
[Browsable(false)]
public override CustomExporter Exporter => (CustomExporter)base.Exporter;
[Browsable(false)]
public override string Format => Exporter.Format;
[Browsable(false)]
public override string Suffix => Exporter.Suffix;
/// <summary>
/// 文件格式
/// </summary>
[Category("[3] "), DisplayName(""), Description("")]
public string CustomFormat { get; set; } = "mp4";
[Category("[2] FFmpeg "), DisplayName(""), Description("-f, ")]
public string CustomFormat { get => Exporter.CustomFormat; set => Exporter.CustomFormat = value; }
/// <summary>
/// 文件名后缀
/// </summary>
[Category("[3] "), DisplayName(""), Description("")]
public string CustomSuffix { get; set; } = ".mp4";
[Category("[2] FFmpeg "), DisplayName(""), Description("")]
public string CustomSuffix { get => Exporter.CustomSuffix; set => Exporter.CustomSuffix = value; }
/// <summary>
/// 文件名后缀
/// </summary>
[Category("[2] FFmpeg "), DisplayName(""), Description(" FFmpeg ")]
public override string CustomArgument { get => Exporter.CustomArgument; set => Exporter.CustomArgument = value; }
}
}

View File

@@ -17,18 +17,18 @@ namespace SpineViewer.PropertyGridWrappers.Exporter
/// 文件格式
/// </summary>
[Category("[2] FFmpeg "), DisplayName(""), Description("-f, ")]
public string Format => Exporter.Format;
public virtual string Format => Exporter.Format;
/// <summary>
/// 文件名后缀
/// </summary>
[Category("[2] FFmpeg "), DisplayName(""), Description("")]
public string Suffix => Exporter.Format;
public virtual string Suffix => Exporter.Suffix;
/// <summary>
/// 文件名后缀
/// </summary>
[Category("[2] FFmpeg "), DisplayName(""), Description(" FFmpeg , , ")]
public string CustomArgument { get => Exporter.CustomArgument; set => Exporter.CustomArgument = value; }
public virtual string CustomArgument { get => Exporter.CustomArgument; set => Exporter.CustomArgument = value; }
}
}

View File

@@ -24,5 +24,11 @@ namespace SpineViewer.PropertyGridWrappers.Exporter
/// </summary>
[Category("[3] "), DisplayName(""), Description("")]
public byte AlphaThreshold { get => Exporter.AlphaThreshold; set => Exporter.AlphaThreshold = value; }
/// <summary>
/// 透明度阈值
/// </summary>
[Category("[3] "), DisplayName(""), Description(", -1 , 0 , [-1, 65535]")]
public int Loop { get => Exporter.Loop; set => Exporter.Loop = value; }
}
}

View File

@@ -16,7 +16,7 @@ namespace SpineViewer.PropertyGridWrappers.Exporter
/// <summary>
/// 编码器
/// </summary>
[StringEnumConverter.StandardValues("libx264", "libx265", "libvpx-vp9", Customizable = true)]
[StringEnumConverter.StandardValues("libx264", "libx265", "libvpx-vp9", "av1_nvenc", Customizable = true)]
[TypeConverter(typeof(StringEnumConverter))]
[Category("[3] "), DisplayName(""), Description("-c:v, 使")]
public string Codec { get => Exporter.Codec; set => Exporter.Codec = value; }

View File

@@ -0,0 +1,50 @@
using SpineViewer.Exporter;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SpineViewer.PropertyGridWrappers.Exporter
{
public class WebpExporterWrapper(WebpExporter exporter) : FFmpegVideoExporterWrapper(exporter)
{
[Browsable(false)]
public override WebpExporter Exporter => (WebpExporter)base.Exporter;
/// <summary>
/// 编码器
/// </summary>
[StringEnumConverter.StandardValues("libwebp", Customizable = true)]
[TypeConverter(typeof(StringEnumConverter))]
[Category("[3] "), DisplayName(""), Description("-c:v, 使")]
public string Codec { get => Exporter.Codec; set => Exporter.Codec = value; }
/// <summary>
/// 是否无损
/// </summary>
[Category("[3] "), DisplayName(""), Description("-lossless, 0 , 1 ")]
public bool Lossless { get => Exporter.Lossless; set => Exporter.Lossless = value; }
/// <summary>
/// CRF
/// </summary>
[Category("[3] "), DisplayName(""), Description("-quality, 0-100, 75")]
public int Quality { get => Exporter.Quality; set => Exporter.Quality = value; }
/// <summary>
/// 像素格式
/// </summary>
[StringEnumConverter.StandardValues("yuv420p", "yuva420p", Customizable = true)]
[TypeConverter(typeof(StringEnumConverter))]
[Category("[3] "), DisplayName(""), Description("-pix_fmt, 使")]
public string PixelFormat { get => Exporter.PixelFormat; set => Exporter.PixelFormat = value; }
/// <summary>
/// 透明度阈值
/// </summary>
[Category("[3] "), DisplayName(""), Description(", 0 , [0, 65535]")]
public int Loop { get => Exporter.Loop; set => Exporter.Loop = value; }
}
}