How povzayd/p-per works
Purpose and Entry Points
This is a terminal-oriented forensic media recovery pipeline: recover JPEG byte ranges from binary evidence, optionally triage them with ML, then reconstruct and annotate a video. Primary executables are pcap2img.py, pcap2imgv2.py, and videogen.py. Included sample evidence includes security-footage-1648933966395.pcap and security-footage-1648933966395.mp4.
1. Lightweight JPEG Carving
pcap2img.py is the interactive, lower-resource extractor. It prompts for an input file, scans its raw bytes for JPEG SOI/EOI signatures (FFD8 / FFD9), and writes sequential frame_XXXX.jpg files into an input-derived directory. It is the simple recovery path for dumps, captures, or media containers, with no protocol-level PCAP parsing or deep JPEG validation.
2. Scalable Extraction and CLI Boundary
pcap2imgv2.py is the automated/high-volume entry point. Its argparse interface accepts required input plus output-directory, archive, and classification options. It processes evidence in chunks to constrain memory use, recovers JPEG ranges, records extraction metrics, and can package the resulting frame directory as ZIP. This creates the main handoff boundary to downstream analysis: a directory or archive of recovered JPEG frames.
3. Optional ImageNet Classification
The --classify branch in pcap2imgv2.py loads pretrained MobileNetV2 through PyTorch/torchvision and applies it to successfully recovered frames. Classification is optional because it adds substantial CPU/GPU and model-runtime cost and may fail or mislabel damaged/non-natural forensic imagery. Labels are triage metadata rather than extraction criteria.
4. Frame-Sequence Ingestion
videogen.py consumes either a frame directory or ZIP archive, orders/loads image frames, derives timestamps from metadata where available, normalizes frames to the selected output resolution, and emits an MP4. Its input contract aligns directly with both extractor outputs, allowing recovery and reconstruction to be invoked as separate stages.
5. Privacy and Evidence Annotation
During video generation, videogen.py can detect faces using OpenCV Haar cascades, either draw detection boxes or blur detected regions. It can also invoke Tesseract OCR to extract visible text and log frame metadata/OCR output to CSV. OCR is explicitly bypassable for faster rendering; face detection and anonymization remain opt-in transformations on recovered evidence.
6. Motion Analysis and Heatmaps
videogen.py computes motion from consecutive grayscale frames via differencing, thresholding, dilation, contour detection, and an accumulated motion matrix. With motion highlighting enabled, detected regions are overlaid on video frames and an OpenCV color-mapped heatmap image is saved; preview is optional. This analysis depends on temporal ordering and treats minor frame changes as potential motion.
Runtime and External Dependencies
The repository is Python-based, with dependencies declared in requirements.txt. Extraction uses CLI/progress/logging libraries; advanced classification requires PyTorch and torchvision and may use CUDA if installed. Video reconstruction depends on OpenCV, Pillow, NumPy, and system-accessible Tesseract via pytesseract. Outputs are local files: JPEG frames, optional ZIPs, MP4 video, CSV logs, and heatmap JPEGs.
Main entry points: videogen.py Frame normalization and MP4 · pcap2imgv2.py Scalable extractor · pcap2img.py Interactive carver
Components 17
JPEG Recovery
- Binary evidence · PCAPs, dumps, or media containers scanned as raw bytes.
- Interactive carver · Low-resource manual recovery path.
pcap2img.py - Scalable extractor · Chunked argparse-driven extraction with metrics.
pcap2imgv2.py - JPEG range recovery · Finds SOI/EOI byte ranges.
- Recovered frames · Sequential frame_XXXX.jpg output and downstream handoff.
- Frame archive · Optional packaged frame directory.
Optional Triage
- MobileNetV2 classifier · PyTorch/torchvision ImageNet triage for recovered frames.
pcap2imgv2.py - Triage labels · Labels do not determine extraction.
Video Reconstruction
- Video generator · Consumes frame directories or ZIP archives.
videogen.py - Frame ordering and timestamps · Loads frames and derives metadata timestamps where available.
videogen.py - Frame normalization and MP4 · Resizes frames to output resolution and emits video.
videogen.py - Face annotation or blur · Haar detection can draw boxes or anonymize faces.
videogen.py - OCR and CSV logging · Extracts visible text and frame metadata.
videogen.py - Motion analysis · Differences consecutive grayscale frames and finds regions.
videogen.py - Reconstructed video
- OCR metadata log
- Motion heatmap · Optional accumulated motion visualization.
Connections 20
- Binary evidence → Interactive carver: interactive input
- Binary evidence → Scalable extractor: CLI input
- Interactive carver → JPEG range recovery: raw scan
- Scalable extractor → JPEG range recovery: chunked scan
- JPEG range recovery → Recovered frames: write JPEGs
- Scalable extractor → Frame archive: optional ZIP
- Recovered frames → MobileNetV2 classifier: --classify
- MobileNetV2 classifier → Triage labels: ImageNet labels
- Recovered frames → Video generator: frame directory
- Frame archive → Video generator: ZIP input
- Video generator → Frame ordering and timestamps: load sequence
- Frame ordering and timestamps → Face annotation or blur: ordered frames
- Face annotation or blur → OCR and CSV logging: annotated frames
- OCR and CSV logging → Motion analysis: render path
- Frame ordering and timestamps → Frame normalization and MP4: normalized sequence
- Face annotation or blur → Frame normalization and MP4: optional transform
- Motion analysis → Frame normalization and MP4: optional overlays
- Frame normalization and MP4 → Reconstructed video: write MP4
- OCR and CSV logging → OCR metadata log: write CSV
- Motion analysis → Motion heatmap: save heatmap