summaryrefslogtreecommitdiff
path: root/app/app.go
diff options
context:
space:
mode:
authorJames Mills <prologic@shortcircuit.net.au>2020-03-26 14:34:19 +1000
committerJames Mills <prologic@shortcircuit.net.au>2020-03-26 14:50:49 +1000
commit8727285bc504f18c0b32b1ee1626b625a587622e (patch)
treec8d1428a8cfa61f20379bd665a9a1c94b9b30bc8 /app/app.go
parent7fa7a38167415301a9a01735d2eb354542c11dcb (diff)
Refactored thumbnail generation with configurable timeout and in-sycn with video transcoding
Diffstat (limited to 'app/app.go')
-rw-r--r--app/app.go23
1 files changed, 23 insertions, 0 deletions
diff --git a/app/app.go b/app/app.go
index ac377be..5150d74 100644
--- a/app/app.go
+++ b/app/app.go
@@ -241,6 +241,8 @@ func (a *App) uploadHandler(w http.ResponseWriter, r *http.Request) {
a.Library.Paths[collection].Path,
fmt.Sprintf("%s.mp4", shortuuid.New()),
)
+ thumbFn1 := fmt.Sprintf("%s.jpg", strings.TrimSuffix(tf.Name(), filepath.Ext(tf.Name())))
+ thumbFn2 := fmt.Sprintf("%s.jpg", strings.TrimSuffix(vf, filepath.Ext(vf)))
// TODO: Use a proper Job Queue and make this async
if err := utils.RunCmd(
@@ -260,6 +262,27 @@ func (a *App) uploadHandler(w http.ResponseWriter, r *http.Request) {
return
}
+ if err := utils.RunCmd(
+ a.Config.Thumbnailer.Timeout,
+ "mt",
+ "-b",
+ "-s",
+ "-n", "1",
+ tf.Name(),
+ ); err != nil {
+ err := fmt.Errorf("error generating thumbnail: %w", err)
+ log.Error(err)
+ http.Error(w, err.Error(), http.StatusInternalServerError)
+ return
+ }
+
+ if err := os.Rename(thumbFn1, thumbFn2); err != nil {
+ err := fmt.Errorf("error renaming generated thumbnail: %w", err)
+ log.Error(err)
+ http.Error(w, err.Error(), http.StatusInternalServerError)
+ return
+ }
+
if err := os.Rename(tf.Name(), vf); err != nil {
err := fmt.Errorf("error renaming transcoded video: %w", err)
log.Error(err)