home-assistant / core

:house_with_garden: Open source home automation that puts local control and privacy first.
https://www.home-assistant.io
Apache License 2.0
73.67k stars 30.8k forks source link

SynologyDSM camera stream throws "Application provided invalid, non monotonically increasing dts to muxer in stream 0" #46299

Closed ruimarinho closed 3 years ago

ruimarinho commented 3 years ago

The problem

As pointed out by @uvjustin, there seems to be a thread concurrency issue when streaming and recording video at the same time from a Synology Surveillance Station server.

The use case is the following: whenever someones rings at the door, an automation calls camera.record and sends a short video to a telegram group.

What is version of Home Assistant Core has the issue?

2021.2.1

What was the last working version of Home Assistant Core?

N/A

What type of installation are you running?

Home Assistant Container

Integration causing the issue

SynologyDSM, Stream

Anything in the logs that might be useful for us?

2021-02-07 20:18:45 ERROR (recorder_save_worker) [libav.mp4] Application provided invalid, non monotonically increasing dts to muxer in stream 0: 346578 >= 346545
2021-02-07 20:18:45 ERROR (recorder_save_worker) [root] Uncaught thread exception
Traceback (most recent call last):
  File "/usr/local/lib/python3.8/threading.py", line 932, in _bootstrap_inner
    self.run()
  File "/usr/local/lib/python3.8/threading.py", line 870, in run
    self._target(*self._args, **self._kwargs)
  File "/usr/src/homeassistant/homeassistant/components/stream/recorder.py", line 64, in recorder_save_worker
    output.mux(packet)
  File "av/container/output.pyx", line 204, in av.container.output.OutputContainer.mux
  File "av/container/output.pyx", line 227, in av.container.output.OutputContainer.mux_one
  File "av/container/core.pyx", line 257, in av.container.core.Container.err_check
  File "av/error.pyx", line 336, in av.error.err_check
av.error.ValueError: [Errno 22] Invalid argument: '/tmp/camera_nas_1_hall_20210207-201832.mp4'; last error log: [mp4] Application provided invalid, non monotonically increasing dts to muxer in stream 0: 346578 >= 346545
Exception ignored in: 'av.container.output.OutputContainer.__dealloc__'
Traceback (most recent call last):
  File "av/container/output.pyx", line 25, in av.container.output.close_output
2021-02-07 20:18:53 ERROR (MainThread) [root] Uncaught exception
Traceback (most recent call last):
  File "av/container/output.pyx", line 25, in av.container.output.close_output
TypeError: 'NoneType' object is not iterable
ruimarinho commented 3 years ago

@uvjustin I don't get the error now but the video sent to telegram is just completely gray:

2021-02-20 10:47:49 INFO (MainThread) [homeassistant.components.automation.record_video_when_hall_front_door_is_opened] Record video when hall front door is opened: Executing step call service
2021-02-20 10:47:49 INFO (MainThread) [homeassistant.components.stream] Started stream: rtsp://xxx:xxxx@xxx:554/Sms=4.unicast
2021-02-20 10:47:50 ERROR (stream_worker) [libav.h264] error while decoding MB 50 63, bytestream -19
2021-02-20 10:48:01 INFO (MainThread) [homeassistant.components.stream] Stopped stream: rtsp://xxx:xxx@xxx:554/Sms=4.unicast
2021-02-20 10:48:01 ERROR (recorder_save_worker) [libav.h264] error while decoding MB 50 63, bytestream -19
2021-02-20 10:48:02 ERROR (recorder_save_worker) [libav.h264] error while decoding MB 50 63, bytestream -19
2021-02-20 10:48:02 ERROR (recorder_save_worker) [libav.h264] error while decoding MB 90 47, bytestream -21
uvjustin commented 3 years ago

I think the new error might be related to the other issue you opened. If you can, try using TCP instead of UDP. Otherwise, have a look here: https://stackoverflow.com/questions/50063707/ffmpeg-rtsp-error-while-decoding-mb. We might have to have an option to send the buffer size to ffmpeg.

ruimarinho commented 3 years ago

Got it. I don’t think I have an option to configure UDP vs TCP on Synology though...

ruimarinho commented 3 years ago

Just found it's actually possible, but I get the exact same error.

image
2021-02-20 12:01:47 INFO (MainThread) [homeassistant.components.stream] Started stream: rtsp://xxx:xxx@192.168.1.8:554/Sms=4.unicast
2021-02-20 12:01:49 ERROR (stream_worker) [libav.h264] error while decoding MB 80 14, bytestream -5
2021-02-20 12:02:00 INFO (MainThread) [homeassistant.components.stream] Stopped stream: rtsp://xxx:xxx@xxx:554/Sms=4.unicast
2021-02-20 12:02:00 ERROR (recorder_save_worker) [libav.h264] error while decoding MB 80 14, bytestream -5
2021-02-20 12:02:01 ERROR (recorder_save_worker) [libav.h264] error while decoding MB 80 14, bytestream -5
ruimarinho commented 3 years ago

Actually, the issue is still manifesting itself:

2021-02-20 15:40:00 ERROR (recorder_save_worker) [libav.mp4] Application provided invalid, non monotonically increasing dts to muxer in stream 0: 1698302 >= 1698220
2021-02-20 15:40:00 ERROR (recorder_save_worker) [root] Uncaught thread exception
Traceback (most recent call last):
  File "/usr/local/lib/python3.8/threading.py", line 932, in _bootstrap_inner
    self.run()
  File "/usr/local/lib/python3.8/threading.py", line 870, in run
  File "/usr/src/homeassistant/homeassistant/components/stream/recorder.py", line 68, in recorder_save_worker
    output.mux(packet)
  File "av/container/output.pyx", line 204, in av.container.output.OutputContainer.mux
  File "av/container/output.pyx", line 227, in av.container.output.OutputContainer.mux_one
  File "av/container/core.pyx", line 257, in av.container.core.Container.err_check
  File "av/error.pyx", line 336, in av.error.err_check
av.error.ValueError: [Errno 22] Invalid argument: '/tmp/camera_nas_1_hall_20210220-153947.mp4'; last error log: [mp4] Application provided invalid, non monotonically increasing dts to muxer in stream 0: 1698302 >= 1698220
2021-02-20 15:40:20 ERROR (MainThread) [root] Uncaught exception
Traceback (most recent call last):
  File "av/container/output.pyx", line 25, in av.container.output.close_output
TypeError: 'NoneType' object is not iterable
TypeError: 'NoneType' object is not iterable
uvjustin commented 3 years ago

@ruimarinho See if the PR that just got merged fixes the issue

ruimarinho commented 3 years ago

@uvjustin it's running beautifully now! I'll be moving the cameras to auto transport (they are in TCP now, but prior to your fix that didn't change anything) and test it again.