Last active
February 15, 2020 13:41
-
-
Save nooptr/b4563e43710dc4259ac7d3fd97e6399c to your computer and use it in GitHub Desktop.
Nginx hls ubuntu 16.04
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Install nginx | |
git clone https://github.com/sergey-dryabzhinsky/nginx-rtmp-module.git | |
sudo apt-get install build-essential libpcre3 libpcre3-dev libssl-dev | |
wget http://nginx.org/download/nginx-1.17.8.tar.gz | |
tar -xf nginx-1.10.1.tar.gz | |
cd nginx-1.10.1 | |
./configure --add-module=../nginx-rtmp-module --with-http_ssl_module --with-http_stub_status_module --prefix=/etc/nginx | |
make -j 1 | |
sudo make install | |
# Install ffmpeg | |
sudo add-apt-repository ppa:mc3man/trusty-media | |
sudo apt-get update | |
sudo apt-get install ffmpeg | |
# /etc/nginx/conf/nginx.conf | |
``` | |
user nobody; | |
worker_processes 1; | |
error_log logs/rtmp_error.log debug; | |
pid logs/nginx.pid; | |
events { | |
worker_connections 1024; | |
} | |
http { | |
server { | |
listen 80; | |
server_name localhost; | |
location /hls { | |
# Serve HLS fragments | |
# 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; | |
} | |
location /stats { | |
stub_status; | |
} | |
} | |
} | |
# Start nginx | |
sudo /etc/nginx/sbin/nginx | |
# Stop nginx | |
sudo /etc/nginx/sbin/nginx -s stop | |
# Convert mp4 to m3u8 | |
ffmpeg -i sample.mp4 -profile:v baseline -level 3.0 -s 640x360 -start_number 0 -hls_time 10 -hls_list_size 0 -f -strict -2 hls sample2.m3u8 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment