文章源自略懂百科-http://wswcn.cn/97060.html
这两天需要做一个视频推流测试,在网上找了一圈资料,使用ffmpeg+nginx是比较快捷和通用的方法,于是就开始动手开整!文章源自略懂百科-http://wswcn.cn/97060.html
文章源自略懂百科-http://wswcn.cn/97060.html
推流测试文章源自略懂百科-http://wswcn.cn/97060.html
一 测试环境
推流:ubuntu18.04,ffmpeg。文章源自略懂百科-http://wswcn.cn/97060.html
服务器+拉流:win7,nginx,rtmp。文章源自略懂百科-http://wswcn.cn/97060.html
二准备
2.1 Ubuntu端文章源自略懂百科-http://wswcn.cn/97060.html
安装ffmpeg,sudo apt install ffmpeg;文章源自略懂百科-http://wswcn.cn/97060.html
安装ssh服务,sudo apt-get install openssh-server;sudo apt-get install openssh-client;文章源自略懂百科-http://wswcn.cn/97060.html
安装lrzsz服务,方便拖拽文件,sudo apt-get install lrzsz;文章源自略懂百科-http://wswcn.cn/97060.html
2.2Win7电脑文章源自略懂百科-http://wswcn.cn/97060.html
搜索并下载nginx-1.7.11.3-Gryphon,这个版本的nginx是包含rtmp服务的。解压后记得把文件名里的空格去掉,改成-就行,路径中不要出现中文;文章源自略懂百科-http://wswcn.cn/97060.html
进入conf目录,用UrtraEdit之类的编辑器打开nginx-win.conf文件,修改相关配置:文章源自略懂百科-http://wswcn.cn/97060.html
文章源自略懂百科-http://wswcn.cn/97060.html
增加rtmp配置文章源自略懂百科-http://wswcn.cn/97060.html
然后,把服务器的监听端口改一下,一般80端口会被占用,我这里改成了88,您随意:文章源自略懂百科-http://wswcn.cn/97060.html
文章源自略懂百科-http://wswcn.cn/97060.html
改一下监听端口号文章源自略懂百科-http://wswcn.cn/97060.html
保存文件,然后另存为nginx.conf;文章源自略懂百科-http://wswcn.cn/97060.html
返回到nginx-1.7.11.3-Gryphon路径,在窗口输入cmd调出命令窗口,敲入start nginx,然后打开浏览器,敲入地址localhost:88,回车,页面如下:文章源自略懂百科-http://wswcn.cn/97060.html
文章源自略懂百科-http://wswcn.cn/97060.html
成功启动nginx文章源自略懂百科-http://wswcn.cn/97060.html
恭喜你,服务已经正常运行了。停止服务的命令是:nginx -s stop;如果有什么问题,可以到logs文件夹下,打开error.log查看。文章源自略懂百科-http://wswcn.cn/97060.html
最后,安装一个vlc播放器,我这里安装的是vlc-3.0.17.4-win64.exe。文章源自略懂百科-http://wswcn.cn/97060.html
三开始推流
把Linux主机和win7电脑接在同一个路由器下,在Linux主机上新建一个目录,例如:文章源自略懂百科-http://wswcn.cn/97060.html
mkdir test;文章源自略懂百科-http://wswcn.cn/97060.html
在win7上,进入xshell,连接上Linux主机,进入刚才新建的目录,把您喜爱的小电影,改一个单纯一些的名字,拖拽进去。然后,敲入下面的命令:文章源自略懂百科-http://wswcn.cn/97060.html
ffmpeg -re -i mv2.mp4 -vcodec copy -acodec copy -f flv "rtmp://192.168.1.102:1935/live/test",文章源自略懂百科-http://wswcn.cn/97060.html
192.168.1.102是我电脑在局域网里的ip地址,改成您自己的就行。文章源自略懂百科-http://wswcn.cn/97060.html
运行成功后,将显示传输状态:文章源自略懂百科-http://wswcn.cn/97060.html
文章源自略懂百科-http://wswcn.cn/97060.html
推流成功文章源自略懂百科-http://wswcn.cn/97060.html
然后,打开vlc播放器,设置网络串流:文章源自略懂百科-http://wswcn.cn/97060.html
文章源自略懂百科-http://wswcn.cn/97060.html
进入串流设置文章源自略懂百科-http://wswcn.cn/97060.html
填入下面的地址即可:文章源自略懂百科-http://wswcn.cn/97060.html
文章源自略懂百科-http://wswcn.cn/97060.html
输入流地址文章源自略懂百科-http://wswcn.cn/97060.html
接下来,就可以开开心心看您喜欢的小电影了!文章源自略懂百科-http://wswcn.cn/97060.html
文章源自略懂百科-http://wswcn.cn/97060.html
观看影片文章源自略懂百科-http://wswcn.cn/97060.html
至此,一个简单的视频推流测试环境就搭建好了,今天测试的是视频文件,过两天再在ubantu上接一个usb 摄像头,来个直播测试!文章源自略懂百科-http://wswcn.cn/97060.html
各位看官有什么想说的,咱们到评论区畅聊!文章源自略懂百科-http://wswcn.cn/97060.html
文章源自略懂百科-http://wswcn.cn/97060.html
评论