Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,12 @@ jobs:
python-version: "3.11"
cache: pip
- run: pip install -r requirements-dev.txt
# For tests/test_nginx_conf.py, which runs nginx/viofosync.conf.
- run: command -v nginx || { sudo apt-get update && sudo apt-get install -y nginx; }
- run: python -m ruff check .
- run: python -m pytest -q
env:
VIOFOSYNC_REQUIRE_NGINX: "1"

# Publishes to Docker Hub: :edge on main pushes, :X.Y + :latest on
# version tags (v2.6 or 2.6 both work), and :<branch-name> on a
Expand Down
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
# Changelog

## Unreleased

### Added

#### Playback

- **nginx can serve video.** Put nginx in front with the ready-made `nginx/viofosync.conf`, and playing or downloading a clip sends the browser to nginx, which serves the file itself, so playback no longer waits on the app. nginx checks the login with the app every 30 seconds or so, in the background, so logging out stops video within 30 seconds, and video keeps playing while the app restarts. Nothing to set on the app. See "Serving video through nginx" in the README.

### Fixed

- **Constant buffering in Safari.** Safari abandons and reopens its video request every half second or so, and the server kept reading each abandoned request to the end of the clip. Dozens of these at once swamped the disk, especially through Docker Desktop's file sharing. Clip and export playback now stop reading as soon as the browser hangs up.

## v2.8 — 2026-11-17

### Added
Expand Down
37 changes: 37 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,43 @@ Confirm it engaged with `docker exec <container> vainfo`, and check the startup
> [!NOTE]
> On arm64 hosts QuickSync won't probe-pass; exports degrade to VAAPI or software automatically.

### Serving video through nginx

If playback buffers, put nginx in front and let it serve the video files. Browsers fetch a playing video as a stream of separate requests (Safari makes several a second), and with nginx none of them wait on the app, however busy it is syncing, making thumbnails or exporting. This made the biggest difference for Safari on Docker Desktop for Mac.

When you play or download a clip, the app checks your login and sends the browser to the file's address on nginx, like `/media/2026-11-15/2026_1115_080000_0001F.MP4`. nginx sends the file from its own read-only mount of the recordings folder, and browsers keep using that address for every range request and seek. nginx asks the app whether the browser is logged in and remembers the answer for 30 seconds, so the app hears from it once in a while rather than on every request, and video never waits for it. Logging out, or changing the password with "log out other sessions", stops video within 30 seconds. While the app restarts (a new image, say), nginx goes on using the answers it has, so video that was playing keeps playing.

**1.** Copy [`nginx/viofosync.conf`](nginx/viofosync.conf) next to your `docker-compose.yml`, in an `nginx` folder.

**2.** Add the nginx service and move the published port from the app to nginx:

```yaml
services:
viofosync:
# ...as before, but with no "ports:" section

nginx:
image: nginx:1.27-alpine
container_name: viofosync-nginx
restart: unless-stopped
depends_on:
- viofosync
ports:
- "8080:8080"
volumes:
- ./nginx/viofosync.conf:/etc/nginx/conf.d/default.conf:ro
- /path/to/recordings:/recordings:ro # the same folder as the app's /recordings
```

**3.** `docker compose up -d`, then play a clip. `docker logs viofosync-nginx` should show one request to `/api/archive/clip/…/video` answered with `302`, then the `/media/…` requests answered with `206`.

There's nothing to set on the app: nginx marks the requests it passes on, and the app only sends browsers to `/media/` for those. Reached directly on its own port, the app sends video itself as before, so publishing that port as well doesn't break anything; it's just the slow way in.

- A `401` for `/media/…` means the browser isn't logged in (any more): log in again and reopen the clip.
- A `404` for `/media/…` means nginx's `/recordings` isn't the app's recordings folder. Mount the same folder at `/recordings` in both, or, if you've set `RECORDINGS` on the app to somewhere else, mount the folder it points to at `/recordings` in nginx. The app's log says which folder it links from.
- The config expects the service to be called `viofosync` and the app to listen on 8080, its default. Change `set $viofosync` in the config if yours differ.
- Behind nginx, every request reaches the app from nginx's address, so the login rate limit (5 tries a minute) is shared by all your devices.

## Configuration

The only Docker-level env vars are:
Expand Down
17 changes: 17 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,20 @@ services:
# Timezone for log timestamps and journey grouping.
# https://en.wikipedia.org/wiki/List_of_tz_database_time_zones
TZ: Europe/London

# Optional: nginx in front, serving clip video itself so playback
# doesn't wait on the app. Uncomment, and remove the app's "ports" above
# so it's reached through nginx. See "Serving video through nginx" in
# the README.
# nginx:
# image: nginx:1.27-alpine
# container_name: viofosync-nginx
# restart: unless-stopped
# depends_on:
# - viofosync
# ports:
# - "8080:8080"
# volumes:
# - ./nginx/viofosync.conf:/etc/nginx/conf.d/default.conf:ro
# # The same recordings folder as above, read-only.
# - /path/to/recordings:/recordings:ro
107 changes: 107 additions & 0 deletions nginx/viofosync.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
# nginx in front of viofosync, serving clip video itself.
#
# Everything is proxied to the app. When you play a clip, the app sends
# the browser to the file's /media/ URL, and nginx sends the file from its
# own read-only mount of the recordings folder. Every range request and
# seek after that goes straight to nginx. nginx asks the app whether the
# browser is logged in, and remembers a yes for 30 seconds, so the app
# hears about it once in a while rather than on every request, and
# logging out (or "log out other sessions") takes effect within that.
#
# Mount at /etc/nginx/conf.d/default.conf in the official nginx image. See
# "Serving video through nginx" in the README.

map $http_upgrade $connection_upgrade {
default upgrade;
'' close;
}

# Downloads use the same URLs, with the name to save the file under in
# name=. The app percent-encodes it, which is the form filename*= takes,
# so it's passed through as it is; anything else in it is ignored, so a
# made-up link can't put odd things in the header. Browsers use
# filename*; filename= is for tools like curl and wget that don't. No
# name means inline playback, with no Content-Disposition.
map $arg_name $media_disposition {
"~^[A-Za-z0-9%._~-]+$" "attachment; filename=\"$arg_name\"; filename*=UTF-8''$arg_name";
default "";
}

# The app's answers to "is this browser logged in?", by cookie.
proxy_cache_path /var/cache/nginx/viofosync_auth levels=1 keys_zone=viofosync_auth:1m
max_size=10m inactive=10m;

server {
listen 8080;

# Look the app up through Docker's DNS on every request, not just at
# startup, so recreating its container (a new image, say) doesn't leave
# nginx pointing at the old address.
resolver 127.0.0.11 valid=10s ipv6=off;
# Change "viofosync:8080" if the app's service name or port differs.
set $viofosync http://viofosync:8080;

location / {
proxy_pass $viofosync;
proxy_http_version 1.1;
proxy_set_header Host $http_host;
# Tells the app nginx is here to serve /media/. Replaces any value
# the browser sent.
proxy_set_header X-Viofosync-Media 1;
# The live progress feed is a WebSocket.
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
proxy_read_timeout 1h;
# Pass uploads (Import manually) straight through as they arrive.
# By default nginx would first write each one whole to a temp file
# in this container, multi-GB clips included, before the app saw
# a byte of it.
client_max_body_size 0;
proxy_request_buffering off;
}

location /media/ {
auth_request /_viofosync_auth;

# Must match the recordings mount on this container.
alias /recordings/;
add_header Content-Disposition $media_disposition;
sendfile on;
tcp_nopush on;
}

location = /_viofosync_auth {
internal;
proxy_pass $viofosync/api/auth/check;
proxy_pass_request_body off;
proxy_set_header Content-Length "";
proxy_set_header Range "";
proxy_set_header Host $http_host;
# Send the app exactly what the answer is cached under, as one
# header (nginx joins repeated Cookie headers into this).
proxy_set_header Cookie $http_cookie;

# Remember the answer for 30 seconds. A no is remembered too, so a
# logged-out tab that keeps retrying (Safari does, many times a
# second) doesn't ask the app every time. Logging in still works
# straight away: it comes with a new cookie, so a new question.
#
# Keyed on the whole Cookie header, not just the session cookie:
# with the session cookie sent twice nginx would pick the first and
# the app the last, and a logged-in browser could then file a yes
# under a cookie the app never checked (even under no cookie).
proxy_cache viofosync_auth;
proxy_cache_key $http_cookie;
proxy_cache_valid 204 401 30s;
proxy_cache_lock on;
proxy_ignore_headers Cache-Control Expires Vary;

# When an answer runs out, keep using it while nginx asks again in
# the background, so playback never waits on the app.
proxy_cache_background_update on;
# And keep using it while the app can't answer (restarting, say),
# rather than failing every video. Answers are kept for up to 10
# minutes after they were last used (inactive= above).
proxy_cache_use_stale updating error timeout http_500 http_502 http_503 http_504;
}
}
Loading
Loading