Watermark and Edit YouTube Videos at Scale: A Download-to-FFmpeg Pipeline

8 min read Summarize with Claude ChatGPT Gemini Perplexity
Watermark and Edit YouTube Videos at Scale: A Download-to-FFmpeg Pipeline

Who builds this, and why it's hard

Brands repurpose their long videos into Shorts and Reels. Agencies add client logos and intros. Creator tools burn captions in because most social video is watched without sound. They're all products built on top of video their users already own.

The edits are well understood: FFmpeg has done them for years. What breaks is the first step. A pipeline that pulls videos from YouTube on a server hits bot checks, IP bans and format changes, and a stuck download means a customer waiting on an edit that never starts.

The pipeline

  1. Ingest. A customer connects their channel or pastes video links.
  2. Download. Each video is fetched with its captions and metadata.
  3. Transform. One FFmpeg pass applies the crop, captions, watermark and resize.
  4. Check. Duration, resolution and file size are checked before anything is delivered.
  5. Deliver. Files go to the customer's storage, or are queued for publishing.
Pipeline for editing YouTube videos: ingest, download, transform, check, deliver
Ingest → download → one FFmpeg pass → check → deliver.

Step 1: Download with what you'll need later

Edit tools need a good-quality source, plus the captions and the metadata. Ask for all three in one request. The fetch_source helper is the same one from our clipping app guide:

Python
import os, time, requests

API_BASE = "https://api.videodl.app"
HEADERS = {"X-API-Key": os.environ["VIDEODL_API_KEY"]}

def fetch_source(url, resolution="720", **extras):
    r = requests.post(f"{API_BASE}/api/start-download", headers=HEADERS,
                      json={"url": url, "resolution": resolution, **extras}, timeout=60)
    r.raise_for_status()
    worker_id = r.json()["worker_id"]
    while True:
        s = requests.get(f"{API_BASE}/api/download-status", headers=HEADERS,
                         params={"worker_id": worker_id}, timeout=60)
        if s.status_code == 429:
            time.sleep(s.json().get("retry_after", 5))
            continue
        data = s.json()
        if data["status"] == "downloaded":
            return data
        if data["status"] == "error":
            raise RuntimeError(f'{data["error_label"]}: {data["error"]}')
        time.sleep(3)

src = fetch_source(url, resolution="1080", captions=True,
                   caption_langs="en", info_json=True)
video_url = src["download_url"]
srt_url = src["extras"]["captions"][0]
meta_url = src["extras"]["info_json"]

The metadata file has the title, duration and description. Use it to plan the edit, for example to skip videos that are too long for a Short, before spending any CPU time.

Step 2: Add a watermark

Scale the logo relative to the video so it looks the same on 720p and 4K, and soften it so it doesn't fight the content:

bash
ffmpeg -i source.mp4 -i logo.png -filter_complex \
  "[1][0]scale2ref=w=oh*mdar:h=ih*0.08[wm][base];[wm]format=rgba,colorchannelmixer=aa=0.7[wm2];[base][wm2]overlay=W-w-24:H-h-24" \
  -c:a copy watermarked.mp4

Step 3: Burn in the captions

You already downloaded the captions as SRT, so burning them in is one filter:

bash
ffmpeg -i source.mp4 \
  -vf "subtitles=captions.en.srt:force_style='Fontsize=22,Outline=2,MarginV=40'" \
  -c:a copy captioned.mp4

Step 4: Make it vertical

The simple version crops the centre of a 16:9 video to 9:16:

bash
ffmpeg -i source.mp4 -vf "crop=ih*9/16:ih,scale=1080:1920" -c:a copy vertical.mp4

When the subject isn't centred, place the whole frame over a blurred, enlarged copy of itself so nothing gets cut off:

bash
ffmpeg -i source.mp4 -filter_complex \
  "[0]scale=1080:1920:force_original_aspect_ratio=increase,crop=1080:1920,boxblur=20[bg];[0]scale=1080:-2[fg];[bg][fg]overlay=(W-w)/2:(H-h)/2" \
  -c:a copy vertical-blur.mp4
Before and after: a 16:9 video turned into a 9:16 vertical video with captions and a logo
Before: the original 16:9 video. After: 9:16 with burned-in captions and a watermark, from one FFmpeg command.

Step 5: Do it all in one pass

Running those steps one after another re-encodes the video four times. Each pass costs CPU and loses a little quality. Chain them into one filter graph instead:

bash
ffmpeg -i source.mp4 -i logo.png -filter_complex \
  "[0]crop=ih*9/16:ih,scale=1080:1920,subtitles=captions.en.srt:force_style='Fontsize=18,Outline=2,MarginV=120'[v];[1]scale=160:-1,format=rgba,colorchannelmixer=aa=0.7[wm];[v][wm]overlay=W-w-40:60" \
  -c:v libx264 -crf 20 -preset veryfast -c:a aac -movflags +faststart short.mp4

-movflags +faststart moves the index to the front of the file, so the result starts playing in a browser before it has fully downloaded.

Scaling the workers

  • One encode per job. Keep each job to one FFmpeg pass and one output. It's easier to retry, and easier to price.
  • Size the pool to CPU, not to downloads. Encoding is the expensive part. If you have GPUs, encoders like h264_nvenc cut encode time sharply.
  • Make jobs idempotent. Name outputs after the video ID and edit settings, so a retried job overwrites the same file instead of creating a duplicate.
  • Keep sources in your bucket. Have the download API deliver straight to your S3 or Google Cloud Storage. Workers read from there, and the source never expires.

Keep the download layer boring

Your customers judge you on the edit, not the download. A managed download API retries temporary failures for you and only reports errors you can act on, such as a private video or a live stream that hasn't ended. That keeps the hardest-to-debug part of the pipeline out of your on-call rotation.

A note on rights

Build branding and editing tools for content your users own or are licensed to edit, such as their own channels or a client's videos. Make that clear in your terms.

FAQ

How do I add a watermark to a video with FFmpeg?

Use the overlay filter with your logo as a second input, for example overlay=W-w-24:H-h-24 for the bottom-right corner. Scale the logo relative to the video width so it looks the same on every resolution.

How do I burn YouTube captions into a video?

Download the captions as an SRT file along with the video, then use FFmpeg's subtitles filter. You can style the font size and outline with force_style.

How do I turn a 16:9 YouTube video into a 9:16 vertical video?

Crop the centre to a 9:16 frame and scale it to 1080x1920. For a softer look, place the original over a blurred, enlarged copy of itself instead of cropping.

Why should I combine edits into one FFmpeg command?

Every re-encode costs CPU time and loses a little quality. Chaining crop, scale, watermark and captions in one filter graph encodes the video once.

Can I watermark any YouTube video?

Only videos you own or are licensed to edit. Branding tools are typically built for creators and companies repurposing their own channels.

Spend your CPU on edits, not on downloads

Get every source video with captions and metadata, delivered to your own bucket. Priced per video. First 100 free.