You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何将动画PNG(APNG)转换为动画WEBP文件?寻求可用的C#库或命令行工具解决方案

APNG to Animated WebP: Solutions for C# & Command Line

I’ve tackled this exact problem before, so here are reliable, up-to-date solutions that align with your requirements:

1. Fixing ImageMagick for Animated WebP Conversion

Your existing ImageMagick setup can work—you just need to adjust the command to preserve animation frames and apply your desired settings. The issue with your initial command is that it defaults to exporting only the first frame of the APNG. Use this command instead:

magick "c:/temp/a.png" -define webp:method=6 -define webp:min-size=true -define webp:thread-level=1 -quality 100 "c:/temp/a.webp"

Key parameter breakdown:

  • webp:method=6: Enables the slowest, highest-compression mode (matches your -m 6 requirement)
  • webp:min-size=true: Optimizes for smallest file size (your -min_size flag)
  • webp:thread-level=1: Enables multi-threaded encoding (equivalent to -mt)

2. C# Library: Magick.NET (Proper Implementation)

You mentioned checking Magick.NET but not finding a solution—this is likely because you used a single MagickImage instead of MagickImageCollection to load all APNG frames. Here’s a working code snippet that mirrors your desired command parameters:

using ImageMagick;

// Load all frames of the APNG
using var apngFrames = new MagickImageCollection(@"path\image.png");

// Configure WebP export settings matching your requirements
var webpSettings = new MagickWriteSettings
{
    Format = MagickFormat.WebP,
    Quality = 100, // Matches -q 100
    Defines = new Dictionary<string, string>
    {
        { "webp:method", "6" }, // Matches -m 6
        { "webp:min-size", "true" }, // Matches -min_size
        { "webp:thread-level", "1" } // Matches -mt (multi-threading)
    }
};

// Export to animated WebP
apngFrames.Write(@"path\image.webp", webpSettings);

Make sure you install the Magick.NET package that matches your ImageMagick architecture (e.g., Magick.NET-Q16-HDRI-x64 to align with your installed DLL).

3. Alternative Command Line Tool: FFmpeg

If you want a modern, maintained replacement for the outdated apng2webp, FFmpeg is a robust option. It handles APNG to animated WebP seamlessly with parameters aligned to your needs:

ffmpeg -i "path\image.png" -q:v 100 -lossless 1 -m 6 -threads auto "path\image.webp"
  • -q:v 100: Sets maximum quality
  • -lossless 1: Enables lossless encoding (switch to 0 for lossy if needed)
  • -m 6: Uses the highest compression level
  • -threads auto: Leverages multi-threading for faster encoding

内容的提问来源于stack exchange,提问作者Furkan Gözükara

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.29 19:42:32