bruschetta

A simple golang web based file browser
Log | Files | Refs | LICENSE

commit ff2c8c63e65ddfeef89ecbf71e64e1e933270982
parent 23effb4ba3fa7f12c2938d94242d80037f8d397b
Author: Peter <peter@minskio.co.uk>
Date:   Fri, 23 Oct 2026 13:27:29 +0100

Fix webm thumbnails by using ffmpeg

Diffstat:
Mmain.go | 36+++++++++++++++++++++++++++++++++---
Mreadme.md | 2+-
2 files changed, 34 insertions(+), 4 deletions(-)

diff --git a/main.go b/main.go @@ -1,6 +1,7 @@ package main import ( + "bytes" "encoding/json" "flag" "fmt" @@ -14,6 +15,7 @@ import ( "log" "net/http" "os" + "os/exec" "path/filepath" "sort" "strings" @@ -518,7 +520,34 @@ func thumbHandler(w http.ResponseWriter, r *http.Request) { } defer f.Close() - img, _, err := image.Decode(f) + var img image.Image + + if strings.EqualFold(filepath.Ext(fsPath), ".webm") { + f.Close() + + cmd := exec.Command( + "ffmpeg", + "-v", "error", + "-i", fsPath, + "-frames:v", "1", + "-f", "image2pipe", + "-vcodec", "mjpeg", + "pipe:1", + ) + + var out bytes.Buffer + cmd.Stdout = &out + + if err := cmd.Run(); err != nil { + servePlaceholder(w) + return + } + + img, _, err = image.Decode(&out) + } else { + img, _, err = image.Decode(f) + } + if err != nil { servePlaceholder(w) return @@ -527,7 +556,8 @@ func thumbHandler(w http.ResponseWriter, r *http.Request) { thumb := resizeNN(img, 200, 150) w.Header().Set("Content-Type", "image/jpeg") w.Header().Set("Cache-Control", "max-age=3600") - jpeg.Encode(w, thumb, &jpeg.Options{Quality: 75}) + _ = jpeg.Encode(w, thumb, &jpeg.Options{Quality: 75}) + } func resizeNN(src image.Image, maxW, maxH int) image.Image { @@ -586,7 +616,7 @@ func buildTree(basePath, urlBase string) []*TreeNode { func isImageExt(ext string) bool { switch ext { - case "jpg", "jpeg", "png", "gif", "webp", "bmp", "avif": + case "jpg", "jpeg", "png", "gif", "webp", "bmp", "avif", "webm": return true } return false diff --git a/readme.md b/readme.md @@ -22,7 +22,7 @@ The application is also buildable via your usual `go build -o bruschetta .`. * Dotfiles are hidden, but still accessible * Collapsable folder tree * Sortable Name, Size and Modified columns -* No dependencies outside stdlib +* No dependencies outside stdlib, does require `ffmpeg` for webm thumbnails * Renders `index.htm(l)` files in directories instead of listing ## Screenshot