mirror of
https://github.com/blakeblackshear/frigate.git
synced 2026-02-14 15:15:22 +03:00
use get_image_from_recording in recordings snapshot api
This commit is contained in:
parent
24f3f02d09
commit
ccee0d9e2b
@ -217,38 +217,10 @@ def get_snapshot_from_recording(camera_name: str, frame_time: str, format: str):
|
|||||||
height = request.args.get("height", type=int)
|
height = request.args.get("height", type=int)
|
||||||
codec = "png" if format == "png" else "mjpeg"
|
codec = "png" if format == "png" else "mjpeg"
|
||||||
|
|
||||||
ffmpeg_cmd = [
|
image_data = get_image_from_recording(
|
||||||
"ffmpeg",
|
recording.path, time_in_segment, codec, height
|
||||||
"-hide_banner",
|
|
||||||
"-loglevel",
|
|
||||||
"warning",
|
|
||||||
"-ss",
|
|
||||||
f"00:00:{time_in_segment}",
|
|
||||||
"-i",
|
|
||||||
recording.path,
|
|
||||||
"-frames:v",
|
|
||||||
"1",
|
|
||||||
"-c:v",
|
|
||||||
codec,
|
|
||||||
"-f",
|
|
||||||
"image2pipe",
|
|
||||||
"-",
|
|
||||||
]
|
|
||||||
|
|
||||||
if height:
|
|
||||||
ffmpeg_cmd.insert(-3, "-vf")
|
|
||||||
ffmpeg_cmd.insert(-3, f"scale=-1:{height}")
|
|
||||||
|
|
||||||
process = sp.run(
|
|
||||||
ffmpeg_cmd,
|
|
||||||
capture_output=True,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
if process.returncode == 0:
|
|
||||||
image_data = process.stdout
|
|
||||||
else:
|
|
||||||
image_data = None
|
|
||||||
|
|
||||||
if not image_data:
|
if not image_data:
|
||||||
return make_response(
|
return make_response(
|
||||||
jsonify(
|
jsonify(
|
||||||
@ -303,7 +275,7 @@ def submit_recording_snapshot_to_plus(camera_name: str, frame_time: str):
|
|||||||
try:
|
try:
|
||||||
recording: Recordings = recording_query.get()
|
recording: Recordings = recording_query.get()
|
||||||
time_in_segment = frame_time - recording.start_time
|
time_in_segment = frame_time - recording.start_time
|
||||||
image_data = get_image_from_recording(recording.path, time_in_segment)
|
image_data = get_image_from_recording(recording.path, time_in_segment, "png", 0)
|
||||||
|
|
||||||
if not image_data:
|
if not image_data:
|
||||||
return make_response(
|
return make_response(
|
||||||
|
|||||||
@ -765,7 +765,7 @@ def add_mask(mask: str, mask_img: np.ndarray):
|
|||||||
|
|
||||||
|
|
||||||
def get_image_from_recording(
|
def get_image_from_recording(
|
||||||
file_path: str, relative_frame_time: float
|
file_path: str, relative_frame_time: float, codec: str, height: int
|
||||||
) -> Optional[any]:
|
) -> Optional[any]:
|
||||||
"""retrieve a frame from given time in recording file."""
|
"""retrieve a frame from given time in recording file."""
|
||||||
|
|
||||||
@ -781,12 +781,16 @@ def get_image_from_recording(
|
|||||||
"-frames:v",
|
"-frames:v",
|
||||||
"1",
|
"1",
|
||||||
"-c:v",
|
"-c:v",
|
||||||
"png",
|
codec,
|
||||||
"-f",
|
"-f",
|
||||||
"image2pipe",
|
"image2pipe",
|
||||||
"-",
|
"-",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
if height:
|
||||||
|
ffmpeg_cmd.insert(-3, "-vf")
|
||||||
|
ffmpeg_cmd.insert(-3, f"scale=-1:{height}")
|
||||||
|
|
||||||
process = sp.run(
|
process = sp.run(
|
||||||
ffmpeg_cmd,
|
ffmpeg_cmd,
|
||||||
capture_output=True,
|
capture_output=True,
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user