Ingest and media analysis
Every Verity case begins with two cheap, foundational stages before any neural detector spins up: admitting the file immutably (MediaIngestor) and measuring its intrinsic technical characteristics (MediaAnalyzer). Together, they establish byte identity and feed DetectorSelector with the facts needed to exclude unsuitable detectors upfront.
Ingest: content-addressed admission (MediaIngestor)
src/verity/ingest/media_ingestor.py admits media files deterministically:
- Resolves the source path (
FileNotFoundErrorif missing) and streams bytes in 64 KiB chunks to compute a full SHA-256 digest. - Assigns
media_id = checksum[:12](MEDIA_ID_LENGTH = 12). - Classifies container MIME type using
filetypeintoMediaType(image,video,audio, orunknown). - Copies the file once into
workspace/media/<media_id><suffix>(skipping if already present) and locks permissions to read-only (chmod 0o444). - Persists a
MediaInfosidecar atworkspace/media/.<media_id>.jsonrecordingoriginal_path,media_type, fullchecksum,size_bytes,mime_type,original_name, and UTCingested_at.
Because the ID derives strictly from file bytes, re-ingesting an identical exhibit is idempotent, while any single-byte edit creates a separate case instead of silently mutating an existing case record.
Analysis: deterministic characterization (MediaAnalyzer)
src/verity/analyze/media_analyzer.py inspects the read-only working copy without modifying any workspace state:
- Container & stream characterization (
_ffprobe): invokesffprobeforvideo_codec,fps,width,height,frame_count(or duration * fps estimate),duration_seconds, andhas_audio_track. Ifffprobeis absent or fails,MediaAnalyzerkeeps filename-derived defaults and continues smoothly. - Deterministic Haar face scan (
_scan_faces): initializes OpenCV'shaarcascade_frontalface_default.xml(bundled cleanly viacv2.data.haarcascadeseven inside PyInstaller binaries) withscaleFactor=1.1,minNeighbors=5,minSize=(40, 40).- For images, inspects the single frame.
- For videos, decodes sequentially via
cv2.VideoCapturereading frames atinterval = max(1, total // 30)(MAX_SAMPLED_FRAMES = 30). Why sequential reading instead of keyframe seeking? Seeking lands on decoder-dependent keyframes across codecs/ffmpeg builds, whereas sequential modulus stride always inspects identical frame indices.
- Computes
face_present,face_count,max_face_size, andsampled_frames, saving<output_dir>/<media_id>/analysis.json.
Why analysis is separate from extraction
verity analyze (and POST /api/analyze) runs cleanly without heavy extraction: an examiner can characterize media and inspect all 58 selection.json inclusion and exclusion reasons even on a lightweight laptop or before provisioning ffmpeg or detector environments. Keeping characterization cheap ensures expensive subprocess runs only launch after eligibility is verified.
Related pages
- Artifact extraction — extracting full PNG frames, crops, and audio.
- Detector selection and trust tiers — how
MediaAnalysisdrives selection rules. - Security, integrity and chain of custody —
verify_integrityandverity export.