Skip to content

Instantly share code, notes, and snippets.

@jordicenzano
Last active September 8, 2021 23:34
Show Gist options
  • Save jordicenzano/c5516b5854eb046bd1c27076fe4ba917 to your computer and use it in GitHub Desktop.
Save jordicenzano/c5516b5854eb046bd1c27076fe4ba917 to your computer and use it in GitHub Desktop.
Live streaming server RTMP in HLS out (1 rendition + overlay)
#!/usr/bin/env bash
# We assume ffmpeg installed (recommened v 4+)
# Acts as RMTP server for application named live (expects stream)
# transcodes the media data into h264-aac, craetes HLS 4s chunks,
# and sends the data to ~/origin
# Create 1 rendition1
# 854x480@30fps 1000Kbps (+ Overlay)
FONT_PATH='/usr/share/fonts/dejavu/DejaVuSans-Bold.ttf'
# Clean up
rm -f ~/origin/*.ts
rm -f ~/origin/*.m3u8
mkdir -p ~/origin
echo "Starting RMTP server"
ffmpeg -hide_banner \
-listen 1 -i "rtmp://0.0.0.0:1935/live/stream" \
-vf scale=854x480 \
-vf "drawtext=fontfile=$FONT_PATH: text=\'RENDITION 1 - Local time %{localtime\: %Y\/%m\/%d %H.%M.%S} (%{n})\': x=0: y=0: fontsize=36: fontcolor=pink: box=1: boxcolor=0x00000099" \
-c:v libx264 -b:v 900k -g 60 -profile:v baseline -preset veryfast \
-c:a aac -b:a 48k \
-hls_flags delete_segments -hls_time 4 -hls_segment_filename ~/origin/480p_%05d.ts ~/origin/480p.m3u8
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment