ubuntu下使用nginx搭建流媒体服务器,实现视频点播
来源:互联网 发布:自学古筝的软件 编辑:程序博客网 时间:2024/04/29 04:01
为了实现视频点播和直播,整了一天,看了N多博客,终于有了不小进展,在这里分享给大家。
什么是视频点播?可能你对这个名词不熟悉,但是爱奇艺,腾讯视频等这些视频播放软件想必你肯定知道。没错,视频点播就是在线观看某个视频。额,视频直播?这个就不解释了吧,美女直播,游戏直播等等,哈哈。
首先我们看如何实现视频点播,视频点播支持flv文件及H264编码视频,ACC编码音频的mp4文件:
第一步,创建单独的目录(因为软件较多,容易混乱),下载需要的软件:
我们需要下载nginx,pcre,zlib,openssl以及nginx-rtmp-module
mkdir workcd workwget http://nginx.org/download/nginx-1.10.3.tar.gzwget http://zlib.net/zlib-1.2.11.tar.gzwget https://ftp.pcre.org/pub/pcre/pcre-8.40.tar.gzwget https://www.openssl.org/source/openssl-1.0.2k.tar.gzwget https://github.com/arut/nginx-rtmp-module/archive/master.zip
第二步,分别解压这四个文件:
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-mastermakesudo 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/ffmpegsudo apt-get updatesudo apt-get install ffmpeg
0 0
- ubuntu下使用nginx搭建流媒体服务器,实现视频点播
- Nginx搭建视频点播服务器(仿真专业流媒体软件)
- ubuntu下Nginx流媒体服务器搭建与测试 一
- ubuntu下搭建流媒体服务器
- Nginx搭建flv视频点播服务器
- Nginx搭建flv视频点播服务器
- Nginx+RTMP 搭建视频点播服务器
- Windows环境下用jwplayer+Nginx搭建视频点播服务器
- Windows环境下用jwplayer+Nginx搭建视频点播服务器
- Nginx搭建rtmp流媒体服务器(Ubuntu 14.10)
- Nginx搭建rtmp流媒体服务器(Ubuntu 14.10)
- Ubuntu 14搭建Nginx-RTMP流媒体服务器
- 【流媒体技术】流媒体(1)使用nginx搭建流媒体服务器
- rtmp与hls流媒体服务器搭建:ubuntu下Nginx搭建初探与rtmp-module的添加
- 使用Nginx搭建rtmp流媒体服务器笔记
- nginx搭建流媒体服务器
- nginx搭建流媒体服务器
- nginx搭建流媒体服务器
- android的与ContentResolver(内容访问者)对ContentProvider(内容提供者)的增删查改
- 树莓派学习
- SparkContext 与 textFile 生成hadoopRdd 源码解读
- 事务仅仅是只读状态,不能自动提交
- 走进Java,jdk,jre,虚拟机简介
- ubuntu下使用nginx搭建流媒体服务器,实现视频点播
- 安卓四大基本组件之一 ContentProvider(自定义内容提供者实例)
- 名企笔试题1~啤酒问题
- 各类发动机工作原理
- 使用maven创建web项目
- 唯一不变的,就是变
- 1001. A+B Format (20)
- python中yield使用方法
- 怎样判断一个exe可执行程序是32位的还是64位的