A Lambda function that compares video frames between monitored and watched videos, using frame similarity analysis to detect potential content matches.
This Lambda function processes video frames stored in S3, comparing frames from a monitored video against frames from watched videos. It uses a similarity algorithm based on SHA-256 hash differences to determine frame similarity and stores the results in Supabase.
- Frame comparison using hash-based similarity analysis
- Support for multiple video platforms (default: Instagram)
- Integration with AWS S3 for frame storage
- Results storage in Supabase
- Job tracking and deduplication
- Configurable debug logging
- AWS Lambda environment
- S3 bucket for frame storage
- Supabase instance
- Python 3.x
The following environment variables need to be configured:
SUPABASE_URL: Your Supabase project URLSUPABASE_KEY: Your Supabase API keyS3_BUCKET: S3 bucket name for frame storage (default: "oriane-contents")DEBUG: Enable debug logging (optional, default: "False")
The function accepts input in the following format:
{
"job_id": "optional-uuid",
"monitored_shortcode": "required-video-code",
"watched_shortcodes": ["video-code-1", "video-code-2"],
"platform": "instagram",
"extension": "jpg"
}The function returns results in the following format:
{
"statusCode": 200,
"body": {
"message": "Processing completed",
"results": [
{
"job_id": "uuid",
"model": "FCM",
"monitored_video": "video-code",
"watched_video": "video-code",
"avg_similarity": 0.95,
"processed_in_secs": 1.23,
"frame_results": [...],
"max_similarity": 0.98
}
],
"total_time": 2.45
}
}Frames should be stored in S3 with the following structure:
<platform>/<shortcode>/frames/0.<extension>
<platform>/<shortcode>/frames/1.<extension>
...
job_id: UUID (primary key)
id: Auto-incrementing primary keyjob_id: UUID (foreign key to ai_jobs)model: String (e.g., "FCM")monitored_video: Stringwatched_video: Stringavg_similarity: Floatprocessed_in_secs: Floatframe_results: JSON arraymax_similarity: Float
code: Stringis_monitored: Boolean
The function includes comprehensive error handling and logging:
- Invalid input validation
- S3 access errors
- Supabase connection issues
- Frame processing errors
- boto3
- supabase
- hashlib (built-in)
- uuid (built-in)
- logging (built-in)
To enable debug logging, set the DEBUG environment variable to "true", "1", or "yes".