From 4333ce12393146a9b13c8d5189cdda2f431e194b Mon Sep 17 00:00:00 2001 From: kev Date: Wed, 24 Feb 2016 13:48:14 +0800 Subject: [PATCH] add rtmp --- README.md | 1 + rtmp/README.md | 84 +++++++++++++++++++++ rtmp/client/Dockerfile | 12 +++ rtmp/client/docker-compose.yml | 7 ++ rtmp/server/data/README.md | 1 + rtmp/server/docker-compose.yml | 8 ++ rtmp/server/nginx/nginx.conf | 129 +++++++++++++++++++++++++++++++++ 7 files changed, 242 insertions(+) create mode 100644 rtmp/README.md create mode 100644 rtmp/client/Dockerfile create mode 100644 rtmp/client/docker-compose.yml create mode 100644 rtmp/server/data/README.md create mode 100644 rtmp/server/docker-compose.yml create mode 100644 rtmp/server/nginx/nginx.conf diff --git a/README.md b/README.md index d36b223..076bdb1 100644 --- a/README.md +++ b/README.md @@ -82,6 +82,7 @@ dockerfiles - [x] redis-arm - [x] revive - [x] rsyncd +- [x] rtmp - [x] samba :beetle: - [x] scrapyd :+1: - [x] shadowsocks diff --git a/rtmp/README.md b/rtmp/README.md new file mode 100644 index 0000000..23dd7e4 --- /dev/null +++ b/rtmp/README.md @@ -0,0 +1,84 @@ +rtmp +==== + +- NGINX-based Media Streaming Server. +- FFMPGE-based Media Streaming Client. + +## Directory Tree + +``` +~/fig/rtmp/ +├── data/ +│ └── video.mp4 +├── docker-compose.yml +└── nginx/ + └── nginx.conf +``` + +## docker-compose.yml + +```yaml +server: + image: vimagick/nginx + ports: + - "1935:1935" + volumes: + - ./nginx/nginx.conf:/etc/nginx/nginx.conf + - ./data:/data + restart: always + +client: + image: vimagick/rtmp-client-arm + devices: + - /dev/video0:/dev/video0 + environment: + - RTMP_URI=rtmp://datageek.info/live/webcam + restart: always +``` + +## Server + +``` +$ cd ~/fig/rtmp/ +$ docker-compose up -d server +$ youtube-dl 'https://www.youtube.com/watch?v=lJZlz-WnXzU' -o data/video.mp4 +``` + +## Client + +``` +# play remote video (remote -> local) +$ vlc rtmp://datageek.info/vod/video.mp4 + +# play local video (local -> remote -> local) +$ ffmpeg -re -i video.mp4 -f flv rtmp://datageek.info/live/video +$ vlc rtmp://datageek.info/live/video.mp4 + +# capture desktop (local -> remote) +$ ffmpeg -f avfoundation -pixel_format bgr0 -i 1:0 -f flv rtmp://datageek.info/live/webcam + +# record webcam (local -> remote) +$ ffmpeg -f qtkit -i 0 -f flv rtmp://datageek.info/live/webcam + +# record pi camera (pi -> remote) +$ ffmpeg -f video4linux2 -r 24 -i /dev/video0 -f flv rtmp://datageek.info/live/webcam + +# record pi camera (pi -> remote) +$ /opt/vc/bin/raspivid -o - -t 0 -hf -w 640 -h 360 -fps 25 | ffmpeg -i - -f flv rtmp://datageek.info/live/webcam + +# watch webcam (remote -> local) +$ vlc rtmp://datageek.info/live/webcam +``` + +Optinally, you can run a docker container as RTMP client on raspberry pi. + +``` +$ cd ~/fig/rtmp/ +$ docker-compose up -d client +``` + +## References + +- https://github.com/arut/nginx-rtmp-module/wiki/Directives +- https://trac.ffmpeg.org/wiki/StreamingGuide +- https://trac.ffmpeg.org/wiki/Capture/Webcam diff --git a/rtmp/client/Dockerfile b/rtmp/client/Dockerfile new file mode 100644 index 0000000..5c391e6 --- /dev/null +++ b/rtmp/client/Dockerfile @@ -0,0 +1,12 @@ +# +# Dockerfile for rtmp-client-arm +# + +FROM vimagick/alpine-arm +MAINTAINER kev + +RUN set -xe \ + && apk add -U ffmpeg \ + && rm -rf /var/cache/apk/* + +CMD ffmpeg -f video4linux2 -r 24 -i /dev/video0 -f flv $RTMP_URI diff --git a/rtmp/client/docker-compose.yml b/rtmp/client/docker-compose.yml new file mode 100644 index 0000000..54a1362 --- /dev/null +++ b/rtmp/client/docker-compose.yml @@ -0,0 +1,7 @@ +client: + image: vimagick/rtmp-client-arm + devices: + - /dev/video0:/dev/video0 + environment: + - RTMP_URI=rtmp://boss.datageek.info/live/webcam + restart: always diff --git a/rtmp/server/data/README.md b/rtmp/server/data/README.md new file mode 100644 index 0000000..0c68e77 --- /dev/null +++ b/rtmp/server/data/README.md @@ -0,0 +1 @@ +PLEASE PUT VIDEO FILES HERE diff --git a/rtmp/server/docker-compose.yml b/rtmp/server/docker-compose.yml new file mode 100644 index 0000000..7a2c2ff --- /dev/null +++ b/rtmp/server/docker-compose.yml @@ -0,0 +1,8 @@ +server: + image: vimagick/nginx + ports: + - "1935:1935" + volumes: + - ./nginx/nginx.conf:/etc/nginx/nginx.conf + - ./data:/data + restart: always diff --git a/rtmp/server/nginx/nginx.conf b/rtmp/server/nginx/nginx.conf new file mode 100644 index 0000000..90f69a4 --- /dev/null +++ b/rtmp/server/nginx/nginx.conf @@ -0,0 +1,129 @@ + +#user nobody; +worker_processes 1; + +#error_log logs/error.log; +#error_log logs/error.log notice; +#error_log logs/error.log info; + +#pid logs/nginx.pid; + + +events { + worker_connections 1024; +} + + +http { + include mime.types; + default_type application/octet-stream; + + #log_format main '$remote_addr - $remote_user [$time_local] "$request" ' + # '$status $body_bytes_sent "$http_referer" ' + # '"$http_user_agent" "$http_x_forwarded_for"'; + + #access_log logs/access.log main; + + sendfile on; + #tcp_nopush on; + + #keepalive_timeout 0; + keepalive_timeout 65; + + #gzip on; + + server { + listen 80; + server_name localhost; + + #charset koi8-r; + + #access_log logs/host.access.log main; + + location / { + root html; + index index.html index.htm; + } + + #error_page 404 /404.html; + + # redirect server error pages to the static page /50x.html + # + error_page 500 502 503 504 /50x.html; + location = /50x.html { + root html; + } + + # proxy the PHP scripts to Apache listening on 127.0.0.1:80 + # + #location ~ \.php$ { + # proxy_pass http://127.0.0.1; + #} + + # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 + # + #location ~ \.php$ { + # root html; + # fastcgi_pass 127.0.0.1:9000; + # fastcgi_index index.php; + # fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name; + # include fastcgi_params; + #} + + # deny access to .htaccess files, if Apache's document root + # concurs with nginx's one + # + #location ~ /\.ht { + # deny all; + #} + } + + + # another virtual host using mix of IP-, name-, and port-based configuration + # + #server { + # listen 8000; + # listen somename:8080; + # server_name somename alias another.alias; + + # location / { + # root html; + # index index.html index.htm; + # } + #} + + + # HTTPS server + # + #server { + # listen 443 ssl; + # server_name localhost; + + # ssl_certificate cert.pem; + # ssl_certificate_key cert.key; + + # ssl_session_cache shared:SSL:1m; + # ssl_session_timeout 5m; + + # ssl_ciphers HIGH:!aNULL:!MD5; + # ssl_prefer_server_ciphers on; + + # location / { + # root html; + # index index.html index.htm; + # } + #} + +} + +rtmp { + server { + listen 1935; + application live { + live on; + } + application vod { + play /data; + } + } +}