目录

环境准备
●Centos系统安装:请查看我的另一篇博客Java后端之路(六)安装Linux系统
●git安装(系统如果没有的话):https://www.cnblogs.com/imyalost/p/8715688.html,git配置完后记得重启系统才能生效,或者执行source /etc/profile命令也可以。
●SRS流媒体服务器安装(官方教程):https://github.com/ossrs/srs/wiki/v1_CN_SampleRTMP
安装完之后还需要将官方的安装说明中的srs.conf里涉及到的端口进行开放。
●Linux端口开放:https://jingyan.baidu.com/article/0eb457e5e1647a03f1a90525.html
●OBS Studio推流软件下载:http://www.onlinedown.net/soft/637537.htm
●VLC拉流软件下载:http://www.onlinedown.net/soft/16216.htm
直播测试
●OBS Studio配置推流:
在来源窗口右键->添加->显示器捕获

然后在控件窗口点击设置进行配置留的推送地址:

配置推流地址,推流的协议为rtmp,后面则是服务器ip+端口号+随意名称(我是live),然后是下面的流名称这里我填的test。

设置完之后就可以开始推流了

●VLC拉流播放:
打开VLC选择工具栏的媒体->流

选择网络选项卡,然后我们输入与推流一样的地址,然后点击播放:

拉流成功的话会显示你屏幕的图像。
Android进行推流
这里我使用的是一个非常好用的Android推流开源库:https://github.com/begeekmyfriend/yasea
使用方式很简单首先导入它的library然后在代码中简单几行即可实现:
布局文件代码:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.itfitness.zhiboapp.MainActivity">
<net.ossrs.yasea.SrsCameraView
android:id="@+id/glsurfaceview_camera"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</RelativeLayout>
Activity代码:
//另外这个Activity还需要实现这些接口:SrsEncodeHandler.SrsEncodeListener, RtmpHandler.RtmpListener, SrsRecordHandler.SrsRecordListener
SrsCameraView cameraView = (SrsCameraView) findViewById(R.id.glsurfaceview_camera);
mPublisher = new SrsPublisher(cameraView);
//编码状态回调
mPublisher.setEncodeHandler(new SrsEncodeHandler(this));
mPublisher.setRecordHandler(new SrsRecordHandler(this));
//rtmp推流状态回调
mPublisher.setRtmpHandler(new RtmpHandler(this));
//预览分辨率
mPublisher.setPreviewResolution(1280, 720);
//推流分辨率
mPublisher.setOutputResolution(720, 1280);
//传输率
mPublisher.setVideoHDMode();
//开启美颜(其他滤镜效果在MagicFilterType中查看)
mPublisher.switchCameraFilter(MagicFilterType.BEAUTY);
//打开摄像头,开始预览(未推流)
mPublisher.startCamera();
//mPublisher.switchToSoftEncoder();//选择软编码
mPublisher.switchToHardEncoder();//选择硬编码
//开始推流 rtmpUrl(ip换成服务器的部署ip)
mPublisher.startPublish("rtmp://192.168.0.102/live/test");
接下来使用VLC进行拉流播放:

如果觉得VLC比较卡的话可以使用一个在线的拉流播放工具:http://www.cutv.com/demo/live_test.swf
网友评论