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
- [Beginner] CLI --queries Syntax Error & ...
Hi everyone! I am a beginner with Appwrite and trying to use the CLI, but I'm stuck with a syntax error. Any guidance would be greatly appreciated! 🙏 **Enviro...
- Cloud function deploy stucks in processi...
Been trying for the last hours to deploy my function but for whatever reason, alwasy stuck on processing!
- [SOLVED] curl error Number: 6 — function...
Hello, I invested a lot of time in this error in a fresh install of appwrite 1.8.1 and lasted until fix, this if for helping anyone that can have the same weird...