gopro-telemetry-exporter/bin/gopro-telemetry-exporter.js
2021-02-20 00:05:19 +01:00

44 lines
1.2 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']), telemetryData => {
if (options.preset === 'csv') {
telemetryData = _.values(telemetryData)[0];
} else if (!_.isString(telemetryData)) {
telemetryData = JSON.stringify(telemetryData);
}
fs.writeFileSync(options.output, telemetryData);
});
}
main(minimist(process.argv.slice(2)));