init
This commit is contained in:
@@ -0,0 +1,2 @@
|
||||
test/
|
||||
scripts/nginx/nginx/
|
||||
@@ -0,0 +1,3 @@
|
||||
# stream-relay
|
||||
|
||||
> Collection of tools and scripts to help in restreaming content
|
||||
Executable
+33
@@ -0,0 +1,33 @@
|
||||
#!/bin/bash
|
||||
|
||||
set -e
|
||||
|
||||
tmpdir="$(mktemp -d)"
|
||||
prefix="$1"
|
||||
|
||||
if [ -z "$prefix" ]; then
|
||||
prefix="$(pwd)/nginx"
|
||||
fi
|
||||
|
||||
mkdir -p "$prefix"
|
||||
|
||||
echo "Downloading nginx to $tmpdir"
|
||||
wget -qO- http://nginx.org/download/nginx-1.21.6.tar.gz | tar -xzv -C "$tmpdir"
|
||||
|
||||
pushd "$tmpdir/nginx-1.21.6"
|
||||
|
||||
echo "Configuring nginx"
|
||||
./configure \
|
||||
--prefix="$prefix" \
|
||||
--with-http_ssl_module --with-threads --with-http_realip_module
|
||||
|
||||
echo "Compiling nginx"
|
||||
make -j "$(nproc)"
|
||||
|
||||
echo "Installing nginx"
|
||||
make install
|
||||
|
||||
popd # "$tmpdir/nginx-1.21.6"
|
||||
|
||||
echo "Cleaning up"
|
||||
rm -rf "$tmpdir"
|
||||
Executable
+66
@@ -0,0 +1,66 @@
|
||||
#!/bin/bash
|
||||
|
||||
hls_flags="-hls_time 1 -hls_list_size 30"
|
||||
|
||||
rtmp2hls() {
|
||||
# Copy the RTMP stream to HLS
|
||||
hls_flags=$(make_hls_flags "$1")
|
||||
ffmpeg \
|
||||
-re -f flv -listen 1 -i "$1" -c copy -bsf:a aac_adtstoasc \
|
||||
-f hls $hls_flags -hls_segment_filename "$2/%d.ts" \
|
||||
"$2/index.m3u8"
|
||||
}
|
||||
|
||||
rtmp2hls_transcode() {
|
||||
# Encode the stream into multiple resolutions
|
||||
ffmpeg -re -f flv -listen 1 -i "$1" \
|
||||
-map 0:v:0 -map 0:a:0 \
|
||||
-map 0:v:0 -map 0:a:0 \
|
||||
-map 0:v:0 -map 0:a:0 \
|
||||
-map 0:v:0 -map 0:a:0 \
|
||||
-c:v:0 copy -b:v:0 5600k -c:a:0 copy -b:a:0 128k \
|
||||
-c:v:1 libx264 -crf 18 -c:a:1 aac -ar:1 48000 \
|
||||
-c:v:2 libx264 -crf 18 -c:a:2 aac -ar:2 44100 \
|
||||
-c:v:3 libx264 -crf 18 -c:a:3 aac -ar:3 44100 \
|
||||
-filter:v:1 'scale=-2:720' -b:a:1 128k \
|
||||
-filter:v:2 'scale=-2:480' -b:a:2 128k \
|
||||
-filter:v:3 'scale=-2:360' -b:a:3 128k \
|
||||
-f hls \
|
||||
-var_stream_map \
|
||||
'v:0,a:0,name:1080p v:1,a:1,name:720p v:2,a:2,name:480p v:3,a:3,name:360p' \
|
||||
$hls_flags \
|
||||
-hls_segment_filename "$2/%v-%04d.ts" \
|
||||
-master_pl_name "index.m3u8" \
|
||||
"$2/index-%v.m3u8"
|
||||
}
|
||||
|
||||
streamlink2rtmp() {
|
||||
streamlink \
|
||||
"$1" best -O \
|
||||
| ffmpeg -i - -c copy -bsf:a aac_adtstoasc \
|
||||
-f flv "$2"
|
||||
}
|
||||
|
||||
hls_prog_copy() {
|
||||
input="$1"
|
||||
progs="$2"
|
||||
outpath="$3"
|
||||
|
||||
imap=; omap=; a=0;
|
||||
for p in $progs; do
|
||||
imap="$imap -map p:$p";
|
||||
omap="$omap v:$a,a:$a";
|
||||
a=$((a+1));
|
||||
done;
|
||||
|
||||
echo "input:$imap";
|
||||
echo "output:$omap";
|
||||
rm -rf "$outpath";
|
||||
mkdir "$outpath";
|
||||
|
||||
ffmpeg -re -i "$input" \
|
||||
$imap -c copy -v warning -stats \
|
||||
-f hls -var_stream_map "$omap" $hls_flags \
|
||||
-hls_segment_filename "$outpath/%v-%08d.ts" \
|
||||
"$outpath/index-%v.m3u8"
|
||||
}
|
||||
Reference in New Issue
Block a user