fix (plg_video_thumbnail): error when backend doesn't support fileseek

This commit is contained in:
MickaelK 2024-12-02 17:24:03 +11:00
parent 0dfa9b3335
commit 177961c62d
2 changed files with 16 additions and 8 deletions

View file

@ -286,6 +286,7 @@ func FileCat(ctx *App, res http.ResponseWriter, req *http.Request) {
SendErrorResult(res, err)
return
}
file_cache.Set(ctx.Session, tmpPath)
if _, err = io.Copy(f, file); err != nil {
f.Close()
file.Close()
@ -293,14 +294,20 @@ func FileCat(ctx *App, res http.ResponseWriter, req *http.Request) {
SendErrorResult(res, err)
return
}
f.Close()
file.Close()
if f, err = os.OpenFile(tmpPath, os.O_RDONLY, os.ModePerm); err != nil {
if err = f.Sync(); err != nil {
f.Close()
file.Close()
Log.Debug("cat::range2 '%s'", err.Error())
SendErrorResult(res, err)
return
}
file_cache.Set(ctx.Session, tmpPath)
f.Close()
file.Close()
if f, err = os.OpenFile(tmpPath, os.O_RDONLY, os.ModePerm); err != nil {
Log.Debug("cat::range3 '%s'", err.Error())
SendErrorResult(res, err)
return
}
if fi, err := f.Stat(); err == nil {
contentLength = fi.Size()
}

View file

@ -2,6 +2,7 @@ package plg_video_thumbnail
import (
"bytes"
"encoding/base64"
"fmt"
"io"
"net/http"
@ -59,7 +60,7 @@ func (this *ffmpegThumbnail) Generate(reader io.ReadCloser, ctx *App, res *http.
errBuff bytes.Buffer
fullURL = strings.Replace(
fmt.Sprintf("http://127.0.0.1:%d%s?%s", Config.Get("general.port").Int(), req.URL.Path, req.URL.RawQuery),
"&thumbnail=true", "", 1,
"&thumbnail=true", "&origin=plg_video_thumbnail", 1,
)
cacheName = "thumb_" + GenerateID(ctx.Session) + "_" + QuickHash(req.URL.Query().Get("path"), 10) + ".jpeg"
cachePath = GetAbsolutePath(VideoCachePath, cacheName)
@ -73,17 +74,17 @@ func (this *ffmpegThumbnail) Generate(reader io.ReadCloser, ctx *App, res *http.
}
cmd := exec.CommandContext(req.Context(), "ffmpeg", []string{
"-headers", "cookie: " + req.Header.Get("Cookie"),
"-hide_banner", "-headers", "cookie: " + req.Header.Get("Cookie") + "\r\n",
"-skip_frame", "nokey",
"-i", fullURL, "-y",
"-an", "-sn",
"-vf", "thumbnail, scale=320:320: force_original_aspect_ratio=decrease", "-vsync", "passthrough", "-frames:v", "1",
"-vf", "thumbnail, scale=320:320: force_original_aspect_ratio=decrease", "-fps_mode", "passthrough", "-frames:v", "1",
"-c:v", "mjpeg", cachePath,
}...)
cmd.Stderr = &errBuff
if err := cmd.Run(); err != nil {
if req.Context().Err() == nil {
Log.Error("plg_video_thumbnail::generate::run err=%s", errBuff.String())
Log.Debug("plg_video_thumbnail::generate::run path=%s err=%s", req.URL.Query().Get("path"), base64.StdEncoding.EncodeToString(errBuff.Bytes()))
return nil, err
}
return nil, err