Skip to content

Instantly share code, notes, and snippets.

@mmckegg
Created June 13, 2016 07:09
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 mmckegg/c23f9bb16e5177b1753b56e0581c2740 to your computer and use it in GitHub Desktop.
Save mmckegg/c23f9bb16e5177b1753b56e0581c2740 to your computer and use it in GitHub Desktop.
var execFile = require('child_process').execFile
module.exports = function (context, path, start, duration, cb) {
var child = execFile('ffmpeg', [
'-i', path,
'-ss', start,
'-t', duration,
'-f', 'wav',
'-acodec', 'pcm_s32le',
'pipe:1'
], { encoding: 'buffer', maxBuffer: 10 * 1024 * 1024 }, function (err, result, stderr) {
if (err) return cb(err)
context.decodeAudioData(new Uint8Array(result).buffer, function (result) {
cb(null, result)
}, function (err) {
cb(err || new Error('Decode error'))
})
})
child.stdin.end()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment