Skip to main content

Overview

The media worker is a BullMQ-based background processor that handles all FFmpeg, ImageMagick, and yt-dlp operations. It polls the media_jobs collection every 1.5 seconds and executes operations asynchronously. Source: media-worker/index.js
pm2 name: media-worker
Queue: Redis-backed BullMQ (polls media_jobs collection)

Architecture

Polling System

Concurrency: 1 (configurable via MEDIA_WORKER_CONCURRENCY)

Environment Variables

Operations

Watermarking

Operation: apply_watermark
Supported formats: Images (JPG, PNG, WebP) and videos (MP4)

Parameters

Image Watermarking (ImageMagick)

  • Scales watermark to 15% of source image width
  • Uses composite command with -dissolve for opacity
  • Preserves aspect ratio

Video Watermarking (FFmpeg)

  • Converts watermark to half-transparent PNG
  • Applies overlay filter: [1:v]scale=iw*0.15:-1[wm];[0:v][wm]overlay=...
  • Re-encodes with H.264 (preset: veryfast, CRF: 22)

Teaser Clip Generation

Operation: create_teaser
Use case: Generate preview clips for social media (TikTok, Instagram Reels, X)

Parameters

Blur Effect

When add_blur_end: true, the worker:
  1. Extracts the full teaser duration
  2. Splits into clean segment (0 to duration-2s) and blur segment (last 2s)
  3. Applies progressive Gaussian blur: gblur=sigma=20
  4. Concatenates both segments

Video Compression

Operation: compress_video
Use case: Reduce file size for platform uploads

Parameters

Codec: H.264 (libx264)
Audio: Copy (no re-encode)

Metadata Stripping

Operations: strip_metadata
Use case: Remove EXIF/GPS/device data before sharing content

Image Stripping (Sharp or ImageMagick)

Primary: sharp().withMetadata(false)
Fallback: convert +profile "*" (removes all embedded profiles/EXIF)

Video Stripping (FFmpeg)

Command: ffmpeg -i input.mp4 -map_metadata -1 -c copy output.mp4
Removes: Global metadata, stream metadata, chapter metadata
Auto-strip: The download_video and scrape_profile operations automatically strip metadata from all downloaded files before upload to Directus.

Download Video (yt-dlp)

Operation: download_video
Supported platforms: YouTube, TikTok, Instagram, X, Reddit, OnlyFans, Fansly, Pornhub, XVideos, and 10+ more

Parameters

Credential Injection

The worker automatically injects cookies or username/password from the download_credentials collection:
  1. Maps input URL domain → platform slug (e.g., onlyfans.comonlyfans)
  2. Fetches active credentials scoped to creator profile
  3. Decrypts credentials using CREDENTIALS_ENC_KEY_B64
  4. Adds --cookies cookies.txt or -u username -p password to yt-dlp args

Image Operations

Resize Image

Command: convert input -resize 1920x1080 output.jpg

Crop Image

Command: convert input -crop 1080x1080+0+0 +repage output.jpg

Convert Image

Command: convert input -quality 85 output.webp

Steganographic Watermarking

Operation: apply_steganographic_watermark
Use case: Embed invisible buyer fingerprints for leak tracking
Requires sharp npm package. Falls back to copying file unchanged if sharp is unavailable.

Parameters

How It Works

  1. Embeds { userId, timestamp, contentId } in red channel LSBs
  2. Offset determined by userId hash (unique per buyer)
  3. Invisible to naked eye (~0.4% pixel change)
  4. Survives JPEG compression and social media re-encoding
Implementation: server/utils/steganography.js (lazy-loaded by worker)

Job Management

Enqueue a Job (from Dashboard)

Check Job Status

Operations Registry

All 17 operations registered in media-worker/index.js:1161-1184:

Logs & Debugging