tropicoo / hikvision-camera-bot

Hikvision Telegram Camera Bot 🇺🇦
MIT License
105 stars 24 forks source link

Task "RecordVideoGifTask" raised an exception #103

Closed Blogoslov closed 1 year ago

Blogoslov commented 1 year ago

Hello, when the camera has an alert then in most keys I see the following issue in the log file:

hikvision_camera_bot | 2023-06-18 10:21:35,993 - [ERROR] - [MakeThumbnailTask:32] - Failed to make thumbnail for /tmp/cam_1-alert-2023-Jun-18--10-21-35 -0dsm.mp4 hikvision_camera_bot | 2023-06-18 10:21:35,993 - [ERROR] - [RecordVideoGifTask:131] - Error during making thumbnail of /tmp/cam_1-alert-2023-Jun-18--10 -21-35-0dsm.mp4 hikvision_camera_bot | 2023-06-18 10:21:35,993 - [ERROR] - [VideoGifRecorder:53] - Task "RecordVideoGifTask" raised an exception hikvision_camera_bot | Traceback (most recent call last): hikvision_camera_bot | File "/app/hikcamerabot/utils/task.py", line 49, in _handle_task_result hikvision_camera_bot | task.result() hikvision_camera_bot | File "/app/hikcamerabot/common/video/tasks/videogif.py", line 93, in run hikvision_camera_bot | await asyncio.gather(self._record(), self._send_confirmation_message()) hikvision_camera_bot | File "/app/hikcamerabot/common/video/tasks/videogif.py", line 105, in _record hikvision_camera_bot | await self._post_process_successful_record() hikvision_camera_bot | File "/app/hikcamerabot/common/video/tasks/videogif.py", line 110, in _post_process_successful_record hikvision_camera_bot | await asyncio.gather(self._get_probe_ctx(), self._make_thumbnail_frame()) hikvision_camera_bot | File "/app/hikcamerabot/common/video/tasks/videogif.py", line 143, in _get_probe_ctx hikvision_camera_bot | self._duration = int(float(self._probe_ctx['format']['duration'])) hikvision_camera_bot | ~~~~~^^^^^^^^^^^^ hikvision_camera_bot | KeyError: 'duration' hikvision_camera_bot | Exiting normally, received signal 2. hikvision_camera_bot | 2023-06-18 10:21:36,000 - [INFO] - [asyncio:211] - <_UnixSubprocessTransport pid=48 running> exited with return code 255

And after this message I see the following type error issue:

===================================================================

