Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add hls support #2794

Open
wants to merge 27 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
7efe718
hls support first commit
mp3butcher Dec 1, 2023
08b9d0e
Update config.yml for hls config
mp3butcher Dec 1, 2023
ed56081
remove useless fields
mp3butcher Dec 1, 2023
17f47ca
CI compliance
mp3butcher Dec 1, 2023
bc5050c
Update install and config
mp3butcher Dec 1, 2023
3119454
make compatible with liquidsoap 1.4 output.file.hls prototype
mp3butcher Dec 2, 2023
c62cb8f
liquidsoap 2.2 removed streaminfos parameter so crossversion hls patt…
mp3butcher Dec 12, 2023
8f3bde7
add an alias to playout hls output
mp3butcher Dec 12, 2023
61aa1fb
use SERVER_PORT for hls stream
mp3butcher Dec 12, 2023
76010bc
liquidsoap 1.4 require differents streams bitrates for player to select
mp3butcher Dec 12, 2023
45af9ed
remove useless host port settings
mp3butcher Dec 13, 2023
faa3f86
document hls output
mp3butcher Dec 13, 2023
7da16a1
add an alias to playout hls output
mp3butcher Dec 13, 2023
a439af8
simplification
mp3butcher Dec 13, 2023
4872cae
add HlsStream to imports
mp3butcher Dec 13, 2023
5ee1e84
Update configuration.md
mp3butcher Dec 13, 2023
28e83ad
add missing changes
mp3butcher Dec 17, 2023
2723f2b
add hls testing
mp3butcher Dec 18, 2023
2d62117
change hls configuration
mp3butcher Dec 18, 2023
0833239
make hls output path an install setting
mp3butcher Dec 20, 2023
44f2dae
update test
mp3butcher Jan 19, 2024
95316d6
update configuration files and manual
mp3butcher Jan 19, 2024
07d9448
setup docker files
mp3butcher Jan 19, 2024
3a6aefd
Merge remote-tracking branch 'upstream/main' into hls
mp3butcher Jan 19, 2024
6f76da0
merge misses
mp3butcher Jan 19, 2024
06cf701
test miss
mp3butcher Jan 19, 2024
c7e95fd
update pytest snapshot
mp3butcher Jan 19, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ RUN set -eux \
&& install --directory --owner=${USER} /etc/libretime /srv/libretime

ENV LIBRETIME_CONFIG_FILEPATH=/etc/libretime/config.yml
ENV LIBRETIME_OUTPUT_PATH=/var/playout/hls

# Shared packages
COPY tools/packages.py /tmp/packages.py
Expand Down Expand Up @@ -124,6 +125,9 @@ COPY playout .
RUN --mount=type=cache,target=/root/.cache/pip \
pip install --editable .[sentry]

RUN mkdir -p $LIBRETIME_OUTPUT_PATH
RUN chown ${USER}:${USER} $LIBRETIME_OUTPUT_PATH

# Run
USER ${UID}:${GID}
WORKDIR /app
Expand Down
30 changes: 27 additions & 3 deletions dev/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,29 +43,53 @@ stream:

icecast:
- <<: *default_icecast_output
enabled: true
enabled: false
mount: main.ogg
public_url: https://localhost:8443/main.ogg
audio:
format: ogg
bitrate: 256

- <<: *default_icecast_output
enabled: true
enabled: false
mount: main.opus
public_url: https://localhost:8443/main.opus
audio:
format: opus
bitrate: 256

- <<: *default_icecast_output
enabled: true
enabled: false
mount: main.mp3
public_url: https://localhost:8443/main.mp3
audio:
format: mp3
bitrate: 256

hls:
- enabled: true
segment_duration: 2.0
segment_count: 5
segments_overhead: 5
public_url:
manifest: main.m3u8
streams:
- segments_prefix: mp3_low
codec: libmp3lame
bitrate: 32k
sample_rate: 44100
format: mpegts
- segments_prefix: mp3_med
format: mpegts
codec: libmp3lame
bitrate: 128k
sample_rate: 44100
- segments_prefix: mp3_hifi
format: mpegts
codec: libmp3lame
bitrate: 256k
sample_rate: 44100

system:
- enabled: false
kind: pulseaudio
3 changes: 3 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ services:
volumes:
- ${LIBRETIME_CONFIG_FILEPATH:-./config.yml}:/etc/libretime/config.yml:ro
- libretime_playout:/app
- libretime_playout_hls:/var/playout/hls
environment:
LIBRETIME_GENERAL_PUBLIC_URL: http://nginx:8080

Expand Down Expand Up @@ -110,6 +111,7 @@ services:
- libretime_assets:/var/www/html:ro
- libretime_storage:/srv/libretime:ro
- ${NGINX_CONFIG_FILEPATH:-./nginx.conf}:/etc/nginx/conf.d/default.conf:ro
- libretime_playout_hls:/var/playout/hls:ro

icecast:
image: ghcr.io/libretime/icecast:2.4.4
Expand All @@ -125,3 +127,4 @@ volumes:
libretime_storage: {}
libretime_assets: {}
libretime_playout: {}
libretime_playout_hls: {}
42 changes: 42 additions & 0 deletions docker/config.template.yml
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,48 @@ stream:
# > default is false
mobile: false

