Added timelapse render progress bar
For issue @485 Added progress bar to the Timelapse tab between the settings and files Added code to process the output of ffmpeg and compute a percentage Added code to communicate the percentage from the server to the client Added myself to the authors Changed tests to reflect new loglevel
This commit is contained in:
1 parent
c55c568bbd
commit
a4ce92c963
7 files changed
+97
-5
No files matched your search
@@ -87,6 +87,7 @@ date of first contribution):
|
||||
* [Josh Major](https://github.com/astateofblank)
|
||||
* ["alex-gh"](https://github.com/alex-gh)
|
||||
* [Bernd Zeimetz](https://github.com/bzed)
|
||||
* [Zachary Nofzinger](https://github.com/ZachNo)
|
||||
|
||||
OctoPrint started off as a fork of [Cura](https://github.com/daid/Cura) by
|
||||
[Daid Braam](https://github.com/daid). Parts of its communication layer and
|
||||
|
||||
@@ -238,6 +238,11 @@ class PrinterStateConnection(sockjs.tornado.SockJSConnection, octoprint.printer.
|
||||
dict(slicer=slicer, source_location=source_location, source_path=source_path, dest_location=dest_location, dest_path=dest_path, progress=progress)
|
||||
)
|
||||
|
||||
def sendRenderProgress(self, progress):
|
||||
self._emit("renderProgress",
|
||||
dict(progress=progress)
|
||||
)
|
||||
|
||||
def on_plugin_message(self, plugin, data):
|
||||
self._emit("plugin", dict(plugin=plugin, data=data))
|
||||
|
||||
|
||||
@@ -218,6 +218,15 @@ function DataUpdater(allViewModels, connectCallback, disconnectCallback) {
|
||||
});
|
||||
};
|
||||
|
||||
self._onRenderProgress = function(event) {
|
||||
self._ifInitialized(function() {
|
||||
var data = event.data;
|
||||
callViewModels(self.allViewModels, "onRenderProgress", [
|
||||
data["progress"]
|
||||
]);
|
||||
});
|
||||
};
|
||||
|
||||
self._onEvent = function(event) {
|
||||
self._ifInitialized(function() {
|
||||
var type = event.data["type"];
|
||||
@@ -347,6 +356,7 @@ function DataUpdater(allViewModels, connectCallback, disconnectCallback) {
|
||||
.onMessage("history", self._onHistoryData)
|
||||
.onMessage("current", self._onCurrentData)
|
||||
.onMessage("slicingProgress", self._onSlicingProgress)
|
||||
.onMessage("renderProgress", self._onRenderProgress)
|
||||
.onMessage("event", self._onEvent)
|
||||
.onMessage("timelapse", self._onTimelapse)
|
||||
.onMessage("plugin", self._onPluginMessage);
|
||||
|
||||
@@ -4,6 +4,7 @@ $(function() {
|
||||
|
||||
self.loginState = parameters[0];
|
||||
|
||||
self.renderProgressBar = undefined;
|
||||
self.timelapsePopup = undefined;
|
||||
|
||||
self.defaultFps = 25;
|
||||
@@ -19,6 +20,7 @@ $(function() {
|
||||
self.timelapseRetractionZHop = ko.observable(self.defaultRetractionZHop);
|
||||
self.timelapseMinDelay = ko.observable(self.defaultMinDelay);
|
||||
|
||||
self.renderProgressText = ko.observable();
|
||||
self.serverConfig = ko.observable();
|
||||
|
||||
self.persist = ko.observable(false);
|
||||
@@ -475,6 +477,16 @@ $(function() {
|
||||
text: _.sprintf(gettext("Now rendering timelapse %(movie_prefix)s. Due to performance reasons it is not recommended to start a print job while a movie is still rendering."), payload),
|
||||
hide: false
|
||||
});
|
||||
|
||||
self.renderProgress
|
||||
.addClass("progress-striped")
|
||||
.addClass("active");
|
||||
self.renderProgressBar.css("width", "0%");
|
||||
self.renderProgressText(_.sprintf(gettext("Rendering %(movie_prefix)s..."), payload));
|
||||
};
|
||||
|
||||
self.onRenderProgress = function(percentage) {
|
||||
self.renderProgressBar.css("width", percentage + "%");
|
||||
};
|
||||
|
||||
self.onEventMovieFailed = function(payload) {
|
||||
@@ -498,6 +510,13 @@ $(function() {
|
||||
type: "error",
|
||||
hide: false
|
||||
});
|
||||
|
||||
self.renderProgress
|
||||
.removeClass("progress-striped")
|
||||
.removeClass("active");
|
||||
self.renderProgressBar
|
||||
.css("width", "0%");
|
||||
self.renderProgressText("");
|
||||
};
|
||||
|
||||
self.onEventMovieDone = function(payload) {
|
||||
@@ -514,10 +533,20 @@ $(function() {
|
||||
}
|
||||
});
|
||||
self.requestData();
|
||||
|
||||
self.renderProgress
|
||||
.removeClass("progress-striped")
|
||||
.removeClass("active");
|
||||
self.renderProgressBar
|
||||
.css("width", "0%");
|
||||
self.renderProgressText("");
|
||||
};
|
||||
|
||||
self.onStartup = function() {
|
||||
self.requestData();
|
||||
|
||||
self.renderProgress = $("#render_progress");
|
||||
self.renderProgressBar = $(".bar", self.renderProgress);
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -90,6 +90,15 @@
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<h1>{{ _('Timelapse Render Progress') }}</h1>
|
||||
|
||||
<div id="render_progress" class="progress progress-text-centered">
|
||||
<span class="progress-text-back" data-bind="text: renderProgressText"></span>
|
||||
<div class="bar">
|
||||
<span class="progress-text-front" data-bind="copyWidth: ':parent :parent', text: renderProgressText"></span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<h1>{{ _('Finished Timelapses') }}</h1>
|
||||
|
||||
<div class="pull-right">
|
||||
|
||||
@@ -16,6 +16,7 @@ try:
|
||||
except ImportError:
|
||||
import Queue as queue
|
||||
import requests
|
||||
import re
|
||||
|
||||
import octoprint.util as util
|
||||
|
||||
@@ -811,7 +812,40 @@ class TimelapseRenderJob(object):
|
||||
with self.render_job_lock:
|
||||
try:
|
||||
self._notify_callback("start", output)
|
||||
p = sarge.run(command_str, stdout=sarge.Capture(), stderr=sarge.Capture())
|
||||
p = sarge.run(command_str, stdout=sarge.Capture(), stderr=sarge.Capture(), async=True)
|
||||
|
||||
self._logger.debug("Parsing ffmpeg output")
|
||||
|
||||
# Compile regex to make it faster
|
||||
duration_regex = re.compile("Duration: (\d{2}):(\d{2}):(\d{2})\.\d{2}")
|
||||
current_regex = re.compile("time=(\d{2}):(\d{2}):(\d{2})\.\d{2}")
|
||||
duration_s = ""
|
||||
|
||||
# Sarge sometimes doesn't populate commands fast enough, so we check if the command exists first, then poll the thread
|
||||
while len(p.commands) == 0 or p.commands[0].poll() is None:
|
||||
line = p.stderr.readline()
|
||||
|
||||
# We should be checking time more often, so try it first
|
||||
time = current_regex.search(line)
|
||||
if time is not None:
|
||||
current_s = self._parsetime(*time.groups())
|
||||
|
||||
progress = current_s / float(duration_s) * 100
|
||||
|
||||
# Update progress bar
|
||||
for callback in _update_callbacks:
|
||||
try:
|
||||
callback.sendRenderProgress(progress)
|
||||
except:
|
||||
self._logger.exception("Exception while pushing render progress")
|
||||
|
||||
else:
|
||||
duration = duration_regex.search(line)
|
||||
if duration is not None:
|
||||
duration_s = self._parsetime(*duration.groups())
|
||||
|
||||
self._logger.debug("Done with parsing")
|
||||
|
||||
if p.returncode == 0:
|
||||
self._notify_callback("success", output)
|
||||
else:
|
||||
@@ -826,6 +860,10 @@ class TimelapseRenderJob(object):
|
||||
finally:
|
||||
self._notify_callback("always", output)
|
||||
|
||||
@staticmethod
|
||||
def _parsetime(hours, minutes, seconds):
|
||||
return (int(hours) * 60 + int(minutes)) * 60 + int(seconds)
|
||||
|
||||
@classmethod
|
||||
def _create_ffmpeg_command_string(cls, ffmpeg, fps, bitrate, threads, input, output, hflip=False, vflip=False,
|
||||
rotate=False, watermark=None, pixfmt="yuv420p"):
|
||||
@@ -854,7 +892,7 @@ class TimelapseRenderJob(object):
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
command = [
|
||||
ffmpeg, '-framerate', str(fps), '-loglevel', 'error', '-i', '"{}"'.format(input), '-vcodec', 'mpeg2video',
|
||||
ffmpeg, '-framerate', str(fps), '-i', '"{}"'.format(input), '-vcodec', 'mpeg2video',
|
||||
'-threads', str(threads), '-r', "25", '-y', '-b', str(bitrate),
|
||||
'-f', 'vob']
|
||||
|
||||
|
||||
@@ -16,15 +16,15 @@ class TimelapseRenderJobTest(unittest.TestCase):
|
||||
@data(
|
||||
(("/path/to/ffmpeg", 25, "10000k", 1, "/path/to/input/files_%d.jpg", "/path/to/output.mpg"),
|
||||
dict(),
|
||||
'/path/to/ffmpeg -framerate 25 -loglevel error -i "/path/to/input/files_%d.jpg" -vcodec mpeg2video -threads 1 -r 25 -y -b 10000k -f vob -vf \'[in] format=yuv420p [out]\' "/path/to/output.mpg"'),
|
||||
'/path/to/ffmpeg -framerate 25 -i "/path/to/input/files_%d.jpg" -vcodec mpeg2video -threads 1 -r 25 -y -b 10000k -f vob -vf \'[in] format=yuv420p [out]\' "/path/to/output.mpg"'),
|
||||
|
||||
(("/path/to/ffmpeg", 25, "10000k", 1, "/path/to/input/files_%d.jpg", "/path/to/output.mpg"),
|
||||
dict(hflip=True),
|
||||
'/path/to/ffmpeg -framerate 25 -loglevel error -i "/path/to/input/files_%d.jpg" -vcodec mpeg2video -threads 1 -r 25 -y -b 10000k -f vob -vf \'[in] format=yuv420p,hflip [out]\' "/path/to/output.mpg"'),
|
||||
'/path/to/ffmpeg -framerate 25 -i "/path/to/input/files_%d.jpg" -vcodec mpeg2video -threads 1 -r 25 -y -b 10000k -f vob -vf \'[in] format=yuv420p,hflip [out]\' "/path/to/output.mpg"'),
|
||||
|
||||
(("/path/to/ffmpeg", 25, "20000k", 4, "/path/to/input/files_%d.jpg", "/path/to/output.mpg"),
|
||||
dict(rotate=True, watermark="/path/to/watermark.png"),
|
||||
'/path/to/ffmpeg -framerate 25 -loglevel error -i "/path/to/input/files_%d.jpg" -vcodec mpeg2video -threads 4 -r 25 -y -b 20000k -f vob -vf \'[in] format=yuv420p,transpose=2 [postprocessed]; movie=/path/to/watermark.png [wm]; [postprocessed][wm] overlay=10:main_h-overlay_h-10 [out]\' "/path/to/output.mpg"')
|
||||
'/path/to/ffmpeg -framerate 25 -i "/path/to/input/files_%d.jpg" -vcodec mpeg2video -threads 4 -r 25 -y -b 20000k -f vob -vf \'[in] format=yuv420p,transpose=2 [postprocessed]; movie=/path/to/watermark.png [wm]; [postprocessed][wm] overlay=10:main_h-overlay_h-10 [out]\' "/path/to/output.mpg"')
|
||||
)
|
||||
@unpack
|
||||
def test_create_ffmpeg_command_string(self, args, kwargs, expected):
|
||||
|
||||
Reference in new issue
Block a user