nginx搭建点播视频(Mp4播放)

首先,环境中必然要有gcc-c++环境

  yum -y install gcc-c++

1 使用openresty

这里使用的是1.11.2.1版本的openresty和1.0.2版本的openssl

      [email protected]: ~#yum install readline-devel pcre-devel openssl-devel gcc

      [email protected]: ~# tar -zxvf openresty-1.11.2.1.tar.gz

      [email protected]: ~#tar -zxvf openssl-1.0.2h.tar.gz

      [email protected]: ~#cd openresty-1.11.2.1

      [email protected]: ~#./configure --prefix=/app/openresty --user=xxx --group=xxx --with-http_v2_module --with-openssl=/home/appdeploy/nginx/openssl-1.0.2h --with-select_module --with-poll_module --with-file-aio --with-http_ssl_module --with-http_realip_module --with-http_gzip_static_module --with-http_secure_link_module --with-http_sub_module --with-http_stub_status_module --with-http_perl_module --with-http_mp4_module --with-http_flv_module

可以在这里设置user和group,也可以稍后使用下面的命令进行设置

chown -R [user]:[group] 文件夹名上面的命令执行之后,编译并安装openrestry,安装目录就是配置中指定的/app/openrestry

   [email protected]: ~#make && make install

如果安装的时候没有权限,可以用su切到root,注意安装之后的openrestry目录的权限即可。
此时openrestry已经安装好,到安装目录中修改openrestry下的nginx文件夹下的nginx.conf配置文件

worker_processes 1;       #工作进程数,一般设置为1就可以了
#error_log  /usr/local/nginx/logs/error.log  crit;
#pid        /usr/local/nginx/logs/nginx.pid;
events {
        use epoll;
        worker_connections      65535;
        }
http {
        include       mime.types;
        default_type  application/octet-stream;
        log_format main  ‘$remote_addr - $remote_user [$time_local] ‘
                                                ‘"$request" $status $bytes_sent ‘
                                                ‘"$http_referer" "$http_user_agent" ‘
                                                ‘"$gzip_ratio"‘;
        keepalive_timeout  60;
        server_names_hash_bucket_size  128;
        client_header_buffer_size    32k;
        large_client_header_buffers  4 32k;
        access_log off;
        gzip on;
        gzip_min_length  1100;
        gzip_buffers     4 8k;
        gzip_types       text/plain;
        output_buffers   1 32k;
        postpone_output  1460;
        client_header_timeout  3m;
        client_body_timeout    3m;
        send_timeout           3m;
        sendfile                on;
        tcp_nopush              on;
        tcp_nodelay             on;
    server {
           listen 8080;
           server_name  10.202.94.16;
           root    /app/openresty/nginx/html/;
           limit_rate_after 30m;
           limit_rate 700k;            #这里根据需要设置,意思是视频缓冲30M之后,限速为700k/s
           index   index.html;
           charset utf-8;
           location ~ \.flv$ {
              flv;
           }
           location ~ \.mp4$ {
              mp4;
           }
           error_page   500 502 503 504  /50x.html;
           location = /50x.html {
               root   html;
           }
    }
}

修改之后,启动nginx服务器

  [email protected]: ~#/app/openresty/nginx/sbin/nginx -c /app/openresty/nginx/conf/nginx.conf

将mp4文件放到/app/openresty/nginx/html/目录下
在浏览器上访问http://10.202.94.16:8080/xxx.mp4即可。

2 使用nginx

建议采用nginx 1.1.3版本之后的nginx,默认支持mp4,就无需再安装一堆繁琐的插件。这里使用的是1.3.14版本。

  [email protected]: ~# tar -zxvf nginx-1.3.14.tar.gz

  [email protected]: ~# cd nginx-1.3.14

  [email protected]: ~# ./configure --prefix=/app/nginx --user=xxx --group=xxx --with-select_module --with-poll_module --with-file-aio --with-http_ssl_module --with-http_realip_module --with-http_gzip_static_module --with-http_secure_link_module --with-http_sub_module --with-http_stub_status_module --with-http_perl_module --with-http_mp4_module --with-http_flv_module

  [email protected]: ~# make&& make install

然后同样的,去/app/nginx做和openrestry中的nginx一样的修改即可,注意修改目录。

效果如下所示,此时的视频是横跨整个屏幕的,如果想要修改,比如做页面的内嵌视频,可以把视频放到HTML5页面中,再通过nginx服务器访问html文件即可。有个开源的video.js很好用,这里就不再赘述了。

报错信息处理:

