Extract frames at full resolution before transcoding clip for browser

Previously frames were extracted after the 720p transcode, resulting in 1280x720
images even when the source was 4K. Now frames are extracted from the original
clip first, then the clip is transcoded to 720p for web playback.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
perco
2026-06-02 17:19:53 +02:00
co-authored by Claude Sonnet 4.6
parent ec214ed7b2
commit 92f435935e
+8 -8
View File
@@ -109,13 +109,19 @@ def _frame_score(frame: np.ndarray, plates: list) -> float:
def _process_clip(event_id: str, event_dir: str, clip_path: str, camera_name: str = None): def _process_clip(event_id: str, event_dir: str, clip_path: str, camera_name: str = None):
"""Process an existing clip: transcode, extract frames, LPR, store in DB.""" """Process an existing clip: extract frames at full res, transcode for browser, LPR, store in DB."""
if camera_name is None: if camera_name is None:
camera_name = CAMERA_NAME camera_name = CAMERA_NAME
frames_pattern = os.path.join(event_dir, "frame_%04d.jpg") frames_pattern = os.path.join(event_dir, "frame_%04d.jpg")
# Transcode to H.264 baseline for browser compatibility # Extract frames at full original resolution BEFORE any transcode
subprocess.run([
"ffmpeg", "-y", "-i", clip_path,
"-vf", f"fps={CAPTURE_FPS}", "-q:v", "2", frames_pattern,
], capture_output=True, timeout=60)
# Transcode to H.264 baseline 720p for browser (after frame extraction)
web_clip = os.path.join(event_dir, "clip_web.mp4") web_clip = os.path.join(event_dir, "clip_web.mp4")
subprocess.run([ subprocess.run([
"ffmpeg", "-y", "-i", clip_path, "ffmpeg", "-y", "-i", clip_path,
@@ -131,12 +137,6 @@ def _process_clip(event_id: str, event_dir: str, clip_path: str, camera_name: st
else: else:
log.warning("Transcode failed, keeping raw clip") log.warning("Transcode failed, keeping raw clip")
# Extract frames
subprocess.run([
"ffmpeg", "-y", "-i", clip_path,
"-vf", f"fps={CAPTURE_FPS}", "-q:v", "2", frames_pattern,
], capture_output=True, timeout=60)
frame_files = sorted(glob.glob(os.path.join(event_dir, "frame_*.jpg"))) frame_files = sorted(glob.glob(os.path.join(event_dir, "frame_*.jpg")))
log.info(f"Extracted {len(frame_files)} frames") log.info(f"Extracted {len(frame_files)} frames")