1、软件安装:

tar -jxvf x264-master.tar.bz2
./configure –prefix=/usr/local/x264 –includedir=/usr/local/include –libdir=/usr/local/lib –enable-shared
make
make install

tar -xf nasm-2.14.tar.gz
./configure
make
make install

tar -xf ffmpeg-4.3.tar.gz
./configure –enable-gpl –enable-shared –enable-libx264
make
make install

tar -xvf nginx-1.19.5.tar.gz
–prefix=/usr/local/nginx –add-module=/usr/local/nginx-rtmp-module –conf-path=/etc/nginx/nginx.conf –error-log-path=/var/log/nginx/error.log –http-log-path=/var/log/nginx/access.log –pid-path=/var/run/nginx.pid –lock-path=/var/run/nginx.lock –http-client-body-temp-path=/var/cache/nginx/client_temp –http-proxy-temp-path=/var/cache/nginx/proxy_temp –http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp –http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp –http-scgi-temp-path=/var/cache/nginx/scgi_temp –user=nginx –group=nginx –with-http_ssl_module –with-http_realip_module –with-http_addition_module –with-http_sub_module –with-http_dav_module –with-http_flv_module –with-http_mp4_module –with-http_gunzip_module –with-http_gzip_static_module –with-http_random_index_module –with-http_secure_link_module –with-http_stub_status_module –with-http_auth_request_module –with-threads –with-stream –with-stream_ssl_module –with-http_slice_module –with-file-aio –with-http_v2_module –with-ipv6
make
make install

vim /etc/ld.so.conf
追加
/usr/local/lib
ldconfig

 

2、nginx : 配置

 

user root;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;

 

events {
worker_connections 1024;
}

http {
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 /var/log/nginx/access.log main;

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;

server {
listen 80 default_server;
# listen [::]:80 default_server;
server_name _;
root /usr/local/nginx/html;

# Load configuration files for the default server block.
include /etc/nginx/default.d/*.conf;
location / {
resolver 8.8.8.8;
proxy_buffers 256 4k;
proxy_max_temp_file_size 0k;
}
error_page 404 /404.html;
location = /40x.html {
}

error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}

server {
listen 8080;
location /stat {
rtmp_stat all;
rtmp_stat_stylesheet stat.xsl;
}
location /stat.xsl {
root /usr/local/nginx-rtmp-module/;
}
location /hls {
types {
application/vnd.apple.mpegurl m3u8;
video/mp2t ts;
}
autoindex on;
alias /usr/local/nginx/html/hls;
expires -1;
add_header Cache-Control no-cache;
add_header ‘Access-Control-Allow-Origin’ ‘*’;
add_header ‘Access-Control-Allow-Credentials’ ‘true’;
add_header ‘Access-Control-Allow-Methods’ ‘GET, POST, OPTIONS’;
add_header ‘Access-Control-Allow-Headers’ ‘DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type’;
}
}

}

rtmp {
server {
listen 1935;
chunk_size 4000;
application vod {
play /usr/local/nginx/html/flvs/;
}
application live {
live on;
}
application hls {
live on;
hls on;
hls_path /usr/local/nginx/html/hls;
hls_fragment 5s;
hls_playlist_length 15s;
hls_continuous on;
hls_cleanup on;
hls_nested on;
}
}
}

 

3、推流验证:

ffmpeg -re -i /home/sedm/dangke.mp4 -r 30 -s 854×480 -c:v libx264 -force_key_frames “expr:gte(t,n_forced*4)” -f flv “rtmp://192.168.0.62:1935/hls/test1”

 

4、拉流验证:

谷歌浏览器安装插件:play-hls-m3u8.crx

http://192.168.0.62:8080/hls/test1/index.m3u8