http://nginx.org/download/nginx-1.9.15.tar.gz下载nginx包(或者wget http://nginx.org/download/nginx-1.9.15.tar.gz直接在Linux上用命令下载)

解压并转到目录下

  [email protected]: ~# tar -zxvf nginx-1.9.15.tar.gz
  [email protected]: ~# cd nginx-1.9.15

设置一下配置信息

  [email protected]: ~#./configure --prefix=/usr/local/nginx ,或者不执行此步,直接默认配置

编译安装

    [email protected]: ~# make
    [email protected]: ~# make install

make的过程是把各种语言写的源码文件,变成可执行文件和各种库文件;
make install是把这些编译出来的可执行文件和库文件复制到合适的地方。

可能出现错误在配置信息

    [email protected]: ~#./configure --prefix=/usr/local/nginx 的时,出现错误:
/configure: error: the HTTP rewrite module requires the PCRE library.

解决方法:安装pcre
 

 [email protected]: ~# yum -y install pcre pcre-devel

-y 是跳过所有需要手动确认的环节

缺少ssl错误,错误信息如下:
[email protected]: ~# ./configureerror: the HTTP cache module requires md5 functions from OpenSSL library. You can either disable the module by using --without-http-cache option, or install the OpenSSL library into the system,or build the OpenSSL library statically from the source with nginx by using
--with-http_ssl_module --with-openssl=<path> options.

解决方法:安装openssl

  [email protected]: ~# yum -y install openssl openssl-devel

缺少编译器,错误信息如下:

    [email protected]: ~# ./configure
    error: C compiler cc is not found

解决方法:安装gcc-c++

    [email protected]: ~# yum -y install gcc-c++ autoconf automake

autoconf是自动配置,automake是自动编译
缺少zlib包,错误信息如下:

    [email protected]: ~# ./configure:
    error: the HTTP gzip module requires the zlib library.You can either disable the module by using –without-http_gzip_module option, or install the zlib library into the system, or build the zlib library statically from the source with nginx by using –with-zlib=<path> option.

解决方法:安装zlib

    [email protected]: ~# yum install -y zlib-devel

确实libxml2,错误信息如下:

    [email protected]: ~# ./configure:
    error: the HTTP XSLT module requires the libxml2/libxslt libraries. You can either do not enable the module or install the libraries.

解决方法:

    [email protected]: ~# yum -y install libxml2 libxml2-dev
    [email protected]: ~# yum -y install libxslt-devel

http_image_filter_module是nginx提供的集成图片处理模块,需要gd-devel的支持,错误信息如下:

    [email protected]: ~# ./configure:
    error: the HTTP image filter module requires the GD library.You can either do not enable the module or install the libraries.

解决方法:

    [email protected]: ~# yum -y install gd-devel

缺少ExtUtils,错误信息如下:

    [email protected]: ~# ./configure:
    error: perl module ExtUtils::Embed is required

解决方法:

    [email protected]: ~# yum -y install perl-devel perl-ExtUtils-Embed

缺少GeoIP,错误信息如下:

    [email protected]: ~# ./configure:
     error: the GeoIP module requires the GeoIP library.You can either do not enable the module or install the library.

解决方法:

    [email protected]: ~# yum -y install GeoIP GeoIP-devel GeoIP-data

安装完成后启动安装成功后 /usr/local/nginx 目录下如下
fastcgi.conf koi-win nginx.conf.default
fastcgi.conf.default logs scgi_params
fastcgi_params mime.types scgi_params.default
fastcgi_params.default mime.types.default uwsgi_params
html nginx uwsgi_params.default
koi-utf nginx.conf win-utf
启动
确保系统的 80 端口没被其他程序占用,运行/usr/local/nginx/nginx
命令来启动 Nginx,

    [email protected]: ~# netstat -ano|grep 80

如果查不到结果后执行,有结果则忽略此步骤(ubuntu下必须用sudo启动,不然只能在前台运行)

    [email protected]: ~# sudo /usr/local/nginx/nginx

打开浏览器访问此机器的 IP,如果浏览器出现 Welcome
to nginx! 则表示 Nginx 已经安装并运行成功。

直播视频搭建:

rtmp  协议

原文地址:https://www.cnblogs.com/Tang-Yuan/p/9856268.html

时间: 2024-08-06 08:01:27

nginx搭建点播视频(Mp4播放)的相关文章

nginx搭建flv、mp4流媒体服务

1.安装pcre-8.33.tar.bz2 #tar -xvf 1.pcre-8.33.tar.bz2 #cd pcre-8.33/ #./configure #make && make install 2.安装openssl-1.0.1h.tar.gz #tar -xvf openssl-1.0.1h.tar.gz # cd openssl-1.0.1h/ #./config #make && make install 3.添加mp4支持模块 下载 http://h264

