Search code examples
javascriptnode.jsarrow-functions

How can I return {vW,vH}, it actually returns Undefined?


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

Solution

  • Change your return line like so:

    return { vW: j.streams[0].width, vH: j.streams[0].height }