---
name: ai-video-broadcast
description: Generate AI-powered broadcast-style videos — news shows, explainers, and narrated content — by combining web scraping, AI scriptwriting, text-to-speech, frame-by-frame rendering (Pillow), and ffmpeg encoding. Use when the user wants to create YouTube videos, news broadcasts, automated content channels, or any narrated video with AI-generated visuals and voice.
metadata:
  version: "1.0.0"
  tags: [video, broadcast, news, youtube, tts, ffmpeg, pillow, automation, content-creation]
---

# AI Video Broadcast

Generate professional broadcast-style videos using a fully automated AI pipeline: scrape news/events → write scripts → generate voice → render frames → encode video.

## When to Use

- User wants to create a YouTube news channel or news brief videos
- User wants automated video content generation
- User mentions "virtual anchor", "AI host", "news broadcast", "video channel"
- User wants to convert text/news into narrated video content
- Any task requiring batch video production with AI narration

## Pipeline Overview

```
Source Material → Script → TTS Audio → Frame Rendering → Video Encoding
(web scrape)    (AI write)  (text_to_speech)  (Pillow)      (ffmpeg)
```

## Step 1: Gather Source Material

Use the browser to scrape news from Google News or other sources:

```
# World news
https://news.google.com/topics/CAAqJggKIiBDQkFTRWdvSUwyMHZNRGx1YlY4U0FucG9HZ0pEVGlnQVAB?hl=en-US&gl=US&ceid=US:en

# Tech news
https://news.google.com/topics/CAAqJggKIiBDQkFTRWdvSUwyMHZNRGRqTVhZU0FucG9HZ0pEVGlnQVAB?hl=en-US&gl=US&ceid=US:en
```

Use `browser_navigate` + `browser_snapshot` to extract headlines and summaries. Aim for 5-8 stories per video.

## Step 2: Write the Script

Write a broadcast-style script in the target language. Structure:

```
- Greeting + date
- Story 1 (lead story, most detail)
- Story 2, 3, 4, 5...
- Sign-off
```

**Style guidelines:**
- Conversational but professional tone
- Each story: 2-3 sentences max
- Total script: aim for 60-90 seconds of speech
- Include transitions: "Turning to...", "In other news...", "And finally..."
- Write for the ear, not the eye — short sentences, simple words

Save script to a text file for reference.

## Step 3: Generate Audio

Use the `text_to_speech` tool:

```
text_to_speech(text=<full script>, output_path=/root/news-audio.mp3)
```

The tool uses Edge TTS by default. For higher quality, consider ElevenLabs (requires API key).

**Audio tips:**
- Keep total duration under 3 minutes for news briefs
- The tool returns an MP3 file
- Verify with `ffprobe` before proceeding

## Step 4: Render Video Frames

Use the Python + Pillow pipeline. See `scripts/gen_broadcast_video.py` for the full implementation.

**Prerequisites (install if missing):**
```bash
# ffmpeg
apt-get install -y ffmpeg

# Pillow (Python imaging)
apt-get install -y python3-pil
# OR if pip is available:
python3 -m pip install Pillow
```

