美文网首页八宝粥I love iOS
iOS直播:LFLiveKit + RTMP实现直播推流

iOS直播:LFLiveKit + RTMP实现直播推流

作者: 丶墨墨丶 | 来源:发表于2019-02-16 19:17 被阅读18次

相关库

LFLiveKit

LFLiveKit + RTMP实现直播推流

RTMP协议:RTMP(the Real-time Messaging Protocol)协议作为客户端和服务器端的传输协议,这是一个专门为高效传输视频、音频和数据而设计的 TCP/IP 协议。

HLS协议: HTTP Live Streaming(HLS)是苹果公司(Apple Inc.)实现的基于HTTP的流媒体传输协议。

1、利用cocoapods加载LFLiveKit

source 'https://github.com/CocoaPods/Specs.git'

target ‘Live_LFLiveKit_RTMP’ do
    pod 'LFLiveKit'
end

2、创建直播会话

// 创建直播会话
@property (nonatomic, strong) LFLiveSession *liveSession;

相关属性的设置,LFLiveKit已经包含了GPUImage,可以进行美颜相关操作

- (LFLiveSession*)liveSession {
    if (!_liveSession) {
        _liveSession = [[LFLiveSession alloc] initWithAudioConfiguration:[LFLiveAudioConfiguration defaultConfiguration] videoConfiguration:[LFLiveVideoConfiguration defaultConfiguration]];
        // 预览视图
        _liveSession.preView = self.view;
        // 设置为后置摄像头
        _liveSession.captureDevicePosition = AVCaptureDevicePositionBack;
        // 开启美颜
        _liveSession.beautyFace = YES;
        _liveSession.delegate = self;
    }
    return _liveSession;
}

3、Nginx服务器配置

参考链接

  • 安装nginx:
    在终端执行
brew install nginx-full --with-rtmp-module 

如果报错的话,要先执行参考链接

brew tap denji/nginx
  • 配置Nginx,支持http协议拉流:
    在终端执行
open -t /usr/local/etc/nginx/nginx.conf

添加配置信息

location /hls {
        #Serve HLS config
        types {
            application/vnd.apple.mpegurl    m3u8;
            video/mp2t ts;
        }
        root /usr/local/var/www;
        add_header Cache-Control    no-cache;
    }
屏幕快照 2019-02-16 下午5.29.47.png
  • 配置Nginx,支持rtmp协议推流:
    在终端执行
open -t /usr/local/etc/nginx/nginx.conf

添加配置信息

rtmp {
    server {
        listen 1935;
        ping 30s;
        notify_method get;

        application myapp {
            live on;
            record off;
        max_connections 1024;
        }

    #增加对HLS支持开始
    application hls {
        live on;
        hls on;
        hls_path /usr/local/var/www/hls;
        hls_fragment 5s;
    }
    #增加对HLS支持结束
    }
}
屏幕快照 2019-02-16 下午7.07.16.png
  • 启动Nginx
    在终端执行
nginx -s reload

nginx: [error] open() "/usr/local/var/run/nginx.pid" failed (2: No such file or directory)

4、开始直播

rtmp协议

// 开始直播
- (void)startLive {
    LFLiveStreamInfo *streamInfo = [LFLiveStreamInfo new];
    streamInfo.url = @"rtmp://172.16.237.61:1935/hls/live1";
    [self.liveSession startLive:streamInfo];
}
WechatIMG132.jpeg

5、拉流

在浏览器输入:http://localhost:8080/hls/live1.m3u8

屏幕快照 2019-02-16 下午7.04.06.png

6、结束直播

// 结束直播
- (void)stopLive {
    [self.liveSession stopLive];
}

采集图像格式、声音格式:

摄像头采集图像并用VideoToolbox编码成H.264码流
麦克风采集声音并用AudioToolbox编码成AAC码流


😊附上demo,如果帮到你了请给个小星星🌟
GitHub

相关文章

  • iOS直播:LFLiveKit + RTMP实现直播推流

    相关库 LFLiveKit LFLiveKit + RTMP实现直播推流 RTMP协议:RTMP(the Rea...

  • Demo

    IOS视频直播 + 推流实现 采用开源框架ijkplayer 以及LFLiveKit实现推流,主要完善关注,分享和登录

  • iOS 视频直播资源收集

    iOS RTMP上推直播视频 HTTP Live Streaming直播(iOS直播)技术分析与实现 iOS开发之...

  • iOS动手做一个直播(原理篇)

    开篇 推流 腾讯直播平台,阿里直播平台,百度直播平台提供均为RTMP的推流和HLS/RTMP等拉流.推流是一个直播...

  • 七牛云3

    直播推流地址: rtmp://推流地址/直播空间名/推流请求返回的 title?key=publishKey 直播...

  • 从零搭建直播项目 iOS

    Mac端:搭建nginx + rtmp 服务器(直播服务器) iOS 端:基于LKLiveKit(实现推流) iO...

  • RTMP

    直播推流实现RTMP协议的一些注意事项

  • iOS 【视频直播一】安装环境

    摘抄:快速集成iOS基于RTMP的视频推流摘抄:iOS中集成ijkplayer视频直播框架 Mac搭建nginx+...

  • iOS开发直播app推流

    基于RTMP协议主要有两种封装库来实现推流: 1、FFmpeg推流(Mac上搭建nginx+rtmp直播服务器)h...

  • LiveQing二次开发接口对接说明示列

    LiveQing云端流媒体服务软件,支持视频视频转码、RTMP推流直播、RTMP/HLS/HTTP-FLV直播分发...

网友评论

    本文标题:iOS直播:LFLiveKit + RTMP实现直播推流

    本文链接:https://www.haomeiwen.com/subject/fcfieqtx.html