diff --git a/src/octoprint/server/api/settings.py b/src/octoprint/server/api/settings.py
index 619128c29..f4126a7e4 100644
--- a/src/octoprint/server/api/settings.py
+++ b/src/octoprint/server/api/settings.py
@@ -548,6 +548,13 @@ def _saveSettings(data):
s.set(["webcam", "ffmpeg"], data["webcam"]["ffmpegPath"])
if "ffmpegCommandline" in data["webcam"]:
commandline = data["webcam"]["ffmpegCommandline"]
+ if not all(
+ map(lambda x: "{" + x + "}" in commandline, ("ffmpeg", "input", "output"))
+ ):
+ abort(
+ 400,
+ description="Invalid webcam.ffmpegCommandline setting, lacks mandatory {ffmpeg}, {input} or {output}",
+ )
try:
commandline.format(
ffmpeg="ffmpeg",
@@ -558,6 +565,7 @@ def _saveSettings(data):
output="output",
videocodec="videocodec",
containerformat="containerformat",
+ filters="filters",
)
except Exception:
# some invalid data we'll refuse to set
diff --git a/src/octoprint/settings.py b/src/octoprint/settings.py
index 4a179c07c..1a248707d 100644
--- a/src/octoprint/settings.py
+++ b/src/octoprint/settings.py
@@ -256,7 +256,7 @@ default_settings = {
"flipH": False,
"flipV": False,
"rotate90": False,
- "ffmpegCommandline": '{ffmpeg} -r {fps} -i "{input}" -vcodec {videocodec} -threads {threads} -b {bitrate} -f {containerformat} -y',
+ "ffmpegCommandline": '{ffmpeg} -r {fps} -i "{input}" -vcodec {videocodec} -threads {threads} -b {bitrate} -f {containerformat} -y {filters} "{output}"',
"timelapse": {
"type": "off",
"options": {},
diff --git a/src/octoprint/templates/snippets/settings/webcam/ffmpegCommandline.jinja2 b/src/octoprint/templates/snippets/settings/webcam/ffmpegCommandline.jinja2
index 7f2f8a471..8f0c4aa75 100644
--- a/src/octoprint/templates/snippets/settings/webcam/ffmpegCommandline.jinja2
+++ b/src/octoprint/templates/snippets/settings/webcam/ffmpegCommandline.jinja2
@@ -3,13 +3,14 @@
{% trans %}
- FFMPEG command line to use. You can adjust the full FFMPEG command here that
+ You can adjust the full FFMPEG command line here that
is used to generate the timelapse recordings, e.g. to add additional command line
parameters as needed. Supported placeholders are:
{ffmpeg} (configured path to ffmpeg), {fps} (configured framerate),
{input} (input files), {videocodec} (configured video codec to use),
{threads} (configured number of threads to use), {bitrate} (configured bitrate to use),
- {containerformat} (configured container format to use).
+ {containerformat} (configured container format to use), {filters} (filter chain for flip/rotate & watermark),
+ {output} (output file).
{% endtrans %}
diff --git a/src/octoprint/timelapse.py b/src/octoprint/timelapse.py
index 62c623d87..f7743a454 100644
--- a/src/octoprint/timelapse.py
+++ b/src/octoprint/timelapse.py
@@ -1166,30 +1166,23 @@ class TimelapseRenderJob(object):
else:
containerformat = "mp4"
+ filter_string = cls._create_filter_string(
+ hflip=hflip, vflip=vflip, rotate=rotate, watermark=watermark
+ )
placeholders = {
"ffmpeg": ffmpeg,
"fps": str(fps),
"input": input,
+ "output": output,
"videocodec": videocodec,
"threads": str(threads),
"bitrate": str(bitrate),
"containerformat": containerformat,
+ "filters": "-vf " + sarge.shell_quote(filter_string) if filter_string else "",
}
- command = commandline.format(**placeholders)
-
- filter_string = cls._create_filter_string(
- hflip=hflip, vflip=vflip, rotate=rotate, watermark=watermark
- )
- if filter_string is not None:
- logger.debug("Applying videofilter chain: {}".format(filter_string))
- command += " -vf " + sarge.shell_quote(filter_string)
-
- # finalize command with output file
logger.debug("Rendering movie to {}".format(output))
- command += ' "{}"'.format(output)
-
- return command
+ return commandline.format(**placeholders)
@classmethod
def _create_filter_string(
diff --git a/tests/timelapse/test_timelapse_renderjob.py b/tests/timelapse/test_timelapse_renderjob.py
index b5a0b0c3d..5ebde491c 100644
--- a/tests/timelapse/test_timelapse_renderjob.py
+++ b/tests/timelapse/test_timelapse_renderjob.py
@@ -16,7 +16,7 @@ class TimelapseRenderJobTest(unittest.TestCase):
@data(
(
(
- '{ffmpeg} -r {fps} -i "{input}" -vcodec {videocodec} -threads {threads} -b {bitrate} -f {containerformat} -y',
+ '{ffmpeg} -r {fps} -i "{input}" -vcodec {videocodec} -threads {threads} -b {bitrate} -f {containerformat} -y {filters} "{output}"',
"/path/to/ffmpeg",
25,
"10000k",
@@ -30,7 +30,7 @@ class TimelapseRenderJobTest(unittest.TestCase):
),
(
(
- '{ffmpeg} -r {fps} -i "{input}" -vcodec {videocodec} -threads {threads} -b {bitrate} -f {containerformat} -y -g 5',
+ '{ffmpeg} -r {fps} -i "{input}" -vcodec {videocodec} -threads {threads} -b {bitrate} -f {containerformat} -y -g 5 {filters} "{output}"',
"/path/to/ffmpeg",
25,
"10000k",
@@ -44,7 +44,7 @@ class TimelapseRenderJobTest(unittest.TestCase):
),
(
(
- '{ffmpeg} -r {fps} -i "{input}" -vcodec {videocodec} -threads {threads} -b {bitrate} -f {containerformat} -y',
+ '{ffmpeg} -r {fps} -i "{input}" -vcodec {videocodec} -threads {threads} -b {bitrate} -f {containerformat} -y {filters} "{output}"',
"/path/to/ffmpeg",
25,
"10000k",
@@ -58,7 +58,7 @@ class TimelapseRenderJobTest(unittest.TestCase):
),
(
(
- '{ffmpeg} -r {fps} -i "{input}" -vcodec {videocodec} -threads {threads} -b {bitrate} -f {containerformat} -y',
+ '{ffmpeg} -r {fps} -i "{input}" -vcodec {videocodec} -threads {threads} -b {bitrate} -f {containerformat} -y {filters} "{output}"',
"/path/to/ffmpeg",
25,
"10000k",
@@ -72,7 +72,7 @@ class TimelapseRenderJobTest(unittest.TestCase):
),
(
(
- '{ffmpeg} -r {fps} -i "{input}" -vcodec {videocodec} -threads {threads} -b {bitrate} -f {containerformat} -y',
+ '{ffmpeg} -r {fps} -i "{input}" -vcodec {videocodec} -threads {threads} -b {bitrate} -f {containerformat} -y {filters} "{output}"',
"/path/to/ffmpeg",
25,
"20000k",