Allow configuring the webcam stream's aspect ratio

Options are 16:9 and 4:3, 16:9 is the default.
This commit is contained in:
Gina Häußge 2017-05-08 17:35:51 +02:00
parent c844217f82
commit 399ec5a909
7 changed files with 23 additions and 1 deletions

View file

@ -98,6 +98,7 @@ def getSettings():
},
"webcam": {
"streamUrl": s.get(["webcam", "stream"]),
"streamRatio": s.get(["webcam", "streamRatio"]),
"snapshotUrl": s.get(["webcam", "snapshot"]),
"ffmpegPath": s.get(["webcam", "ffmpeg"]),
"bitrate": s.get(["webcam", "bitrate"]),
@ -299,6 +300,7 @@ def _saveSettings(data):
if "webcam" in data.keys():
if "streamUrl" in data["webcam"]: s.set(["webcam", "stream"], data["webcam"]["streamUrl"])
if "streamRatio" in data["webcam"] and data["webcam"]["streamRatio"] in ("16:9", "4:3"): s.set(["webcam", "streamRatio"], data["webcam"]["streamRatio"])
if "snapshotUrl" in data["webcam"]: s.set(["webcam", "snapshot"], data["webcam"]["snapshotUrl"])
if "ffmpegPath" in data["webcam"]: s.set(["webcam", "ffmpeg"], data["webcam"]["ffmpegPath"])
if "bitrate" in data["webcam"]: s.set(["webcam", "bitrate"], data["webcam"]["bitrate"])

View file

@ -155,6 +155,7 @@ default_settings = {
},
"webcam": {
"stream": None,
"streamRatio": "16:9",
"snapshot": None,
"ffmpeg": None,
"ffmpegThreads": 1,

View file

@ -49,6 +49,14 @@ $(function() {
return self.keycontrolActive() && self.keycontrolPossible();
});
self.webcamRatioClass = ko.pureComputed(function() {
if (self.settings.webcam_streamRatio() == "4:3") {
return "ratio43";
} else {
return "ratio169";
}
});
self.settings.printerProfiles.currentProfileData.subscribe(function () {
self._updateExtruderCount();
self.settings.printerProfiles.currentProfileData().extruder.count.subscribe(self._updateExtruderCount);

View file

@ -91,6 +91,8 @@ $(function() {
}
};
self.webcam_available_ratios = ["16:9", "4:3"];
var auto_locale = {language: "_default", display: gettext("Autodetect from browser"), english: undefined};
self.locales = ko.observableArray([auto_locale].concat(_.sortBy(_.values(AVAILABLE_LOCALES), function(n) {
return n.display;
@ -110,6 +112,7 @@ $(function() {
self.printer_defaultExtrusionLength = ko.observable(undefined);
self.webcam_streamUrl = ko.observable(undefined);
self.webcam_streamRatio = ko.observable(undefined);
self.webcam_snapshotUrl = ko.observable(undefined);
self.webcam_ffmpegPath = ko.observable(undefined);
self.webcam_bitrate = ko.observable(undefined);

View file

@ -2,6 +2,7 @@
<form class="form-horizontal">
{% include "snippets/settings/webcam/webcamStreamUrl.jinja2" %}
{% include "snippets/settings/webcam/webcamStreamRatio.jinja2" %}
{% include "snippets/settings/webcam/webcamOrientation.jinja2" %}
</form>

View file

@ -0,0 +1,7 @@
<div class="control-group" title="{{ _('Aspect ratio of the webcam stream, either 16:9 or 4:3') }}">
<label class="control-label" for="settings-webcamStreamRatio">{{ _('Stream aspect ratio') }}</label>
<div class="controls">
<select data-bind="options: webcam_available_ratios, value: webcam_streamRatio"></select>
<span class="help-inline">{% trans %}If the stream has a different aspect ratio than configured here it will be letterboxed.{% endtrans %}</span>
</div>
</div>

View file

@ -10,7 +10,7 @@
</div>
</div>
<div id="webcam_rotator" data-bind="css: { webcam_rotated: settings.webcam_rotate90(), webcam_unrotated: !settings.webcam_rotate90() }">
<div class="webcam_fixed_ratio ratio169">
<div class="webcam_fixed_ratio" data-bind="css: webcamRatioClass">
<div class="webcam_fixed_ratio_inner">
<img id="webcam_image" data-bind="css: { flipH: settings.webcam_flipH(), flipV: settings.webcam_flipV() }, event: { load: onWebcamLoaded, error: onWebcamErrored }, visible: !webcamError()">
</div>