Skip to content

Commit 00df681

Browse files
Copilotanacrolix
andcommitted
Replace ffmpegthumbnailer with ffmpeg for thumbnail generation
Co-authored-by: anacrolix <[email protected]>
1 parent f48b324 commit 00df681

File tree

3 files changed

+27
-22
lines changed

3 files changed

+27
-22
lines changed

.gitignore

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Binaries for programs and plugins
2+
dms
3+
*.exe
4+
*.exe~
5+
*.dll
6+
*.so
7+
*.dylib
8+
9+
# Test binary, built with `go test -c`
10+
*.test
11+
12+
# Output of the go coverage tool, specifically when used with LiteIDE
13+
*.out
14+
15+
# Dependency directories (remove the comment below to include it)
16+
# vendor/

dlna/dms/dms.go

Lines changed: 11 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,18 @@ package dms
22

33
import (
44
"bytes"
5+
"context"
56
"crypto/md5"
67
"encoding/xml"
78
"errors"
89
"fmt"
910
"io"
1011
"io/ioutil"
11-
"math/rand"
1212
"net"
1313
"net/http"
1414
"net/http/pprof"
1515
"net/url"
1616
"os"
17-
"os/exec"
1817
"os/user"
1918
"path"
2019
"path/filepath"
@@ -652,32 +651,22 @@ func (s *Server) filePath(_path string) string {
652651

653652
func (me *Server) serveIcon(w http.ResponseWriter, r *http.Request) {
654653
filePath := me.filePath(r.URL.Query().Get("path"))
655-
c := r.URL.Query().Get("c")
656-
if c == "" {
657-
c = "png"
658-
}
659-
args := []string{}
660-
_, fqThumbnail := os.LookupEnv("DMS_THUMBNAIL_FULLQUALITY")
661-
if fqThumbnail {
662-
args = append(args, "-s", "0", "-q", "10")
663-
}
664-
665-
_, randThumbnail := os.LookupEnv("DMS_THUMBNAIL_RANDOM")
666-
if randThumbnail {
667-
args = append(args, "-t", strconv.Itoa(rand.Intn(100)))
668-
}
654+
655+
// Create a context with timeout for thumbnail generation
656+
ctx, cancel := context.WithTimeout(r.Context(), 30*time.Second)
657+
defer cancel()
669658

670-
args = append(args, "-i", filePath, "-o", "/dev/stdout", "-c"+c)
671-
cmd := exec.Command("ffmpegthumbnailer", args...)
672-
// cmd.Stderr = os.Stderr
673-
body, err := cmd.Output()
659+
// Generate thumbnail using ffmpeg
660+
body, err := generateThumbnailFFmpeg(ctx, filePath)
674661
if err != nil {
675-
// serve 1st Icon if no ffmpegthumbnailer
662+
// serve 1st Icon if thumbnail generation fails
676663
w.Header().Set("Content-Type", me.Icons[0].Mimetype)
677664
http.ServeContent(w, r, "", time.Time{}, bytes.NewReader(me.Icons[0].Bytes))
678-
// http.Error(w, err.Error(), http.StatusInternalServerError)
679665
return
680666
}
667+
668+
// Serve the generated thumbnail as PNG
669+
w.Header().Set("Content-Type", "image/png")
681670
http.ServeContent(w, r, "", time.Now(), bytes.NewReader(body))
682671
}
683672

dms

-14.4 MB
Binary file not shown.

0 commit comments

Comments
 (0)