JurajNyiri / pytapo

Python library for communication with Tapo Cameras
MIT License
277 stars 58 forks source link

Is is possible to do a partial download? #98

Closed morrowwm closed 7 months ago

morrowwm commented 7 months ago

I'm working on a script to integrate motion detection videos into a timelapse video of the entire day. If the motion video is too long, I only want the first few seconds.

I tried a modification to experiments/DownloadRecordings.py (attached) download_partial_motions.py.txt

It forces the end time of the video:

        for recording in recordings:
            for key in recording:
                if int(recording[key]["endTime"] - recording[key]["startTime"]) > 40:
                    print("Setting endTime to 40s for large video")
                    recording[key]["endTime"] = recording[key]["startTime"] + 40
                else:

This is giving an error from the asyncio loop:

Downloading /opt2/surveillance/eyeball2/motions/2024-01-17 05_11_48-2024-01-17 05_11_58.mp4...          
could not convert string to float: b'N/A\n'
Warning: Could not calculate length from stream.
Traceback (most recent call last):ll2/motions/2024-01-17 05_11_48-2024-01-17 05_11_58.mp4: 4.13 / 10          
  File "/opt2/surveillance/eyeball2/download_motions.py", line 71, in <module>
    loop.run_until_complete(download_motions())
  File "/usr/lib/python3.9/asyncio/base_events.py", line 629, in run_until_complete
    self.run_forever()
  File "/usr/lib/python3.9/asyncio/base_events.py", line 596, in run_forever
    self._run_once()
  File "/usr/lib/python3.9/asyncio/base_events.py", line 1854, in _run_once
    event_list = self._selector.select(timeout)
  File "/usr/lib/python3.9/selectors.py", line 469, in select
    fd_event_list = self._selector.poll(timeout, max_ev)

I think this is happening because this idea is too brutal.

Could you suggest a clean way to stop the playback at a clean point?

JurajNyiri commented 7 months ago
Traceback (most recent call last):ll2/motions/2024-01-17 05_11_48-2024-01-17 05_11_58.mp4: 4.13 / 10  

Your video has only 10 seconds, if you set the end time to more than that it will not work.

Large recordings work without issues, even multiple hours segments.

What you might be also encountering is sometimes the script fails to download the last video. Try it with more than 1 recording and make sure the original script works before modifications.

You also probably want

if int(recording[key]["endTime"]) - int(recording[key]["startTime"]) > 40:

instead of what you have now.

morrowwm commented 7 months ago

Thank you for the suggestion. It seems to be working. I'll run for a day to get more motion files.

download_partial_motions.py.txt