Command failed error when using ffmpeg in Lambda

0

I have created zip from ec2 instance with binary files both ffmpeg and ffprobe and saved it in s3. I am using a layer of that zip to use ffmpeg commands in my lambda function. The following code is working fine I can get output and use the ffprobe command-

import { promisify } from 'util'; import { exec } from 'child_process'; const commander = promisify(exec); export const handler = async (event) => { const { stdout } = await commander('/opt/ffmpeg/ffprobe -v 0 -of default=nw=1:nk=1 -show_program_version | head -1');

return { statusCode: 200, body: JSON.stringify(stdout), }; };

but when I am using some other command which usually works on my system ffprobe -i https://dwzxne.cloudfront.net/ad1.mp4 -show_entries format=duration -v quiet -of csv="p=0"

is giving error "Command failed"

Harshit
asked 2 months ago215 views
2 Answers
0

The issue with the ffprobe command not working is likely due to network restrictions on Lambda. By default, Lambda functions cannot make outbound connections to the internet.

Use the --allowed-extensions AV option when creating the Lambda layer to enable AV extensions which provide broader network access needed for ffprobe to connect to the remote URL.

Host the video file you want to probe on S3 instead of a remote URL and pass the S3 path to ffprobe instead. This avoids the network restriction.

Use the Lambda Layer with FFmpeg you referenced earlier to wrap the ffprobe command. Some layers are configured to allow broader network access needed for commands like ffprobe to work with remote files.

As an alternative, you could convert the remote video to a local file within your function first using ffmpeg before passing to ffprobe.

profile picture
EXPERT
answered a month ago
-1

Please capture error, run this code.

import { promisify } from 'util'; import { exec } from 'child_process';

const commander = promisify(exec);

export const handler = async (event) => { try { const command = '/opt/ffmpeg/ffprobe -i "https://dwzxneeggli32.cloudfront.net/ad1.mp4" -show_entries format=duration -v quiet -of csv="p=0"'; const { stdout, stderr } = await commander(command); return { statusCode: 200, body: JSON.stringify({ output: stdout }), }; } catch (error) { console.error('Error executing ffprobe:', error); return { statusCode: 500, body: JSON.stringify({ error: error.message, stderr: error.stderr }), }; } };

rgk
answered 2 months ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions