-
Notifications
You must be signed in to change notification settings - Fork 271
HalfScreenStream
jiangdsuccess edited this page May 5, 2017
·
4 revisions
半屏推流,该功能从v2.0.3版本开始引入,即将视频与评论、弹幕以及礼物等分离,让直播变得更多样化
- 先构造kit类的实例
KSYGPUStreamerKit * kit = [[KSYGPUStreamerKit alloc] initWithDefaultCfg];
_preView = [[GPUImageView alloc] initWithFrame:CGRectMake(0, 0, wdt, wdt * 9 / 16)];
_text = [[UILabel alloc] initWithFrame:CGRectMake(0, self.view.frame.size.height/2, self.view.frame.size.width, 30)];
_text.text = @"Comments";
CGSize preSz = _preView.frame.size;
// 1. preView的宽高比大于1的情况下,需要避免根据方向进行调整previewDimension
kit.videoOrientation = preSz.width > preSz.height ? UIInterfaceOrientationLandscapeRight : UIInterfaceOrientationPortrait;
// 2. 设置采集画面输出方向(手机竖屏, 采集的画面也是竖屏)
kit.vCapDev.outputImageOrientation = UIDeviceOrientationPortrait;
// 3. 根据_preView的[宽高比]进行设置预览和推流分辨率,即可做到任意size的半屏推流
CGFloat ratio = preSz.height / preSz.width;
kit.previewDimension = CGSizeMake(1080, 1080 * ratio);
kit.streamDimension = CGSizeMake(720, 720 *ratio);
[kit startPreview:_preView];
NSString *rtmpSrv = @"rtmp://test.uplive.ksyun.com/live/888";
NSURL* _hostURL = [[NSURL alloc] initWithString:rtmpSrv];
[kit.streamerBase startStream:_hostURL];
[kit.streamerBase stopStream];
[kit.streamerBase stopPreview];