Fix encodage clip : H.264 baseline 720p CRF28 pour compatibilité navigateur
- Transcode clip en H.264 baseline level 3.1 (compatible tous navigateurs) - Downsample à 720p pour réduire la taille (17MB raw → ~2.5MB encodé) - CRF 28 + preset fast = bon compromis qualité/vitesse - Sans audio (inutile pour surveillance) - -movflags +faststart pour lecture streaming sans téléchargement complet Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 4.6
parent
6aae4ef40c
commit
d333a29c4c
+10
-3
@@ -138,14 +138,21 @@ def _process_event():
|
|||||||
"-vf", f"fps={CAPTURE_FPS}", "-q:v", "2", frames_pattern,
|
"-vf", f"fps={CAPTURE_FPS}", "-q:v", "2", frames_pattern,
|
||||||
], capture_output=True, timeout=30)
|
], capture_output=True, timeout=30)
|
||||||
|
|
||||||
# Step 2b: remux clip for browser compatibility (moov atom at start)
|
# Step 2b: transcode to H.264 baseline for browser compatibility
|
||||||
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,
|
||||||
"-c", "copy", "-movflags", "+faststart", web_clip,
|
"-c:v", "libx264", "-profile:v", "baseline", "-level", "3.1",
|
||||||
], capture_output=True, timeout=20)
|
"-preset", "fast", "-crf", "28",
|
||||||
|
"-vf", "scale=-2:720", # downsample to 720p — enough for review
|
||||||
|
"-an", # no audio needed for surveillance
|
||||||
|
"-movflags", "+faststart", # moov atom at front for streaming
|
||||||
|
web_clip,
|
||||||
|
], capture_output=True, timeout=60)
|
||||||
if os.path.exists(web_clip):
|
if os.path.exists(web_clip):
|
||||||
os.replace(web_clip, clip_path)
|
os.replace(web_clip, clip_path)
|
||||||
|
else:
|
||||||
|
log.warning("Transcode failed, keeping raw clip")
|
||||||
|
|
||||||
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")
|
||||||
|
|||||||
Reference in New Issue
Block a user