Windows:php
一、下載文件:html
連接:https://pan.baidu.com/s/1c2LmIHHw-dwLOlRN6iTIMg
提取碼:g7sj
二、解壓文件:nginx
解壓到nginx-1.7.11.3-Gryphonc++
三、進入windows的cmd; git
> cd nginx-1.7.11.3-Gryphon //進入nginx的目錄github
> nginx.exe -c conf\nginx-win-rtmp.conf //運行rtmp配置文件 windows
注意:此時命令行會一直處於執行中 不用理會 也不要關閉瀏覽器
測試:瀏覽器輸入localhost:80 ,查看是否配置nginx啓動成功!
四、推流:bash
ffmpeg -re -i 123.mp4 -vcodec libx264 -acodec aac -f flv rtmp://你的ip地址:1935/live/homeapp
五、拉流:
電腦打開vlc播放器 輸入地址:rtmp://你的ip地址:1935/live/home
Linux:
一、安裝工具:
#gcc gcc-c++ perl 編譯軟件包用
yum install -y net-tools wget unzip gcc gcc-c++ perl
二、安裝nginx及rtmp:
#切換的homme目錄 cd /home
#下載pcre包 wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.41.tar.gz #解壓pcre包 tar -zxvf pcre-8.41.tar.gz
#下載zlib包 wget http://www.zlib.net/zlib-1.2.11.tar.gz #解壓zlib包 tar -zxvf zlib-1.2.11.tar.gz
#下載openssl包 wget https://www.openssl.org/source/old/1.0.1/openssl-1.0.1i.tar.gz #解壓openssl包 tar -zxvf openssl-1.0.1i.tar.gz #切換到openssl裏 cd openssl-1.0.1i #生成配置文件 默認配置 ./config #編譯程序 make #安裝程序 make install
#下載rtmp包 wget https://github.com/arut/nginx-rtmp-module/archive/master.zip #解壓下載包 unzip -o master.zip #修改文件夾名 mv master nginx-rtmp-module
nginx wget http://nginx.org/download/nginx-1.12.2.tar.gz #解壓 nignx tar -zxvf nginx-1.12.2.tar.gz #切換到nginx中 cd nginx-1.12.2 #生成配置文件,將上述下載的文件配置到configure中 ./configure --prefix=/usr/local/nginx --with-pcre=/home/pcre-8.41 --with-zlib=/home/zlib-1.2.11 --with-openssl=/home/openssl-1.0.1i --add-module=/home/nginx-rtmp-module #編譯程序 make #安裝程序 make install
#建立全局命令
ln -s /usr/local/nginx/sbin/nginx /usr/bin/nginx
#查看nginx模塊 nginx -V
安裝FFmpeg:
安裝ffmpeg時須要提早安裝yasm插件:
cd /home wget http://www.tortall.net/projects/yasm/releases/yasm-1.3.0.tar.gz tar -xvf yasm-1.3.0.tar.gz cd yasm-1.3.0/ ./configure && make && make install
開始安裝ffmpeg:
cd /home wget http://www.ffmpeg.org/releases/ffmpeg-3.4.tar.gz tar -xvf ffmpeg-3.4.tar.gz cd ffmpeg-3.4/ ./configure && make && make install
編譯成功後測試:
ffmpeg --help
新建配置文件:
vi /usr/local/nginx/conf/nginx-rtmp.conf
輸入內容:
#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; } #RTMP閰嶇疆 rtmp{ server{ listen 1935; application myapp{ live on; } application hls{ live on; hls on; hls_path /tmp/hls; } } } # 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; # sendfile on; ##tcp_nopush on; # ##keepalive_timeout 0; keepalive_timeout 65; # gzip on; #include /usr/local/nginx/conf.d/*.conf; server { listen 80; server_name localhost; # ##charset koi8-r; # ##access_log logs/host.access.log main; # location / { root html; index index.html index.htm; } location /hls { types{ application/vnd.apple.mpegurl m3u8; video/mp2t ts; } root /tmp; add_header Cache-Control no-cache; } ##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 configurati ##error_page 404 /404.html; # ## redirect server error pages to the static page /50x.html ##
/usr/local/nginx/sbin/nginx
systemctl stop firewalld systemctl disable firewalld
ffmpeg -re -i 123.mp4 -vcodec copy -codec copy -f flv rtmp://你的ip/hls/cctv
視頻切片保存位置:/tmp/hls/ m3u8視頻訪問地址:http://你的ip/hls/cctv.m3u8
重啓nginx
/usr/local/nginx/sbin/nginx -s reload