Reputation: 11
I have being trying to debug but to no avail, I've done everything on the internet.
I Used WSL (Ubuntu) - Error: spawn usr/bin/ffmpeg ENOENT. I Used windows - Error: spawn path/to/ffmpeg.exe ENOENT. I had to SAM deploy --guide and then added a lambda layer on aws console. Moved Ffmpeg file to my project root folder also ENOENT.
Ffmpeg exists in those parts, "path/to/ffmpeg -version" prints version/other info.
I gave permissions using chmod +x, I used AI too.
3days of struggle
import { spawn } from 'child_process';
import ffmpeg from 'fluent-ffmpeg';
const isLocal = process.env.AWS_SAM_LOCAL; // Detect local SAM environment
const ffmpegPath = isLocal ? 'C:\\ProgramData\\chocolatey\\lib\\ffmpeg\\tools\\ffmpeg\\bin\\ffmpeg.exe' : '/opt/bin';
ffmpeg.setFfmpegPath(ffmpegPath);
const ffmpegArgs = [
'-i',
inputFilePath,
'-vf',
`crop=9/16*ih:ih:scale=1080:1920`,
'-c:v',
'libx264',
'-c:a',
'aac',
'-strict',
'experimental',
outputFilePath,
];
const ffmpegProcess = spawn(ffmpegPath, ffmpegArgs);
Update
After running "sam build", then I moved ffmpeg file into the build folder and changed the path to:
import { spawn } from 'child_process';
import ffmpeg from 'fluent-ffmpeg';
const ffmpegPath = path.resolve(__dirname, 'bin', 'ffmpeg');
ffmpeg.setFfmpegPath(ffmpegPath);
So i'm deploying with ffmpeg in my project folder rather than creating an ffmpeg layer in the console.
created a json file to move ffmpeg into build folder
{
"scripts": {
"prebuild": "echo 'Running prebuild...'",
"build": "sam build",
"postbuild": "cp -r ./api/bin ./.aws-sam/build/ProcessVideoFunction/ && echo 'bin copied'"
}
}
Update 2
Okay, works on localhost but not when deployed.
No errors, ffmpeg doesn't run, tried with the ffmpeg-layer I created also but no progress.
Upvotes: 1
Views: 59