use get_image_from_recording in recordings snapshot api

This commit is contained in:
Josh Hawkins 2024-09-04 08:30:05 -05:00
parent 24f3f02d09
commit ccee0d9e2b
2 changed files with 9 additions and 33 deletions

View File

@ -217,38 +217,10 @@ def get_snapshot_from_recording(camera_name: str, frame_time: str, format: str):
height = request.args.get("height", type=int)
codec = "png" if format == "png" else "mjpeg"
ffmpeg_cmd = [
"ffmpeg",
"-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,
image_data = get_image_from_recording(
recording.path, time_in_segment, codec, height
)
if process.returncode == 0:
image_data = process.stdout
else:
image_data = None
if not image_data:
return make_response(
jsonify(
@ -303,7 +275,7 @@ def submit_recording_snapshot_to_plus(camera_name: str, frame_time: str):
try:
recording: Recordings = recording_query.get()
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:
return make_response(

View File

@ -765,7 +765,7 @@ def add_mask(mask: str, mask_img: np.ndarray):
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]:
"""retrieve a frame from given time in recording file."""
@ -781,12 +781,16 @@ def get_image_from_recording(
"-frames:v",
"1",
"-c:v",
"png",
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,