summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Cady <d@jerkface.net>2022-12-26 03:54:59 -0500
committerAndrew Cady <d@jerkface.net>2022-12-26 03:54:59 -0500
commitbc28734fcfb8da25c54b5a02a0bacad2b5d6c1a6 (patch)
tree1608b9dca21e2ada434e62561e47b2e5b72ecae0
parent985fcc318c4445486b36707e39086d90ce83944e (diff)
move sort into haskell
-rw-r--r--vmail/src/WebApp.hs15
1 files changed, 9 insertions, 6 deletions
diff --git a/vmail/src/WebApp.hs b/vmail/src/WebApp.hs
index 7fbd1c4..3fcf243 100644
--- a/vmail/src/WebApp.hs
+++ b/vmail/src/WebApp.hs
@@ -34,7 +34,7 @@ import Servant.JS (vanillaJS, jsForAPI)
34import Servant.Multipart 34import Servant.Multipart
35import System.Directory 35import System.Directory
36import qualified Rebase.Data.Text as Text 36import qualified Rebase.Data.Text as Text
37import Database.SQLite.Simple hiding ((:.)) 37import Database.SQLite.Simple hiding ((:.), changes)
38import System.Random 38import System.Random
39import System.Systemd.Daemon 39import System.Systemd.Daemon
40 40
@@ -363,6 +363,7 @@ addBlob addr uuid blobData@RTCBlob{..} = do
363 queryG <&> recordBlob uuid now addr blobData >>= updateG 363 queryG <&> recordBlob uuid now addr blobData >>= updateG
364 return "success" 364 return "success"
365 365
366withoutMetaData :: WithMetaData a -> a
366withoutMetaData (WithMetaData _ _ payload) = payload 367withoutMetaData (WithMetaData _ _ payload) = payload
367 368
368saveVideoClip :: FilePath -> [FilePath] -> Float -> Float -> IO () 369saveVideoClip :: FilePath -> [FilePath] -> Float -> Float -> IO ()
@@ -371,8 +372,8 @@ saveVideoClip outputFile inputChunks _ stopTime | stopTime == 0 = do
371 cmd_ (AddEnv "output" outputFile) 372 cmd_ (AddEnv "output" outputFile)
372 (["sh", "-xc", cmdScript, "sh"] ++ inputChunks) 373 (["sh", "-xc", cmdScript, "sh"] ++ inputChunks)
373saveVideoClip outputFile inputChunks startTime stopTime = do 374saveVideoClip outputFile inputChunks startTime stopTime = do
374 -- let cmdScript = "printf '%s\n' \"$@\" | sort -n | xargs cat | ffmpeg -i - -c:v libx264 -f mp4 -ss \"$start\" -t \"$stop\" \"$output\"" :: String 375 -- let cmdScript = "cat \"$@\" | ffmpeg -i - -c:v libx264 -f mp4 -ss \"$start\" -t \"$stop\" \"$output\"" :: String
375 let cmdScript = "printf '%s\n' \"$@\" | sort -n | xargs cat | ffmpeg -i - -c:v libvpx -c:a libvorbis -ss \"$start\" -t \"$stop\" \"$output\"" :: String 376 let cmdScript = "cat \"$@\" | ffmpeg -i - -c:v libvpx -c:a libvorbis -ss \"$start\" -t \"$stop\" \"$output\"" :: String
376 cmd_ (AddEnv "start" $ show startTime) 377 cmd_ (AddEnv "start" $ show startTime)
377 (AddEnv "stop" $ show (stopTime - startTime)) 378 (AddEnv "stop" $ show (stopTime - startTime))
378 (AddEnv "output" outputFile) 379 (AddEnv "output" outputFile)
@@ -391,11 +392,13 @@ saveMessage addr uuid start stop = do
391 g <- queryG 392 g <- queryG
392 let changes :: [MessageChange] 393 let changes :: [MessageChange]
393 changes = view (messages . at uuid . _Just . messageModifications . to (fmap withoutMetaData)) g 394 changes = view (messages . at uuid . _Just . messageModifications . to (fmap withoutMetaData)) g
394 blobs :: [FilePath] 395 blobs :: [RTCBlob]
395 blobs = reverse $ [inputDir </> blobFileName blob | AppendBlob blob <- changes] 396 blobs = [blob | AppendBlob blob <- changes]
397 inputVideos :: [FilePath]
398 inputVideos = (inputDir </>) . blobFileName <$> sortBy (comparing blobSeqNo) blobs
396 updateG $ g & messageAppend uuid now addr (SetStartTime $ toRational start) 399 updateG $ g & messageAppend uuid now addr (SetStartTime $ toRational start)
397 & messageAppend uuid now addr (SetStopTime $ toRational stop) 400 & messageAppend uuid now addr (SetStopTime $ toRational stop)
398 -- TODO: pipe concatenated blobs into ffmpeg, saving result into htdocs, then redirect to the hosted file 401 -- TODO: pipe concatenated blobs into ffmpeg, saving result into htdocs, then redirect to the hosted file
399 liftIO $ saveVideoClip tempFile blobs start stop 402 liftIO $ saveVideoClip tempFile inputVideos start stop
400 liftIO $ renameFile tempFile outputFile 403 liftIO $ renameFile tempFile outputFile
401 return outputUrl 404 return outputUrl