diff --git a/docs/api/settings.rst b/docs/api/settings.rst index c5947c4b5..466cb839a 100644 --- a/docs/api/settings.rst +++ b/docs/api/settings.rst @@ -254,6 +254,8 @@ mapped from the same fields in ``config.yaml`` unless otherwise noted: - * - ``webcam.ffmpegThreads`` - + * - ``webcam.ffmpegVideoCodec`` + - * - ``webcam.watermark`` - * - ``webcam.flipH`` diff --git a/docs/configuration/config_yaml.rst b/docs/configuration/config_yaml.rst index 79795f021..74fb7ed2d 100644 --- a/docs/configuration/config_yaml.rst +++ b/docs/configuration/config_yaml.rst @@ -1194,6 +1194,9 @@ Use the following settings to configure webcam support: # Should be left at 1 for RPi1. ffmpegThreads: 1 + # Videocodec to be used for encoding. Defaults to mpeg2video. + ffmpegVideoCodec: mpeg2video + # The bitrate to use for rendering the timelapse video. This gets directly passed to ffmpeg. bitrate: 5000k diff --git a/src/octoprint/server/api/settings.py b/src/octoprint/server/api/settings.py index f5983769a..c064449a8 100644 --- a/src/octoprint/server/api/settings.py +++ b/src/octoprint/server/api/settings.py @@ -108,6 +108,7 @@ def getSettings(): "ffmpegPath": s.get(["webcam", "ffmpeg"]), "bitrate": s.get(["webcam", "bitrate"]), "ffmpegThreads": s.get(["webcam", "ffmpegThreads"]), + "ffmpegVideoCodec": s.get(["webcam", "ffmpegVideoCodec"]), "watermark": s.getBoolean(["webcam", "watermark"]), "flipH": s.getBoolean(["webcam", "flipH"]), "flipV": s.getBoolean(["webcam", "flipV"]), @@ -348,6 +349,8 @@ def _saveSettings(data): if "ffmpegPath" in data["webcam"]: s.set(["webcam", "ffmpeg"], data["webcam"]["ffmpegPath"]) if "bitrate" in data["webcam"]: s.set(["webcam", "bitrate"], data["webcam"]["bitrate"]) if "ffmpegThreads" in data["webcam"]: s.setInt(["webcam", "ffmpegThreads"], data["webcam"]["ffmpegThreads"]) + # Add a whitelist for vcodecs like aspect ration has? + if "ffmpegVideoCodec" in data["webcam"]: s.set(["webcam", "ffmpegVideoCodec"], data["webcam"]["ffmpegVideoCodec"]) if "watermark" in data["webcam"]: s.setBoolean(["webcam", "watermark"], data["webcam"]["watermark"]) if "flipH" in data["webcam"]: s.setBoolean(["webcam", "flipH"], data["webcam"]["flipH"]) if "flipV" in data["webcam"]: s.setBoolean(["webcam", "flipV"], data["webcam"]["flipV"]) diff --git a/src/octoprint/settings.py b/src/octoprint/settings.py index 7e3575dd7..d97da7ac1 100644 --- a/src/octoprint/settings.py +++ b/src/octoprint/settings.py @@ -208,6 +208,7 @@ default_settings = { "snapshotSslValidation": True, "ffmpeg": None, "ffmpegThreads": 1, + "ffmpegVideoCodec": "mpeg2video", "bitrate": "5000k", "watermark": True, "flipH": False, diff --git a/src/octoprint/static/js/app/viewmodels/settings.js b/src/octoprint/static/js/app/viewmodels/settings.js index ee6c44ba1..40a96b2c9 100644 --- a/src/octoprint/static/js/app/viewmodels/settings.js +++ b/src/octoprint/static/js/app/viewmodels/settings.js @@ -129,6 +129,7 @@ $(function() { self.webcam_ffmpegPath = ko.observable(undefined); self.webcam_bitrate = ko.observable(undefined); self.webcam_ffmpegThreads = ko.observable(undefined); + self.webcam_ffmpegVideoCodec = ko.observable(undefined); self.webcam_watermark = ko.observable(undefined); self.webcam_flipH = ko.observable(undefined); self.webcam_flipV = ko.observable(undefined); diff --git a/src/octoprint/templates/dialogs/settings/webcam.jinja2 b/src/octoprint/templates/dialogs/settings/webcam.jinja2 index 7a1330edc..f9b72b069 100644 --- a/src/octoprint/templates/dialogs/settings/webcam.jinja2 +++ b/src/octoprint/templates/dialogs/settings/webcam.jinja2 @@ -26,6 +26,7 @@ {% include "snippets/settings/webcam/ffmpegThreads.jinja2" %} {% include "snippets/settings/webcam/webcamSnapshotTimeout.jinja2" %} {% include "snippets/settings/webcam/webcamSnapshotSslValidation.jinja2" %} + {% include "snippets/settings/webcam/ffmpegVideoCodec.jinja2" %} diff --git a/src/octoprint/templates/snippets/settings/webcam/ffmpegVideoCodec.jinja2 b/src/octoprint/templates/snippets/settings/webcam/ffmpegVideoCodec.jinja2 new file mode 100644 index 000000000..920a534c6 --- /dev/null +++ b/src/octoprint/templates/snippets/settings/webcam/ffmpegVideoCodec.jinja2 @@ -0,0 +1,6 @@ +
+ +
+ +
+
diff --git a/src/octoprint/timelapse.py b/src/octoprint/timelapse.py index 6b9ee6258..985ac4590 100644 --- a/src/octoprint/timelapse.py +++ b/src/octoprint/timelapse.py @@ -165,6 +165,7 @@ def render_unrendered_timelapse(name, gcode=None, postfix=None, fps=25): capture_dir = settings().getBaseFolder("timelapse_tmp") output_dir = settings().getBaseFolder("timelapse") threads = settings().get(["webcam", "ffmpegThreads"]) + videocodec = settings().get(["webcam", "ffmpegVideoCodec"]) job = TimelapseRenderJob(capture_dir, output_dir, name, postfix=postfix, @@ -172,6 +173,7 @@ def render_unrendered_timelapse(name, gcode=None, postfix=None, fps=25): output_format=_output_format, fps=fps, threads=threads, + videocodec=videocodec, on_start=_create_render_start_handler(name, gcode=gcode), on_success=_create_render_success_handler(name, gcode=gcode), on_fail=_create_render_fail_handler(name, gcode=gcode), @@ -786,7 +788,7 @@ class TimelapseRenderJob(object): def __init__(self, capture_dir, output_dir, prefix, postfix=None, capture_glob="{prefix}-*.jpg", capture_format="{prefix}-%d.jpg", output_format="{prefix}{postfix}.mpg", fps=25, threads=1, - on_start=None, on_success=None, on_fail=None, on_always=None): + videocodec="mpeg2video", on_start=None, on_success=None, on_fail=None, on_always=None): self._capture_dir = capture_dir self._output_dir = output_dir self._prefix = prefix @@ -796,6 +798,7 @@ class TimelapseRenderJob(object): self._output_format = output_format self._fps = fps self._threads = threads + self._videocodec = videocodec self._on_start = on_start self._on_success = on_success self._on_fail = on_fail @@ -853,7 +856,8 @@ class TimelapseRenderJob(object): # prepare ffmpeg command command_str = self._create_ffmpeg_command_string(ffmpeg, self._fps, bitrate, self._threads, input, output, - hflip=hflip, vflip=vflip, rotate=rotate, watermark=watermark) + self._videocodec, hflip=hflip, vflip=vflip, rotate=rotate, + watermark=watermark) self._logger.debug("Executing command: {}".format(command_str)) with self.render_job_lock: @@ -904,7 +908,7 @@ class TimelapseRenderJob(object): 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, + def _create_ffmpeg_command_string(cls, ffmpeg, fps, bitrate, threads, input, output, videocodec, hflip=False, vflip=False, rotate=False, watermark=None, pixfmt="yuv420p"): """ Create ffmpeg command string based on input parameters. @@ -914,7 +918,8 @@ class TimelapseRenderJob(object): fps (int): Frames per second for output bitrate (str): Bitrate of output threads (int): Number of threads to use for rendering - input (str): Absolute path to input files including file mask + videocodec (str): Videocodec to be used for encoding + input (str): Absolute path to input files including file mask output (str): Absolute path to output file hflip (bool): Perform horizontal flip on input material. vflip (bool): Perform vertical flip on input material. @@ -931,7 +936,7 @@ class TimelapseRenderJob(object): logger = logging.getLogger(__name__) command = [ - ffmpeg, '-framerate', str(fps), '-i', '"{}"'.format(input), '-vcodec', 'mpeg2video', + ffmpeg, '-framerate', str(fps), '-i', '"{}"'.format(input), '-vcodec', videocodec, '-threads', str(threads), '-r', "25", '-y', '-b', str(bitrate), '-f', 'vob']