配置 nginx 支持 f4v视频格式播放

Nginx默认不支持f4v视频格式播放,解决方法为编辑mime.types文件,在video/mp4加上f4v即可 types {   # Data interchange     application/atom+xml                  atom;     application/json                      json map topojson;     application/ld+json                   jsonld;     

nginx+jwplayer配置flv/MP4点播系统, 视频拖动支持

一 配置nginx 1. 下载 nginx 最新版 http://nginx.org/ 2. 安装依赖库, 以ubuntu为例 apt-get install libpcre3 libpcre3-dev libssl-dev openssl 3. 编译nginx, 增加flv和MP4的支持 /configure --with-http_flv_module --with-http_mp4_module --with-http_ssl_module --with-debug 编译时可以指定安装目录

使用HLS协议连接nginx实现近实时流方式播放视频

目录 1. 流媒体 1.1 流式传输 2. 点播 2.1 点播方案 2.2 什么是HLS 3. 视频编码 3.1 视频编码格式 3.2 FFmpeg 的基本使用 3.3 生成m3u8/ts文件 3.4 码率的设置 4. 播放器 4.1 技术选型 4.2 video.js 5. 开始配置nginx 6. 编写测试页面video.html 7. 测试 demo 地址 1. 流媒体 流媒体就是将视频文件分成许多小块儿,将这些小块儿作为数据包通过网络发送出去,实现一边传输视 频 数据 包一边观看视频.

Nginx搭建flv mp4流媒体服务器[转]

Nginx搭建flv mp4流媒体服务器 作者:二蛋 时间:December 1, 2014 分类:Note 环境:Centos 6.4 32bit 一.安装依赖包 1.安装zlib wget http://zlib.net/zlib-1.2.8.tar.gz tar xzvf zlib-1.2.8.tar.gz cd zlib-1.2.8 ./configure make && make install 2.安装gcc-c++ yum -y install gcc-c++ 3.安装pcr

[终极精简版][图解]Nginx搭建flv mp4流媒体服务器

[终极精简版][图解]Nginx搭建flv mp4流媒体服务器 卧槽,就是被新版的jwplayer坑了,用了博主的 startparam: "start",primary: "flash" 最终搞定了,特意注册一个账号顶一下!谢谢. 花了我接近3周,历经了重重问题,今日终于把流媒体服务器搞定,赶紧的写个博文以免忘记... 起初是跟着网上的一些教程来的,但是说的很不全面,一些东西也过时不用了(比如jwplayer老版本).我这次是用的最新版jwplayer6.8,在配

[置顶][终极精简版][图解]Nginx搭建flv mp4流媒体服务器

花了我接近3周,历经了重重问题,今日终于把流媒体服务器搞定,赶紧的写个博文以免忘记... 起初是跟着网上的一些教程来的,但是说的很不全面,一些东西也过时不用了(比如jwplayer老版本).我这次是用的最新版jwplayer6.8,在配置上有很多不同的地方,也很坑,值得注意一下!在配置方面,我精简了很多,没有了那么多繁琐的配置项需要修改. 注意:本人是在虚拟机centos6.2系统下搭建的流媒体服务器,在win7主机上做测试. 另,文章最后有下载地址,可下载搭建过程中所有用到的包和其他文件. 废

nginx安装-添加MP4播放模块

nginx安装很简单,但是有的时候是已经安装的nginx ,升级增加nginx 模块功能. 最近公司要nginx增加一个可以播放 MP4的模块,安装还算顺利,不说废话上命令. 1 安装依赖 yum install -y make zilb-devel openssl-devel pcre-devel libaio libaio-devel wget http://nginx.org/download/nginx-1.10.3.tar.gz #创建用户和用户组 groupadd wwwuserad

nginx搭建支持http和rtmp协议的流媒体服务器之一

实验目的: 让Nginx支持flv和mp4格式文件,支持RTMP协议的直播和点播: 同时打开RTMP的HLS功能 ?资料: HTTP Live Streaming(缩写是 HLS)是一个由苹果公司提出的基于HTTP的流媒体网络传输协议. HLS只请求基本的HTTP报文,与实时传输协议(RTP)不同,HLS可以穿过任何允许HTTP数据通过的防火墙或者代理服务器. 它也很容易使用内容分发网络来传输媒体流. 使用ffmpeg来完成对flv.mp4.mp3等格式的转化(点播实验暂时不测试) 一.准备工作