Skip to content

Effort free video editing!

Add WebP encoding behind ENABLE_WEBP

WyattBlue18b47b00bbe0
diff --git a/ae.nimble b/ae.nimble
index 5fe09f74..535860d2 100644
--- a/ae.nimble
+++ b/ae.nimble
@@ -18,6 +18,8 @@ let disableHevc = getEnv("DISABLE_HEVC").len > 0
let enableWhisper = getEnv("DISABLE_WHISPER").len == 0
let enableVpl = getEnv("DISABLE_VPL").len == 0
let enableLibass = getEnv("DISABLE_LIBASS").len == 0
+# Off unless asked for: only the GUI app writes WebP.
+let enableWebp = getEnv("ENABLE_WEBP").len > 0
let
nativeBuildPath = absolutePath("build")
@@ -287,6 +289,19 @@ let libass = Package(
"-Dcompare=disabled", "-Dprofile=disabled", "-Dfuzz=disabled",
"-Dcheckasm=disabled", "-Dlibunibreak=enabled"],
)
+let webp = Package(
+ name: "libwebp",
+ sourceUrl: "https://storage.googleapis.com/downloads.webmproject.org/releases/webp/libwebp-1.6.0.tar.gz",
+ sha256: "e4ab7009bf0629fd11982d4c2aa83964cf244cffba7347ecd39019a9e38c4564",
+ buildSystem: "cmake",
+ # The libraries alone: libwebpmux is what encodes an animation.
+ buildArguments: @["-DWEBP_BUILD_ANIM_UTILS=OFF", "-DWEBP_BUILD_CWEBP=OFF",
+ "-DWEBP_BUILD_DWEBP=OFF", "-DWEBP_BUILD_GIF2WEBP=OFF",
+ "-DWEBP_BUILD_IMG2WEBP=OFF", "-DWEBP_BUILD_VWEBP=OFF",
+ "-DWEBP_BUILD_WEBPINFO=OFF", "-DWEBP_BUILD_WEBPMUX=OFF",
+ "-DWEBP_BUILD_EXTRAS=OFF", "-DWEBP_BUILD_LIBWEBPMUX=ON"],
+ ffFlag: "--enable-libwebp",
+)
let ffmpeg = Package(
name: "ffmpeg",
sourceUrl: "https://ffmpeg.org/releases/ffmpeg-9.1.tar.xz",
@@ -318,6 +333,8 @@ proc selectPackages(kind: CrossKind = native): seq[Package] =
result.add svtav1
if not disableHevc and not isWasm:
result.add x265
+ if enableWebp and not isWasm:
+ result.add webp
return result
func location(package: Package): string =
@@ -1055,6 +1072,9 @@ proc setupCommonFlags(packages: seq[Package], kind: CrossKind = native): string
enableEncoders.add "libsvtav1"
if package.name == "amf-headers" and not isCrossWasm:
enableEncoders &= ["h264_amf", "hevc_amf", "av1_amf"]
+ if package.name == "libwebp":
+ enableEncoders &= ["libwebp", "libwebp_anim"]
+ enableMuxers.add "webp"
let isMacNative = defined(macosx) and kind == native
let isWindows = kind in [winX64, winArm] or (defined(windows) and kind == native)
@@ -1141,7 +1161,9 @@ proc setupDeps =
exec "pip install " & toInstall.join(" ")
task downloaddeps, "Download and Extract Cxx Dependencies":
- let allPackages = @[ffmpeg, nvheaders, amfheaders, alsa, libvpl, whisper, bwlame, opus, dav1d, x264, zlib, vpx, svtav1, x265, freetype, fribidi, harfbuzz, libunibreak, libass]
+ var allPackages = @[ffmpeg, nvheaders, amfheaders, alsa, libvpl, whisper, bwlame, opus, dav1d, x264, zlib, vpx, svtav1, x265, freetype, fribidi, harfbuzz, libunibreak, libass]
+ if enableWebp:
+ allPackages.add webp
mkDir "ffmpeg_sources"
withDir "ffmpeg_sources":
for package in allPackages:
diff --git a/config.nims b/config.nims
index c692b0aa..eab3f13c 100644
--- a/config.nims
+++ b/config.nims
@@ -6,6 +6,7 @@ var enableHevc = getEnv("DISABLE_HEVC").len == 0 and not defined(emscripten)
var enableWhisper = getEnv("DISABLE_WHISPER").len == 0
var enableVpl = getEnv("DISABLE_VPL").len == 0 and not defined(macosx)
var enableLibass = getEnv("DISABLE_LIBASS").len == 0
+var enableWebp = getEnv("ENABLE_WEBP").len > 0 and not defined(emscripten)
when defined(danger) or defined(release):
switch("panics", "on")
@@ -121,6 +122,8 @@ if not defined(dynamic):
switch("passL", "-lSvtAv1Enc")
if enableHevc:
switch("passL", "-lx265")
+ if enableWebp:
+ switch("passL", "-lwebpmux -lwebp -lsharpyuv")
when not defined(emscripten):
if enableVpl and not (hostCPU == "arm64" and hostOS == "windows") and
not (hostCPU == "arm" and hostOS == "linux"):
diff --git a/src/render/format.nim b/src/render/format.nim
index f6a5ca7f..3cf04415 100644
--- a/src/render/format.nim
+++ b/src/render/format.nim
@@ -170,6 +170,10 @@ proc makeMedia*(args: mainArgs, inputVideo: VideoSettings, audio: AudioSettings,
warning "Fragmented is enabled, will not apply faststart."
elif not args.noFaststart:
options.add("movflags", "faststart")
+ if rules.format.name == "webp":
+ # The muxer's own default plays an animation once and stops; a GIF's
+ # repeats forever.
+ options.add("loop", "0")
var output = openWrite(outputPath, rules.format)
output.options = options