Round up for stream record lookback (#75580)

pull/75758/head
uvjustin 2022-07-22 11:46:00 +08:00 committed by Franck Nijhof
parent ec4835ef04
commit 0407fc4581
No known key found for this signature in database
GPG Key ID: D62583BA8AB11CA3
1 changed files with 4 additions and 3 deletions

View File

@ -503,15 +503,16 @@ class Stream:
await self.start()
self._logger.debug("Started a stream recording of %s seconds", duration)
# Take advantage of lookback
hls: HlsStreamOutput = cast(HlsStreamOutput, self.outputs().get(HLS_PROVIDER))
if lookback > 0 and hls:
num_segments = min(int(lookback // hls.target_duration), MAX_SEGMENTS)
if hls:
num_segments = min(int(lookback / hls.target_duration) + 1, MAX_SEGMENTS)
# Wait for latest segment, then add the lookback
await hls.recv()
recorder.prepend(list(hls.get_segments())[-num_segments - 1 : -1])
self._logger.debug("Started a stream recording of %s seconds", duration)
await recorder.async_record()
async def async_get_image(