ubuntu下使用nginx搭建流媒体服务器,实现视频点播
2017-02-06 23:40
726 查看
为了实现视频点播和直播,整了一天,看了N多博客,终于有了不小进展,在这里分享给大家。
什么是视频点播?可能你对这个名词不熟悉,但是爱奇艺,腾讯视频等这些视频播放软件想必你肯定知道。没错,视频点播就是在线观看某个视频。额,视频直播?这个就不解释了吧,美女直播,游戏直播等等,哈哈。
首先我们看如何实现视频点播,视频点播支持flv文件及H264编码视频,ACC编码音频的mp4文件:
第一步,创建单独的目录(因为软件较多,容易混乱),下载需要的软件:
我们需要下载nginx,pcre,zlib,openssl以及nginx-rtmp-module
什么是视频点播?可能你对这个名词不熟悉,但是爱奇艺,腾讯视频等这些视频播放软件想必你肯定知道。没错,视频点播就是在线观看某个视频。额,视频直播?这个就不解释了吧,美女直播,游戏直播等等,哈哈。
首先我们看如何实现视频点播,视频点播支持flv文件及H264编码视频,ACC编码音频的mp4文件:
第一步,创建单独的目录(因为软件较多,容易混乱),下载需要的软件:
我们需要下载nginx,pcre,zlib,openssl以及nginx-rtmp-module
mkdir work cd work wget http://nginx.org/download/nginx-1.10.3.tar.gz wget http://zlib.net/zlib-1.2.11.tar.gz wget https://ftp.pcre.org/pub/pcre/pcre-8.40.tar.gz wget https://www.openssl.org/source/openssl-1.0.2k.tar.gz wget https://github.com/arut/nginx-rtmp-module/archive/master.zip[/code]
第二步,分别解压这四个文件:tar -zxvf 文件名
第三步,编译安装nginx:./configure --prefix=/usr/local/nginx --with-debug --with-pcre=../pcre-8.40 --with-zlib=../zlib-1.2.11 --with-openssl=../openssl-1.0.2k --add-module=../nginx-rtmp-module-master make sudo make install
第四步,进入 /usr/local/nginx/conf,配置nginx.conf文件,在文件末尾添加如下内容:rtmp { server { listen 1935; application vod { play /var/flvs; #指定存放视频文件的路径 } application vod_http { #myserver.com及服务器地址,如果只是本地播放,填写127.0.0.1:端口号 就行,端口好看配置文件中http监听的端口下同 play http://myserver.com/vod; } application vod_mirror { play /var/local_mirror http://myserver.com/vod; } } }
示例完整版:#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 { server { listen 1935; application vod { play /video_test; } application vod_http { play http://192.168.1.102:8080/vod; } application vod_mirror { # try local location first, then access remote location play /var/local_mirror http://192.168.1.102:8080/vod; } } } 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; server { listen 8080; server_name localhost; #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; # } #} }
然后,进入与conf文件夹同级的sbin目录下,运行:sudo ./nginx
至此,服务器搭建完成,可以实现视频点播了。
视频点播测试:
播放位于 /video_test 下的file.flv视频文件:ffplay rtmp://localhost/vod//file.flv
可以使用VLC这个播放器或者ffplay(需要安装ffmpeg),VLC自行百度安装即可。
ffmpeg安装:sudo apt-add-repository ppa:jon-severinsson/ffmpeg sudo apt-get update sudo apt-get install ffmpeg
相关文章推荐
- ubuntu下使用nginx搭建流媒体服务器,实现视频点播
- 实时监控、直播流、流媒体、视频网站开发方案流媒体服务器搭建及配置详解:使用nginx搭建rtmp直播、rtmp点播、,hls直播服务配置详解
- 实时监控、直播流、流媒体、视频网站开发方案流媒体服务器搭建及配置详解:使用nginx搭建rtmp直播、rtmp点播、,hls直播服务配置详解
- ubuntu搭建nginx服务器实现视频直播点播
- 使用 nginx 和 rtmp 插件搭建视频直播和点播服务器
- 视频演示-Ubuntu 14搭建Nginx-RTMP流媒体服务器
- Nginx搭建视频点播服务器(仿真专业流媒体软件)
- 使用nginx搭建点播和直播流媒体服务器的方法步骤
- 使用 nginx 和 rtmp 插件搭建视频直播和点播服务器
- Ubuntu下使用nginx和nginx-rtmp-module搭建流媒体服务器的正确姿势
- Nginx搭建flv视频点播服务器
- rtmp与hls流媒体服务器搭建:ubuntu下Nginx搭建初探与rtmp-module的添加
- 使用nginx-rtmp搭建视频直播服务器
- ubuntu 14.04服务器上使用nginx搭建wordpress博客详解
- 搭建视频点播服务器 nginx/ flv /jw flv player
- Red5流服务器搭建(实现在线直播,流媒体视频播放和在线视频会议)
- 使用nginx+nginx-rtmp-module+ffmpeg搭建流媒体服务器
- Nginx学习-2 使用Nginx搭建HTML web服务器 实现SSL证书安全访问
- Nginx搭建流媒体FLV视频服务器配置示例
- nginx搭建基于http协议的视频点播服务器