1

I'm facing an issue executing the ffprobe binary within a Node.js script on my local machine. I have a Node.js script that uses the fluent-ffmpeg library to extract video metadata using ffprobe. While I can execute the ffprobe binary directly from my terminal and retrieve the expected output, I'm encountering issues when attempting to run it within my Node.js script.

Project Structure:

project-root/
├── assets/
│   └── video.mp4
├── node_modules/
├── src/
│   └── index.js
├── layers/
│   └── ffmpeg/
│       └── ffprobe   <-- This is the binary I'm trying to execute
├── package.json
├── package-lock.json

Example Code:

const { exec } = require('child_process');
const binaryPath = './layers/ffmpeg/ffprobe';

exec(binaryPath, (error, stdout, stderr) => {
    if (error) {
        console.error(`Error: ${error.message}`);
        return;
    }

    console.log('Command executed successfully');
    console.log('stdout:', stdout);
    console.error('stderr:', stderr);
});

Error Message:

Error: Command failed: ./layers/ffmpeg/ffprobe
./layers/ffmpeg/ffprobe: ./layers/ffmpeg/ffprobe: cannot execute binary file

Troubleshooting:

  1. Ensured that the ffprobe binary has executable permissions using chmod +x.
  2. Verified that the architecture of the ffprobe binary is arm64, which matches my local system.
  3. Checked that the path to the binary is correct and doesn't contain special characters.
  4. Tested the basic execution of ffprobe using the exec function, but it still fails.

I've tried various troubleshooting steps, including verifying permissions, checking the architecture, and testing basic execution. Despite these efforts, I'm still unable to execute the ffprobe binary within the Node.js environment. I expected the script to successfully run the ffprobe binary and provide the expected output, just like when I run the binary directly from the terminal.

Could anyone provide insights into why the ffprobe binary fails to execute within the Node.js environment, even though it works perfectly when executed from the terminal? Are there any additional considerations I might be missing?

Thank you for your help!

1 Answers1

0

Checking the fluent-ffmpeg docs on the NPM page, it seems it's pretty simple to run ffprobe on a video file.

Assuming ffprobe.exe is on your PATH, their example code should print metadata:

var ffmpeg = require('fluent-ffmpeg');
ffmpeg.ffprobe('./assets/file.mp4', function(err, metadata) {
    console.dir(metadata);
});

Not sure why you're trying to execute directly the binary. I understand that you should use the Node library as a worker layer.

If you need a custom ffprobe binary, they provide setFfprobePath() to set its location. But I suppose it has to be an .exe.

mortalis
  • 2,060
  • 24
  • 34
  • I believe my question is not accurate. This pertains to calling a function in AWS Lambda. Lambda cannot execute this function because it is unable to read the binary file. Nevertheless, the issue has been resolved by recompiling that binary file for the Amazon Linux OS. – dzul.stellar Aug 28 '23 at 03:50