1 parent
43e5c65472
commit
7e37569613
7 files changed
+79
-27
No files matched your search
@@ -131,6 +131,7 @@ def getSettings():
|
||||
"snapshotTimeout": s.getInt(["webcam", "snapshotTimeout"]),
|
||||
"snapshotSslValidation": s.getBoolean(["webcam", "snapshotSslValidation"]),
|
||||
"ffmpegPath": s.get(["webcam", "ffmpeg"]),
|
||||
"ffmpegCommandline": s.get(["webcam", "ffmpegCommandline"]),
|
||||
"bitrate": s.get(["webcam", "bitrate"]),
|
||||
"ffmpegThreads": s.get(["webcam", "ffmpegThreads"]),
|
||||
"ffmpegVideoCodec": s.get(["webcam", "ffmpegVideoCodec"]),
|
||||
@@ -545,6 +546,25 @@ def _saveSettings(data):
|
||||
)
|
||||
if "ffmpegPath" in data["webcam"]:
|
||||
s.set(["webcam", "ffmpeg"], data["webcam"]["ffmpegPath"])
|
||||
if "ffmpegCommandline" in data["webcam"]:
|
||||
commandline = data["webcam"]["ffmpegCommandline"]
|
||||
try:
|
||||
commandline.format(
|
||||
ffmpeg="ffmpeg",
|
||||
fps="fps",
|
||||
bitrate="bitrate",
|
||||
threads="threads",
|
||||
input="input",
|
||||
output="output",
|
||||
videocodec="videocodec",
|
||||
containerformat="containerformat",
|
||||
)
|
||||
except Exception:
|
||||
# some invalid data we'll refuse to set
|
||||
logger.exception("Invalid webcam.ffmpegCommandline setting")
|
||||
abort(400, description="Invalid webcam.ffmpegCommandline setting")
|
||||
else:
|
||||
s.set(["webcam", "ffmpegCommandline"], commandline)
|
||||
if "bitrate" in data["webcam"]:
|
||||
s.set(["webcam", "bitrate"], data["webcam"]["bitrate"])
|
||||
if "ffmpegThreads" in data["webcam"]:
|
||||
|
||||
@@ -256,6 +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',
|
||||
"timelapse": {
|
||||
"type": "off",
|
||||
"options": {},
|
||||
|
||||
@@ -157,6 +157,7 @@ $(function () {
|
||||
self.webcam_snapshotTimeout = ko.observable(undefined);
|
||||
self.webcam_snapshotSslValidation = ko.observable(undefined);
|
||||
self.webcam_ffmpegPath = ko.observable(undefined);
|
||||
self.webcam_ffmpegCommandline = ko.observable(undefined);
|
||||
self.webcam_bitrate = ko.observable(undefined);
|
||||
self.webcam_ffmpegThreads = ko.observable(undefined);
|
||||
self.webcam_ffmpegVideoCodec = ko.observable(undefined);
|
||||
|
||||
@@ -29,6 +29,7 @@
|
||||
<div><small><a href="#" class="muted" data-bind="toggleContent: { class: 'fa-caret-right fa-caret-down', parent: '.form-horizontal', container: '.hide' }"><i class="fas
|
||||
fa-caret-right"></i> {{ _('Advanced options') }}</a></small></div>
|
||||
<div class="hide">
|
||||
{% include "snippets/settings/webcam/ffmpegCommandline.jinja2" %}
|
||||
{% include "snippets/settings/webcam/ffmpegBitrate.jinja2" %}
|
||||
{% include "snippets/settings/webcam/ffmpegThreads.jinja2" %}
|
||||
{% include "snippets/settings/webcam/webcamSnapshotTimeout.jinja2" %}
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
<div class="control-group" title="{{ _('FFMPEG command line to use')|edq }}">
|
||||
<label class="control-label" for="settings-webcamFfmpegCommandline">{{ _('FFMPEG command line') }}</label>
|
||||
<div class="controls">
|
||||
<input type="text" class="input-block-level" data-bind="value: webcam_ffmpegCommandline" id="settings-webcamFfmpegCommandline">
|
||||
<span class="help-block">{% trans %}
|
||||
FFMPEG command line to use. You can adjust the full FFMPEG command here that
|
||||
is used to generate the timelapse recordings, e.g. to add additional command line
|
||||
parameters as needed. Supported placeholders are:
|
||||
<code>{ffmpeg}</code> (configured path to ffmpeg), <code>{fps}</code> (configured framerate),
|
||||
<code>{input}</code> (input files), <code>{videocodec}</code> (configured video codec to use),
|
||||
<code>{threads}</code> (configured number of threads to use), <code>{bitrate}</code> (configured bitrate to use),
|
||||
<code>{containerformat}</code> (configured container format to use).
|
||||
{% endtrans %}</span>
|
||||
</div>
|
||||
</div>
|
||||
+18
-22
@@ -980,6 +980,7 @@ class TimelapseRenderJob(object):
|
||||
"""Rendering runnable."""
|
||||
|
||||
ffmpeg = settings().get(["webcam", "ffmpeg"])
|
||||
commandline = settings().get(["webcam", "ffmpegCommandline"])
|
||||
bitrate = settings().get(["webcam", "bitrate"])
|
||||
if ffmpeg is None or bitrate is None:
|
||||
self._logger.warning(
|
||||
@@ -1034,6 +1035,7 @@ class TimelapseRenderJob(object):
|
||||
|
||||
# prepare ffmpeg command
|
||||
command_str = self._create_ffmpeg_command_string(
|
||||
commandline,
|
||||
ffmpeg,
|
||||
self._fps,
|
||||
bitrate,
|
||||
@@ -1118,6 +1120,7 @@ class TimelapseRenderJob(object):
|
||||
@classmethod
|
||||
def _create_ffmpeg_command_string(
|
||||
cls,
|
||||
commandline,
|
||||
ffmpeg,
|
||||
fps,
|
||||
bitrate,
|
||||
@@ -1135,6 +1138,7 @@ class TimelapseRenderJob(object):
|
||||
Create ffmpeg command string based on input parameters.
|
||||
|
||||
Arguments:
|
||||
commandline (str): Command line template to use
|
||||
ffmpeg (str): Path to ffmpeg
|
||||
fps (int): Frames per second for output
|
||||
bitrate (str): Bitrate of output
|
||||
@@ -1162,38 +1166,30 @@ class TimelapseRenderJob(object):
|
||||
else:
|
||||
containerformat = "mp4"
|
||||
|
||||
command = [
|
||||
ffmpeg,
|
||||
"-framerate",
|
||||
str(fps),
|
||||
"-i",
|
||||
'"{}"'.format(input),
|
||||
"-vcodec",
|
||||
videocodec,
|
||||
"-threads",
|
||||
str(threads),
|
||||
"-r",
|
||||
"25",
|
||||
"-y",
|
||||
"-b",
|
||||
str(bitrate),
|
||||
"-f",
|
||||
containerformat,
|
||||
]
|
||||
placeholders = {
|
||||
"ffmpeg": ffmpeg,
|
||||
"fps": str(fps),
|
||||
"input": input,
|
||||
"videocodec": videocodec,
|
||||
"threads": str(threads),
|
||||
"bitrate": str(bitrate),
|
||||
"containerformat": containerformat,
|
||||
}
|
||||
|
||||
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.extend(["-vf", sarge.shell_quote(filter_string)])
|
||||
command += " -vf " + sarge.shell_quote(filter_string)
|
||||
|
||||
# finalize command with output file
|
||||
logger.debug("Rendering movie to {}".format(output))
|
||||
command.append('"{}"'.format(output))
|
||||
command += ' "{}"'.format(output)
|
||||
|
||||
return " ".join(command)
|
||||
return command
|
||||
|
||||
@classmethod
|
||||
def _create_filter_string(
|
||||
|
||||
@@ -16,6 +16,7 @@ class TimelapseRenderJobTest(unittest.TestCase):
|
||||
@data(
|
||||
(
|
||||
(
|
||||
'{ffmpeg} -r {fps} -i "{input}" -vcodec {videocodec} -threads {threads} -b {bitrate} -f {containerformat} -y',
|
||||
"/path/to/ffmpeg",
|
||||
25,
|
||||
"10000k",
|
||||
@@ -25,10 +26,25 @@ class TimelapseRenderJobTest(unittest.TestCase):
|
||||
"mpeg2video",
|
||||
),
|
||||
{},
|
||||
'/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 -r 25 -i "/path/to/input/files_%d.jpg" -vcodec mpeg2video -threads 1 -b 10000k -f vob -y -vf \'[in] format=yuv420p [out]\' "/path/to/output.mpg"',
|
||||
),
|
||||
(
|
||||
(
|
||||
'{ffmpeg} -r {fps} -i "{input}" -vcodec {videocodec} -threads {threads} -b {bitrate} -f {containerformat} -y -g 5',
|
||||
"/path/to/ffmpeg",
|
||||
25,
|
||||
"10000k",
|
||||
1,
|
||||
"/path/to/input/files_%d.jpg",
|
||||
"/path/to/output.mpg",
|
||||
"mpeg2video",
|
||||
),
|
||||
{},
|
||||
'/path/to/ffmpeg -r 25 -i "/path/to/input/files_%d.jpg" -vcodec mpeg2video -threads 1 -b 10000k -f vob -y -g 5 -vf \'[in] format=yuv420p [out]\' "/path/to/output.mpg"',
|
||||
),
|
||||
(
|
||||
(
|
||||
'{ffmpeg} -r {fps} -i "{input}" -vcodec {videocodec} -threads {threads} -b {bitrate} -f {containerformat} -y',
|
||||
"/path/to/ffmpeg",
|
||||
25,
|
||||
"10000k",
|
||||
@@ -38,10 +54,11 @@ class TimelapseRenderJobTest(unittest.TestCase):
|
||||
"libx264",
|
||||
),
|
||||
{},
|
||||
'/path/to/ffmpeg -framerate 25 -i "/path/to/input/files_%d.jpg" -vcodec libx264 -threads 1 -r 25 -y -b 10000k -f mp4 -vf \'[in] format=yuv420p [out]\' "/path/to/output.mp4"',
|
||||
'/path/to/ffmpeg -r 25 -i "/path/to/input/files_%d.jpg" -vcodec libx264 -threads 1 -b 10000k -f mp4 -y -vf \'[in] format=yuv420p [out]\' "/path/to/output.mp4"',
|
||||
),
|
||||
(
|
||||
(
|
||||
'{ffmpeg} -r {fps} -i "{input}" -vcodec {videocodec} -threads {threads} -b {bitrate} -f {containerformat} -y',
|
||||
"/path/to/ffmpeg",
|
||||
25,
|
||||
"10000k",
|
||||
@@ -51,10 +68,11 @@ class TimelapseRenderJobTest(unittest.TestCase):
|
||||
"mpeg2video",
|
||||
),
|
||||
{"hflip": True},
|
||||
'/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 -r 25 -i "/path/to/input/files_%d.jpg" -vcodec mpeg2video -threads 1 -b 10000k -f vob -y -vf \'[in] format=yuv420p,hflip [out]\' "/path/to/output.mpg"',
|
||||
),
|
||||
(
|
||||
(
|
||||
'{ffmpeg} -r {fps} -i "{input}" -vcodec {videocodec} -threads {threads} -b {bitrate} -f {containerformat} -y',
|
||||
"/path/to/ffmpeg",
|
||||
25,
|
||||
"20000k",
|
||||
@@ -64,13 +82,13 @@ class TimelapseRenderJobTest(unittest.TestCase):
|
||||
"mpeg2video",
|
||||
),
|
||||
{"rotate": True, "watermark": "/path/to/watermark.png"},
|
||||
'/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"',
|
||||
'/path/to/ffmpeg -r 25 -i "/path/to/input/files_%d.jpg" -vcodec mpeg2video -threads 4 -b 20000k -f vob -y -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):
|
||||
actual = TimelapseRenderJob._create_ffmpeg_command_string(*args, **kwargs)
|
||||
self.assertEqual(actual, expected)
|
||||
self.assertEqual(expected, actual)
|
||||
|
||||
@data(
|
||||
({}, "[in] format=yuv420p [out]"),
|
||||
|
||||
Reference in new issue
Block a user