Skip to content
This repository has been archived by the owner on Apr 19, 2023. It is now read-only.

Commit

Permalink
Use log filename as suggested video export filename
Browse files Browse the repository at this point in the history
  • Loading branch information
thenickdude committed Dec 30, 2016
1 parent 255a2c7 commit 86e6fb9
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 25 deletions.
24 changes: 16 additions & 8 deletions app/js/flightlog_video_renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -276,14 +276,22 @@ function FlightLogVideoRenderer(flightLog, logParameters, videoOptions) {
prepareRender = Promise.resolve();
}

prepareRender
.then(function() {
renderChunk();
})
.catch(function(error) {
console.error(error);
notifyCompletion(false);
});
/* Ensure caller can have a chance to update the DOM before we start trying to render (so they can throw up
* a "video rendering..." message)
*/
setTimeout(
function() {
prepareRender
.then(function() {
renderChunk();
})
.catch(function(error) {
console.error(error);
notifyCompletion(false);
})
},
0
);
};

/**
Expand Down
24 changes: 16 additions & 8 deletions app/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const

fs = require('fs'),

{formatTime} = require("./misc.js"),
{formatTime, setFileExtension} = require("./misc.js"),
FlightLogVideoRenderer = require("./flightlog_video_renderer.js"),
FlightLogFieldPresenter = require("./flightlog_fields_presenter.js"),
VideoExportDialog = require("./video_export_dialog.js"),
Expand Down Expand Up @@ -67,6 +67,8 @@ function BlackboxLogViewer() {
graphLegend = null,
fieldPresenter = FlightLogFieldPresenter,

logFilename = null,

hasVideo = false, hasLog = false,
video = $(".log-graph video")[0],
canvas = $("#graphCanvas")[0],
Expand Down Expand Up @@ -501,6 +503,7 @@ function BlackboxLogViewer() {
return;
}

logFilename = file.path;
renderLogFileInfo(file);

hasLog = true;
Expand Down Expand Up @@ -582,30 +585,35 @@ function BlackboxLogViewer() {
prefs.set('videoConfig', videoConfig);

if (videoConfig.format == "webm") {
pickFilename = pickOutputFile("video.webm", {
pickFilename = pickOutputFile(setFileExtension(logFilename, ".webm"), {
name: "WebM video",
extensions: ["webm"]
});
} else {
pickFilename = pickOutputFile("video.png", {
pickFilename = pickOutputFile(setFileExtension(logFilename, ".png"), {
name: "PNG frames",
extensions: ["png"]
});
}

pickFilename
.catch(function() {
videoExportDialog.close();

return Promise.reject();
})
.then(function(filename) {
videoConfig.filename = filename;
})
.then(function() {
var
videoRenderer = new FlightLogVideoRenderer(flightLog, logParameters, videoConfig);
videoRenderer.start();
videoExportDialog.onRenderingBegin(videoRenderer);
videoRenderer.start();
videoExportDialog.onRenderingBegin(videoRenderer);

videoExportDialog.once("cancel", function() {
videoExportDialog.once("cancel", function() {
videoRenderer.cancel();
});
});
Expand Down
29 changes: 28 additions & 1 deletion app/js/misc.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
const
path = require("path");

function leftPad(string, pad, minLength) {
// Coerce value to string:
string = "" + string;
Expand Down Expand Up @@ -28,4 +31,28 @@ function formatTime(msec, displayMsec) {
+ (displayMsec ? "." + leftPad(msec, "0", 3) : "");
}

module.exports = {leftPad, formatTime};
/**
* Change the extension of the given filename.
*
* @param {String} filename - A valid path and filename
* @param {String} extension - Should include the dot, e.g. ".jpg"
* @returns {string}
*/
function setFileExtension(filename, extension) {
var
directory = path.dirname(filename),
name = path.basename(filename);

if (name.length == 0) {
throw new Error("Empty filename not allowed");
}

// Remove existing file extension if present
if (name.lastIndexOf(".") > -1) {
name = name.substring(0, name.lastIndexOf("."));
}

return path.join(directory, name + extension);
}

module.exports = {leftPad, formatTime, setFileExtension};
20 changes: 12 additions & 8 deletions app/js/video_export_dialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,18 @@ function VideoExportDialog(dialog) {
populateConfig(videoConfig);
};

this.close = function() {
dialog.modal("hide");
};

this.onRenderingBegin = function(videoRenderer) {
progressBar.prop('value', 0);
progressRenderedFrames.text('');
progressRemaining.text('');
progressSize.text('Calculating...');

setDialogMode(DIALOG_MODE_IN_PROGRESS);

renderStartTime = Date.now();
lastEstimatedTimeMsec = false;

Expand All @@ -173,7 +184,7 @@ function VideoExportDialog(dialog) {
$(".video-export-result").text("Rendered " + frameCount + " frames in " + formatTime(Date.now() - renderStartTime, false));
setDialogMode(DIALOG_MODE_COMPLETE);
} else {
dialog.modal('hide');
that.close();
}
});
};
Expand All @@ -182,13 +193,6 @@ function VideoExportDialog(dialog) {
e.preventDefault();

that.emit("optionsChosen", that.logParameters, convertUIToVideoConfig());

progressBar.prop('value', 0);
progressRenderedFrames.text('');
progressRemaining.text('');
progressSize.text('Calculating...');

setDialogMode(DIALOG_MODE_IN_PROGRESS);
});

$(".video-export-dialog-cancel").click(function(e) {
Expand Down

0 comments on commit 86e6fb9

Please sign in to comment.