Skip to content

Commit

Permalink
Introduce extra_input_cmd to be able to specify input-side parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
andras-tim committed Jun 15, 2022
1 parent c73eca5 commit 9d944ff
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
1 change: 1 addition & 0 deletions homeassistant/components/ffmpeg/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
CONF_INPUT = "input"
CONF_FFMPEG_BIN = "ffmpeg_bin"
CONF_EXTRA_ARGUMENTS = "extra_arguments"
CONF_EXTRA_INPUT_ARGUMENTS = "extra_input_arguments"
CONF_OUTPUT = "output"

DEFAULT_BINARY = "ffmpeg"
Expand Down
12 changes: 10 additions & 2 deletions homeassistant/components/ffmpeg/camera.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,17 @@
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType

from . import CONF_EXTRA_ARGUMENTS, CONF_INPUT, DATA_FFMPEG, async_get_image
from . import CONF_EXTRA_ARGUMENTS, CONF_EXTRA_INPUT_ARGUMENTS, CONF_INPUT, DATA_FFMPEG, async_get_image

DEFAULT_NAME = "FFmpeg"
DEFAULT_ARGUMENTS = "-pred 1"
DEFAULT_INPUT_ARGUMENTS = None

PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
{
vol.Required(CONF_INPUT): cv.string,
vol.Optional(CONF_EXTRA_ARGUMENTS, default=DEFAULT_ARGUMENTS): cv.string,
vol.Optional(CONF_EXTRA_INPUT_ARGUMENTS, default=DEFAULT_INPUT_ARGUMENTS): cv.string,
vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string,
}
)
Expand Down Expand Up @@ -50,6 +52,7 @@ def __init__(self, hass, config):
self._name = config.get(CONF_NAME)
self._input = config.get(CONF_INPUT)
self._extra_arguments = config.get(CONF_EXTRA_ARGUMENTS)
self._extra_input_arguments = config.get(CONF_EXTRA_INPUT_ARGUMENTS)

async def stream_source(self):
"""Return the stream source."""
Expand All @@ -64,13 +67,18 @@ async def async_camera_image(
self._input,
output_format=IMAGE_JPEG,
extra_cmd=self._extra_arguments,
extra_input_cmd=self._extra_input_arguments,
)

async def handle_async_mjpeg_stream(self, request):
"""Generate an HTTP MJPEG stream from the camera."""

stream = CameraMjpeg(self._manager.binary)
await stream.open_camera(self._input, extra_cmd=self._extra_arguments)
await stream.open_camera(
self._input,
extra_cmd=self._extra_arguments,
extra_input_cmd=self._extra_input_arguments
)

try:
stream_reader = await stream.get_reader()
Expand Down

0 comments on commit 9d944ff

Please sign in to comment.