Skip to content

Instantly share code, notes, and snippets.

@konsumer
Created April 28, 2019 01:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save konsumer/fc102f623d6b31f12dd7a7890f3d28d3 to your computer and use it in GitHub Desktop.
Save konsumer/fc102f623d6b31f12dd7a7890f3d28d3 to your computer and use it in GitHub Desktop.
Get info about about video streams in nodejs, using `ffprobe`
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