**Key architecture decisions:**\n- Use Pillow for frame-by-frame rendering (not ffmpeg drawtext — it's unreliable on headless servers)\n- Generate PNG frames in a temp directory\n- Use ffmpeg to encode frames → video\n- Resolution: 1920x1080 (1080p) for professional YouTube output; 1280x720 for quick drafts\n- FPS: 30\n- For best quality: `-preset slow -crf 18`; for faster iteration: `-preset medium -crf 23`\n- Full HD + slow preset ≈ 10 min encoding time for 90s video on a standard VPS

**Visual layout per frame:**
- Top header bar (60px): "LIVE" indicator, channel name, date
- Left accent bar (8px): color-coded per segment
- Main content area: title + description text
- Right sidebar (180px): "AI ANCHOR" avatar box
- Bottom ticker (80px): scrolling headline text + "BREAKING" blink
- Color theme changes per news segment

**Avatar:** Draw a face with Pillow. For production quality, include:\n- Hair (arc + ellipse on top of head)\n- Eyes with whites, iris, pupils, and highlight dots\n- Eyebrow arcs\n- Nose (small arc)\n- Mouth that animates open/closed synced to speech rhythm (`math.sin(frame_num * 0.25)`)\n- Neck and shoulders/suit with tie in accent color\n- Blinking: `abs(math.sin(frame_num * 0.04)) > 0.97` → shrink eye height\n\nFor ultimate quality, replace with HeyGen or D-ID API.

## Step 5: Encode Video

```bash
# Step A: frames → video
ffmpeg -y -framerate 30 -i frames/frame_%06d.png \
  -c:v libx264 -preset medium -crf 23 \
  -pix_fmt yuv420p -movflags +faststart \
  video_only.mp4

# Step B: add audio
ffmpeg -y -i video_only.mp4 -i audio.mp3 \
  -c:v copy -c:a aac -b:a 128k \
  -shortest final_output.mp4
```

Use `-shortest` to trim video to audio length (frames may be slightly longer).

## Step 6: Cleanup

Remove temp frame directory and intermediate video file. Keep only the final output.

## Production Upgrade Path

The Pillow-based renderer produces basic but functional output. For production YouTube channels:

1. **Real B-Roll Footage** (highest impact): Source real news video clips to intercut with AI anchor segments. See "Sourcing Real News Footage" section below.
2. **Virtual Anchor**: Replace Pillow avatar with HeyGen or D-ID API for realistic talking-head video
3. **Better TTS**: Use ElevenLabs for more natural voice (set voice_id for consistency)
4. **Subtitles**: Burn subtitles into frames using Pillow `draw.text` with word-level timing
5. **Thumbnail**: Generate eye-catching thumbnails with Pillow or AI image generation
6. **Automation**: Set up a cron job to run the full pipeline daily

## Sourcing Real News Footage

For professional news broadcasts, real B-roll footage is essential. AI-generated backgrounds look amateur; real news clips build credibility.

### Method 1: Direct CDN Links (Fastest)

Many news sites embed videos with direct CDN URLs that can be downloaded with `curl`:

**AP News (JWPlayer CDN):**
```bash
# Scrape video page for MP4 links
curl -sL -H "User-Agent: Mozilla/5.0 ..." 'https://apnews.com/hub/videos' | grep -oP 'https?://cdn\.jwplayer\.com/videos/[^\s"\'<>]+\.mp4'
# Download
curl -sL -o clip.mp4 -H "Referer: https://apnews.com/" "https://cdn.jwplayer.com/videos/AYBcNbhG.mp4"
```

**India Today (tosshub CDN):**
```bash
curl -sL -H "User-Agent: Mozilla/5.0 ..." 'https://www.indiatoday.in/videos' | grep -oP 'https?://video-indiatoday\.tosshub\.com[^\s"\'<>]+\.mp4'
curl -sL -o clip.mp4 -H "Referer: https://www.indiatoday.in/" "<url>"
```

**Pattern:** Use `curl` + regex to extract `.mp4` URLs from page HTML, then download with proper `Referer` header.

### Method 2: yt-dlp (Limited on Ubuntu 22.04)

The system yt-dlp on Ubuntu 22.04 is **outdated (2022.04.08)** and cannot download YouTube videos due to YouTube's JS player changes. `yt-dlp -U` fails because apt manages the package. **Do not rely on yt-dlp for YouTube downloads on this server.**

If you must use YouTube footage, use the browser to find Creative Commons videos and download via alternative means.

### Method 3: Transcoding Clips

Downloaded clips need to be normalized before compositing:

```bash
# Scale to 720p, pad to fill, re-encode
ffmpeg -y -i raw_clip.mp4 -t 10 \
  -vf "scale=1280:720:force_original_aspect_ratio=decrease,pad=1280:720:(ow-iw)/2:(oh-ih)/2" \
  -c:v libx264 -preset ultrafast -crf 23 -c:a aac -b:a 128k \
  processed_clip.mp4
```

Use `ultrafast` preset for transcoding (speed matters more than compression for intermediate files).

### Compositing: Anchor + Real Footage Alternation

The professional pattern is: **Anchor introduces story → Real footage plays → Anchor summarizes → Next story**

```
[anchor_intro 3s] → [anchor_hanta 2s] → [real_clip1 8s] → [anchor_starmer 2s] → [real_clip2 8s] → ... → [anchor_outro 3s]
```

1. Generate anchor segments as PNG sequences → encode to short MP4s
2. Transcode real footage clips to matching format
3. Trim each to desired duration with `ffmpeg -t`
4. Concatenate with `ffmpeg -f concat`
5. Add audio track last

**Important:** The `terminal` tool does NOT support shell `&` backgrounding. Run ffmpeg commands sequentially or use `terminal(background=true, notify_on_complete=true)` for long operations.

### Reliable News Video Sources

| Source | Method | Notes |
|--------|--------|-------|
| AP News | JWPlayer CDN via curl | Works reliably, 480x270 clips |
| India Today | toshub CDN via curl | Works, 360x202 preview clips |
| Al Jazeera | Browser scrape | JS-rendered, harder to extract |
| BBC | Browser scrape | No direct MP4 links in HTML |
| NTA Nigeria | JSON API (not direct MP4) | Returns JSON metadata, not video |
| YouTube | yt-dlp broken | Use browser or alternative |
| Reuters | No direct MP4 in HTML | JS-rendered player |
| France24 | No direct MP4 in HTML | JS-rendered player |
| DW News | No direct MP4 in HTML | JS-rendered player |

**Key insight:** Indian news sites (India Today, NDTV) are more likely to have direct CDN MP4 links in their HTML than Western news sites (BBC, Reuters) which use JS-rendered players. For African news, options are very limited — consider using AP News or Reuters footage that covers African topics.

## Copyright & Fair Use

- Using short clips of news footage for news reporting falls under Fair Use in most jurisdictions
- Always add original narration/commentary — don't just rebroadcast
- Creative Commons sources (Pexels, Pixabay, Wikimedia) are safest
- Attribute sources in video description
- News headlines themselves are not copyrightable (facts), but the expression is

## Known Pitfalls

1. **ffmpeg drawtext filter is unreliable on headless servers.** Font paths may not resolve, filter syntax errors are cryptic. Use Pillow for text rendering instead.

2. **No pip3 on minimal Ubuntu.** Use `apt-get install python3-pil` instead of `pip install Pillow`.

3. **Font fallback.** Always wrap `ImageFont.truetype()` in try/except with `ImageFont.load_default()` fallback. DejaVu fonts are usually present on Ubuntu.

4. **Frame count mismatch.** Generate slightly more frames than needed, use `-shortest` in ffmpeg to trim to audio duration.

5. **Large temp directories.** 30fps × 90s = 2700 PNG files ≈ 500MB. Always clean up after encoding.

6. **text_to_speech tool limits.** Very long text may need to be split into chunks. Keep scripts under 3000 characters per call.

7. **text_to_speech may return .ogg format.** The Hermes TTS tool may return `.ogg` (Vorbis) instead of `.mp3`. Convert with: `ffmpeg -y -i audio.ogg -b:a 192k audio.mp3`

8. **ImageDraw mode must be "RGBA" for transparency.** When drawing overlays (semi-transparent bars, glow effects), create the draw context with `ImageDraw.Draw(bg, "RGBA")`. A typo like `"RGFA"` will crash silently or produce wrong colors.

9. **Nginx reverse proxy blocks static files.** If Nginx is proxying all traffic to a backend (e.g., WebChat on :8888), requests to `/media/` will 404. Add a location block:
   ```
   location /media/ {
       alias /var/www/html/media/;
   }
   ```
   Then `nginx -t && systemctl reload nginx`.

10. **No pip on minimal Ubuntu 22.04.** Use `apt-get install python3-pil python3-numpy python3-requests` instead of pip. The `python3-pip` package may not be installed.

11. **Encoding time budget.** Full HD (1080p) + slow preset + CRF 18 on a 2-core VPS ≈ 10-15 minutes for a 90-second video. Use `terminal(background=true)` and `notify_on_complete=true` to avoid timeout.

12. **User expects maximum quality on first attempt.** When the user asks you to do something, go all-out on quality — don't produce a minimal/rough version first and ask if they want better. They expect the best you can do. Use the highest resolution, best encoding settings, and most complete feature set from the start.

13. **Shell `&` backgrounding doesn't work in terminal tool.** The Hermes `terminal` tool rejects commands with `&`, `nohup`, `disown`, `setsid`. For parallel ffmpeg encoding, run commands sequentially or use `terminal(background=true)` on a single command. Multiple parallel encodes will saturate the CPU anyway on a VPS.

14. **Real news footage is hard to source programmatically.** Most major news sites (BBC, Reuters, Al Jazeera, DW, France24) use JS-rendered video players with no direct MP4 links in HTML. Indian news sites (India Today, NDTV) are more likely to have direct CDN links. AP News uses JWPlayer with extractable MP4 URLs. African news sources are extremely limited — NTA Nigeria returns JSON not video, SABC embeds YouTube. Always verify downloaded files with `ffprobe` — some "MP4" URLs return JSON error pages or HTML.

15. **Google and Bing may block automated search.** When doing market research, Google may return CAPTCHA pages and Bing may show Cloudflare challenges. Use DuckDuckGo as a fallback, or use `curl` directly against YouTube's search results page (which is more tolerant of data center IPs).

15. **Nginx serves wrong content for static file paths.** When adding a new URL path for serving files (e.g., `/media/`), remember that if Nginx has a catch-all `location /` proxy_pass, the new location block must be added BEFORE it or the proxy will intercept first. Always run `nginx -t && systemctl reload nginx` after config changes.

16. **Server without GPU is extremely slow for AI video.** A 2GB RAM / no-GPU server can handle ffmpeg encoding and TTS, but AI image generation (Stable Diffusion, etc.) will be 10-50x slower than with a GPU. For users without GPU: (a) use simpler Pillow-based rendering, (b) consider the hybrid approach where server prepares assets and user's local PC does final editing in剪映, (c) be upfront about encoding times — a 90s 1080p video can take 15-30 min on CPU-only.

17. **Pillow may not be installed on minimal servers.** Always check with `python3 -c "from PIL import Image; print('OK')"`. If missing, install with `apt-get install python3-pil` (not pip, which may not be available on minimal Ubuntu).

18. **User quality bar may exceed server capability — and user knows it.** 张哥 explicitly said "我做的那个新闻视频我根本就看不上眼" about AI-generated news videos. The Pillow-based renderer produces output that looks amateur to experienced creators. When the user has a high quality bar AND their own editing skills (剪映), the best workflow is: AI prepares assets (script, TTS, subtitles,素材 links), user assembles locally. Don't try to produce final video on a no-GPU server for users who can tell the difference.

19. **Don't assume user wants pure AI-generated content.** YouTube 2026 policy cracks down on fully AI-generated content. The best approach is "AI-assisted + human original": AI handles scripting/TTS/editing, human provides voice/personality/analysis. Real B-roll footage from news sources dramatically improves credibility over AI-generated backgrounds.

## YouTube Market Research

When the user asks you to research YouTube niches, competition, or market opportunities:

1. **Extract data from YouTube search results** using `curl` + `ytInitialData` regex (see `references/youtube-news-market.md` for the full Python snippet). This works without authentication.

2. **Search multiple query variations** to get a complete picture: try the niche name + "channel", + "2026", + "popular", + "new".

3. **Analyze both videos AND channels** — use `sp=EgIQAg%253D%253D` filter for channels-only results.

4. **Cross-reference with DuckDuckGo/Bing** for articles about YouTube trends, CPM rates, and policy changes.

5. **Compile findings into a structured report**: competition level, top performers, view counts, CPM estimates, opportunities, risks.

See `references/youtube-news-market.md` for the full research template, CPM benchmarks, niche analysis framework, and YouTube 2026 AI content policy summary.

## Support Files

| File | Purpose |
|---|---|
| `scripts/gen_broadcast_video.py` | Complete 1080p frame rendering + ffmpeg encoding script (production-ready) |
| `references/youtube-optimization.md` | YouTube upload best practices, SEO, thumbnails |
| `references/copyright-guide.md` | Fair use rules, CC sources, attribution templates |
| `references/news-video-sourcing.md` | **Real news footage sourcing** — working CDN sources (AP News, India Today), non-working sources (YouTube, BBC), transcoding pipeline |
| `references/server-environment-notes.md` | **Server environment** — current server specs, what works/doesn't, hybrid workflow recommendation |
| `references/youtube-news-market.md` | **YouTube market intelligence** — search data extraction method, niche analysis, CPM benchmarks, 2026 AI policy, channel strategy |
