基于RTMP协议的直播思路
Snip20160725_1.png配置Naginx服务器
来源于满山李子: 配置Naginx服务器
直播推流
/*********************推流**************************/
-(void)pushVideo{
//创建视频摄像头
self.camera = [[GPUImageVideoCamera alloc]initWithSessionPreset:AVCaptureSessionPreset1280x720 cameraPosition:AVCaptureDevicePositionBack];
//设置帧率
self.camera.frameRate = 25;
//设置输出图片方向
self.camera.outputImageOrientation = UIInterfaceOrientationPortrait;
//创建展示摄像头的GPUImageView
GPUImageView * imageView = [[GPUImageView alloc]init];
imageView.frame = self.view.bounds;
[self.view addSubview:imageView];
//添加GPUImageView为摄像头输出
[self.camera addTarget:imageView];
//创建GDLRawDataOutput对象
self.output = [[GDLRawDataOutput alloc]initWithVideoCamera:self.camera withImageSize:CGSizeMake(720, 1280)];
//添加数据输出对象为摄像头输出目标
[self.camera addTarget:self.output];
//开始捕获视频
[self.camera startCameraCapture];
//开始推流
[self.output startUploadStreamWithURL:@"rtmp://10.254.4.2:1935/gzhm" andStreamKey:@"room"];
}
直播拉流
/*********************拉流**************************/
-(void)getVideo{
//为了方便调试设置日志
#ifdef DEBUG
//设置显示日志报告
[IJKFFMoviePlayerController setLogReport:YES];
//设置日志等级
[IJKFFMoviePlayerController setLogLevel:k_IJK_LOG_DEBUG];
#else
//设置日志报告不显示
[IJKFFMoviePlayerController setLogReport:YES];
//设置日志等级
[IJKFFMoviePlayerController setLogLevel:k_IJK_LOG_INFO];
#endif
IJKFFOptions * options = [IJKFFOptions optionsByDefault];
//创建播放控制器
self.player = [[IJKFFMoviePlayerController alloc]initWithContentURLString:@"rtmp://10.254.4.2:1935/gzhm/room" withOptions:options];
//设置属性
//设置自动播放
self.player.shouldAutoplay = YES;
//设置缩放
self.player.scalingMode = IJKMPMovieScalingModeAspectFit;
//设置view的属性
self.player.view.frame = self.view.bounds;
//适配横竖屏
self.player.view.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
[self.view addSubview:self.player.view];
[self.view setAutoresizesSubviews:YES];
}
网友评论