fix: Wails file drop, duplicate listeners, trim drag, crop stage, preview cache/pixfmt, NSIS temp quoting
Build Windows Installer / build (push) Successful in 8m46s
Build Windows Installer / build (push) Successful in 8m46s
This commit is contained in:
12 files changed
+563
-226
No files matched your search
@@ -22,6 +22,8 @@ import (
|
||||
type Server struct {
|
||||
addr string
|
||||
httpSrv *http.Server
|
||||
ctx context.Context
|
||||
cancel context.CancelFunc
|
||||
ffmpegBin string
|
||||
mu sync.RWMutex
|
||||
files map[string]registeredFile
|
||||
@@ -41,8 +43,11 @@ func Start(ffmpegBin string) (*Server, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
s := &Server{
|
||||
addr: ln.Addr().String(),
|
||||
ctx: ctx,
|
||||
cancel: cancel,
|
||||
ffmpegBin: ffmpegBin,
|
||||
files: make(map[string]registeredFile),
|
||||
proxyLocks: make(map[string]*sync.Mutex),
|
||||
@@ -78,7 +83,12 @@ func (s *Server) BaseURL() string {
|
||||
}
|
||||
|
||||
func (s *Server) Register(info *media.VideoInfo) string {
|
||||
sum := sha1.Sum([]byte(info.Path))
|
||||
var modUnix int64
|
||||
if st, err := os.Stat(info.Path); err == nil {
|
||||
modUnix = st.ModTime().UnixNano()
|
||||
}
|
||||
key := fmt.Sprintf("%s|%d|%d", info.Path, info.SizeBytes, modUnix)
|
||||
sum := sha1.Sum([]byte(key))
|
||||
id := hex.EncodeToString(sum[:8])
|
||||
|
||||
s.mu.Lock()
|
||||
@@ -88,6 +98,9 @@ func (s *Server) Register(info *media.VideoInfo) string {
|
||||
}
|
||||
|
||||
func (s *Server) Close() {
|
||||
if s.cancel != nil {
|
||||
s.cancel()
|
||||
}
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 2*time.Second)
|
||||
defer cancel()
|
||||
if s.httpSrv != nil {
|
||||
@@ -166,7 +179,7 @@ func (s *Server) handleProxy(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
if proxyPath == "" {
|
||||
proxyPath = filepath.Join(os.TempDir(), fmt.Sprintf("convert_preview_%s.mp4", cacheKey))
|
||||
if err := s.buildProxy(r.Context(), ffmpegBin, rf.info, merge, proxyPath); err != nil {
|
||||
if err := s.buildProxy(s.ctx, ffmpegBin, rf.info, merge, proxyPath); err != nil {
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
@@ -211,8 +224,8 @@ func (s *Server) buildProxy(ctx context.Context, ffmpegBin string, info *media.V
|
||||
args = append(args, "-map", "0:v:0", "-map", "0:a:0", "-c:a", "aac", "-b:a", "128k")
|
||||
}
|
||||
|
||||
if info.VideoCodec == "h264" {
|
||||
// Remux video stream instantaneously when codec is already H.264
|
||||
if info.VideoCodec == "h264" && media.IsH264BrowserNativePixFmt(info.PixFmt) {
|
||||
// Remux video stream instantaneously when codec is already browser-native 8-bit H.264
|
||||
args = append(args, "-c:v", "copy")
|
||||
} else {
|
||||
args = append(args,
|
||||
@@ -220,7 +233,7 @@ func (s *Server) buildProxy(ctx context.Context, ffmpegBin string, info *media.V
|
||||
"-preset", "ultrafast",
|
||||
"-crf", "26",
|
||||
"-pix_fmt", "yuv420p",
|
||||
"-vf", "scale='min(1280,iw)':-2",
|
||||
"-vf", "scale='min(1280,trunc(iw/2)*2)':-2",
|
||||
)
|
||||
}
|
||||
args = append(args, "-movflags", "+faststart", outPath)
|
||||
|
||||
Reference in new issue
Block a user