hikvision_camera_bot | Traceback (most recent call last): hikvision_camera_bot | File "/usr/local/lib/python3.11/asyncio/tasks.py", line 490, in wait_for hikvision_camera_bot | return fut.result() hikvision_camera_bot | ^^^^^^^^^^^^ hikvision_camera_bot | File "/usr/local/lib/python3.11/asyncio/subprocess.py", line 137, in wait hikvision_camera_bot | return await self._transport._wait() hikvision_camera_bot | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ hikvision_camera_bot | File "/usr/local/lib/python3.11/asyncio/base_subprocess.py", line 230, in _wait hikvision_camera_bot | return await waiter hikvision_camera_bot | ^^^^^^^^^^^^ hikvision_camera_bot | asyncio.exceptions.CancelledError hikvision_camera_bot | hikvision_camera_bot | The above exception was the direct cause of the following exception: hikvision_camera_bot | hikvision_camera_bot | Traceback (most recent call last): hikvision_camera_bot | File "/app/hikcamerabot/common/video/tasks/videogif.py", line 162, in _start_ffmpeg_subprocess hikvision_camera_bot | await asyncio.wait_for(proc.wait(), timeout=proc_timeout) hikvision_camera_bot | File "/usr/local/lib/python3.11/asyncio/tasks.py", line 492, in wait_for hikvision_camera_bot | raise exceptions.TimeoutError() from exc hikvision_camera_bot | TimeoutError hikvision_camera_bot | hikvision_camera_bot | During handling of the above exception, another exception occurred: hikvision_camera_bot | hikvision_camera_bot | Traceback (most recent call last): hikvision_camera_bot | File "/usr/local/lib/python3.11/logging/init.py", line 1110, in emit hikvision_camera_bot | msg = self.format(record) hikvision_camera_bot | ^^^^^^^^^^^^^^^^^^^ hikvision_camera_bot | File "/usr/local/lib/python3.11/logging/init.py", line 953, in format hikvision_camera_bot | return fmt.format(record) hikvision_camera_bot | ^^^^^^^^^^^^^^^^^^ hikvision_camera_bot | File "/usr/local/lib/python3.11/logging/init.py", line 687, in format hikvision_camera_bot | record.message = record.getMessage() hikvision_camera_bot | ^^^^^^^^^^^^^^^^^^^ hikvision_camera_bot | File "/usr/local/lib/python3.11/logging/init.py", line 377, in getMessage hikvision_camera_bot | msg = msg % self.args hikvision_camera_bot | ~~^~~~~ hikvision_camera_bot | TypeError: %d format: a real number is required, not str hikvision_camera_bot | Call stack: hikvision_camera_bot | File "/app/./bot.py", line 16, in hikvision_camera_bot | asyncio.run(main()) hikvision_camera_bot | File "/usr/local/lib/python3.11/asyncio/runners.py", line 190, in run hikvision_camera_bot | return runner.run(main) hikvision_camera_bot | File "/usr/local/lib/python3.11/asyncio/runners.py", line 118, in run hikvision_camera_bot | return self._loop.run_until_complete(task) hikvision_camera_bot | File "/usr/local/lib/python3.11/asyncio/base_events.py", line 640, in run_until_complete hikvision_camera_bot | self.run_forever() hikvision_camera_bot | File "/usr/local/lib/python3.11/asyncio/base_events.py", line 607, in run_forever hikvision_camera_bot | self._run_once() hikvision_camera_bot | File "/usr/local/lib/python3.11/asyncio/base_events.py", line 1914, in _run_once hikvision_camera_bot | handle._run() hikvision_camera_bot | File "/usr/local/lib/python3.11/asyncio/events.py", line 80, in _run hikvision_camera_bot | self._context.run(self._callback, *self._args) hikvision_camera_bot | File "/app/hikcamerabot/common/video/tasks/videogif.py", line 103, in _record hikvision_camera_bot | await self._start_ffmpeg_subprocess() hikvision_camera_bot | File "/app/hikcamerabot/common/video/tasks/videogif.py", line 164, in _start_ffmpeg_subprocess hikvision_camera_bot | self._log.error( hikvision_camera_bot | Message: 'Failed to record %s: FFMPEG process ran longer than expected (%ds) and was killed' hikvision_camera_bot | Arguments: (30, '/tmp/cam_1-alert-2023-Jun-18--10-22-57-57di.mp4') hikvision_camera_bot | 2023-06-18 10:23:27,865 - [ERROR] - [RecordVideoGifTask:178] - Failed to validate /tmp/cam_1-alert-2023-Jun-18--10-22-57-57di.mp 4: File does not exist hikvision_camera_bot | 2023-06-18 10:23:27,865 - [ERROR] - [RecordVideoGifTask:116] - Failed to record /tmp/cam_1-alert-2023-Jun-18--10-22-57-57di.mp4

===================================================================

Could you please suggest how to avoid this issue?

Blogoslov commented 1 year ago

I see that the issue about process timeout is come from the place videogif.py where timeout is hardcoded as 30 sec, but I changed default values in the config.json to have more longer video (40 sec).

As a proposal I think we need to change _PROCESS_TIMEOUT = 30 to the calculated value from the user config.json setup (rewind + duration) and plus some extra seconds to complete video processing.

tropicoo commented 1 year ago

As a proposal I think we need to change _PROCESS_TIMEOUT = 30 to the calculated value from the user config.json setup (rewind + duration) and plus some extra seconds to complete video processing.

That's how it was supposed to work but it had a bug. I've pushed changes with the fix. Please update the bot and thanks for catching this!

Blogoslov commented 1 year ago

Yes, now it works as expected. Thanks a lot!