Created
May 28, 2018 02:05
-
-
Save improve100/ea04a7f38890cfe5e8cf79577dbe82d0 to your computer and use it in GitHub Desktop.
rtsp rtmp deploy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1.建立源码编译的目录 | |
mkdir nginx-src && cd nginx-src | |
2.下载源码仓库 | |
http://nginx.org/en/download.html 下载最新ngix | |
git clone https://github.com/arut/nginx-rtmp-module.git | |
3.安装依赖 | |
sudo apt install libpcre3 libpcre3-dev | |
sudo apt install openssl libssl-dev | |
4.编译安装ngix | |
./configure --with-http_ssl_module --add-module=../nginx-rtmp-module-master | |
sudo make&& make install | |
5.配置nginx: | |
sudo vim /usr/local/nginx/conf/nginx.conf | |
添加: | |
rtmp { | |
server { | |
listen 1935; #监听的端口 | |
chunk_size 4000; | |
application hls { #rtmp推流请求路径 | |
live on; | |
hls on; | |
hls_path /usr/local/nginx/html/hls;这里的视频流目录 hls_path设置为 /usr/local/nginx/html/hls,这个目录的权限用chmod设置为775。 | |
hls_fragment 5s; | |
} | |
} | |
} | |
修改: | |
http { | |
server { | |
listen 8080; | |
location /stat { | |
rtmp_stat all; | |
rtmp_stat_stylesheet stat.xsl; | |
} | |
location /stat.xsl { | |
root /usr/local/src/nginx-rtmp-module/; | |
} | |
location /control { | |
rtmp_control all; | |
} | |
location /hls { | |
# Serve HLS fragments | |
types { | |
application/vnd.apple.mpegurl m3u8; | |
video/mp2t ts; | |
} | |
root html; | |
expires -1; | |
} | |
location ~\.flv { | |
flv; | |
} | |
location ~\.mp4$ { | |
mp4; | |
} | |
} | |
} | |
6.启动 | |
进入/usr/local/nginx目录下,键入sudo ./sbin/nginx就可以启动。 | |
相关命令用-s参数发信号,-s后跟stop,quit,reopen,reload等可以停止/推出/重新开启/重新加载 | |
sudo service nginx restart /usr/local/nginx/sbin/nginx -s reload | |
7.安装ffmpag | |
$ add-apt-repository ppa:kirillshkrogalev/ffmpeg-next | |
$ apt-get update | |
$ apt-get install ffmpeg | |
8.使用ffmpeg向服务器推送一个视频 | |
ffmpeg -re -i /home/alic/Desktop/demo/film.mp4 -c copy -f flv rtmp://localhost:2016/live/film | |
or | |
# 推荐 可用于浏览器播放 | |
ffmpeg -re -i /home/alic/Desktop/demo/film.mp4 -c copy -f flv rtmp://localhost:2016/hls_alic/film | |
eg: | |
ffmpeg -re -i /home/vk/rtmp_data/test.mp4 -c copy -f flv rtmp://localhost:1935/live/film | |
ffmpeg -i rtsp://admin:[email protected]/h264/ch1/main/av_stream -vcodec copy -acodec copy -f flv rtmp://192.168.5.86:1935/live/stream | |
rtsp:服务器搭建 | |
wget http://www.live555.com/liveMedia/public/live555-latest.tar.gz | |
tar xzf live555-latest.tar.gz | |
cd live | |
./genMakefiles linux-64bit #注意后面这个参数是根据当前文件夹下config.<后缀>获取得到的 | |
make | |
最后就会在当前目录下生成mediaServer 文件夹,有一个live555MediaServer可执行文件 | |
cd mediaServer | |
./live555MediaServer | |
这样就启动了一个 rtsp server,根据提示当前只支持部分视频格式,并不支持.mp4后缀的文件。 | |
我的解决方法是格式转换,转换.mp4为.mkv 文件,live555支持.mkv 输出的。 | |
使用avconv 工具 | |
sudo apt-get install libav-tools | |
avconv -i file.mp4 -c copy file.mkv | |
将此mkv文件复制到和上面live555MediaServer可执行文件的同一个目录, | |
可用vlc在打开网络中输入地址 rtsp://your_ip/file.mkv 观看视频了。 | |
还可以生成 m3u8文件在手机上访问,http://your_ip:8000/file.mkv |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment