mirror of
https://github.com/blakeblackshear/frigate.git
synced 2026-05-04 04:27:42 +03:00
use clipFrom to in vod module endpoint to start at the correct time
This commit is contained in:
parent
468778aa8f
commit
1a461b1cc5
@ -645,7 +645,12 @@ def recording_clip(
|
|||||||
@router.get("/vod/{camera_name}/start/{start_ts}/end/{end_ts}")
|
@router.get("/vod/{camera_name}/start/{start_ts}/end/{end_ts}")
|
||||||
def vod_ts(camera_name: str, start_ts: float, end_ts: float):
|
def vod_ts(camera_name: str, start_ts: float, end_ts: float):
|
||||||
recordings = (
|
recordings = (
|
||||||
Recordings.select(Recordings.path, Recordings.duration, Recordings.end_time)
|
Recordings.select(
|
||||||
|
Recordings.path,
|
||||||
|
Recordings.duration,
|
||||||
|
Recordings.end_time,
|
||||||
|
Recordings.start_time,
|
||||||
|
)
|
||||||
.where(
|
.where(
|
||||||
Recordings.start_time.between(start_ts, end_ts)
|
Recordings.start_time.between(start_ts, end_ts)
|
||||||
| Recordings.end_time.between(start_ts, end_ts)
|
| Recordings.end_time.between(start_ts, end_ts)
|
||||||
@ -665,17 +670,25 @@ def vod_ts(camera_name: str, start_ts: float, end_ts: float):
|
|||||||
clip = {"type": "source", "path": recording.path}
|
clip = {"type": "source", "path": recording.path}
|
||||||
duration = int(recording.duration * 1000)
|
duration = int(recording.duration * 1000)
|
||||||
|
|
||||||
# Determine if we need to end the last clip early
|
# adjust start offset if start_ts is after recording.start_time
|
||||||
|
clip_from = 0
|
||||||
|
if start_ts > recording.start_time:
|
||||||
|
clip_from = int((start_ts - recording.start_time) * 1000)
|
||||||
|
# adjust duration to account for the trimmed start
|
||||||
|
duration -= clip_from
|
||||||
|
|
||||||
|
# adjust end if recording.end_time is after end_ts
|
||||||
if recording.end_time > end_ts:
|
if recording.end_time > end_ts:
|
||||||
duration -= int((recording.end_time - end_ts) * 1000)
|
duration -= int((recording.end_time - end_ts) * 1000)
|
||||||
|
|
||||||
if duration == 0:
|
if duration <= 0:
|
||||||
# this means the segment starts right at the end of the requested time range
|
# skip if the clip has no valid duration
|
||||||
# and it does not need to be included
|
|
||||||
continue
|
continue
|
||||||
|
|
||||||
if 0 < duration < max_duration_ms:
|
if 0 < duration < max_duration_ms:
|
||||||
clip["keyFrameDurations"] = [duration]
|
clip["keyFrameDurations"] = [duration]
|
||||||
|
if clip_from > 0:
|
||||||
|
clip["clipFrom"] = clip_from
|
||||||
clips.append(clip)
|
clips.append(clip)
|
||||||
durations.append(duration)
|
durations.append(duration)
|
||||||
else:
|
else:
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user