Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
cdn [2024/01/29 10:45] – ischluff | cdn [2025/05/22 11:22] (current) – ischluff | ||
---|---|---|---|
Line 2: | Line 2: | ||
< | < | ||
- | This documentation describes our Livestreaming CDN as of 2024. | + | This documentation describes our Livestreaming CDN as of 2025. |
The File-CDN for media.ccc.de is described on [[software: | The File-CDN for media.ccc.de is described on [[software: | ||
</ | </ | ||
- | |||
- | |||
- | |||
- | == The Future of Streaming | ||
- | |||
- | For redundancy and ease of use the CDN is managed by a distributed system built on consul. | ||
- | |||
- | Damit ist es möglich redundante CDN-Master sowie redundante Ingest-Server zu betreiben und trotzdem ein Web-Backend mit allen relevanten Streaming-Infos bereitzustellen. Weiterhin könnte die Streaming-Webseite intelligent auf das Vorhandensein/ | ||
- | |||
- | Ein weiterer Vorteil des angedachten Setups sind deutlich geringere Latenz durch den fehlenden Fanout, sowie deutlich schnellere Stream-Restarts durch aktive Benachrichtigung der Transcoder. | ||
- | |||
- | === Übersicht | ||
- | {{drawio> | ||
==== Repo Links | ==== Repo Links | ||
Line 26: | Line 13: | ||
== Architecture | == Architecture | ||
- | The CDN-Cascade has 5 stages: Master-Encoder, | + | The CDN-Cascade has 6 stages: Master-Encoder, |
{{: | {{: | ||
Line 32: | Line 19: | ||
=== 1. Master-Encoder | === 1. Master-Encoder | ||
The master stream encoding is created near the stage on the encoder PC running voctomix or on with other videoencoder for third party streams. | The master stream encoding is created near the stage on the encoder PC running voctomix or on with other videoencoder for third party streams. | ||
- | The master encoding contains a 1080p25 video signal. | + | The master encoding contains a 1080p25 |
- | Das Master-Encoding entsteht auf dem encoder-cube im Saal aus dem Ausgabesignal des Voctomix. Das Master-Encoding enthält den Mix als 1080p25 in h264 sowie die Slides als 1080p5 | + | The translated audio tracks and the slide video track are optional. |
- | Das Master-Encoding wird von einem Script erzeugt, welches vom ansible aus folgendem Template erzeugt wird: https:// | + | The master |
- | Das Master-Encoding wird auf den lokalen (= auf dem encoder-cube laufenden) Icedist (= Icecast zur internen Distribution) auf Port 7999 gepusht (http://encoderX.lan.c3voc.de: | + | === 2. Ingest |
+ | The ingest machines run both [[https://github.com/voc/ | ||
+ | Additionally the ingest machines run a stream-api daemon which scrapes the local stream information from both srtrelay and nginx-rtmp and publishes it to consul KV. | ||
+ | The consul KV path is / | ||
+ | ``` | ||
+ | # consul kv get /stream/s96 | ||
+ | {" | ||
+ | ``` | ||
- | ==== Debugging | + | === 3. Transcoder |
+ | The stream transcoding transforms the mpegts stream into multiple segmented streams (one per quality) via one big ffmpeg script. Additionally it creates thumbnails and preview images. | ||
+ | The transcoding script can be found here https:// | ||
- | http://195.54.164.164: | + | A python script runs constantly on each transcoder which fetches streams from consul and tries to claim streams which don't have a transcoder assigned yet. |
+ | The consul KV path is /stream/<stream slug>/transcoder | ||
``` | ``` | ||
- | voc@live.ber: | + | # consul kv get /stream/s96/transcoder |
- | ● icedist.service - distribution Icecast | + | myloc-transcoder3 |
- | | + | |
- | Active: active (running) since Tue 2019-07-30 19:50:07 CEST; 3 weeks 0 days ago | + | |
- | Main PID: 794 (icecast2) | + | |
- | Tasks: 25 (limit: 4915) | + | |
- | | + | |
- | | + | |
- | sudo tail -f /var/log/icedist/ | + | # To reallocate a transcoder for a stuck stream |
+ | consul kv delete | ||
``` | ``` | ||
- | === 1.5 Exkurs Stream-API | + | Every time a transcoder claims a stream it writes an env file and starts a systemd unit to run the transcoding script. |
- | Die " | + | The transcode updates are also published to the #voc-wok IRC. |
- | Aktuelles Beispiel siehe https:// | + | |
- | Das JSON wird periodisch auf dem Master | + | The transcoding outputs are directly pushed with HTTP uploads to the Master |
- | === 2. Transcoder | + | === 4. Master Relay |
- | Das Transcoding läuft auf verschiedenen Transcodern. Aktuelle Zuordnung siehe '' | + | Runs the upload server (https:// |
+ | The upload server has some additional logic to rewrite the HLS playlists on the fly in order to properly handle stream restarts. | ||
- | Jeder Transcoder pollt regelmäßig die Stream-Api und startet/ | + | The segmented streams, thumbnails |
- | Abhängig von der Hardware starten diese entweder einzelne " | + | |
- | Die Pull/Push-Konfiguration jedes Streams wird aus der Stream-API entnommen und in ein File entsprechend "/ | + | === 5. Edge-Relays |
+ | The edge relays run nginx with caching proxy config | ||
- | Die Quelle eines transkodierten Streams ist immer eine Icecast-URL der Form http:// | + | === 6. Loadbalancer |
- | (Beispiel: http://live.ber.c3voc.de:7999/s1 -> http:// | + | The end-user facing domains '' |
- | Die transkodierten Formate sind dabei: h264, vpx (VP9), audio (MP3, Opus) und thumbnail (MJPEG mit 0.1Hz). | + | ==== streaming.media.ccc.de |
- | Dementsprechend z.B.: | + | The load-balancers serve the [[:software:streamingwebsite|Streaming-Webseite]] under this domain. The sites run completely independent and are just kept in sync by the deployment script. With this procedure one or more load-balancers can easily be taken out of the DNS rotation if necessary. |
- | * http:// | + | |
- | * http:// | + | |
- | * http://live.lan.c3voc.de: | + | |
- | * http:// | + | |
+ | ==== cdn.c3voc.de | ||
+ | Requests to '' | ||
- | Die Scripte dazu werden vom ansible aus folgenden Templates erzeugt: https:// | + | The relay weight distribution is stored in consul KV and can be tweaked in real time. The haproxy configs automatically get updated by consul-template after a change. |
- | Da jeder Format-Stream aus einem einzelnen ffmpeg-Prozess stammt und in einem Container landet sind die darin enthaltenen Videoströme Zeitsynchron zueinander. | + | ``` |
+ | # Get the current weight distribution, | ||
+ | consul kv get -recurse / | ||
+ | services/ | ||
+ | services/ | ||
+ | ``` | ||
- | + | Because | |
- | ==== Verwaltung | + | |
- | Die Verteilung der Transcodings wird wie oben erwähnt über die Stream-API realisiert. Dadurch werden die Streams immer gleichmäßig verteilt und es gibt keine doppelten Zuweisungen. | + | |
- | + | ||
- | Die Maximalzahl der Streams pro Transcoder und eventuelle Stream-Bindungen an bestimmte Transcoder können über Variablen im ansible gesteuert werden. | + | |
- | + | ||
- | Um einen Überblick über die derzeit aktivierten Transcodings zu erhalten kann folgender Befehl verwendet werden: | + | |
- | + | ||
- | < | + | |
- | voc@tweety.int: | + | |
- | UNIT LOAD | + | |
- | transcode_s1_audio.service | + | |
- | transcode_s1_h264.service | + | |
- | transcode_s1_vpx.service | + | |
- | transcode_s2_audio.service | + | |
- | … | + | |
- | transcode_s1.target | + | |
- | transcode_s2.target | + | |
- | … | + | |
- | </ | + | |
- | + | ||
- | Der Zustand des API-Clients ist gelegentlich sinnvoll abzufragen | + | |
- | < | + | |
- | sudo journalctl -afu update_transcoding | + | |
- | </ | + | |
- | + | ||
- | === 3. Fanout | + | |
- | Die Format-Streams je Raum werden von der nächsten Stufe auf dem Master-Relay ('' | + | |
- | + | ||
- | Dabei entstehen alle Kombinationen aus '' | + | |
- | + | ||
- | Die WebM- und die Audio-Streams werden gegen den Icecast auf http:// | + | |
- | Segmente im File-System: | + | |
- | * / | + | |
- | * / | + | |
- | * / | + | |
- | * / | + | |
- | + | ||
- | Die Scripte dazu werden vom ansible aus folgenden Templates erzeugt werden: https:// | + | |
- | + | ||
- | + | ||
- | Um einen Überblick über die laufenden Fanout Skripte zu erhalten kann folgender Befehl verwendet werden: | + | |
- | + | ||
- | < | + | |
- | voc@live.ber: | + | |
- | </ | + | |
- | + | ||
- | Die Pull-Quelle und das Push-Ziel sowie der Pfad unter dem die HLS/DASH-Schnipsel und Playlisten abgelegt werden ist über Group-Vars konfigurierbar: | + | |
- | + | ||
- | < | + | |
- | + | ||
- | * Youtube ist derzeit deaktiviert und wird üblicherweise nur für den Congress aktiviert. | + | |
- | + | ||
- | Das Transcoding und Fanout reagiert dynamisch auf die Konfiguration des Streams der vom encoder-cube gesendet wird. Fehlt die Slides-Spur oder die Translation-Spuren wird diese nicht in den Master-Playlists und Dash-Manifestd für Adaptives streaming angeboten. Dadurch kann von Event zu Event entschieden werden, ob der Einsatz der Slide-Spur bzw. von Translations sinn ergibt. Siehe dazu [[voctomix: | + | |
- | + | ||
- | === 4. Transport- und Master-Relays | + | |
- | Im Non-Congress Setup ist '' | + | |
- | + | ||
- | === 5. Edge-Relays | + | |
- | Die ganzjährigen Edge-Relay lauten: | + | |
- | * '' | + | |
- | * '' | + | |
- | * '' | + | |
- | * '' | + | |
- | * '' | + | |
- | * '' | + | |
- | + | ||
- | Diese pullen alle Icecast-Streams (Port :8000) – *nicht* die Icedist-Streams – von '' | + | |
- | Für die schlussendliche Auslieferung kommt ein nginx zum Einsatz, der abhängig von der URL Daten von einem der unterschiedlichen Backend proxied: | + | |
- | * Für Anfragen zu einem WebM, MP3 oder Opus-Stream (z.B: http:// | + | |
- | * Für Anfragen nach HLS oder DASH-Schnipseln, | + | |
== Stream-URLs | == Stream-URLs | ||
- | Die endgültigen Stream-URLs für einen Beispielstream sX sind dann wie folgt: | + | The resulting stream |
- | MPEG-DASH (VPx Multi-Qualität + Multi-Lang) | + | HLS (H.264 multi-quality |
- | * http:// | + | * http:// |
- | + | ||
- | HLS (h.264 Multi-Qualität | + | |
- | * http:// | + | |
Moar HLS | Moar HLS | ||
- | * http:// | + | |
- | * http:// | + | * http:// |
- | * http:// | + | * http:// |
- | * http:// | + | * http:// |
- | * http:// | + | * http:// |
- | + | ||
- | Legacy VPx-HD: | + | |
- | * http:// | + | |
- | * http:// | + | |
- | * http:// | + | |
- | Legacy VPx-SD: | + | **Currently not active:** |
- | * http:// | + | |
- | * http:// | + | |
- | * http:// | + | |
- | Legacy | + | MPEG-DASH (VPx multi-quality + multi-language) |
- | * http:// | + | * http:// |
- | * http://cdn.c3voc.de/ | + | |
- | * http:// | + | |
Audio-MP3: | Audio-MP3: | ||
- | * http:// | + | * http:// |
- | * http:// | + | * http:// |
- | * http:// | + | * http:// |
Audio-Opus: | Audio-Opus: | ||
- | * http:// | + | * http:// |
- | * http:// | + | * http:// |
- | * http:// | + | * http:// |
+ | == Dynamic SRT/RTMP endpoints with RTMP Auth | ||
+ | SRT and RTMP Endpoints can be created under https:// | ||
- | == Loadbalancer | + | The RTMP-URL for the endpoint '' |
- | Neben den Transport- und Edge-Relays gibt es noch drei Loadbalancer: | + | |
- | * '' | + | The SRT-URL would be : '' |
- | * '' | + | |
- | * '' | + | |
- | Diese sind sowohl für die Domains '' | + | == Future improvements |
- | === streaming.media.ccc.de | + | The diagram below shows the envisioned architecture as of 2020. In the meantime many of the improvements have been integrated into the CDN. |
- | Unter dieser Domain liefern beide LBs unabhängig von einander die [[:software: | + | Some more potential improvements are as follows: |
+ | * Dynamically adapting the streaming-website to the existence/ | ||
+ | * Building a live status dashboard which shows the current stream-> | ||
+ | * To gracefully shutdown a relay it could be instructed via consul KV to redirect all clients back to a load balancer while taking it out of the haproxy redirects. That way all clients would be redistributed to different relays. | ||
+ | * Build master relay redundancy using dynamic upload client and relay upstream configuration. (Relay upstreams need to be sticky, because the HLS playlists generated on the master relay are not deterministic) | ||
+ | * Use DNS rotation on ingest | ||
+ | * Finalize srtrelay meshing to allow pushed streams to be pulled from any ingest machine. | ||
- | === cdn.c3voc.de | + | {{drawio> |
- | Die Domain '' | + | |
- | + | ||
- | Der HAProxy verteilt dabei ausschließlich per Redirect, er proxied (entgegen seines Namens) nicht. | + | |
- | + | ||
- | == RTMP Ingest | + | |
- | Für Spezialanwendungen (z.B. Cam-Only Streaming im Fritz-Studio) existieren die RTMP-Endpunkte '' | + | |
- | Die Push-Targets lauten '' | + | |
- | + | ||
- | Achtung: Aufgrund der langen rtmp-Timeouts in ffmpeg kann es bis zu 40 Sekunden dauern, bis die Streams auftauchen und weitere 30 Sekunden, bis alle Formate zur Verfügung stehen. Keine Ungeduld. | + | |
- | + | ||
- | === Dynamische endpunkte mit rtmp-auth | + | |
- | RTMP Endpunkte können unter https:// | + | |
- | Die RTMP-Url für den endpunkt '' | ||