NGU-Web/docs/video-clips.md
Zaldimmar 06a0e07a79 Let a downloaded video be saved whole, before or without cutting
Save to library and Save to Drive on a finished download, not only on
clips. The download stays on the server to cut clips from either way;
a clip's library save still clears its working file.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-30 00:14:26 -05:00

112 lines
4.4 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# Video clips
Admin → Tools → Video clips (admins and up). Paste one of our YouTube or
Facebook links; the server downloads it, then you cut clips from it:
- **Trim**: set the start and end while watching, or type them (`1:23.5`).
- **Shape**: as filmed, landscape 16:9 (1920×1080), square (1080×1080) or
vertical 9:16 (1080×1920, for Reels, Shorts and TikTok). A slider moves
the crop; the white box over the video shows what's kept.
- **Format**: video (MP4, H.264 and AAC) or audio only (MP3).
A downloaded video can be kept whole too, before or without cutting
it: **Save to library** and **Save to Drive** on the download itself.
It stays on the server to cut clips from either way (until the day's
sweep).
Clips queue and run one at a time. A finished clip is deleted from the
server once it's downloaded, unless **Save to library** is pressed first,
which puts it in the media library as an upload (usable as a featured
video or in a video block). Everything is cleared a day after it's made.
**Save to Drive** puts a copy in a folder under Media in the shared
Google Drive (pick it, eg. `Media/Videos` or `Media/Audio`; the list is
Tools → Media → Files's folders, and the one named for the clip's kind
is chosen first). It becomes a Files entry, shared with anyone who has
the link, so pages link to it with Choose a file. It's uploaded straight
from the server's copy (the working file, or the library's), streamed
rather than read into memory, so a long clip is fine; nginx isn't in the
way. A clip can be in both the library and Drive. Needs Google Drive set
up (`docs/google-drive-and-mail.md`) and migration 051.
Only YouTube and Facebook links are accepted, and only for videos NGU owns
or has permission to use. Sources can be up to 4 hours and 4 GB; clips up
to an hour. Limits are constants at the top of `server/src/clips.js`.
## Server setup
1. **ffmpeg** (with ffprobe):
```sh
sudo apt install ffmpeg
```
2. **yt-dlp**: the standalone binary, kept current (YouTube changes often,
and an old yt-dlp is the usual reason downloads start failing):
```sh
sudo curl -L https://github.com/yt-dlp/yt-dlp/releases/latest/download/yt-dlp_linux -o /usr/local/bin/yt-dlp
sudo chmod a+rx /usr/local/bin/yt-dlp
sudo yt-dlp -U # to update later
```
YouTube needs a JavaScript runtime to list formats; the tool hands
yt-dlp the Node that runs the API, so nothing else is needed.
3. **A working folder** the service can write, and the settings on the
`ngu-api` unit (`systemctl edit ngu-api`):
```sh
sudo mkdir -p /var/lib/ngu/clips
sudo chown <ngu-api user>: /var/lib/ngu/clips
```
```ini
[Service]
Environment=CLIPS_DIR=/var/lib/ngu/clips
# Only if they aren't on the service's PATH:
# Environment=YTDLP_PATH=/usr/local/bin/yt-dlp
# Environment=FFMPEG_PATH=/usr/bin/ffmpeg
# Environment=FFPROBE_PATH=/usr/bin/ffprobe
```
A source can be several GB, so leave room on that disk.
**If YouTube says "Sign in to confirm you're not a bot"**, it's
refusing the VPS's address, and yt-dlp needs a signed-in account's
cookies. Use a separate Google account made for this, never a
personal one: whoever has the cookies is signed in as it. Then set
one of:
```ini
# A cookies.txt exported from a browser signed in to that account
# (a "Get cookies.txt" browser extension, Netscape format). Keep it
# readable only by the service: chmod 600, owned by its user.
Environment=YTDLP_COOKIES=/var/lib/ngu/youtube-cookies.txt
# Or: read them from a browser installed and signed in on the VPS
# itself, as yt-dlp's --cookies-from-browser takes it.
# Environment=YTDLP_COOKIES_FROM_BROWSER=firefox
```
The file is copied for each download, so yt-dlp never rewrites the
original. Cookies expire; when downloads start failing again, export
a fresh file.
4. **nginx**: the editor's video and clip downloads are big streams. Give
them their own block so nginx passes them straight through:
```nginx
location /api/admin/clips/ {
proxy_pass http://127.0.0.1:3001;
proxy_http_version 1.1;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_buffering off;
proxy_read_timeout 300s;
}
```
The Video clips page says if yt-dlp or ffmpeg is missing.