First commit
This commit is contained in:
@@ -0,0 +1,21 @@
|
|||||||
|
MIT License
|
||||||
|
|
||||||
|
Copyright (c) 2023 Jon Staab
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
# Video Thumbnail Service
|
||||||
|
|
||||||
|
A lightweight microservice that generates video thumbnails by extracting a frame using ffmpeg.
|
||||||
|
|
||||||
|
## Requirements
|
||||||
|
|
||||||
|
- Node.js 18+
|
||||||
|
- ffmpeg installed on the system
|
||||||
|
|
||||||
|
## Setup
|
||||||
|
|
||||||
|
```bash
|
||||||
|
npm install
|
||||||
|
npm start
|
||||||
|
```
|
||||||
|
|
||||||
|
The service runs on port 3100 by default. Set the `PORT` environment variable to change it.
|
||||||
|
|
||||||
|
## Usage
|
||||||
|
|
||||||
|
```
|
||||||
|
GET /thumbnail?url=https://example.com/video.mp4
|
||||||
|
```
|
||||||
|
|
||||||
|
Returns a JPEG image of the first frame (at 1 second).
|
||||||
|
|
||||||
|
## Configuration
|
||||||
|
|
||||||
|
Set `VITE_THUMBNAIL_URL` in the Flotilla `.env` file to the deployed service URL:
|
||||||
|
|
||||||
|
```
|
||||||
|
VITE_THUMBNAIL_URL=https://your-thumbnail-service.example.com
|
||||||
|
```
|
||||||
@@ -0,0 +1,44 @@
|
|||||||
|
import express from "express"
|
||||||
|
import ffmpeg from "fluent-ffmpeg"
|
||||||
|
import {PassThrough} from "stream"
|
||||||
|
|
||||||
|
const app = express()
|
||||||
|
const PORT = process.env.PORT || 3100
|
||||||
|
|
||||||
|
app.get("/thumbnail", async (req, res) => {
|
||||||
|
const videoUrl = req.query.url
|
||||||
|
|
||||||
|
if (!videoUrl) {
|
||||||
|
return res.status(400).json({error: "Missing 'url' query parameter"})
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
const passthrough = new PassThrough()
|
||||||
|
|
||||||
|
ffmpeg(videoUrl)
|
||||||
|
.seekInput(1)
|
||||||
|
.frames(1)
|
||||||
|
.format("image2")
|
||||||
|
.outputOptions("-vcodec", "mjpeg")
|
||||||
|
.on("error", err => {
|
||||||
|
if (!res.headersSent) {
|
||||||
|
res.status(500).json({error: "Failed to generate thumbnail"})
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.pipe(passthrough, {end: true})
|
||||||
|
|
||||||
|
res.setHeader("Content-Type", "image/jpeg")
|
||||||
|
res.setHeader("Cache-Control", "public, max-age=86400")
|
||||||
|
passthrough.pipe(res)
|
||||||
|
} catch {
|
||||||
|
res.status(500).json({error: "Failed to process video"})
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
app.get("/health", (_req, res) => {
|
||||||
|
res.json({status: "ok"})
|
||||||
|
})
|
||||||
|
|
||||||
|
app.listen(PORT, () => {
|
||||||
|
console.log(`Video thumbnail service running on port ${PORT}`)
|
||||||
|
})
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
{
|
||||||
|
"name": "flotilla-video-thumbnails",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"description": "Microservice to generate video thumbnails for Flotilla",
|
||||||
|
"main": "index.js",
|
||||||
|
"type": "module",
|
||||||
|
"scripts": {
|
||||||
|
"start": "node index.js"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"express": "^4.21.0",
|
||||||
|
"fluent-ffmpeg": "^2.1.3"
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user