Overview
The media worker is a BullMQ-based background processor that handles all FFmpeg, ImageMagick, and yt-dlp operations. It polls themedia_jobs collection every 1.5 seconds and executes operations asynchronously.
Source: media-worker/index.jspm2 name:
media-workerQueue: Redis-backed BullMQ (polls
media_jobs collection)
Architecture
Polling System
MEDIA_WORKER_CONCURRENCY)
Environment Variables
| Variable | Default | Purpose |
|---|---|---|
DIRECTUS_URL | http://127.0.0.1:8055 | Directus API base |
DIRECTUS_ADMIN_TOKEN | agentx-directus-admin-static-2026 | Admin auth token |
CREDENTIALS_ENC_KEY_B64 | — | AES-256-GCM key for decrypting download credentials |
MEDIA_WORKER_ID | media-worker-1 | Worker instance ID |
MEDIA_WORKER_POLL_MS | 1500 | Poll interval (ms) |
MEDIA_TMP_DIR | /tmp/agentx-media | Temp directory for processing |
Operations
Watermarking
Operation:apply_watermarkSupported formats: Images (JPG, PNG, WebP) and videos (MP4)
Parameters
Image Watermarking (ImageMagick)
- Scales watermark to 15% of source image width
- Uses
compositecommand with-dissolvefor 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_teaserUse case: Generate preview clips for social media (TikTok, Instagram Reels, X)
Parameters
Blur Effect
Whenadd_blur_end: true, the worker:
- Extracts the full teaser duration
- Splits into clean segment (0 to duration-2s) and blur segment (last 2s)
- Applies progressive Gaussian blur:
gblur=sigma=20 - Concatenates both segments
Video Compression
Operation:compress_videoUse case: Reduce file size for platform uploads
Parameters
libx264)Audio: Copy (no re-encode)
Metadata Stripping
Operations:strip_metadataUse 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.mp4Removes: 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_videoSupported 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 thedownload_credentials collection:
- Maps input URL domain → platform slug (e.g.,
onlyfans.com→onlyfans) - Fetches active credentials scoped to creator profile
- Decrypts credentials using
CREDENTIALS_ENC_KEY_B64 - Adds
--cookies cookies.txtor-u username -p passwordto yt-dlp args
Image Operations
Resize Image
convert input -resize 1920x1080 output.jpg
Crop Image
convert input -crop 1080x1080+0+0 +repage output.jpg
Convert Image
convert input -quality 85 output.webp
Steganographic Watermarking
Operation:apply_steganographic_watermarkUse case: Embed invisible buyer fingerprints for leak tracking
Parameters
How It Works
- Embeds
{ userId, timestamp, contentId }in red channel LSBs - Offset determined by
userIdhash (unique per buyer) - Invisible to naked eye (~0.4% pixel change)
- Survives JPEG compression and social media re-encoding
server/utils/steganography.js (lazy-loaded by worker)
Job Management
Enqueue a Job (from Dashboard)
Check Job Status
Operations Registry
All 17 operations registered inmedia-worker/index.js:1161-1184:
| Operation | Category | Tools |
|---|---|---|
convert_image | Image | ImageMagick |
resize_image | Image | ImageMagick |
crop_image | Image | ImageMagick |
resize_video | Video | FFmpeg |
crop_video | Video | FFmpeg |
compress_video | Video | FFmpeg |
download_video | Download | yt-dlp |
ytdlp_info | Download | yt-dlp |
trim_videos | Video | FFmpeg |
join_videos | Video | FFmpeg |
apply_watermark | Protection | FFmpeg + ImageMagick |
create_teaser | Video | FFmpeg |
strip_metadata | Privacy | FFmpeg + Sharp/ImageMagick |
apply_steganographic_watermark | Protection | Sharp |
scrape_profile | Scraping | Stagehand (see Platform Scraping) |
publish_post | Publishing | Stagehand (see Post Scheduling) |
Logs & Debugging
Related
- Platform Scraping —
scrape_profileoperation - Post Scheduling —
publish_postoperation - Dashboard — Job enqueue from UI
