Question

Using FFmpeg with Serverless function.

I am facing difficulty with serverless function to creating video and upload it to digital occan spaces. The ffmpeg gives me error while generating the video. here is my generating and uploading process:

const { PassThrough } = require("stream");
const passThroughStream = **new** PassThrough();
              const buffers = [];

              passThroughStream.on('data', (chunk) => buffers.push(chunk));
              passThroughStream.on('end', async () => {
                const buffer = Buffer.concat(buffers);
                const contentLength = buffer.length;

                try {
                  const url = await uploadFile(userId, buffer, videoPath, contentLength);
                  resolve({ url, duration });
                } catch (uploadError) {
                  reject(uploadError);
                }
              });

              ffmpeg()
                .input(svgPaths[index][dim])
                .loop(
                  index === audioMappings.length - 1 ? duration + 2.7 : duration
                )
                .input(audioFilePath)
                .audioCodec("aac")
                .videoCodec("libx264")
                .videoBitrate(950)
                .format("mp4")
                .fps(25)
                .size(dim)
                .output(passThroughStream)
                .on('start', (commandLine) => {
                  console.log('Spawned Ffmpeg with command:', commandLine);
                })
                .on('stderr', (stderrLine) => {
                  console.log('Stderr output:', stderrLine);
                })
                .on('error', (err, stdout, stderr) => {
                  const errorResponse = { error: "ffmpeg error", details: err.message, stdout, stderr };
                  reject(errorResponse);
                })
                .on('end', () => {
                  console.log(`ffmpeg processing complete for index ${index} and dimension ${dim}`);
                })
                .run();
            });
          });

          outputVideoPaths.push(result.url);

Submit an answer


This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Bobby Iliev
Site Moderator
Site Moderator badge
June 16, 2024
Accepted Answer

Hey!

Can you share the exact error that you are getting here?

Keep in mind that functions have the following limits:

  • The maximum timeout is 15 minutes. This includes initialization and function execution.

  • The maximum size of input parameters is 1 MB.

  • The maximum size of result responses is 1 MB.

  • The maximum size of the built function is 48 MB. See the Building Functions reference for details on the build process.

  • The maximum build time for remote builds is 2 minutes.

  • Memory is limited from 128 MB – 1 GB, defaulting to 256 MB.

The Limits section allows for editing the function’s timeout and memory limits. Click the Edit text to change these settings:

https://docs.digitalocean.com/products/functions/how-to/configure-functions/#resource-limits

The maximum memory setting is currently 1024MB (1GB) so if your function needs more than that, it might explain the problem.

If this is the case here, you might be better off using a Droplet instead where you would have more control over the environment.

- Bobby

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

Featured on Community

Get our biweekly newsletter

Sign up for Infrastructure as a Newsletter.

Hollie's Hub for Good

Working on improving health and education, reducing inequality, and spurring economic growth? We'd like to help.

Become a contributor

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

Welcome to the developer cloud

DigitalOcean makes it simple to launch in the cloud and scale up as you grow — whether you're running one virtual machine or ten thousand.

Learn more
DigitalOcean Cloud Control Panel