RTMP協(xié)議下的直播

基于RTMP協(xié)議的直播思路

Snip20160725_1.png

配置Naginx服務(wù)器

來源于滿山李子: 配置Naginx服務(wù)器

直播推流

/*********************推流**************************/
-(void)pushVideo{
    //創(chuàng)建視頻攝像頭
    self.camera = [[GPUImageVideoCamera alloc]initWithSessionPreset:AVCaptureSessionPreset1280x720 cameraPosition:AVCaptureDevicePositionBack];
    //設(shè)置幀率
    self.camera.frameRate = 25;
    //設(shè)置輸出圖片方向
    self.camera.outputImageOrientation = UIInterfaceOrientationPortrait;
    //創(chuàng)建展示攝像頭的GPUImageView
    GPUImageView * imageView = [[GPUImageView alloc]init];
    imageView.frame = self.view.bounds;
    [self.view addSubview:imageView];
    //添加GPUImageView為攝像頭輸出
    [self.camera addTarget:imageView];
    //創(chuàng)建GDLRawDataOutput對(duì)象
    self.output = [[GDLRawDataOutput alloc]initWithVideoCamera:self.camera withImageSize:CGSizeMake(720, 1280)];
    //添加數(shù)據(jù)輸出對(duì)象為攝像頭輸出目標(biāo)
    [self.camera addTarget:self.output];
    //開始捕獲視頻
    [self.camera startCameraCapture];
    //開始推流
    [self.output startUploadStreamWithURL:@"rtmp://10.254.4.2:1935/gzhm" andStreamKey:@"room"];
}

直播拉流

/*********************拉流**************************/
-(void)getVideo{
    
    //為了方便調(diào)試設(shè)置日志
#ifdef DEBUG

    //設(shè)置顯示日志報(bào)告
    [IJKFFMoviePlayerController setLogReport:YES];
    
    //設(shè)置日志等級(jí)
    [IJKFFMoviePlayerController setLogLevel:k_IJK_LOG_DEBUG];
    
#else
    
    //設(shè)置日志報(bào)告不顯示
    [IJKFFMoviePlayerController setLogReport:YES];
    //設(shè)置日志等級(jí)
    [IJKFFMoviePlayerController setLogLevel:k_IJK_LOG_INFO];
#endif
    
    
    IJKFFOptions * options = [IJKFFOptions optionsByDefault];
    //創(chuàng)建播放控制器
    self.player = [[IJKFFMoviePlayerController alloc]initWithContentURLString:@"rtmp://10.254.4.2:1935/gzhm/room" withOptions:options];
    //設(shè)置屬性
    //設(shè)置自動(dòng)播放
    self.player.shouldAutoplay = YES;
    //設(shè)置縮放
    self.player.scalingMode = IJKMPMovieScalingModeAspectFit;
    //設(shè)置view的屬性
    self.player.view.frame = self.view.bounds;
    //適配橫豎屏
    self.player.view.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
    
    [self.view addSubview:self.player.view];
    [self.view setAutoresizesSubviews:YES];
    
}
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

推薦閱讀更多精彩內(nèi)容