Skip to content

Commit 8ba06a5

Browse files
committed
Updated readme
1 parent dc543bc commit 8ba06a5

3 files changed

Lines changed: 103 additions & 168 deletions

File tree

.env.example

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1+
# To use this file, copy it to `.env` and update and/or add your own values.
2+
# Be sure to read the `Environment Variables` section in the README.
13
# Website to capture and stream
24
WEBSITE_URL=https://example.com
3-
45
# RTMP endpoint to stream to
56
RTMP_URL=rtmp://localhost:1935/live/stream
6-
7-
# Output resolution (720p or 1080p)
8-
RESOLUTION=1080p
7+
# Output resolution (720p, 1080p, or 2k)
8+
RESOLUTION=720p
9+
# Output framerate (30 or 60)
10+
FRAMERATE=30

README.md

Lines changed: 96 additions & 162 deletions
Original file line numberDiff line numberDiff line change
@@ -1,67 +1,41 @@
1-
# Stream Website
1+
# Stream Website Container
22

3-
A Go application that captures live website content (both visual and audio) and streams it to an RTMP endpoint using Chrome headless browser and FFmpeg.
3+
A containerized application to stream a webpage live over RTMP. Just pass a `WEBSITE_URL` and a `RTMP_URL` and the container will open a browser, capture the video and audio, and send it to the specified location. It can even be configured to automatically restart the stream for supported services.
44

5-
## Features
5+
## Uses
66

