# Technik PCS 3.0

**Legende:**

---

<img src="/img/streams/pcs3-legend.svg" />

---

<img src="/img/streams/pcs3-graph.svg" />

**Bekannte Latenzen:**

| von | bis | Latenz |
| -------- | -------- | -------- |
| `Übersetzer*in`     | `/audio`     | ca. 1s     |
| `/audio`     | `OBS`     | ca. 4-5s     |




[1] Service: `rec-<CHANNEL>.service`
```
.venv/bin/python3 -m c3lingo_mumble.recv_stdout mumble.octycs.eu <CHANNEL> | \
    ffmpeg -re -fflags nobuffer -probesize 32 -f s16le -ac 1 -ar 48000 -i pipe:0 \
           -filter_complex pan=7.1|BL=c0[a] -map [a] -c:a aac -ac 8 -ar 44100 \
           -f flv rtmp://localhost:1935/audio/<CHANNEL>
```

[2] Datei: `/opt/forwarder.sh`
```
ffmpeg -fflags nobuffer \
       -i rtmp://localhost:1935/input/$1 -c:v copy \
       -filter_complex "[a:0]pan=7.1|FL=c0|FR=c0" -c:a aac -ac 8 -ar 44100 \
       -f flv rtmp://localhost:1935/output/$1
```

[3] (Bisher nur zwei Sprachen) Datei: `/opt/splitter.sh`
```
ffmpeg -re -fflags nobuffer \
       -i rtmp://localhost:1935/split_in/live \
       -filter_complex \
          "[0:a]pan=stereo|c0=c0|c1=c1,aresample=async=1000[a0];
           [0:a]pan=stereo|c0=0.02*c0+0.98*c4|c1=0.02*c1+0.98*c4,aresample=async=1000[a1]" \
       -map 0:v -copyts -start_at_zero -vcodec copy \
         -map [a0] -c:a aac -ac 2 \
         -f flv rtmp://a.rtmp.youtube.com/live2/<Stream-Key-DE> \
       -map 0:v -copyts -start_at_zero -vcodec copy \
         -map [a1] -c:a aac -ac 2 \
         -f flv rtmp://a.rtmp.youtube.com/live2/<Stream-Key-EN>
```

[4] Die Streams von `/input` und `/output` sind funktional gleich, nur dass das Video bei `/output` 8 Kanäle hat und deswegen in OBS alle Kanäle angezeigt werden. Das ist nur relevant, falls die Kanäle in OBS anders gemixt werden mit dem rematrix Plugin. ~~Im Zweifel `/input` nehmen.~~
Es scheint OBS hat Probleme mit Mono input im 7.1 Modus, deswegen besser `/output` nehmen. (Sollte das nicht möglich sein: unter `Advanced Audio Properties` das Häkchen bei `Downmix to Mono` aktivieren.)

### Z.B. dann so konfiguriert in Nginx RTMP
```nginx
application input {
    live on;
    exec /opt/forwarder.sh $name;
    exec_kill_signal term;

    record all;
    record_path /opt/rec;
    record_suffix -%Y-%m-%dT%T.flv;
}
```

und dann in `/opt/forwarder.sh`:
```bash
#!/bin/bash
on_die() {
  pkill -KILL -P $$
}
trap 'on_die' TERM

ffmpeg -fflags nobuffer \
       -i rtmp://localhost:1935/input/$1 -c:v copy \
       -filter_complex "[a:0]pan=7.1|FL=c0|FR=c0" -c:a aac -ac 8 -ar 44100 \
       -f flv rtmp://localhost:1935/output/$1 &
wait
```