Skip to content

orianexxx/FramesComparer-lambda

Repository files navigation

FramesComparer-lambda

A Lambda function that compares video frames between monitored and watched videos, using frame similarity analysis to detect potential content matches.

Overview

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.

Features

  • 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

Prerequisites

  • AWS Lambda environment
  • S3 bucket for frame storage
  • Supabase instance
  • Python 3.x

Environment Variables

The following environment variables need to be configured:

  • SUPABASE_URL: Your Supabase project URL
  • SUPABASE_KEY: Your Supabase API key
  • S3_BUCKET: S3 bucket name for frame storage (default: "oriane-contents")
  • DEBUG: Enable debug logging (optional, default: "False")

Input Format

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"
}

Output Format

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
    }
}

S3 Structure

Frames should be stored in S3 with the following structure:

<platform>/<shortcode>/frames/0.<extension>
<platform>/<shortcode>/frames/1.<extension>
...

Database Schema

ai_jobs

  • job_id: UUID (primary key)

ai_results

  • id: Auto-incrementing primary key
  • job_id: UUID (foreign key to ai_jobs)
  • model: String (e.g., "FCM")
  • monitored_video: String
  • watched_video: String
  • avg_similarity: Float
  • processed_in_secs: Float
  • frame_results: JSON array
  • max_similarity: Float

insta_content

  • code: String
  • is_monitored: Boolean

Error Handling

The function includes comprehensive error handling and logging:

  • Invalid input validation
  • S3 access errors
  • Supabase connection issues
  • Frame processing errors

Dependencies

  • boto3
  • supabase
  • hashlib (built-in)
  • uuid (built-in)
  • logging (built-in)

Development

To enable debug logging, set the DEBUG environment variable to "true", "1", or "yes".

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published