38 lines
1.0 KiB
JavaScript
Executable File
38 lines
1.0 KiB
JavaScript
Executable File
#!/usr/bin/env node
|
|
|
|
'use strict';
|
|
|
|
const gpmfExtract = require('gpmf-extract');
|
|
const goproTelemetry = require(`gopro-telemetry`);
|
|
const fs = require('fs');
|
|
const minimist = require('minimist');
|
|
const _ = require('lodash');
|
|
|
|
async function main(options) {
|
|
const res = await gpmfExtract(bufferAppender(options.input, 10 * 1024 * 1024));
|
|
|
|
function bufferAppender(path, chunkSize) {
|
|
return function (mp4boxFile) {
|
|
var stream = fs.createReadStream(path, { highWaterMark: chunkSize });
|
|
var bytesRead = 0;
|
|
stream.on('end', () => {
|
|
mp4boxFile.flush();
|
|
});
|
|
stream.on('data', chunk => {
|
|
var arrayBuffer = new Uint8Array(chunk).buffer;
|
|
arrayBuffer.fileStart = bytesRead;
|
|
mp4boxFile.appendBuffer(arrayBuffer);
|
|
bytesRead += chunk.length;
|
|
});
|
|
stream.resume();
|
|
};
|
|
}
|
|
|
|
goproTelemetry(res, _.omit(options, ['_', 'input', 'output']), telemetry => {
|
|
fs.writeFileSync(options.output, telemetry);
|
|
});
|
|
|
|
}
|
|
|
|
main(minimist(process.argv.slice(2)));
|