* With videojs disabled, you can scrub backwards and forwards on the video timeline. If you scrub to the end (the most recent segment), you can achieve really quite low latency, as low as 3 seconds.
* Slow (if videojs is enabled). Using videojs is slower because you have to make many separate GET requests, without it you only need to make one. If you lower the HLS segment size to something like 2 seconds, you get very low latency without videojs (smallest i've got is 3 seconds) but with videojs the stream becomes unwatchable because of the overhead of each GET request you have to make. The stream delay is >30 seconds with videojs and >3 seconds without it. Hopefully this will decrease when congestion control gets into Tor: https://youtu.be/watch?v=zQDbfHSjbnI. ([This article](https://www.martin-riedl.de/2020/04/17/using-ffmpeg-as-a-hls-streaming-server-part-8-reducing-delay/) explains what causes HLS to have latency.)
* There's a bug that causes the server to refuse to respond to any more requests. It happens after it's been up for a few days, and inexplicably in some other circumstances. I don't know why it happens, it's probably something to do with `/stream.mp4` or `concatenate.py`.
* Scrolling direction is reversed in the chat because of the css trickery involved there, unsure if it can be fixed
<summary>Explanation of the FFmpeg command in `stream.sh`
</summary>
<div>The FFmpeg command in `stream.sh` was based on [this series of articles by Martin Riedl](https://www.martin-riedl.de/2020/04/17/using-ffmpeg-as-a-hls-streaming-server-overview/).
</div>
<br>
<div><b>video input (differs between OSs)</b></div>
<div>• `scale=$VIDEO_WIDTH:$VIDEO_HEIGHT` scales the video to the desired size</div>
<div>• `drawtext...` draws the date and time in the top left</div>
<div>• you might need to change the font `/usr/share/fonts/truetype/freefont/FreeMonoBold.ttf` if you're on macOS and definitely if you're on Windows</div>
| `Keyframe interval (frames)` | `30` (the same as your framerate, or exactly half) |
| `Video Encoder` | either leave it default or select an H.264 hardware encoder that matches your graphics card (e.g. `nvenc_h264` for Nvidia, [see here](https://trac.ffmpeg.org/wiki/HWAccelIntro)) |
`stream.sh` as it exists in this repo is set up to record your screen and system audio on Linux. See https://trac.ffmpeg.org/wiki/Capture/Desktop for the syntax for different OSs.
As an aside: you can change the command in stream.sh to record anything you want, it doesn't have to be just your screen and system audio. If you want to change stuff around, just know that all that's required is: (1) HLS segments appear as `stream/stream*.m4s`, (2) `stream/init.mp4` is the inital HLS segment, and (3) `stream/stream.m3u8` is the HLS playlist. (All this is taken care of in `stream.sh` by default.)
Before you start streaming you might need to edit `config.toml`. That file has a list of fonts used by the captcha, and you might not have them. You can either replace them with some fonts you do have, or you can download the fonts that are already listed there and make sure the paths in `config.toml` are correct:
If you're using OBS Studio, click Start Recording (**not** Start Streaming). If you're using the script instead, then go to the project root and type `sh stream.sh`.
Now your webserver is running on port 5000 (or whichever port you set it to, if you did that). We need to tell tor to create a hidden service and to point it at port 5000.
In your [torrc](https://support.torproject.org/tbb/tbb-editing-torrc/), add these two lines
where `$PROJECT_ROOT` is the root folder of this project. When you reload tor it will create the `hidden_service` directory and your website will be online. Your onion address is in `hidden_service/hostname`. You only need to do this once.
To appear as the broadcaster in chat, go to `/broadcaster` and log in with the username `broadcaster` and the password printed in your terminal when you started Flask.