Skip to content

GOWA - WhatsApp REST API with support for UI, Multi Account, Webhooks, and MCP, and Chatwoot. Built with Golang for efficient memory use.

fix(send): drop -vsync from sticker WebP conversion for ffmpeg 9 (#847)

MalikD2004701ad9b4f66c
diff --git a/src/usecase/send.go b/src/usecase/send.go
index 3ef6fdb1..30abde16 100644
--- a/src/usecase/send.go
+++ b/src/usecase/send.go
@@ -94,6 +94,24 @@ func buildHDVideoFFmpegArgs(inputPath, outputPath string) []string {
}
}
+// buildStickerWebPFFmpegArgs converts a single still PNG into a static WebP sticker.
+// It must not pass -vsync: ffmpeg deprecated it in 5.1 and removed it in 9.0, and
+// frame-rate sync does nothing for a one-frame input anyway.
+func buildStickerWebPFFmpegArgs(inputPath, outputPath string) []string {
+ return []string{
+ "-y",
+ "-i", inputPath,
+ "-vcodec", "libwebp",
+ "-lossless", "0",
+ "-compression_level", "6",
+ "-q:v", "60",
+ "-preset", "default",
+ "-loop", "0",
+ "-an",
+ outputPath,
+ }
+}
+
func buildVideoTranscodeArgs(inputPath, outputPath string, compress, hd bool) ([]string, bool) {
if hd {
return buildHDVideoFFmpegArgs(inputPath, outputPath), true
@@ -1873,7 +1891,7 @@ func (service serviceSend) SendSticker(ctx context.Context, request domainSend.S
// Check if ffmpeg is available
if _, err := exec.LookPath("ffmpeg"); err == nil {
// Use ffmpeg to convert to WebP with transparency support, overwrite if exists
- convertCmd = exec.CommandContext(convCtx, "ffmpeg", "-y", "-i", pngPath, "-vcodec", "libwebp", "-lossless", "0", "-compression_level", "6", "-q:v", "60", "-preset", "default", "-loop", "0", "-an", "-vsync", "0", webpPath)
+ convertCmd = exec.CommandContext(convCtx, "ffmpeg", buildStickerWebPFFmpegArgs(pngPath, webpPath)...)
} else if _, err := exec.LookPath("cwebp"); err == nil {
// Use cwebp as fallback
convertCmd = exec.CommandContext(convCtx, "cwebp", "-q", "60", "-o", webpPath, pngPath)
diff --git a/src/usecase/send_test.go b/src/usecase/send_test.go
index 192b3c8a..ec6b1ba5 100644
--- a/src/usecase/send_test.go
+++ b/src/usecase/send_test.go
@@ -6,8 +6,10 @@ import (
"errors"
"image"
"image/jpeg"
+ "image/png"
"net/http"
"os"
+ "os/exec"
"path/filepath"
"testing"
@@ -134,6 +136,49 @@ func TestBuildHDVideoFFmpegArgsUses1280BoundingBoxWithoutUpscaling(t *testing.T)
assert.Equal(t, want, buildHDVideoFFmpegArgs("input.mp4", "output.mp4"))
}
+func TestBuildStickerWebPFFmpegArgs(t *testing.T) {
+ want := []string{
+ "-y",
+ "-i", "input.png",
+ "-vcodec", "libwebp",
+ "-lossless", "0",
+ "-compression_level", "6",
+ "-q:v", "60",
+ "-preset", "default",
+ "-loop", "0",
+ "-an",
+ "output.webp",
+ }
+
+ got := buildStickerWebPFFmpegArgs("input.png", "output.webp")
+ assert.Equal(t, want, got)
+ assert.NotContains(t, got, "-vsync", "ffmpeg 9 removed -vsync; passing it fails the whole conversion")
+}
+
+func TestBuildStickerWebPFFmpegArgsConvertWithInstalledFFmpeg(t *testing.T) {
+ if _, err := exec.LookPath("ffmpeg"); err != nil {
+ t.Skip("ffmpeg not installed")
+ }
+
+ dir := t.TempDir()
+ pngPath := filepath.Join(dir, "sticker.png")
+ webpPath := filepath.Join(dir, "sticker.webp")
+
+ pngFile, err := os.Create(pngPath)
+ require.NoError(t, err)
+ require.NoError(t, png.Encode(pngFile, image.NewNRGBA(image.Rect(0, 0, 4, 4))))
+ require.NoError(t, pngFile.Close())
+
+ output, err := exec.Command("ffmpeg", buildStickerWebPFFmpegArgs(pngPath, webpPath)...).CombinedOutput()
+ require.NoError(t, err, string(output))
+
+ webp, err := os.ReadFile(webpPath)
+ require.NoError(t, err)
+ require.GreaterOrEqual(t, len(webp), 12)
+ assert.Equal(t, "RIFF", string(webp[0:4]))
+ assert.Equal(t, "WEBP", string(webp[8:12]))
+}
+
func TestBuildVideoTranscodeArgsSelectsRequestedQuality(t *testing.T) {
hdArgs := buildHDVideoFFmpegArgs("input.mp4", "output.mp4")
legacyArgs := []string{