Skip to content

Instantly share code, notes, and snippets.

@ArnyminerZ
Created January 26, 2020 21:19
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 ArnyminerZ/ca28e722308b7e322e8739eafe9a9974 to your computer and use it in GitHub Desktop.
Save ArnyminerZ/ca28e722308b7e322e8739eafe9a9974 to your computer and use it in GitHub Desktop.
Analize your GoPro footage and animate your content
function analize(file, yMin, yMax){
eval("var gopro=" + footage(file).sourceText);
// (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min
outMax = yMax; // Y max
outMin = yMin; // Y min
inMax = parseFloat(gopro.streams.GPS5.min_alt);
inMin = parseFloat(gopro.streams.GPS5.max_alt);
samplesDuration = parseInt(gopro.streams.GPS5.duration);
samplesCount = gopro.streams.GPS5.samples.length;
sampleDuration = samplesDuration / samplesCount;
timeMillis = time * 1000;
var currentItemIndex = parseInt(timeMillis/sampleDuration);
var item = gopro.streams.GPS5.samples[currentItemIndex];
itemAlt = item.alt;
itemLat = item.lat;
itemLon = item.lon;
y = (itemAlt - inMin) * (outMax - outMin) / (inMax - inMin) + outMin;
return {
y: y,
alt: itemAlt,
lat: itemLat,
lon: itemLon
};
}
var result = analize("out.json", 0, 635);
npm install gopro-telemetry
npm install gpmf-extract
const gpmfExtract = require('gpmf-extract');
const goproTelemetry = require('gopro-telemetry');
const fs = require('fs');
const readline = require("readline");
const { promisify } = require('util');
const writeFileAsync = promisify(fs.writeFile);
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
async function toJSON(data) {
try {
const result = goproTelemetry(
{ rawData: data },
{
stream: 'GPS5',
repeatSticky: true,
repeatHeaders: true,
GPS5Fix: 2,
GPSPrecision: 500
}
);
var res = result["1"];
res.device_name = res["device name"];
delete res["device name"];
var str = JSON.stringify(res);
str = str.replace(/altitude system/g, "alt_system");
str = str.replace(/GPS \(Lat.\) \[deg\]/g, "lat");
str = str.replace(/GPS \(Long.\) \[deg\]/g, "lon");
str = str.replace(/GPS \(Alt.\) \[m\]/g, "alt");
str = str.replace(/GPS \(2D speed\) \[m\/s\]/g, "2d_speed");
str = str.replace(/GPS \(3D speed\) \[m\/s\]/g, "3d_speed");
res = JSON.parse(str);
var maxAlt = 0;
var minAlt = 10000;
const samples = res.streams.GPS5.samples;
for (let i = 0; i < samples.length; i++) {
const item = samples[i];
const alt = item.alt;
if (alt > maxAlt)
maxAlt = alt;
if (alt < minAlt)
minAlt = alt;
}
const firstFrameTime = Date.parse(samples[0].date);
const lastFrameTime = Date.parse(samples[samples.length - 1].date);
const duration = lastFrameTime - firstFrameTime;
res.streams.GPS5["max_alt"] = maxAlt.toString();
res.streams.GPS5["min_alt"] = minAlt.toString();
res.streams.GPS5["duration"] = duration.toString();
await writeFileAsync('./out-new.json', JSON.stringify(res));
console.log('File saved');
} catch (error) {
console.log(error);
} finally {
rl.close();
}
}
rl.question("Please, type the filename:", function (name) {
const file = fs.readFileSync(name);
gpmfExtract(file)
.then(result => {
console.log('Length of data received:', result.rawData.length);
console.log('Framerate of data received:', result.timing.frameDuration);
toJSON(result.rawData);
})
.catch(error => console.log(error));
});
rl.on("close", function () {
console.log("\nBYE BYE !!!");
process.exit(0);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment