# MP4 Mobile Normalizer

A minimal web tool that normalizes AI-exported MP4 files for reliable iOS/Android, `expo-video`, and HTML5 `<video>` playback.

## What it fixes

- Moves `moov` before `mdat` with `-movflags +faststart`.
- Ignores problematic source edit lists with `-ignore_editlist 1`.
- Re-encodes H.264 High Profile Level 4.0, `yuv420p`.
- Disables B-frames with `-bf 0` so output edit lists stay identity (`media_time=0`).
- Drops audio by default for muted loop/banner videos, or keeps AAC 128k when selected.
- Optionally scales odd dimensions down to even dimensions.

## Run locally

```bash
npm install
npm start
# open http://localhost:5173
```

Environment variables:

```bash
PORT=5173
MAX_UPLOAD_MB=500
```

## Docker

```bash
docker build -t mp4-mobile-normalizer .
docker run --rm -p 5173:5173 -e MAX_UPLOAD_MB=500 mp4-mobile-normalizer
```

## Cloudflare deployment note

Cloudflare Workers / Pages Functions cannot run native `ffmpeg` via `child_process`, so the production-friendly architecture is:

```text
Browser -> Cloudflare DNS/Proxy/Tunnel -> Node server/container with ffmpeg
```

For quick testing without a Cloudflare account:

```bash
npm start
cloudflared tunnel --url http://localhost:5173
```

For production, create a named Cloudflare Tunnel and route your domain to `http://localhost:5173` or to the Docker container on your server.

Example named-tunnel config:

```yaml
tunnel: YOUR_TUNNEL_ID
credentials-file: /etc/cloudflared/YOUR_TUNNEL_ID.json

ingress:
  - hostname: video-normalizer.example.com
    service: http://localhost:5173
  - service: http_status:404
```

Then:

```bash
cloudflared tunnel run YOUR_TUNNEL_NAME
```
