Created
April 28, 2019 01:44
-
-
Save konsumer/fc102f623d6b31f12dd7a7890f3d28d3 to your computer and use it in GitHub Desktop.
Get info about about video streams in nodejs, using `ffprobe`
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const { exec } = require('child_process') | |
const { promisify } = require('util') | |
const unflatten = require('unflatten') | |
const run = promisify(exec) | |
// get stream info about a video file | |
const getStreams = async inFile => { | |
const { stdout } = await run(`ffprobe -show_streams '${inFile}'`) | |
const streams = stdout.replace(/\[\/STREAM\]/g, '').split('[STREAM]').filter(s => s.trim() !== '').map(streamText => { | |
const stream = {} | |
streamText.split('\n').forEach(line => { | |
const l = line.trim() | |
if (l && l !== '') { | |
const [n, v] = l.split('=') | |
stream[n.replace(/:/g, '.').toLowerCase()] = v | |
} | |
}) | |
return unflatten(stream) | |
}) | |
return streams | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment