用于iOS使用的librtmp包装类

・3 分钟阅读

  • 源代码名称: rtmp-wrapper
  • 源代码网址: https://www.github.com/minsikzzang/rtmp-wrapper
  • rtmp-wrapper的文档
  • rtmp-wrapper的源代码下载
  • Git URL:
    git://www.github.com/minsikzzang/rtmp-wrapper.git
  • Git Clone代码到本地:
    git clone https://www.github.com/minsikzzang/rtmp-wrapper
  • Subversion代码到本地:
    $ svn co --depth empty https://www.github.com/minsikzzang/rtmp-wrapper
                              Checked out revision 1.
                              $ cd repo
                              $ svn up trunk
              
  • 封装封装器

    rtmp包装器是iOS平台的一个librtmp包装库

    启动

    安装先决条件

    安装库

    SDK的源代码可在GitHub上获得

    
    $ git clone git@github.com:ifactorylab/rtmp-wrapper.git
    
    
    
    

    运行 CocoaPods

    CocoaPods为库项目安装所有依赖项

    
    $ cd rtmp-wrapper
    
    
    $ pods install
    
    
    $ open rtmp-wrapper.xcworkspace
    
    
    
    

    将rtmp包装添加到项目中

    如果不存在,则创建 Podfile,在下面添加

    
    pod 'rtmp-wrapper', '~> 1.0.6'
    
    
    
    

    发布RTMP流

    
    #import"RtmpWrapper.h"
    
    
    
    RtmpWrapper *rtmp = [[RtmpWrapper alloc] init];
    
    
    BOOL ret = [rtmp rtmpOpenWithURL:@"YOUR RTMP PUBLISHING POINT" enableWrite:YES];
    
    
    if (ret) { 
    
    
     NSData *video =
    
    
     [NSData dataWithContentsOfURL:[NSURL URLWithString:@"FLV VIDEO URL ON THE NET"]];
    
    
     NSLog(@"original video length: %d", [video length]);
    
    
     NSUInteger length = [video length]; 
    
    
     NSUInteger chunkSize = 10 * 5120;
    
    
     NSUInteger offset = 0;
    
    
    
    //Let's split video to small chunks to publish to media server
    
    
     do {
    
    
     NSUInteger thisChunkSize = length - offset> chunkSize? chunkSize : length - offset;
    
    
     NSData* chunk = [NSData dataWithBytesNoCopy:(char *)[video bytes] + offset
    
    
     length:thisChunkSize
    
    
     freeWhenDone:NO];
    
    
     offset += thisChunkSize;
    
    
    
    //Write new chunk to rtmp server
    
    
     NSLog(@"%d", [rtmp rtmpWrite:chunk]);
    
    
     sleep(1);
    
    
     } while (offset <length);
    
    
    }
    
    
    
    //Close rtmp connection and release class object
    
    
    [rtmp rtmpClose];
    
    
    [rtmp release];
    
    
    
    

    版本详细信息

    1.0.8

    • 启用 arc

    1.0.6

    • 异步打开/写入
    • autoreconnect已经删除

    1.0.5

    • sigpipe => ignored
    • 重新连接功能已经添加

    1.0.4

    • 已经添加连接和 autoReconnect
    讨论
    Fansisi profile image