-1

I'm trying to read the metadata from an *.mp4 video using ffprobe and exec, then parsing its json results but it returns undefined...

const video_metadata = `ffprobe ".\\video.mp4" -v error -show_entries stream=width,height -of json`;

const {vW,vH} = exec(video_metadata, async (err, stdout, stderr) => {
    if (err) {
        await console.error(`exec error: ${err}`);
        return;
    }
    const j = JSON.parse(stdout);

    return j.streams[0].width, j.streams[0].height;
});

console.log(vW); // Undefined
console.log(vH); // Undefined
Jeflopo
  • 2,192
  • 4
  • 34
  • 46

1 Answers1

2

Change your return line like so:

return { vW: j.streams[0].width, vH: j.streams[0].height }
thedude
  • 9,388
  • 1
  • 29
  • 30
  • you can't `await` exec, as it does not returns a promise. The values of the parsed json can only be accessed in the callback. You could wrap your exec with a promise and the you'd be able to `await` it – thedude Jun 16 '19 at 11:25
  • Despite I got it downvoted *(by someone other I guess)*, Thank you sir for the help. I figured it out and solved it wrapping it within a promise as you said. – Jeflopo Jun 16 '19 at 16:55