2

I correctly installed ffmpeg I'm able to check it by writing ffmpeg in cmd which give me this result

img

Now in my electron app in my index.html I'm geting input from user and sending custom event to electron side of app which lays in index.js entry point

index.html

<script>
    const electron = require('electron');
    const { ipcRenderer } = electron;

    document.querySelector('form').addEventListener('submit', (e) => {
        e.preventDefault();
        const { path } = document.querySelector('input').files[0];

        ipcRenderer.send('video:submit', path);
    });
</script>

and using ffmpeg.ffprobe I'm trying to get metadata of video updated to input in electron side like so:

const electron = require('electron');
const ffmpeg = require('fluent-ffmpeg');

const { app, BrowserWindow, ipcMain } = electron;

app.on('ready', () => {
    const mainWindow = new BrowserWindow({});
    mainWindow.loadURL(`file://${__dirname}/index.html`);
});

ipcMain.on('video:submit', (event, path) => {
    ffmpeg.ffprobe(path, (err, metadata) => {
        console.log(metadata);
        //console.log(metadata.format.duration);
    });
});

And it console that metadata is undefined, when I uncomment console.log(metadata.format.duration) it says

typeError: cannot read property 'format' of undefined

What I'm doing wrong?


So I set two new environment variables and now other error occure when I console.log(error):

{ Error: spawn C:\Users\Borys\Documents\videoinfo\ffmpeg\bin ENOENT
at exports._errnoException (util.js:1024:11)
at Process.ChildProcess._handle.onexit (internal/child_process.js:192:19)
at onErrorNT (internal/child_process.js:374:16)
at _combinedTickCallback (internal/process/next_tick.js:138:11)
at process._tickCallback (internal/process/next_tick.js:180:9)
code: 'ENOENT',
errno: 'ENOENT',
syscall: 'spawn C:\\Users\\Borys\\Documents\\videoinfo\\ffmpeg\\bin',
path: 'C:\\Users\\Borys\\Documents\\videoinfo\\ffmpeg\\bin',
spawnargs:
[ '-show_streams',
 '-show_format',
 'C:\\Users\\Borys\\Documents\\portfolio\\img\\header_video.mp4' ] }`

( I had to paste it as code because it was saying that my post containt code that is not properly formatted)

BT101
  • 3,666
  • 10
  • 41
  • 90
  • At first glance I'd say you're getting some error (stored in `err`) which is the reason for `metadata` to be `undefined`. Try logging `err`. – Alexander Leithner May 02 '18 at 15:58
  • Oh sure.. I have error Error: Cannot find ffprobe – BT101 May 02 '18 at 16:07
  • The [documentation on fluent-ffmpeg](https://www.npmjs.com/package/fluent-ffmpeg) states that Windows users will have to add the ffmpeg executable to their `%PATH` variable. So you will either have to add it to `%PATH` or set the `%FFMPEG_PATH` and/or `%FFPROBE_PATH` environmental variables. – Alexander Leithner May 02 '18 at 16:14
  • I did only specify %PATH% by using some cmd command – BT101 May 02 '18 at 16:15
  • What values should %FFMPEG_PATH and %FFPROBE_PATH has? – BT101 May 02 '18 at 16:19
  • I mean to which directories it shoud direct? – BT101 May 02 '18 at 16:20
  • To the directory where ffmpeg and ffprobe were installed, but the documentation shows some other ways on how to set the binary paths manually in your Electron code. – Alexander Leithner May 02 '18 at 16:22
  • I set those 2 new variables and now other error occure there pls take a look at edit – BT101 May 02 '18 at 16:32

1 Answers1

2

Alright thanks to @Alexander Leithner and this question I figured it out. So error was my environment variables which should be:

  • FFMPEG_PATH with value of path to ffmeg.exe
  • FFPROBE_PATH with value of path to ffprobe.exe
  • PATH with value of C:.......\ffmpeg\bin
BT101
  • 3,666
  • 10
  • 41
  • 90