Meteor + FFMPEG, Does it works fine?

Hi Everyone,

Need to build an App that should have video compression algorithms in place & thought of Using the FFMPEG library for the same, (Please suggest, if there is any better library than this)

have the following queries regarding the same

  1. As It takes the path of the file on which we want to perform the operation, How to get the file on Meteor, If we deploy it using docker then how to get the path of the file
  2. After getting the file how to use FFmpeg commands to compress the video file
  3. Can we upload the converted file to S3 Bucket

Do we have to configure a separate node project, in case it’s not compatible with the Meteor. Please share your inputs on the same. Also, explored the libraries which Meteor has for this tool but not sure whether they are still working or not

  1. This depends on how you upload the file. For example, using Meteor-Files, the files will be stored at the location specified in config.storagePath
  2. There are plenty of ffmpeg wrappers on npm, any of these will work. I’ve used the one that actually installs the ffmpeg binary into node_modules (which is heavy, but means its available everywhere, including CI)
  3. Yes, you can use the aws-sdk for this. Meteor-Files has a decent guide on how to integrate S3 storage here: Meteor-Files/aws-s3-integration.md at master · veliovgroup/Meteor-Files · GitHub
    Though you will need to adjust it to include ffmpeg processing first.

Fundamentally, a Meteor app is a Node app. So anything you can do in node, you can do in Meteor :slight_smile:

1 Like

Thanks. Will try this now

1 Like

Your model:

User → Meteor Server (uncompressed)
Meteor Server → S3 (compressed)

Different model 1:
User → S3 (uncompressed)
Lambda function listen to S3 folder and start an AWS Elemental Media Convert.
Drop new video format to another folder and link URL to where it is needed.

Different model 2:
User → your own FFmpeg processor server (different than Meteor).
Your own FFmpeg server → PUT to S3

  1. Both cases, you construct the path. The path in S3 (or Cloudfront) is given by the “key” you use to upload the file to S3. The key can be dynamically generated as you wish.
  2. For Media Convert you just listen with Lambda to an S3 folder, for the other case, you can use Claudia.JS to build an interface (or any other REST API) and you do a POST in the interface to transfer the file to your processing server.
  3. You can use the new AWS-SDK V3 which is split into functional components so that you only need to add the one that you actually user (in your case client-s3):

Have these env vars set on your uploading server( e.g your Meteor server):

 AWS_ACCESS_KEY_ID: '...',
 AWS_SECRET_ACCESS_KEY:'...',

import { S3Client, PutObjectCommand } from '@aws-sdk/client-s3'

const s3 = new S3Client({
  region: 'eu-central-1', // your region here
  sslEnabled: true, // optional
  httpOptions: {  // optional
    timeout: 6000,
    agent: false
  }
})

 const command = new PutObjectCommand({
        Bucket: 'your_bucket',
        Key: key, // this is the file path e.g. 'users/videos/filename.mp4' 
        ContentType: 'your file content type', // you should get this with the FS API or something else
        ContentLength: 'your file length',
        // Expires: 'Thu, 15 Dec 2050 04:08:00 GMT', // add this if you want it set.
        CacheControl: 'max-age=8460000', // this is 100 days.
        Body: body // buffer of your file to be uploaded
      })

   // example callback function. With s3.send you can also use async or Promise.
    const callback = err => {
        if (err) { console.error('Could not upload video to S3, ', err) }
      }

      s3.send(command, callback)

If you plan to deliver for both desktop (e.g. 4k ) and mobile (e.g. 480p) I suggest you use HLS with multiple file resolutions and compressions.

1 Like