hls:
- # Whether the output is enabled.
# > default is false
enabled: true
# > segment_duration (default:2.0)
segment_duration: 2.0
# > segments count (default:5)
segment_count: 5
# > segments_overhead (default:5)
segments_overhead: 5
# Output public url, If not defined, the value will be generated from
# the [general.public_url] hostname, the output port and mount.
public_url:
# hls mount point
# > this field is REQUIRED
manifest: main.m3u8
streams:
- # > prefix of generated fragment
# > this field is REQUIRED
segments_prefix: mp3_low
# > must be one of ('mpegts', 'adts')
# > this field is REQUIRED
format: mpegts
# > codec must be one of ('libmp3lame', 'aac')
# > this field is REQUIRED
codec: libmp3lame
# > bitrate of the stream
# > this field is REQUIRED
bitrate: 32k
# > sampling rate (default: 44100Hz)
sample_rate: 44100
- segments_prefix: mp3_med
format: mpegts
codec: libmp3lame
bitrate: 128k
sample_rate: 44100
- segments_prefix: mp3_hifi
format: mpegts
codec: libmp3lame
bitrate: 256k
sample_rate: 44100

# System outputs.
# > max items is 1
system:
Expand Down
42 changes: 42 additions & 0 deletions docker/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,48 @@ stream:
# > default is false
mobile: false

hls:
- # Whether the output is enabled.
# > default is false
enabled: true
# > segment_duration (default:2.0)
segment_duration: 2.0
# > segments count (default:5)
segment_count: 5
# > segments_overhead (default:5)
segments_overhead: 5
# Output public url, If not defined, the value will be generated from
# the [general.public_url] hostname, the output port and mount.
public_url:
# hls mount point
# > this field is REQUIRED
manifest: main.m3u8
streams:
- # > prefix of generated fragment
# > this field is REQUIRED
segments_prefix: mp3_low
# > must be one of ('mpegts', 'adts')
# > this field is REQUIRED
format: mpegts
# > codec must be one of ('libmp3lame', 'aac')
# > this field is REQUIRED
codec: libmp3lame
# > bitrate of the stream
# > this field is REQUIRED
bitrate: 32k
# > sampling rate (default: 44100Hz)
sample_rate: 44100
- segments_prefix: mp3_med
format: mpegts
codec: libmp3lame
bitrate: 128k
sample_rate: 44100
- segments_prefix: mp3_hifi
format: mpegts
codec: libmp3lame
bitrate: 256k
sample_rate: 44100

# System outputs.
# > max items is 1
system:
Expand Down
42 changes: 42 additions & 0 deletions docker/example/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,48 @@ stream:
# > default is false
mobile: false

hls:
- # Whether the output is enabled.
# > default is false
enabled: true
# > segment_duration (default:2.0)
segment_duration: 2.0
# > segments count (default:5)
segment_count: 5
# > segments_overhead (default:5)
segments_overhead: 5
# Output public url, If not defined, the value will be generated from
# the [general.public_url] hostname, the output port and mount.
public_url:
# hls mount point
# > this field is REQUIRED
manifest: main.m3u8
streams:
- # > prefix of generated fragment
# > this field is REQUIRED
segments_prefix: mp3_low
# > must be one of ('mpegts', 'adts')
# > this field is REQUIRED
format: mpegts
# > codec must be one of ('libmp3lame', 'aac')
# > this field is REQUIRED
codec: libmp3lame
# > bitrate of the stream
# > this field is REQUIRED
bitrate: 32k
# > sampling rate (default: 44100Hz)
sample_rate: 44100
- segments_prefix: mp3_med
format: mpegts
codec: libmp3lame
bitrate: 128k
sample_rate: 44100
- segments_prefix: mp3_hifi
format: mpegts
codec: libmp3lame
bitrate: 256k
sample_rate: 44100

# System outputs.
# > max items is 1
system:
Expand Down
4 changes: 4 additions & 0 deletions docker/nginx.conf
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ server {
client_max_body_size 512M;
client_body_timeout 300s;

location /hls {
alias /var/playout/hls;
}

location ~ \.php$ {
fastcgi_buffers 64 4K;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
Expand Down
60 changes: 60 additions & 0 deletions docs/admin-manual/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,7 @@ stream:
outputs:
icecast: # See the [stream.outputs.icecast] section.
shoutcast: # See the [stream.outputs.shoutcast] section.
hls: # See the [stream.outputs.hls] section.
system: # See the [stream.outputs.system] section.
```

Expand Down Expand Up @@ -535,6 +536,65 @@ stream:
mobile: false
```

#### Hls

The `stream.outputs.hls` section configures the HLS output streams.

HLS is an HTTP-based adaptive bitrate streaming protocol.

It consists on presenting multiple streams with varying qualities to the client player which select the most fitted to its bandwidth.

To configure hls streams, first describe the container of these streams by its **format**.

Then setup the composites streams with various **codec**s and **bitrate**s.

:::warning

For security purposes, liquidsoap produces hls files in the webserver mount point **hls/** instead of creating its own.

```yml
stream:
outputs:
# Shoutcast output streams.
# > max items is 1
hls:
- # Whether the output is enabled.
# > default is false
enabled: true
# > segment_duration (default:2.0)
segment_duration: 2.0
# > segments count (default:5)
segment_count: 5
# > segments_overhead (default:5)
segments_overhead: 5
# Output public url, If not defined, the value will be generated from
# the [general.public_url] hostname, the output port and mount.
public_url:
# hls mount point
# > this field is REQUIRED
manifest: main.m3u8
streams:
- # > prefix of generated fragment
# > this field is REQUIRED
segments_prefix: mp3_low
# > must be one of ('mpegts', 'adts')
# > this field is REQUIRED
format: mpegts
# > codec must be one of ('libmp3lame', 'aac')
# > this field is REQUIRED
codec: libmp3lame
# > bitrate of the stream
# > this field is REQUIRED
bitrate: 32k
# > sampling rate (default: 44100Hz)
sample_rate: 44100
- segments_prefix: mp3_hifi
format: mpegts
codec: libmp3lame
bitrate: 256k
sample_rate: 44100
```

#### System

The `stream.outputs.system` section configures the system outputs.
Expand Down