Building Viralio, an AI Video Clipper CMS

Notes on building Viralio — a Laravel + Filament app that turns long YouTube videos into scored, subtitled vertical clips automatically, and publishes them straight back to YouTube.

8 min read

I built Viralio: paste a YouTube URL in, get a set of scored, subtitled, vertical short clips out — the kind of Shorts/Reels/TikTok cutting that’s normally a manual, tedious editing job. This one turned into my most ambitious side project so far, mostly because it’s not really one feature, it’s a pipeline: download, transcribe, analyze, cut, reframe, subtitle, thumbnail, and now even publish, each step its own queued job.

What It Does

You paste a YouTube URL into a Filament admin panel. From there:

  1. The video downloads via yt-dlp
  2. Audio gets extracted and transcribed
  3. Gemini reads the transcript and picks the strongest highlight moments
  4. Each highlight becomes a clip: cut, reframed to 9:16, subtitled, and given a thumbnail
  5. Finished clips show up with inline preview and download — or get pushed straight to a connected YouTube channel

The whole thing runs on Laravel 12, PHP 8.4, Filament v4, PostgreSQL, Redis, Horizon, FFmpeg, yt-dlp, and Gemini.

A Pipeline, Not a Feature

The part I spent the most time getting right wasn’t any single step — it was making sure a nine-step pipeline with an AI call and heavy media processing in the middle could fail gracefully, retry, and not take down every other video in flight when one thing goes wrong.

The architecture stays deliberately thin at the framework layer. Controllers and Filament pages call Actions, which orchestrate Jobs, Services, and Repositories:

CreateVideoAction
  └─ Bus::chain:
       DownloadYoutubeJob → ExtractAudioJob → TranscribeAudioJob → AnalyzeHighlightJob
                                                                        │
                        Bus::batch (one chain per highlight) ───────────┘
                          GenerateClipJob → GenerateSubtitleJob → GenerateThumbnailJob
                                                                        │
                                                              FinishVideoJob (batch → then)

The first four steps are a strict Bus::chain — downloading has to finish before extraction, extraction before transcription, and so on. Once highlights are identified, though, each highlight’s clip pipeline runs as its own chain inside a Bus::batch, so a dozen highlights get cut, subtitled, and thumbnailed in parallel instead of one after another. FinishVideoJob runs once the whole batch settles, whether some clips failed or not.

Every step writes a processing_logs entry and a queue_histories row, and updates the video or clip status directly. A failure in one clip’s chain raises a typed exception and marks that clip failed — it doesn’t cancel its siblings or the batch. Kicking the whole thing off from the entry point stays almost boring:

final class CreateVideoAction
{
    public function execute(string $youtubeUrl, ?int $userId = null): Video
    {
        $youtubeId = YoutubeUrl::extractId($youtubeUrl);
        // ...validate, persist a Video row as Pending...
        return $this->startProcessing->execute($video);
    }
}

All the actual complexity — chaining, batching, retries — lives behind StartProcessingAction, not scattered across a controller.

Letting Gemini Pick the Highlights

The core value proposition is: a 40-minute video has maybe three or four moments actually worth clipping, and finding them by hand is the slow part. Gemini reads the transcript and scores each candidate segment 0–100 across six axes — hook, curiosity, emotion, education, entertainment, shareability — plus an overall score.

The model is asked to return strict JSON, and that response gets validated before anything touches the database — malformed output raises a GeminiException rather than silently persisting garbage. Prompts live centralized in App\Services\Gemini\Prompts, not inlined next to the API call, so tuning the scoring criteria doesn’t mean hunting through job classes to find where the prompt actually lives.

Transcription itself is behind a TranscriptionManager that can route to either Gemini or Whisper — swapping the provider is a config change, not a pipeline edit, same as swapping the storage disk from local to S3.

Turning a Highlight into a Clip

Once a highlight is picked, FfmpegService cuts the segment, reframes it to 9:16 for vertical viewing, and a SubtitleGenerator produces an SRT track from the transcript slice. A thumbnail gets pulled from the clip itself. Each of those is its own job (GenerateClipJob, GenerateSubtitleJob, GenerateThumbnailJob) rather than one monolithic “process the clip” job — partly for retry granularity (a thumbnail failure shouldn’t force re-cutting the video), partly because Horizon’s per-job visibility becomes genuinely useful for debugging when you can see exactly which of the three steps stalled.

