Automatically generate different resolutions for uploaded videos
- 0
- Self Hosted
- Functions
- Web
- Storage
Hey everyone! 👋
I’m looking for a way to automatically generate different video resolutions from an uploaded video. My goal is to build a tool that provides multiple resolutions (e.g., 1080p, 720p, 480p) for a video player, but it would be ideal if this could be done automatically through a function after the video is uploaded.
I’m using the self-hosted version of Appwrite (1.6.0) and have been trying to get FFmpeg to work within an Appwrite Function, but I wasn’t able to make it run successfully. I’ve looked at various resources related to FFmpeg, but none of them really helped with this setup.
If anyone has experience with video processing in Appwrite Functions or knows a better approach to handle this, I’d really appreciate your help! 🙏
Thanks in advance!
package.json
{
"name": "starter-template",
"version": "1.0.0",
"description": "",
"main": "src/main.js",
"type": "module",
"scripts": {
"format": "prettier --write ."
},
"dependencies": {
"ffmpeg-static": "^5.2.0",
"ffprobe-static": "^3.1.0",
"node-appwrite": "^14.1.0"
},
"devDependencies": {
"prettier": "^3.2.5"
}
}
src/main.js:
import { Client, Users } from 'node-appwrite';
import ffmpegPath from 'ffmpeg-static';
import { path as ffprobePath } from 'ffprobe-static';
import { exec } from 'child_process';
export default async ({ req, res, log, error }) => {
const client = new Client()
.setEndpoint(process.env.APPWRITE_FUNCTION_API_ENDPOINT)
.setProject(process.env.APPWRITE_FUNCTION_PROJECT_ID)
.setKey(req.headers['x-appwrite-key'] ?? '');
const users = new Users(client);
try {
const response = await users.list();
log(`Total users: ${response.total}`);
} catch (err) {
error("Could not list users: " + err.message);
}
// Log paths
log(`FFmpeg Path: ${ffmpegPath}`);
log(`FFprobe Path: ${ffprobePath}`);
// Execute FFmpeg
exec(`/bin/bash -c "${ffmpegPath} -version"`, (err, stdout, stderr) => {
if (err) {
error(`FFmpeg Error: ${err.message}`);
log(`FFmpeg STDERR: ${stderr}`);
return;
}
log(`FFmpeg STDOUT: ${stdout}`);
});
// Execute FFprobe
exec(`/bin/bash -c "${ffprobePath} -version"`, (err, stdout, stderr) => {
if (err) {
error(`FFprobe Error: ${err.message}`);
log(`FFprobe STDERR: ${stderr}`);
return;
}
log(`FFprobe STDOUT: ${stdout}`);
});
return res.json({
message: "Function executed successfully",
});
};```
**log:**
```bash
Total users: 0
FFmpeg Path: /usr/local/server/src/function/node_modules/ffmpeg-static/ffmpeg
FFprobe Path: /usr/local/server/src/function/node_modules/ffprobe-static/bin/linux/x64/ffprobe
Recommended threads
- MongoDb Database Breaks integer[] & bigi...
I've got a table with the below column created. When I try to insert the value `[-3408048000]` into it, the dart sdk cloud function call is successful (no error...
- Appwrite Functions cold start
Hello. I'm seeing really long cold starts on Appwrite Cloud Functions and wanted to know if this is expected. My function just authenticates the user, fetches ...
- Error can not create `tablesdb` event wi...
When i'm trying to add an event with `tablesdb` i get an error message My event value: `tablesdb.mtg-decklist-dev.tables.queue_parsing.rows.*.create` Same err...