Dump ffmpeg stderr to ESPhome debug log (#130808)

* dump the stderr from ffmpeg to debug log

* add pid to indentify the ffmpeg process

* be more explosive :)

* move stderr task into _write_ffmpeg_data
This commit is contained in:
Michael 2024-11-27 00:09:04 +01:00 committed by GitHub
parent ce20670d84
commit 70c8c57401
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -212,6 +212,10 @@ class FFmpegConvertResponse(web.StreamResponse):
assert proc.stdout is not None
assert proc.stderr is not None
stderr_task = self.hass.async_create_background_task(
self._dump_ffmpeg_stderr(proc), "ESPHome media proxy dump stderr"
)
try:
# Pull audio chunks from ffmpeg and pass them to the HTTP client
while (
@ -230,18 +234,14 @@ class FFmpegConvertResponse(web.StreamResponse):
raise # don't log error
except:
_LOGGER.exception("Unexpected error during ffmpeg conversion")
# Process did not exit successfully
stderr_text = ""
while line := await proc.stderr.readline():
stderr_text += line.decode()
_LOGGER.error("FFmpeg output: %s", stderr_text)
raise
finally:
# Allow conversion info to be removed
self.convert_info.is_finished = True
# stop dumping ffmpeg stderr task
stderr_task.cancel()
# Terminate hangs, so kill is used
if proc.returncode is None:
proc.kill()
@ -250,6 +250,16 @@ class FFmpegConvertResponse(web.StreamResponse):
if request.transport and not request.transport.is_closing():
await writer.write_eof()
async def _dump_ffmpeg_stderr(
self,
proc: asyncio.subprocess.Process,
) -> None:
assert proc.stdout is not None
assert proc.stderr is not None
while self.hass.is_running and (chunk := await proc.stderr.readline()):
_LOGGER.debug("ffmpeg[%s] output: %s", proc.pid, chunk.decode().rstrip())
class FFmpegProxyView(HomeAssistantView):
"""FFmpeg web view to convert audio and stream back to client."""