구축

RTMP NGINX 라이브 스트리밍 서버 - FreeBSD

상석하대 2023. 7. 20. 16:39

❚ 개요

캡처도구 ---> OBS 송출 ---> (rtmp)서버(hls) ---> WEB <--- video TAG

 

❚ ffmpeg 설치

cd /usr/ports/multimedia/ffmpeg

make config

make BATCH=yes install clean

시간이 꽤 걸린다.

디스크에 여유 공간이 20GB 가량 있어야 한다.

설치를 마치면 점검한다.

ffmpeg -codecs
ffmpeg -formats
ffmpeg -i test.mp4 test.avi

 

❚ nginx 설치

cd /usr/ports/www/nginx
make config

RTMP를 스페이스바 키로 선택한다.

make BATCH=yes install clean
rehash

mkdir /usr/local/www/live
chown www:www /usr/local/www/live/

 

❚ 라이브 스트리밍 설정
ee /usr/local/etc/nginx/nginx.conf

load_module /usr/local/libexec/nginx/ngx_stream_module.so;
load_module /usr/local/libexec/nginx/ngx_rtmp_module.so;
worker_processes  4;

events {
    worker_connections  1024;
}

rtmp {
    server {
        listen 1935;
        chunk_size 4096;

        application stream {
            live on;
            record off;

            exec ffmpeg -i rtmp://localhost/stream/$name
                -c:a aac -b:a 128k -c:v libx264 -b:v 2500k -f flv -g 30 -r 30 -s 1280x720 -preset superfast -profile:v baseline rtmp://localhost/hls/$name_720p2628kbs
                -c:a aac -b:a 128k -c:v libx264 -b:v 1000k -f flv -g 30 -r 30 -s 854x480 -preset superfast -profile:v baseline rtmp://localhost/hls/$name_480p1128kbs
                -c:a aac -b:a 128k -c:v libx264 -b:v 750k -f flv -g 30 -r 30 -s 640x360 -preset superfast -profile:v baseline rtmp://localhost/hls/$name_360p878kbs
                -c:a aac -b:a 128k -c:v libx264 -b:v 400k -f flv -g 30 -r 30 -s 426x240 -preset superfast -profile:v baseline rtmp://localhost/hls/$name_240p528kbs
                -c:a aac -b:a 64k -c:v libx264 -b:v 200k -f flv -g 15 -r 15 -s 426x240 -preset superfast -profile:v baseline rtmp://localhost/hls/$name_240p264kbs;
        }

        application hls {
            live on;
            hls on;
            hls_fragment_naming system;
            hls_fragment 2s;
            hls_playlist_length 4s;
            hls_path /usr/local/www/live/hls;
            hls_nested on;
            hls_variant _720p2628kbs BANDWIDTH=2628000,RESOLUTION=1280x720;
            hls_variant _480p1128kbs BANDWIDTH=1128000,RESOLUTION=854x480;
            hls_variant _360p878kbs BANDWIDTH=878000,RESOLUTION=640x360;
            hls_variant _240p528kbs BANDWIDTH=528000,RESOLUTION=426x240;
            hls_variant _240p264kbs BANDWIDTH=264000,RESOLUTION=426x240;
        }
    }
}

http {
    tcp_nopush on;
    sendfile off;
    server_tokens off;
    default_type application/octet-stream;

    server {
        listen 8080;
        location /hls {
            types {
                application/vnd.apple.mpegurl m3u8;
                video/mp2t ts;
            }
            root /usr/local/www/live;
            add_header Cache-Control no-cache;
            add_header Access-Control-Allow-Origin *;
        }

        location /live {
          alias /usr/local/www/live/hls;
          types {
              application/vnd.apple.mpegurl m3u8;
              video/mp2t ts;
          }
          add_header Cache-Control no-cache;
          add_header Access-Control-Allow-Origin *;
        }

        location /stat {
            rtmp_stat all;
            rtmp_stat_stylesheet stat.xsl;
        }

        location /stat.xsl {
            root /usr/local/www/live/static;
        }

        location /crossdomain.xml {
            default_type text/xml;
            expires 24h;
        }
    }
}

 

❚ 서비스 시작

nginx -t
/usr/local/etc/rc.d/nginx enable
/usr/local/etc/rc.d/nginx start

반응형

'구축' 카테고리의 다른 글

FTPs 설치 - Windows, IIS  (0) 2023.07.27
네트워크 공유폴더 - Samba 4, FreeBSD 13  (0) 2023.07.26
WebDAV 설치  (0) 2023.06.07
네트워크 공유 폴더 만들기  (0) 2023.06.02
IIS 10 - SNI(서버 이름 표시)  (0) 2023.04.25