Skip to content

Commit

Permalink
Poc video monitoring
Browse files Browse the repository at this point in the history
  • Loading branch information
mbugeia committed Dec 14, 2020
1 parent 38dee29 commit 7343a71
Show file tree
Hide file tree
Showing 2 changed files with 104 additions and 9 deletions.
12 changes: 6 additions & 6 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,23 @@ services:
- 10001:10001/udp
- 8500:8500/tcp
volumes:
- ./radio:/radio
- ./hls:/hls
- ./radio:/radio
- ./hls:/hls
nginx:
build:
context: nginxhls
image: privyplace/nginxhls:v1
container_name: nginx
restart: unless-stopped
networks:
- default
- default
expose:
- "80"
ports:
- 8080:80/tcp
- 8080:80/tcp
volumes:
- ./hls:/hls
- ./nginxhls/stream.conf:/etc/nginx/conf.d/stream.conf
- ./hls:/hls
- ./nginxhls/stream.conf:/etc/nginx/conf.d/stream.conf
prometheus:
image: prom/prometheus:v2.23.0
container_name: prometheus
Expand Down
101 changes: 98 additions & 3 deletions radio/live.liq
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ set("frame.audio.samplerate",44100)
set("frame.audio.channels",2)
set("audio.converter.samplerate.libsamplerate.quality","fast")

# Video settings
set("frame.video.height",1080)
set("frame.video.samplerate",25)
set("frame.video.width",1920)

# Clocks settings
set("root.max_latency",5.)
set("clock.allow_streaming_errors",false)
Expand Down Expand Up @@ -149,9 +154,14 @@ live = switch(id="switch_live",
[(is_playing("srt1"), srt1),
(is_playing("srt2"), srt2)])

radio_preprod = fallback(id="fallback_preprod",
track_sensitive=false,
[live, srt1, srt2])


radio_prod = fallback(id="fallback_prod",
track_sensitive=false,
[live, srt1, srt2, safe_blank])
[radio_preprod, safe_blank])

# Get metrics on output
latency_metric(label_values=["default","output","radio_prod"],radio_prod)
Expand Down Expand Up @@ -207,6 +217,50 @@ radio_prod = blank.detect(id="on_blank_radio_prod",

### END Radio logic

### Video logic
raw_audio_encoder = %ffmpeg(%audio.raw)
raw_video_encoder = %ffmpeg(%video.raw)

raw_audio = ffmpeg.raw.audio(raw_audio_encoder, radio_preprod)

def make_video(s) =
def mkfilter(graph) =
s = ffmpeg.filter.audio.input(graph, s)
s = ffmpeg.filter.showspectrum(
graph,
s,
size="1920x1080",
mode=1,
slide=1,
scale=2,
color=1,
saturation=0.2
)
ffmpeg.filter.video.output(graph, s)
end
ffmpeg.filter.create(mkfilter)
end

video_main = make_video(raw_audio)

#video_fallback = mksafe(drop_audio(video.external.testsrc()))

video_fallback = video.add_text.native("No audio", blank())

video_fallback = ffmpeg.raw.video(raw_video_encoder, video_fallback)

video_prod =
fallback(
id="fallback_video_prod",
track_sensitive=false,
[
video_main,
video_fallback
]
)

### END Video logic

### HTTP API

# Define default http response
Expand Down Expand Up @@ -322,7 +376,25 @@ aac_hifi =
)
)

# Output to HLS
# Define video outputs formats
video_mpegts =
%ffmpeg(
format="mpegts",
%audio(
channels=2,
samplerate=44100,
codec="aac",
b="196k",
profile="aac_low"
),
%video.raw(
codec="libx264",
b="5M",
flags="+global_header"
),
)

# HLS segment utils

def segment_name(~position,~extname,stream_name) =
timestamp = int_of_float(time())
Expand All @@ -336,6 +408,8 @@ def on_file_change(~state,fname) =
end
end

# Output audio to HLS

output.file.hls(id="output_hls",
playlist="live.m3u8",
segment_duration=2.0,
Expand All @@ -350,4 +424,25 @@ output.file.hls(id="output_hls",
("aac_hifi", aac_hifi)],
radio_prod)

### END Outputs
# Output video to HLS

output.file.hls(
id="output_video_hls",
playlist="video.m3u8",
segment_duration=2.0,
segments=5,
fallible=true,
segments_overhead=5,
segment_name=segment_name,
on_file_change=on_file_change,
persist_at="statevideo.config",
!hlspath,
[
("mpegts", video_mpegts)
],
mux_audio(
audio=radio_prod,
video_prod
))

### END Outputs

0 comments on commit 7343a71

Please sign in to comment.