mirror of
https://github.com/home-assistant/core.git
synced 2025-07-22 12:47:08 +00:00
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
@ -82,7 +82,7 @@ class AmcrestCam(Camera):
|
|||||||
try:
|
try:
|
||||||
return await async_aiohttp_proxy_stream(
|
return await async_aiohttp_proxy_stream(
|
||||||
self.hass, request, stream,
|
self.hass, request, stream,
|
||||||
'multipart/x-mixed-replace;boundary=ffserver')
|
self._ffmpeg.ffmpeg_stream_content_type)
|
||||||
finally:
|
finally:
|
||||||
await stream.close()
|
await stream.close()
|
||||||
|
|
||||||
|
@ -104,7 +104,7 @@ class ArloCam(Camera):
|
|||||||
try:
|
try:
|
||||||
return await async_aiohttp_proxy_stream(
|
return await async_aiohttp_proxy_stream(
|
||||||
self.hass, request, stream,
|
self.hass, request, stream,
|
||||||
'multipart/x-mixed-replace;boundary=ffserver')
|
self._ffmpeg.ffmpeg_stream_content_type)
|
||||||
finally:
|
finally:
|
||||||
await stream.close()
|
await stream.close()
|
||||||
|
|
||||||
|
@ -101,7 +101,7 @@ class CanaryCamera(Camera):
|
|||||||
try:
|
try:
|
||||||
return await async_aiohttp_proxy_stream(
|
return await async_aiohttp_proxy_stream(
|
||||||
self.hass, request, stream,
|
self.hass, request, stream,
|
||||||
'multipart/x-mixed-replace;boundary=ffserver')
|
self._ffmpeg.ffmpeg_stream_content_type)
|
||||||
finally:
|
finally:
|
||||||
await stream.close()
|
await stream.close()
|
||||||
|
|
||||||
|
@ -68,7 +68,7 @@ class FFmpegCamera(Camera):
|
|||||||
try:
|
try:
|
||||||
return await async_aiohttp_proxy_stream(
|
return await async_aiohttp_proxy_stream(
|
||||||
self.hass, request, stream,
|
self.hass, request, stream,
|
||||||
'multipart/x-mixed-replace;boundary=ffserver')
|
self._manager.ffmpeg_stream_content_type)
|
||||||
finally:
|
finally:
|
||||||
await stream.close()
|
await stream.close()
|
||||||
|
|
||||||
|
@ -213,7 +213,8 @@ class ONVIFHassCamera(Camera):
|
|||||||
if not self._input:
|
if not self._input:
|
||||||
return None
|
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)
|
loop=self.hass.loop)
|
||||||
await stream.open_camera(
|
await stream.open_camera(
|
||||||
self._input, extra_cmd=self._ffmpeg_arguments)
|
self._input, extra_cmd=self._ffmpeg_arguments)
|
||||||
@ -221,7 +222,7 @@ class ONVIFHassCamera(Camera):
|
|||||||
try:
|
try:
|
||||||
return await async_aiohttp_proxy_stream(
|
return await async_aiohttp_proxy_stream(
|
||||||
self.hass, request, stream,
|
self.hass, request, stream,
|
||||||
'multipart/x-mixed-replace;boundary=ffserver')
|
ffmpeg_manager.ffmpeg_stream_content_type)
|
||||||
finally:
|
finally:
|
||||||
await stream.close()
|
await stream.close()
|
||||||
|
|
||||||
|
@ -142,7 +142,7 @@ class RingCam(Camera):
|
|||||||
try:
|
try:
|
||||||
return await async_aiohttp_proxy_stream(
|
return await async_aiohttp_proxy_stream(
|
||||||
self.hass, request, stream,
|
self.hass, request, stream,
|
||||||
'multipart/x-mixed-replace;boundary=ffserver')
|
self._ffmpeg.ffmpeg_stream_content_type)
|
||||||
finally:
|
finally:
|
||||||
await stream.close()
|
await stream.close()
|
||||||
|
|
||||||
|
@ -161,6 +161,6 @@ class XiaomiCamera(Camera):
|
|||||||
try:
|
try:
|
||||||
return await async_aiohttp_proxy_stream(
|
return await async_aiohttp_proxy_stream(
|
||||||
self.hass, request, stream,
|
self.hass, request, stream,
|
||||||
'multipart/x-mixed-replace;boundary=ffserver')
|
self._manager.ffmpeg_stream_content_type)
|
||||||
finally:
|
finally:
|
||||||
await stream.close()
|
await stream.close()
|
||||||
|
@ -147,6 +147,6 @@ class YiCamera(Camera):
|
|||||||
try:
|
try:
|
||||||
return await async_aiohttp_proxy_stream(
|
return await async_aiohttp_proxy_stream(
|
||||||
self.hass, request, stream,
|
self.hass, request, stream,
|
||||||
'multipart/x-mixed-replace;boundary=ffserver')
|
self._manager.ffmpeg_stream_content_type)
|
||||||
finally:
|
finally:
|
||||||
await stream.close()
|
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/
|
https://home-assistant.io/components/ffmpeg/
|
||||||
"""
|
"""
|
||||||
import logging
|
import logging
|
||||||
|
import re
|
||||||
|
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
@ -16,7 +17,7 @@ from homeassistant.helpers.dispatcher import (
|
|||||||
import homeassistant.helpers.config_validation as cv
|
import homeassistant.helpers.config_validation as cv
|
||||||
from homeassistant.helpers.entity import Entity
|
from homeassistant.helpers.entity import Entity
|
||||||
|
|
||||||
REQUIREMENTS = ['ha-ffmpeg==1.9']
|
REQUIREMENTS = ['ha-ffmpeg==1.11']
|
||||||
|
|
||||||
DOMAIN = 'ffmpeg'
|
DOMAIN = 'ffmpeg'
|
||||||
|
|
||||||
@ -60,6 +61,8 @@ async def async_setup(hass, config):
|
|||||||
conf.get(CONF_FFMPEG_BIN, DEFAULT_BINARY)
|
conf.get(CONF_FFMPEG_BIN, DEFAULT_BINARY)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
await manager.async_get_version()
|
||||||
|
|
||||||
# Register service
|
# Register service
|
||||||
async def async_service_handle(service):
|
async def async_service_handle(service):
|
||||||
"""Handle service ffmpeg process."""
|
"""Handle service ffmpeg process."""
|
||||||
@ -96,12 +99,37 @@ class FFmpegManager:
|
|||||||
self.hass = hass
|
self.hass = hass
|
||||||
self._cache = {}
|
self._cache = {}
|
||||||
self._bin = ffmpeg_bin
|
self._bin = ffmpeg_bin
|
||||||
|
self._version = None
|
||||||
|
self._major_version = None
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def binary(self):
|
def binary(self):
|
||||||
"""Return ffmpeg binary from config."""
|
"""Return ffmpeg binary from config."""
|
||||||
return self._bin
|
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):
|
class FFmpegBase(Entity):
|
||||||
"""Interface object for FFmpeg."""
|
"""Interface object for FFmpeg."""
|
||||||
|
@ -487,7 +487,7 @@ greenwavereality==0.5.1
|
|||||||
gstreamer-player==1.1.2
|
gstreamer-player==1.1.2
|
||||||
|
|
||||||
# homeassistant.components.ffmpeg
|
# homeassistant.components.ffmpeg
|
||||||
ha-ffmpeg==1.9
|
ha-ffmpeg==1.11
|
||||||
|
|
||||||
# homeassistant.components.media_player.philips_js
|
# homeassistant.components.media_player.philips_js
|
||||||
ha-philipsjs==0.0.5
|
ha-philipsjs==0.0.5
|
||||||
|
@ -101,7 +101,7 @@ geojson_client==0.3
|
|||||||
georss_client==0.5
|
georss_client==0.5
|
||||||
|
|
||||||
# homeassistant.components.ffmpeg
|
# homeassistant.components.ffmpeg
|
||||||
ha-ffmpeg==1.9
|
ha-ffmpeg==1.11
|
||||||
|
|
||||||
# homeassistant.components.hangouts
|
# homeassistant.components.hangouts
|
||||||
hangups==0.4.6
|
hangups==0.4.6
|
||||||
|
Loading…
x
Reference in New Issue
Block a user