Fix ffmpeg v4 stream issue (#20314)
* Add ffmpeg version * Add ffmpeg stream content type * Change ffmpeg camera stream content type * Change ffmpeg stream content type * Lint * Add a none guard * Fix * Fix * Update onvif.py * Fix version match regrex * Fix regrex * Upgrade ha-ffmpeg to 1.11 * Lint * Get ffmpeg version in ffmpeg component setup
This commit is contained in:
parent
a40c5bf70e
commit
7455d950b1
11 changed files with 41 additions and 12 deletions
|
@ -82,7 +82,7 @@ class AmcrestCam(Camera):
|
|||
try:
|
||||
return await async_aiohttp_proxy_stream(
|
||||
self.hass, request, stream,
|
||||
'multipart/x-mixed-replace;boundary=ffserver')
|
||||
self._ffmpeg.ffmpeg_stream_content_type)
|
||||
finally:
|
||||
await stream.close()
|
||||
|
||||
|
|
|
@ -104,7 +104,7 @@ class ArloCam(Camera):
|
|||
try:
|
||||
return await async_aiohttp_proxy_stream(
|
||||
self.hass, request, stream,
|
||||
'multipart/x-mixed-replace;boundary=ffserver')
|
||||
self._ffmpeg.ffmpeg_stream_content_type)
|
||||
finally:
|
||||
await stream.close()
|
||||
|
||||
|
|
|
@ -101,7 +101,7 @@ class CanaryCamera(Camera):
|
|||
try:
|
||||
return await async_aiohttp_proxy_stream(
|
||||
self.hass, request, stream,
|
||||
'multipart/x-mixed-replace;boundary=ffserver')
|
||||
self._ffmpeg.ffmpeg_stream_content_type)
|
||||
finally:
|
||||
await stream.close()
|
||||
|
||||
|
|
|
@ -68,7 +68,7 @@ class FFmpegCamera(Camera):
|
|||
try:
|
||||
return await async_aiohttp_proxy_stream(
|
||||
self.hass, request, stream,
|
||||
'multipart/x-mixed-replace;boundary=ffserver')
|
||||
self._manager.ffmpeg_stream_content_type)
|
||||
finally:
|
||||
await stream.close()
|
||||
|
||||
|
|
|
@ -213,7 +213,8 @@ class ONVIFHassCamera(Camera):
|
|||
if not self._input:
|
||||
return None
|
||||
|
||||
stream = CameraMjpeg(self.hass.data[DATA_FFMPEG].binary,
|
||||
ffmpeg_manager = self.hass.data[DATA_FFMPEG]
|
||||
stream = CameraMjpeg(ffmpeg_manager.binary,
|
||||
loop=self.hass.loop)
|
||||
await stream.open_camera(
|
||||
self._input, extra_cmd=self._ffmpeg_arguments)
|
||||
|
@ -221,7 +222,7 @@ class ONVIFHassCamera(Camera):
|
|||
try:
|
||||
return await async_aiohttp_proxy_stream(
|
||||
self.hass, request, stream,
|
||||
'multipart/x-mixed-replace;boundary=ffserver')
|
||||
ffmpeg_manager.ffmpeg_stream_content_type)
|
||||
finally:
|
||||
await stream.close()
|
||||
|
||||
|
|
|
@ -142,7 +142,7 @@ class RingCam(Camera):
|
|||
try:
|
||||
return await async_aiohttp_proxy_stream(
|
||||
self.hass, request, stream,
|
||||
'multipart/x-mixed-replace;boundary=ffserver')
|
||||
self._ffmpeg.ffmpeg_stream_content_type)
|
||||
finally:
|
||||
await stream.close()
|
||||
|
||||
|
|
|
@ -161,6 +161,6 @@ class XiaomiCamera(Camera):
|
|||
try:
|
||||
return await async_aiohttp_proxy_stream(
|
||||
self.hass, request, stream,
|
||||
'multipart/x-mixed-replace;boundary=ffserver')
|
||||
self._manager.ffmpeg_stream_content_type)
|
||||
finally:
|
||||
await stream.close()
|
||||
|
|
|
@ -147,6 +147,6 @@ class YiCamera(Camera):
|
|||
try:
|
||||
return await async_aiohttp_proxy_stream(
|
||||
self.hass, request, stream,
|
||||
'multipart/x-mixed-replace;boundary=ffserver')
|
||||
self._manager.ffmpeg_stream_content_type)
|
||||
finally:
|
||||
await stream.close()
|
||||
|
|
|
@ -5,6 +5,7 @@ For more details about this component, please refer to the documentation at
|
|||
https://home-assistant.io/components/ffmpeg/
|
||||
"""
|
||||
import logging
|
||||
import re
|
||||
|
||||
import voluptuous as vol
|
||||
|
||||
|
@ -16,7 +17,7 @@ from homeassistant.helpers.dispatcher import (
|
|||
import homeassistant.helpers.config_validation as cv
|
||||
from homeassistant.helpers.entity import Entity
|
||||
|
||||
REQUIREMENTS = ['ha-ffmpeg==1.9']
|
||||
REQUIREMENTS = ['ha-ffmpeg==1.11']
|
||||
|
||||
DOMAIN = 'ffmpeg'
|
||||
|
||||
|
@ -60,6 +61,8 @@ async def async_setup(hass, config):
|
|||
conf.get(CONF_FFMPEG_BIN, DEFAULT_BINARY)
|
||||
)
|
||||
|
||||
await manager.async_get_version()
|
||||
|
||||
# Register service
|
||||
async def async_service_handle(service):
|
||||
"""Handle service ffmpeg process."""
|
||||
|
@ -96,12 +99,37 @@ class FFmpegManager:
|
|||
self.hass = hass
|
||||
self._cache = {}
|
||||
self._bin = ffmpeg_bin
|
||||
self._version = None
|
||||
self._major_version = None
|
||||
|
||||
@property
|
||||
def binary(self):
|
||||
"""Return ffmpeg binary from config."""
|
||||
return self._bin
|
||||
|
||||
async def async_get_version(self):
|
||||
"""Return ffmpeg version."""
|
||||
from haffmpeg.tools import FFVersion
|
||||
|
||||
ffversion = FFVersion(self._bin, self.hass.loop)
|
||||
self._version = await ffversion.get_version()
|
||||
|
||||
self._major_version = None
|
||||
if self._version is not None:
|
||||
result = re.search(r"(\d+)\.", self._version)
|
||||
if result is not None:
|
||||
self._major_version = int(result.group(1))
|
||||
|
||||
return self._version, self._major_version
|
||||
|
||||
@property
|
||||
def ffmpeg_stream_content_type(self):
|
||||
"""Return HTTP content type for ffmpeg stream."""
|
||||
if self._major_version is not None and self._major_version > 3:
|
||||
return 'multipart/x-mixed-replace;boundary=ffmpeg'
|
||||
|
||||
return 'multipart/x-mixed-replace;boundary=ffserver'
|
||||
|
||||
|
||||
class FFmpegBase(Entity):
|
||||
"""Interface object for FFmpeg."""
|
||||
|
|
|
@ -487,7 +487,7 @@ greenwavereality==0.5.1
|
|||
gstreamer-player==1.1.2
|
||||
|
||||
# homeassistant.components.ffmpeg
|
||||
ha-ffmpeg==1.9
|
||||
ha-ffmpeg==1.11
|
||||
|
||||
# homeassistant.components.media_player.philips_js
|
||||
ha-philipsjs==0.0.5
|
||||
|
|
|
@ -101,7 +101,7 @@ geojson_client==0.3
|
|||
georss_client==0.5
|
||||
|
||||
# homeassistant.components.ffmpeg
|
||||
ha-ffmpeg==1.9
|
||||
ha-ffmpeg==1.11
|
||||
|
||||
# homeassistant.components.hangouts
|
||||
hangups==0.4.6
|
||||
|
|
Loading…
Add table
Reference in a new issue