一、安装nginx服务依赖
root@nginx:~# apt-get update
root@nginx:~# apt install -y build-essential #安装gcc
root@nginx:~# apt install -y libpcre3 libpcre3-dev
root@nginx:~# apt install -y libssl-dev
root@nginx:~# apt install -y zlib1g-dev
root@nginx:~# apt install -y libxml2 libxml2-dev
root@nginx:~# apt install -y libxslt-dev
root@nginx:~# apt install -y libgd-dev
二、下载相关软件包
root@nginx:~# wget http://h264.code-shop.com/download/nginx_mod_h264_streaming-2.2.7.tar.gz
root@nginx:~# wget http://nginx.org/download/nginx-1.15.9.tar.gz
root@nginx:~# git clone https://github.com/arut/nginx-rtmp-module
root@nginx:~# git clone https://github.com/pschultz/ngx_http_allow_methods_module.git
三、解压相关软件包
root@nginx:~# tar xf nginx-1.15.9.tar.gz
root@nginx:~# tar xf nginx_mod_h264_streaming-2.2.7.tar.gz
四、编译安装nginx(ngx_http_allow_methods_module模块用于允许http访问的请求类型,不需要安装)
root@nginx:~/nginx-1.15.9# ./configure --prefix=/usr/local/nginx --add-module=/root/nginx_mod_h264_streaming-2.2.7 \
--add-module=/root/nginx-rtmp-module --with-http_flv_module --with-http_mp4_module \
--with-http_gzip_static_module --with-http_stub_status_module --with-http_ssl_module \
--add-module=/root/ngx_http_allow_methods_module
五、编译安装nginx_mod_h264_streaming-2.2.7模块报错编辑ngx_http_streaming_module.c文件,把158到161行注释掉
root@nginx:~# vim nginx_mod_h264_streaming-2.2.7/src/ngx_http_streaming_module.c
157 /* TODO: Win32 */
158 // if (r->zero_in_uri)
159 // {
160 // return NGX_DECLINED;
161 // }
六、编辑Makefile文件,删除-Werror
root@nginx:~/nginx-1.15.9# vim objs/Makefile
root@nginx:~/nginx-1.15.9# make && make install
七、nginx配置
#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;
}
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 main;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
gzip on;
gzip_min_length 1k;
gzip_buffers 4 16k;
gzip_comp_level 2;
gzip_types text/plain application/x-javascript text/css application/xml;
gzip_vary on;
output_buffers 1 32k;
postpone_output 1460;
client_header_timeout 3m;
client_body_timeout 3m;
send_timeout 3m;
tcp_nopush on;
tcp_nodelay on;
open_file_cache max=64 inactive=30d;
open_file_cache_min_uses 1;
open_file_cache_valid 3m;
server {
listen 80;
server_name i.video.com;
charset utf-8;
location ~ \.mp4$|\.m4v$ {
root html/mp4m4v/;
}
location ~ \.flv$ {
root html/flv/;
}
}
server {
listen 80;
server_name www.video.com;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root html;
index index.html index.htm;
}
#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 configuration
#
#server {
# listen 8000;
# listen somename:8080;
# server_name somename alias another.alias;
# location / {
# root html;
# index index.html index.htm;
# }
#}
# HTTPS server
#
#server {
# listen 443 ssl;
# server_name localhost;
# ssl_certificate cert.pem;
# ssl_certificate_key cert.key;
# ssl_session_cache shared:SSL:1m;
# ssl_session_timeout 5m;
# ssl_ciphers HIGH:!aNULL:!MD5;
# ssl_prefer_server_ciphers on;
# location / {
# root html;
# index index.html index.htm;
# }
#}
}
八、index.html页面
<html>
<head>
<link href="https://vjs.zencdn.net/7.17.0/video-js.css" rel="stylesheet" />
<!-- If you'd like to support IE8 (for Video.js versions prior to v7) -->
<!-- <script src="https://vjs.zencdn.net/ie8/1.1.2/videojs-ie8.min.js"></script> -->
</head>
<body>
<video
id="my-video"
class="video-js"
controls
preload="auto"
width="640"
height="264"
poster="MY_VIDEO_POSTER.jpg"
data-setup="{}"
>
<source src="http://i.video.com/abc.mp4" type="video/mp4" />
<p class="vjs-no-js">
To view this video please enable JavaScript, and consider upgrading to a
web browser that
<a href="https://videojs.com/html5-video-support/" target="_blank"
>supports HTML5 video</a
>
</p>
</video>
<script src="https://vjs.zencdn.net/7.17.0/video.min.js"></script>
</body>
</html>
九、安装ffmpeg
CentOS8
[root@centos8 ~]# dnf install https://download1.rpmfusion.org/free/el/rpmfusion-free-release-8.noarch.rpm
[root@centos8 ~]# wget http://rpmfind.net/linux/centos/8.5.2111/PowerTools/x86_64/os/Packages/SDL2-2.0.10-2.el8.x86_64.rpm
[root@centos8 ~]# rpm -ivh SDL2-2.0.10-2.el8.x86_64.rpm
[root@centos8 ~]# dnf install ffmpeg
[root@centos8 ~]# ffmpeg -i inputfile.mp4 -s 1280*720 -b:v 1.5M /tmp/outputfile.mp4 -y
# MP4格式转m3u8(-segment_time 10:把xxxx.mp4切成每10秒一个的ts视频的m3u8文件)
[root@centos8 ~]# ffmpeg -i xxxx.mp4 -f segment -segment_time 10 -segment_format mpegts -segment_list ./m3u8/test/test.m3u8 -c copy -bsf:v h264_mp4toannexb -map 0 ./m3u8/test/test%03d.ts
CenOS7
1.安装epel并update yum
[root@centos7 ~]# yum install epel-release -y
[root@centos7 ~]# yum update -y
2.安装Nux Dextop Yum 源
[root@centos7 ~]# rpm --import http://li.nux.ro/download/nux/RPM-GPG-KEY-nux.ro
[root@centos7 ~]# rpm -Uvh http://li.nux.ro/download/nux/dextop/el7/x86_64/nux-dextop-release-0-5.el7.nux.noarch.rpm
3.安装FFmpeg 和 FFmpeg开发包
[root@centos7 ~]# yum install ffmpeg ffmpeg-devel -y
Ubuntu
root@ubuntu:~# sudo add-apt-repository ppa:savoury1/graphics
root@ubuntu:~# sudo add-apt-repository ppa:savoury1/multimedia
root@ubuntu:~# sudo add-apt-repository ppa:savoury1/ffmpeg4
root@ubuntu:~# sudo apt-get update
root@ubuntu:~# sudo apt-get install ffmpeg
参考链接:
https://leefige.github.io/2019/03/05/%E5%9F%BA%E4%BA%8ENginx%E9%85%8D%E7%BD%AEWeb%E8%A7%86%E9%A2%91%E6%B5%81%E5%AA%92%E4%BD%93%E6%9C%8D%E5%8A%A1%E5%99%A8/
https://lxneng.com/posts/160?lang=zh_CN #编译nginx报错解决
https://github.com/pschultz/ngx_http_allow_methods_module
http://rpmfind.net/linux/rpm2html/search.php?query=libSDL2-2.0.so.0()(64bit)
http://t.zoukankan.com/architectforest-p-12807683.html #centos8上安装ffmpeg
https://api.freeconverting.com #在线格式转换
https://my.oschina.net/weitao520lin/blog/5280537 #ubuntu ffmpeg apt-get安装
https://www.johnvansickle.com/ffmpeg/ #ffmpeg静态版本,解压后可直接使用
https://launchpad.net/~savoury1/+archive/ubuntu/ffmpeg4 #ubuntu ffmpeg版本
https://ffmpeg.org/ffmpeg.html # ffmpeg官方文档