android rtmp推流_Android 端实现无人机直播

29750a3f48133955e4085afecaf4c5e1.png

黑客技术 点击右侧关注,了解黑客的世界! 72393c2ae9c587355e338ef9fd918cb4.png

4dd859b4615c9ebeca6006441fc34ef5.png

Java开发进阶 点击右侧关注,掌握进阶之路! 72393c2ae9c587355e338ef9fd918cb4.png

5616a31129f30fe443b6deecad103074.png

Python开发 点击右侧关注,探讨技术话题! 72393c2ae9c587355e338ef9fd918cb4.png 作者丨codelang 来源: https://juejin.im/post/5d6544715188252373306018 在 MSDK-4.9 版本就已支持了直播的功能,只需提供 rtmp 地址就可以实现无人机直播。

客户端推流

MSDK-4.9 提供了 LiveStreamManager 来管理图传的推流: https://developer.dji.com/api-reference/android-api/Components/LiveStreamManager/DJILiveStreamManager.html?search=livestreammanager&i=0djilivestreammanager_isstreaming_inline
LiveStreamManager.java
 DJISDKManager.getInstance().getLiveStreamManager()
LiveStreamManager 实现直播功能非常简单,只需要实现三个 步骤:
  1. 设置 rtmp 抓流地址
  2. 启动推流
  3. 关闭推流
1、设置 rtmp 地址
Sets the URL address of the RTMP Server.
DJISDKManager.getInstance().getLiveStreamManager().setLiveUrl(liveShowUrl);
2、启动直播
Starts the live streaming.The encoder will start to encoding the video frame if it is needed. The video will be streamed to the RTMP server if the server is available
int result = DJISDKManager.getInstance().getLiveStreamManager().startStream();
返回的 result 是一个 error code. 3、关闭直播
Stop the live streaming. The operation is asynchronous
 DJISDKManager.getInstance().getLiveStreamManager().stopStream();
当然,LiveStreamManager 也提供了其他功能的设置,具体参数设置可以查看  MSDK-LiveStreamManager Doc

https://developer.dji.com/api-reference/android-api/Components/LiveStreamManager/DJILiveStreamManager.html?search=livestreammanager&i=0&

服务端抓流

其实,只要服务端支持 rtmp 协议的都是可以直接解析播放的,如果为了能直观的看到效果,可以使用 B 站的直播间: c209231a3e6e3ca2b499f8014e79937a.png 将 rtmp 地址与直播码拼接成 liveShowUrl ,直接 set 给 LiveStreamManager,然后 startStream 开启直播:
String liveShowUrl = rtmp 地址+直播码
DJISDKManager.getInstance().getLiveStreamManager().setLiveUrl(liveShowUrl);
DJISDKManager.getInstance().getLiveStreamManager().startStream();
等待一小段时间,就可以在直播间看到无人机传输过来的直播视频了。 我们也可以基于一些第三方的开源框架,搭建自己的抓流服务端.
Red5-Server
Red5  是一个用Java编写的开源Flash服务器,支持的功能有:
  • Streaming Video (FLV, F4V, MP4, 3GP)
  • Streaming Audio (MP3, F4A, M4A, AAC)
  • Recording Client Streams (FLV and AVC+AAC in FLV container)
  • Shared Objects
  • Live Stream Publishing
  • Remoting
  • Protocols: RTMP, RTMPT, RTMPS, and RTMPE
https://github.com/Red5/red5-server
下载
当前最新版本是 Release-1.1.1 版本, https://github.com/Red5/red5-server/releases 下载最新的 red5-server-1.1.1.zip 即可
https://link.juejin.im/?target=https%3A%2F%2Fgithub.com%2FRed5%2Fred5-server%2Freleases%2Fdownload%2Fv1.1.1%2Fred5-server-1.1.1.zip
安装
  • MacOS 安装
  • Linux 安装
https://github.com/Red5/red5-server/wiki/Installation-on-MacOS https://github.com/Red5/red5-server/wiki/Installation-on-Linux 如果嫌弃上面安装过于繁琐的话,这里推荐个简易安装:
  1. JDK 环境必须安装
  2. 在 red5-server-1.1.1 文件夹下运行 ./red5.sh start 命令,启动 red5 服务
2dd8b6a98611a1532cb0f19087f0ea11.png
运行
  1. 在浏览器中输入本地的 red5 服务地址: http://localhost:5080/
  2. 选择  launch a demo
  3. 选择  Publisher demo
fd153f72f3460ef5194af32b55a43244.png Publisher 页面解释(从上而下):
  • Monitor:  View(预览页面)/Publish(推送)切换
  • Log:  当前执行的日志
  • Name: 直播码,和 B 站的直播码类似
  • Stop: 停止直播
  • Play/Pause: 播放/暂停直播
  • Enable Aundio/Video :  勾选当前可用
  • servers:  直播地址
  • close/connect : 关闭/连接直播服务
  • Location: rtmp 推流地址
server 端设置步骤: 1、填写自己的 Name ,设置直播码 2、点击  servers 的 connect 按钮开启服务,开启成功时,按钮会变成 close 3、点击 Play 开始抓流播放,播放成功时,按钮会变成 Pause client 端设置步骤: 1、将 Location 的 rtmp 地址与 Name 直播码拼接成直播地址 rtmp://Red5 IP地址/oflaDemo/codelang  2、setLiveUrl 3、startStream e53ef3eadbe85de4072942a4b3299a88.png

 推荐↓↓↓ 

0977e963c697ada1c9339873d546f6f9.png

?16个技术公众号】都在这里!

涵盖:程序员大咖、源码共读、程序员共读、数据结构与算法、黑客技术和网络安全、大数据科技、编程前端、Java、Python、Web编程开发、Android、iOS开发、Linux、数据库研发、幽默程序员等。

439ccc01d5c620917f8776f8786c0775.png万水千山总是情,点个 “ 在看” 行不行
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值