Spaces:
Sleeping
Sleeping
Create index.js
Browse files
index.js
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
const express = require('express')
|
| 2 |
+
const multer = require('multer')
|
| 3 |
+
const ffmpeg = require('fluent-ffmpeg')
|
| 4 |
+
const fs = require('fs')
|
| 5 |
+
const path = require('path')
|
| 6 |
+
const archiver = require('archiver')
|
| 7 |
+
|
| 8 |
+
const app = express()
|
| 9 |
+
const upload = multer({ dest: '/tmp' })
|
| 10 |
+
|
| 11 |
+
app.post('/upload', upload.single('video'), (req, res) => {
|
| 12 |
+
const video = req.file.path
|
| 13 |
+
const out = `/tmp/f_${Date.now()}`
|
| 14 |
+
fs.mkdirSync(out)
|
| 15 |
+
|
| 16 |
+
ffmpeg(video)
|
| 17 |
+
.output(`${out}/frame_%d.png`)
|
| 18 |
+
.on('end', () => {
|
| 19 |
+
const zip = `${out}.zip`
|
| 20 |
+
const stream = fs.createWriteStream(zip)
|
| 21 |
+
const archive = archiver('zip')
|
| 22 |
+
stream.on('close', () => {
|
| 23 |
+
fs.rmSync(video)
|
| 24 |
+
fs.rmSync(out, { recursive: true, force: true })
|
| 25 |
+
res.download(zip, () => fs.unlinkSync(zip))
|
| 26 |
+
})
|
| 27 |
+
archive.pipe(stream)
|
| 28 |
+
archive.directory(out, false)
|
| 29 |
+
archive.finalize()
|
| 30 |
+
})
|
| 31 |
+
.run()
|
| 32 |
+
})
|
| 33 |
+
|
| 34 |
+
app.listen(7860)
|