Back

Automatically generate different resolutions for uploaded videos

  • 0
  • Self Hosted
  • Functions
  • Web
  • Storage
VanillaFish
9 Jan, 2025, 13:47

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!

TL;DR
Developers want to automatically create different video resolutions. They are using Appwrite 1.6.0 and FFmpeg but are facing issues. They seek advice or alternative methods for video processing in Appwrite Functions.
VanillaFish
9 Jan, 2025, 13:54

package.json

TypeScript
{
  "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:

TypeScript
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
Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more