Publishing Straight to YouTube

This is the part that went further than I originally scoped: clips don’t just sit there waiting to be downloaded, they can be pushed straight to a connected YouTube channel from the admin panel. Connect a channel via Google OAuth2 once, and from then on:

  • Click Upload to YouTube on any completed clip
  • Fill in title, description, tags, category, privacy, and — optionally — a scheduled publish time
  • The upload is queued (resumable, chunked) and retryable from an Upload Queue view, with the same job re-run on retry rather than a duplicate
  • Access tokens refresh automatically before every upload and hourly for anything close to expiring; if a refresh token gets revoked, the account is flagged Reconnect Required instead of failing silently
  • Views/likes/comments sync hourly per connected channel via a scheduled job
'.../auth/youtube.upload'
'.../auth/youtube.readonly'
'.../auth/youtube.force-ssl'

Scheduling publish time without a separate cron system was a nice side effect of already being on a queue: a future timestamp just means the job is dispatched with a delay. No extra scheduler logic needed for something that’s fundamentally “run this job later.”

Admin Panel: Filament, Not a Custom Build

The entire operator-facing UI — video submission, pipeline progress, clip previews, YouTube account management, settings, API keys — is Filament v4, not a hand-rolled dashboard. For an internal tool like this, that trade was an easy one: Filament’s resource/table/form conventions cover CRUD and status views almost for free, and the time saved went into the pipeline and the Gemini integration instead of building yet another admin table component.

API keys and OAuth client secrets are encrypted at rest, and settings that need to be tunable without a redeploy — Gemini model, binary paths, default clip settings — live in a system_settings table with a config-first, DB-override pattern, cached after first read.

Shipping It

Everything is containerized:

ServicePurpose
nginxWeb entrypoint → Filament panel + API
appPHP-FPM — Laravel, ffmpeg, yt-dlp baked into the image
horizonQueue worker for the whole pipeline
schedulerRuns schedule:work — Horizon snapshots, pruning, hourly analytics/token-refresh jobs
postgresDatabase
redisCache, queue, sessions

The last piece I added was Caddy in front of the internal nginx service, purely for TLS:

{$APP_DOMAIN} {
    encode zstd gzip
    request_body {
        max_size 512MB
    }
    reverse_proxy nginx:80
    header {
        Strict-Transport-Security "max-age=31536000; includeSubDomains"
        X-Content-Type-Options "nosniff"
        X-Frame-Options "SAMEORIGIN"
        Referrer-Policy "strict-origin-when-cross-origin"
        -Server
    }
}

Caddy provisions and renews the Let’s Encrypt certificate automatically, so nginx stays internal-only and doesn’t need to know anything about certificates at all — it just serves plain HTTP on the Docker network and lets Caddy handle the public edge. The max_size 512MB on the request body is there deliberately: generated clips can be sizeable, and the default limit would otherwise reject exactly the uploads this app exists to produce.

What I Learned

  • Chain what must be sequential, batch what doesn’t need to be. The download-to-transcript steps are strictly ordered; once you have highlights, there’s no reason to cut clips one at a time. Mixing Bus::chain and Bus::batch in the same pipeline mapped that naturally instead of forcing everything into one shape.
  • One job per side effect beats one job per feature. Splitting clip generation into cut/subtitle/thumbnail jobs made retries cheap and Horizon’s dashboard actually diagnostic instead of a black box.
  • Validate AI output like any other untrusted input. Gemini returning well-formed JSON almost all the time is not the same as always — the strict-JSON-then-validate step turned “occasionally garbage in the database” into a clean, typed exception.
  • Let the admin framework carry the boring 80%. Filament wasn’t a compromise here — it freed up the time that went into the parts of this project that actually needed custom thought: the pipeline and the Gemini prompts.
  • TLS is infrastructure, not application code. Keeping nginx internal-only and letting Caddy own certificates at the edge meant the app never has to think about renewal — one less thing that can silently expire.

The roadmap still has social publishing to other platforms, face/speaker detection, and multi-language support sitting as clean extension points. But even at this stage, watching a raw YouTube URL turn into ready-to-publish vertical clips with zero manual editing is still the most satisfying “it actually works” moment I’ve had on a side project in a while.