Under the Hood.

How SnapMusic transforms your static assets into viral videos using robust cloud engineering.

1
📤

Upload & Validate

User uploads Image (JPG/PNG) & Audio (MP3/WAV). System validates mime-types and file integrity.

POST /upload
Content-Type: multipart/form-data
2
⚙️

Queue & Encode

Job pushed to queue. Worker picks it up and triggers FFmpeg conversion.

App\Jobs\ProcessVideoJob
dispatch($video)
3
💾

Store & Notify

MP4 stored in private storage. Frontend polls for completion status.

Status: COMPLETED
storage/app/videos/{id}.mp4

📹 The FFmpeg Engine

We use FFmpeg to combine the static image and audio stream. Crucially, we apply a complex filter to ensure compatibility across all players.

Scale Filter Logic

scale=trunc(iw/2)*2:trunc(ih/2)*2

Why? H.264 encoding requires even dimensions. This filter forces width and height to be divisible by 2, preventing encoding errors on odd-sized user images.

Async Queue Workers

Video processing is heavy. To keep the UI snappy, we offload the heavy lifting to background workers.

Worker Command

php artisan queue:work --tries=3 --timeout=120

How it works: The web request finishes instantly, returning a "Pending" status. The worker picks up the job, runs FFmpeg, and updates the database state to "Completed".

System Data Flow

Client (Browser)
POST /videos
Laravel Web Server
Database (Job Created)
Dispatch
Queue Worker
FFmpeg Process
Storage (MP4)