基于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];
}