diff --git a/frigate/api/media.py b/frigate/api/media.py index 52045b160..b8efd1f22 100644 --- a/frigate/api/media.py +++ b/frigate/api/media.py @@ -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( diff --git a/frigate/util/image.py b/frigate/util/image.py index 7c470a2a0..1dc8506fe 100644 --- a/frigate/util/image.py +++ b/frigate/util/image.py @@ -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,