서론
인터넷으로 영상을 송수신하는 과정은 상당히 많은 기술에 대한 이해를 필요로 합니다. 우선, 카메라 영상을 인터넷을 통해 송수신하기 위해서는 디지털 인코딩(encoding)/디코딩(decoding) 하는 과정이 필요합니다. 디지털 영상 신호를 주고 받기 위한 통신 규약(protocol)에도 RTP/RTSP, RTMP, HLS, MPEG-Dash 등 다양한 방식이 존재합니다. 영상을 보는 방법도 영상 파일을 다운로드 받아서 재생해서 보던 방식에서 벗어나 초고속 인터넷과 스마트폰 시대가 도래하면서 실시간 스트리밍 방식으로 변화하고 있습니다. 이전에는 파일 전송을 위한 전용 FTP 서버가 필요했다면 현재는 전체 파일 다운로드 없이 실시간 스트리밍으로 영상을 송출할 수 있는 서버가 필요합니다. 하나의 영상 소스를 다양한 재생 기기에 맞도록 실시간 변환해서 스트리밍을 하기 위해서는 어떻게 해야 하는 것일까요? 이럴 때 필요한 것이 ‘스트리밍 서버’ 입니다. 가장 대표적으로 Wowza 가 있습니다만 2백만원이 넘는 고가입니다. 저렴한 대안으로 nginx-rtmp 모듈이 있습니다. 기존의 nginx 웹 서버에 추가하여 RTMP 실시간 스트리밍이 가능하도록 하는 확장 기능 모듈입니다.
https://harry.web.id/2018/11/16/rtmp-server-hls-ubuntu-18-04-1-lts/
본 글에서는 Docker 와 nginx-rtmp 모듈을 이용하여 스트리밍 서버를 구축하는 방법을 정리해 보았습니다. 이를 위해서 docker 가 필요한데 아직 설치하지 않으셨다면 “Raspberry PI 에서 docker 설치와 실행하기” 를 보시고 docker 설치를 먼저 진행 하시기 바랍니다.
전체 과정 요약
- 준비
- Dockerfile 수정
- nginx-rtmp build
- nginx-rtmp 기동
- ffmpeg 설치
- 실시간 스트리밍 서비스 개시
- 시험 영상 확인
RTMP server + HLS Ubuntu 18.04.1 LTS
Install Nginx
sudo apt install libnginx-mod-rtmp
Install rtmp-module
sudo apt install libnginx-mod-rtmp service nginx restart
Setting nginx conf
nano /etc/nginx/nginx.conf
rtmp { server { listen 1935; chunk_size 4000; allow play all; application live { allow play all; live on; } application hls { live on; # Turn on HLS hls on; hls_path /mnt/hls/; hls_fragment 3; hls_playlist_length 60; # disable consuming the stream from nginx as rtmp deny play all; } } }
Create new nginx config file
nano /etc/nginx/conf.d/hls.conf
server { listen 8080; location /hls { # Disable cache add_header Cache-Control no-cache; # CORS setup add_header 'Access-Control-Allow-Origin' '*' always; add_header 'Access-Control-Expose-Headers' 'Content-Length'; # allow CORS preflight requests if ($request_method = 'OPTIONS') { add_header 'Access-Control-Allow-Origin' '*'; add_header 'Access-Control-Max-Age' 1728000; add_header 'Content-Type' 'text/plain charset=UTF-8'; add_header 'Content-Length' 0; return 204; } types { application/vnd.apple.mpegurl m3u8; video/mp2t ts; } root /mnt; add_header Cache-Control no-cache; } }
Restart Nginx…Done
Basic uri syntax: rtmp://your_ip/hls/stream_name
video will be available as http://your_ip:8080/hls/stream_name.m3u8
This entry was posted in Linux on November 16, 2018.
'Network > Application' 카테고리의 다른 글
MPEG-DASH live streaming in nginx-rtmp-module (0) | 2019.06.21 |
---|---|
동영상 기본용어 (0) | 2019.06.20 |
FFMPEG이란 (0) | 2019.06.19 |
코덱 정리 (0) | 2019.06.19 |
Streaming Protocol 종류 (0) | 2019.06.19 |