-
Notifications
You must be signed in to change notification settings - Fork 271
BrushStream
Franken Zeng edited this page Jul 7, 2017
·
12 revisions
在直播过程中,主播使用画笔画出任意文字、图形等,通过与摄像头画面合成后,再一起推送给观众端,该功能从v2.4.0版本引入
- 先构造kit类的实例
KSYGPUBrushStreamerKit * brushKit = [[KSYGPUBrushStreamerKit alloc] initWithDefaultCfg];
KSYGPUBrushStreamerKit继承KSYGPUStreamerKit类,在KSYGPUStreamerKit的基础上添加了一个画笔图层drawLayer和画笔图层的显示位置drawPicRect
//构建图层
_drawView = [[KSYDrawingView alloc] initDraw:_drawViewRect];
_drawView.frame = _drawViewRect;
//图层边框颜色和大小
[_drawView.layer setBorderColor:[[UIColor blueColor] CGColor]];
[_drawView.layer setBorderWidth:2.0f];
//加载图层
[self.view addSubview:_drawView];
//利用UIBezierPath和画图
@property (nonatomic, strong) UIBezierPath *path;
//画图起点
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event;
//画线
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event;
KSYDrawingView是我们定义的一个简单画笔图层演示类,用户可以根据画图需求自己来定义
UIImage * img = [self imageFromUIView:_drawView];
_drawPic = [[GPUImagePicture alloc] initWithImage:img];
[self addDrawPic:_drawPic ToMixerAt:_drawLayer];
[_drawPic processImage];
将画笔图层作为推流的一个新图层,利用定时器NSTimer来刷新画笔图层
[brushKit startPreview:self.view];
NSString *rtmpSrv = @"rtmp://test.uplive.ksyun.com/live/888";
NSURL* _hostURL = [[NSURL alloc] initWithString:rtmpSrv];
[brushKit.streamerBase startStream:_hostURL];
[brushKit.streamerBase stopStream];
[brushKit stopPreview];