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
- Cannot Execute deployed functions on my ...
I have a very simple function that i'm playing around with. i'm not able to run it once i move it to a selfhosted instance.
- Failed to add attribute
The attribute is not seems active, so I delete it and recreate the attribute by the same name "userId" but end up getting this error: SQLSTATE[42S21]: Column al...
- Issue when i try to migrate from 1.3.8 t...
Hi, I've been trying to update my version of appwrite since few months but it seems not migrate data after update i can't connect to console and i have these li...