Browse Source

Initial commit

Volodymyr Tkach 2 years ago
parent
commit
4b9dfe3aee

+ 8 - 0
.dockerignore

@@ -0,0 +1,8 @@
+.git
+build
+.dockerignore
+.gitignore
+Dockerfile
+LICENSE
+Makefile
+README.md

+ 2 - 15
.gitignore

@@ -1,15 +1,2 @@
-# Binaries for programs and plugins
-*.exe
-*.exe~
-*.dll
-*.so
-*.dylib
-
-# Test binary, built with `go test -c`
-*.test
-
-# Output of the go coverage tool, specifically when used with LiteIDE
-*.out
-
-# Dependency directories (remove the comment below to include it)
-# vendor/
+/build/*
+!/build/.keep

+ 32 - 0
Dockerfile

@@ -0,0 +1,32 @@
+FROM debian:latest
+MAINTAINER Vova Tkach <vladimirok5959@gmail.com>
+
+ARG DEBIAN_FRONTEND=noninteractive
+
+RUN apt-get -y update && \
+	apt-get -y upgrade && \
+	apt-get -y install build-essential && \
+	apt-get -y install libpcre3 && \
+	apt-get -y install libpcre3-dev && \
+	apt-get -y install libssl-dev && \
+	apt-get -y install curl && \
+	apt-get -y install nginx && \
+	apt-get -y install ffmpeg && \
+	apt-get -y install libnginx-mod-rtmp && \
+	mkdir /var/www/html/recordings && \
+	chown -R www-data:www-data /var/www/html/recordings && \
+	echo "" >> /root/.profile && \
+	echo "TIME_ZONE=\$(cat /etc/timezone)" >> /root/.profile && \
+	echo "export TZ=\"\${TIME_ZONE}\"" >> /root/.profile && \
+	echo "" >> /root/.bashrc && \
+	echo "TIME_ZONE=\$(cat /etc/timezone)" >> /root/.bashrc && \
+	echo "export TZ=\"\${TIME_ZONE}\"" >> /root/.bashrc
+
+COPY --chown=root:root ./docker /
+
+EXPOSE 1935
+EXPOSE 8999
+
+STOPSIGNAL SIGQUIT
+
+CMD /usr/sbin/nginx

+ 30 - 0
Makefile

@@ -0,0 +1,30 @@
+VERSION="1.0.0"
+
+docker-build:
+	@-docker rmi docker-nginx-mod-rtmp:latest
+	docker build -t docker-nginx-mod-rtmp:latest ./
+
+docker-export:
+	@-rm ./build/docker-nginx-mod-rtmp.tar
+	docker save docker-nginx-mod-rtmp:latest > ./build/docker-nginx-mod-rtmp.tar
+
+docker-import:
+	@-docker rmi docker-nginx-mod-rtmp:latest
+	docker load < ./build/docker-nginx-mod-rtmp.tar
+
+docker-test:
+	docker run --rm \
+		--network host \
+		--name docker-nginx-mod-rtmp-test \
+		-v /etc/timezone:/etc/timezone:ro \
+		-it docker-nginx-mod-rtmp:latest
+
+docker-push:
+	docker tag docker-nginx-mod-rtmp:latest vladimirok5959/nginx-mod-rtmp:${VERSION}
+	docker tag docker-nginx-mod-rtmp vladimirok5959/nginx-mod-rtmp:latest
+	docker login
+	docker push vladimirok5959/nginx-mod-rtmp:${VERSION}
+	docker push vladimirok5959/nginx-mod-rtmp:latest
+	docker rmi vladimirok5959/nginx-mod-rtmp:${VERSION}
+	docker rmi vladimirok5959/nginx-mod-rtmp:latest
+	docker rmi docker-nginx-mod-rtmp:latest

+ 0 - 0
build/.keep


+ 31 - 0
docker/etc/nginx/nginx.conf

@@ -0,0 +1,31 @@
+daemon off;
+user www-data;
+pid /run/nginx.pid;
+worker_processes auto;
+include /etc/nginx/modules-enabled/*.conf;
+
+events {
+	worker_connections 768;
+}
+
+http {
+	sendfile on;
+	tcp_nopush on;
+	tcp_nodelay on;
+	keepalive_timeout 65;
+	types_hash_max_size 2048;
+
+	include /etc/nginx/mime.types;
+	default_type application/octet-stream;
+
+	ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
+	ssl_prefer_server_ciphers on;
+
+	access_log /dev/stdout;
+	error_log /dev/stdout info;
+
+	include /etc/nginx/conf.d/*.conf;
+	include /etc/nginx/sites-enabled/*;
+}
+
+include /etc/nginx/rtmp.conf;

+ 7 - 0
docker/etc/nginx/publish_done.sh

@@ -0,0 +1,7 @@
+#!/bin/bash
+
+FILE_NAME="$1"     # stream
+FILE_PATH="$2"     # /var/www/html/recordings/stream-1653927205-30052022-161325.flv
+FILE_BASENAME="$3" # stream-1653927205-30052022-161325
+
+# Do something here...

+ 7 - 0
docker/etc/nginx/publish_start.sh

@@ -0,0 +1,7 @@
+#!/bin/bash
+
+FILE_NAME="$1"     # stream
+FILE_PATH="$2"     # /var/www/html/recordings/stream-1653927205-30052022-161325.flv
+FILE_BASENAME="$3" # stream-1653927205-30052022-161325
+
+# Do something here...

+ 12 - 0
docker/etc/nginx/record_done.sh

@@ -0,0 +1,12 @@
+#!/bin/bash
+
+FILE_NAME="$1"     # stream
+FILE_PATH="$2"     # /var/www/html/recordings/stream-1653927205-30052022-161325.flv
+FILE_BASENAME="$3" # stream-1653927205-30052022-161325
+
+# Convert FLV to MP4
+/usr/bin/ffmpeg -i ${FILE_PATH} -c copy /tmp/${FILE_BASENAME}.mp4 && \
+/bin/mv /tmp/${FILE_BASENAME}.mp4 /var/www/html/recordings && \
+/bin/rm ${FILE_PATH}
+
+# Do something here...

+ 6 - 0
docker/etc/nginx/rtmp-pwd.conf

@@ -0,0 +1,6 @@
+location /auth {
+	if ($arg_pwd = 'my-secret-password-here') {
+			return 200;
+	}
+	return 401;
+}

+ 6 - 0
docker/etc/nginx/rtmp-recordings.conf

@@ -0,0 +1,6 @@
+record off;
+# record all;
+# record_unique on;
+# record_max_size 1200000K;
+# record_suffix -%d%m%Y-%H%M%S.flv;
+# record_path /var/www/html/recordings;

+ 7 - 0
docker/etc/nginx/rtmp-twitch.conf

@@ -0,0 +1,7 @@
+application twitch {
+	live on;
+	record off;
+	allow publish 127.0.0.1;
+	deny publish all;
+	# push rtmp://live-cdg.twitch.tv/app/my_secret_stream_key_here;
+}

+ 7 - 0
docker/etc/nginx/rtmp-youtube.conf

@@ -0,0 +1,7 @@
+application youtube {
+	live on;
+	record off;
+	allow publish 127.0.0.1;
+	deny publish all;
+	# push rtmp://a.rtmp.youtube.com/live2/my-secret-stream-key-here;
+}

+ 29 - 0
docker/etc/nginx/rtmp.conf

@@ -0,0 +1,29 @@
+rtmp {
+	server {
+		ping 5s;
+		listen 1935;
+		chunk_size 4096;
+		notify_method get;
+		publish_notify on;
+
+		application live {
+			live on;
+			on_publish http://localhost:8999/auth;
+
+			idle_streams off;
+			drop_idle_publisher 10s;
+
+			push rtmp://localhost/twitch;
+			push rtmp://localhost/youtube;
+
+			include /etc/nginx/rtmp-recordings.conf;
+
+			exec_publish bash -c "/etc/nginx/publish_start.sh '${name}' '${path}' '${basename}'";
+			exec_publish_done bash -c "/etc/nginx/publish_done.sh '${name}' '${path}' '${basename}'";
+			exec_record_done bash -c "/etc/nginx/record_done.sh '${name}' '${path}' '${basename}'";
+		}
+
+		include /etc/nginx/rtmp-twitch.conf;
+		include /etc/nginx/rtmp-youtube.conf;
+	}
+}

+ 24 - 0
docker/etc/nginx/sites-available/default

@@ -0,0 +1,24 @@
+server {
+	listen 8999 default_server;
+	listen [::]:8999 default_server;
+
+	root /var/www/html;
+	index index.html index.htm index.nginx-debian.html;
+
+	server_name _;
+
+	location / {
+			try_files $uri $uri/ =404;
+	}
+
+	include /etc/nginx/rtmp-pwd.conf;
+
+	location /recordings {
+			autoindex on;
+	}
+
+	location ~ /recordings/.*\.flv$ {
+			deny all;
+			return 403;
+	}
+}