gopro-telemetry-exporter/bin/gopro-telemetry-exporter.js

41 lines
1.1 KiB
JavaScript
Raw Normal View History

#!/usr/bin/env node
'use strict';
2021-01-31 13:57:01 +01:00
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();
};
}
2021-02-19 23:52:30 +01:00
goproTelemetry(res, _.omit(options, ['_', 'input', 'output']), telemetryData => {
if (!_.isString(telemetryData)) {
telemetryData = JSON.stringify(telemetryData);
}
fs.writeFileSync(options.output, telemetryData);
2021-01-31 13:57:01 +01:00
});
}
main(minimist(process.argv.slice(2)));