7-
- **Website Capture**: Captures any website content including dynamic content, videos, and audio
8-
- **Live Streaming**: Streams captured content to RTMP endpoints in real-time
9-
- **Configurable Resolution**: Supports 720p and 1080p output resolutions
10-
- **Docker Support**: Fully containerized with multi-stage builds
11-
- **Graceful Shutdown**: Handles shutdown signals properly
12-
- **Logging**: Structured logging with Zap
7+
- Quickly spinning up a test stream without needing to install anything other than a container runtime.
8+
- Setting up a long running stream for a [Twitch Extension Review](https://dev.twitch.tv/docs/extensions/life-cycle/#review) when a test stream is needed.
9+
- Setting up a way to broadcast an overlay [like YarpBot does for its status page](https://www.twitch.tv/yarpbot) without a GUI client.
10+
- Other.... stuff (you figure it out).
1311

14-
## How It Works
15-
16-
1. **Chrome Browser**: Launches a Chrome browser instance to render the target website
17-
2. **Screen Capture**: Uses FFmpeg's x11grab to capture the browser window
18-
3. **Audio Capture**: Captures system audio using PulseAudio
19-
4. **Encoding**: Encodes video with H.264 and audio with AAC
20-
5. **Streaming**: Streams the encoded content to the specified RTMP endpoint
21-
22-
## Environment Variables
23-
24-
| Variable | Description | Default |
25-
|----------|-------------|---------|
26-
| `WEBSITE_URL` | URL of the website to capture | `https://example.com` |
27-
| `RTMP_URL` | RTMP endpoint to stream to | `rtmp://localhost:1935/live/stream` |
28-
| `RESOLUTION` | Output resolution (720p or 1080p) | `1080p` |
29-
30-
## Quick Start
12+
## Running From Source
3113

3214
### Using Docker Compose
3315

34-
1. Clone the repository and navigate to the stream-website directory:
35-
```bash
36-
cd stream-website
37-
```
16+
1. Clone the repository
3817

39-
2. Set environment variables (optional):
40-
```bash
41-
export WEBSITE_URL="https://www.youtube.com/watch?v=dQw4w9WgXcQ"
42-
export RTMP_URL="rtmp://your-rtmp-server/live/stream"
43-
export RESOLUTION="1080p"
44-
```
18+
2. Set environment variables (through copying [`.env.example`](./.env.example) to `.env` or other methods)
4519

4620
3. Start the application:
4721
```bash
4822
docker-compose up --build
4923
```
5024

51-
### With RTMP Test Server
25+
### Local Development With RTMP Test Server
5226

5327
To test with a local RTMP server:
5428

5529
```bash
5630
# Start with the included RTMP server
57-
docker-compose --profile rtmp-server up --build
31+
docker-compose --profile dev up --build
5832

5933
# The RTMP server will be available at:
60-
# - RTMP: rtmp://localhost:1935/live/stream
61-
# - Web interface: http://localhost:8080
62-
# - Stream stats: http://localhost:8080/stat
34+
# rtmp://localhost:1935/live/stream
6335
```
6436

37+
You can then use a program like VLC to view the stream to ensure it works (use `Media` -> `Open Network Stream` and use the address `rtmp://localhost:1935/live/stream` for this example).
38+
6539
### Using Docker Only
6640

6741
```bash
@@ -72,127 +46,87 @@ docker build -t stream-website .
7246
docker run -e WEBSITE_URL="https://example.com" \
7347
-e RTMP_URL="rtmp://your-server/live/stream" \
7448
-e RESOLUTION="1080p" \
75-
--security-opt seccomp:unconfined \
76-
--cap-add SYS_ADMIN \
77-
-v /dev/shm:/dev/shm \
7849
stream-website
7950
```
8051

81-
## Local Development
82-
83-
### Prerequisites
84-
85-
- Go 1.21 or later
86-
- FFmpeg
87-
- Google Chrome
88-
- PulseAudio
89-
- X11 (for display)
90-
91-
### Running Locally
92-
93-
1. Install dependencies:
94-
```bash
95-
go mod download
96-
```
97-
98-
2. Set environment variables:
99-
```bash
100-
export WEBSITE_URL="https://example.com"
101-
export RTMP_URL="rtmp://localhost:1935/live/stream"
102-
export RESOLUTION="1080p"
103-
```
104-
105-
3. Run the application:
106-
```bash
107-
go run main.go
108-
```
109-
110-
## Configuration
111-
112-
### Supported Resolutions
113-
114-
- **720p**: 1280x720 pixels
115-
- **1080p**: 1920x1080 pixels (default)
116-
117-
### FFmpeg Settings
118-
119-
The application uses optimized FFmpeg settings for live streaming:
120-
121-
- **Video Codec**: H.264 with libx264
122-
- **Preset**: veryfast (for low latency)
123-
- **CRF**: 23 (balanced quality)
124-
- **Max Bitrate**: 3000k
125-
- **Buffer Size**: 6000k
126-
- **Audio Codec**: AAC at 128k bitrate
127-
- **Frame Rate**: 30 FPS
128-
129-
## Troubleshooting
130-
131-
### Common Issues
132-
133-
1. **Chrome fails to start**:
134-
- Ensure the container has proper permissions
135-
- Check that `--security-opt seccomp:unconfined` and `--cap-add SYS_ADMIN` are set
136-
137-
2. **No audio capture**:
138-
- Audio is captured using PulseAudio with virtual audio devices
139-
- The container automatically creates virtual speakers and microphones
140-
- Check the startup logs for audio device debugging information
141-
- If audio issues persist, try restarting the container
142-
143-
3. **FFmpeg errors**:
144-
- Verify the RTMP endpoint is accessible
145-
- Check network connectivity
146-
- Ensure the RTMP server supports the streaming format
147-
148-
4. **High CPU usage**:
149-
- Consider using 720p resolution for lower resource usage
150-
- Adjust FFmpeg preset (use "faster" or "fast" instead of "veryfast")
151-
152-
### Logs
153-
154-
The application provides structured JSON logs showing:
155-
- Startup configuration
156-
- Browser navigation status
157-
- FFmpeg command execution
158-
- Error details
159-
160-
### Performance Tuning
161-
162-
For better performance:
163-
164-
1. **Use 720p resolution** for lower CPU usage:
165-
```bash
166-
export RESOLUTION="720p"
167-
```
168-
169-
2. **Adjust FFmpeg settings** by modifying the FFmpeg arguments in `main.go`
170-
171-
3. **Allocate more shared memory** by increasing the `/dev/shm` volume size
172-
173-
## Architecture
174-
175-
```
176-
┌─────────────┐ ┌──────────────┐ ┌─────────────┐ ┌──────────────┐
177-
│ Website │ -> │ Chrome │ -> │ FFmpeg │ -> │ RTMP Server │
178-
│ │ │ Browser │ │ (capture │ │ │
179-
│ │ │ │ │ & encode) │ │ │
180-
└─────────────┘ └──────────────┘ └─────────────┘ └──────────────┘
181-
```
182-
183-
1. Chrome renders the target website
184-
2. FFmpeg captures the Chrome window using x11grab
185-
3. FFmpeg captures system audio using PulseAudio
186-
4. FFmpeg encodes and streams to RTMP endpoint
187-
188-
## Contributing
189-
190-
1. Fork the repository
191-
2. Create a feature branch
192-
3. Make your changes
193-
4. Test with Docker
194-
5. Submit a pull request
195-
196-
## License
197-
198-
This project is part of the Stream Website ecosystem.
52+
> [!WARNING]
53+
> While you **can** run this locally by compiling the go code and executing it, I wouldn't recommend it as you need to make sure all the dependencies such as Chrome and [ffmpeg](https://ffmpeg.org) are there and reachable. Plus, having this be a container's kind of the point.
54+
55+
## Status Checking
56+
57+
If an environmental variable such as `TWITCH_CHANNEL` (see below) is set, then the container will check that channel to make sure the stream is live and attempt to restart the stream if it is not. This is so the stream can automatically be restarted for platforms that have maximum stream lengths (such as Twitch's [being 48 hours per stream](https://help.twitch.tv/s/article/broadcasting-guidelines?language=en_US)).
58+
59+
### Twitch
60+
61+
To enable status checking for Twitch, provide a `TWITCH_CHANNEL`, `TWITCH_CLIENT_ID`, and `TWITCH_CLIENT_SECRET` environmental variable (see below for details).
62+
63+
> [!NOTE]
64+
> Currently Twitch is the only supported platform but you can always file a PR if you want another platform.
65+
66+
## Environmental Variables
67+
68+
- `FRAMERATE`
69+
- Enum
70+
- `30`
71+
- `60`
72+
- Default: `30`
73+
- Sets the framerate of the stream. Currently supports `30` or `60` frames per second.
74+
- `LOG_FORMAT`
75+
- Enum
76+
- `json`
77+
- `console`
78+
- Default: `json`
79+
- Sets the format for logs printed.
80+
- `LOG_LEVEL`
81+
- Enum
82+
- `debug`
83+
- `info`
84+
- `warn`
85+
- `warning`
86+
- `error`
87+
- `dpanic`
88+
- `panic`
89+
- `fatal`
90+
- Default: `info`
91+
- Level of logs that are printed. Defined by [`zap` log levels](https://pkg.go.dev/go.uber.org/zap/zapcore#Level).
92+
- `PORT`
93+
- String
94+
- Default: `8080`
95+
- Port to run the health and metrics endpoint on.
96+
- `STATUS_CRON_SCHEDULE`
97+
- String
98+
- Default: `*/10 * * * *` (every 10 minutes)
99+
- Cron string to define how often to check the status of the stream if status checking is enabled.
100+
- `RESOLUTION`
101+
- Enum
102+
- `720p`
103+
- `1080p`
104+
- `2k`
105+
- Default: `720p`
106+
- What resolution the RTMP stream should be.
107+
- `RTMP_URL`
108+
- String
109+
- Default: `rtmp://localhost:1935/live/stream`
110+
- RMTP endpoint to send the stream to. If using a service such as [Twitch](https://help.twitch.tv/s/twitch-ingest-recommendation?language=en_US), be sure your stream key is at the end of it.
111+
- `TWITCH_CHANNEL`
112+
- String
113+
- If provided a value, the application will attempt to check the status of the stream at the provided channel as per the `STATUS_CRON_SCHEDULE` and will restart the stream if it is detected to not be live.
114+
- Requires the `TWITCH_CLIENT_ID` and `TWITCH_CLIENT_SECRET` to be defined to work properly.
115+
- `TWITCH_CLIENT_ID`
116+
- String
117+
- Twitch Client ID obtained from the [Twitch Developer Console](https://dev.twitch.tv/console) for checking stream status if the `TWITCH_CHANNEL` environmental variable is set.
118+
- Checking for the stream status on Twitch will not work without this and `TWITCH_CLIENT_SECRET` being set.
119+
- For more information about registering an app on Twitch, see [the developer documentation](https://dev.twitch.tv/docs/authentication/register-app/).
120+
- `TWITCH_CLIENT_SECRET`
121+
- String
122+
- Twitch Client ID obtained from the [Twitch Developer Console](https://dev.twitch.tv/console) for checking stream status if the `TWITCH_CHANNEL` environmental variable is set.
123+
- Checking for the stream status on Twitch will not work without this and `TWITCH_CLIENT_ID` being set.
124+
- For more information about registering an app on Twitch, see [the developer documentation](https://dev.twitch.tv/docs/authentication/register-app/).
125+
- `WEBSITE_URL`
126+
- String
127+
- Default: `https://google.com`
128+
- The website to stream.
129+
130+
## About
131+
132+
Cobbled together by [Zac Lovoy](https://bsky.app/profile/zwlovoy.bsky.social) (aka [BigZoz on Twitch](https://www.twitch.tv/bigzoz)). If you're interested in some of other streaming adjacent stuff, check out [YarpBot](https://yarpbot.com) or the [Filters Extension for Twitch](https://dashboard.twitch.tv/extensions/npqfekui52xl3nuuk91h2pmrszod57). Or whatever; I'm not your dad.

docker-compose.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,10 @@ services:
1515
- WEBSITE_URL=${WEBSITE_URL:-https://google.com}
1616
ports:
1717
- "${PORT:-8080}:${PORT:-8080}"
18-
depends_on:
19-
- "rtmp-server"
2018

2119
# RTMP server for testing
2220
rtmp-server:
2321
image: tiangolo/nginx-rtmp
22+
profiles: ["dev"]
2423
ports:
2524
- "1935:1935"

0 commit comments

Comments
 (0)