-
Notifications
You must be signed in to change notification settings - Fork 15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Component stops working after a while if environment is too silent #32
Comments
By the way, to find out if Home Assistant is hanging in such a situation, you can try the following:
As a side note, I experimented around that problem by artificially reducing the size of the buffer in https://github.com/home-assistant-libs/ha-ffmpeg/blob/master/haffmpeg/core.py#L175, replacing
with
(If I recall correctly) |
I can confirm I have experienced this issue as well and the above patch fixes it. Good job on diagnosing it, thanks. |
Address buffer saturation during extended periods of silence, as per home-assistant-libs#32
I've created a pull request for the above fix in #33 |
Actually, an even better fix was to add We could add this switch by default when starting the process if we don't expect any other component (e.g camera, sensor) to ever use this kind of information from the output. That would be a breaking change however. |
hello. this is still happening. HA 2021.2.3 (docker on a Synology NAS) apparently there seems to be a workaround mentioned above by @maxlaverse could anyone help me implement that into my installation? |
Add |
@rjlee added that last night. woke up and sensor is still working. |
Closing in favor of home-assistant/core#49183 |
When there has been silence for a certain amount of time, the ffmpeg_noise component stops detecting any further noise.
I'm using Home Assistant 0.117.5 with Python 3.8.2 on Linux 5.4.51-v7+. The input is a USB Microphone.
The ffmpeg_noise component of Home Assistant starts a
ffmpeg
process and parses its standard outputs looking for certain patterns. The vast majority of whatffmpeg
outputs (when started by this components) can be divided in two categories:[silencedetect @ 0x1023f10] silence_start: 0.000291667
size=N/A time=00:00:02.68 bitrate=N/A speed=0.997x
The loop inside haffmpeg processing
ffmpeg
's output is the following:I believe the problem is the following. The loop is using a
readline()
call that only returns when a new line separator is read from the output. A log line with a new line separator is printed whenffmpeg
detects the start or the end of the silence. When the situation is not changing, meaning it keeps being noisy or it keeps being silent, the only output fromffmpeg
are the progress information. Those are not using a new line separator but overwrite the same line with a carriage return character. As an effect, during long silences the main loop is waiting forreadline()
to return, waiting for a new line separator. In the meantime however, the buffer keeps growing with progress information. Eventually the buffer is saturated, an Exception is raised and the main loop exits. According to the documentation the buffer's size is supposed to be 64KiB.I don't know which approach you'd like to take. Ideally, I would have wished for a buffer that is smart enough to detect the carriage return and erase the previous line, instead of just appending data. I'm not Python fluent and I searched a bit over Internet, but I couldn't find anything in that direction. As a workaround I patched my installation by emptying part of the buffer when it's full with the following additional exception handler.
Since the meaningful payload is usually less than a 100 bytes, removing the first 1024 bytes of a 64KiB buffer full with most likely useless data sounds acceptable to me.
The following issues might be related: #30 (comment), home-assistant/core#42204
The text was updated successfully, but these errors were encountered: