跳至內容

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"

已提問 3 年前檢視次數 1131 次

2 個答案
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.

專家

已回答 3 年前

-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 }), }; } };

已回答 3 年前

您尚未登入。 登入 去張貼答案。

一個好的回答可以清楚地回答問題並提供建設性的意見回饋,同時有助於提問者的專業成長。