git ssb

5+

Matt McKegg / ferment



Tree: ce8c9a23510ffcaae086aac41d0d04be17ab0af0

Files: ce8c9a23510ffcaae086aac41d0d04be17ab0af0 / lib / generate-meta.js

1019 bytesRaw
1var ffmpeg = require('./exec-ffmpeg')
2
3module.exports = function (path, cb) {
4 var count = 200
5 ffmpeg([
6 '-i', path,
7 '-ac', 1,
8 '-filter:a', 'aresample=1000',
9 '-map', '0:a',
10 '-c:a', 'pcm_s8',
11 '-f', 's8',
12 'pipe:1'
13 ], function (err, stdout, stderr) {
14 if (err) return cb(err)
15 var durationMatch = stderr.toString().match(/Duration: ([0-9]+):([0-9]{2}):([0-9]{2}.[0-9]{2})/)
16 var duration = (parseInt(durationMatch[1], 10) * 3600) + (parseInt(durationMatch[2], 10) * 60) + parseFloat(durationMatch[3])
17
18 var samples = new Int8Array(stdout.buffer)
19 var frameLength = Math.floor(samples.length / count)
20 var bins = new Uint8Array(count)
21 for (var i = 0; i < count; i += 1) {
22 var sum = 0
23 for (var x = 0; x < frameLength; x++) {
24 sum += Math.abs(samples[i * frameLength + x] * 2)
25 }
26 bins[i] = Math.floor(sum / frameLength)
27 }
28 cb(null, {
29 overview: Buffer.from(bins.buffer).toString('base64'),
30 duration: duration
31 })
32 })
33}
34

Built with git-ssb-web