LaiFengiOS / LFLiveKit

LaiFeng IOS Live Kit,H264 and AAC Hard coding,support GPUImage Beauty, rtmp transmission,weak network lost frame,Dynamic switching rate
MIT License
4.39k stars 1.11k forks source link

WatermarkView does not redraw if the underlying view changes #184

Open iosdev-republicofapps opened 7 years ago

iosdev-republicofapps commented 7 years ago

Hi,

Thanks for LFLiveKit, it is great! :-) I really appreciate all of the work you do on this great library.

I noticed that if the WatermarkView redraws itself after it has been set on the LFLiveSession, then it does not get updated in the video. The WatermarkView only seems to get drawn once, when it is added to the LiveSession, and changes to the appearance of the WatermarkView after that do not propagate.

Any idea how to fix this @chenliming777 ?

For example:

UIView *myWatermarkView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];
myWatermarkView.backgroundColor = [UIColor redColor];

LFLiveLession *myLiveSession = ...;
myLiveSession.wartermarkView = myWatermarkView;
// red watermark view is seen in the video

// wait 1 second ...

myWatermarkView.backgroundColor = [UIColor greenColor];
[myWatermarkView setNeedsDisplay];
// I would expect the watermark in the video to appear green now, but it stays red ...

The only way I can see to get the watermark view to update in the video is to keep invoking LFLiveSession.setWartermarkView over and over each time my watermark view changes. That feels really inefficient because every time I set the watermark view, the LFVideoCapture.reloadFilter is invoked and that sets up a bunch of things that might be cpu or memory expensive.

If I know that the size of the video dimension and the size of the watermark view are not changing, just their contents are, is there any way to make this more efficient?

Thanks! :-)

y4nnick commented 7 years ago

Since (i suppose) this LFLiveKit is using FFmpeg the watermarks are just some filters which get overlayed over the video. So each time you set the watermark view the last overlay-filter gets removed and the new one gets added. See doc for overlay filter here: https://ffmpeg.org/ffmpeg-filters.html#overlay-1

So basically i think its not possible (with this library) what you want to achieve. Maybe you could implement some kind of listener if the overlay view changed and then reset the watermark view. Nevertheless this would only be a dirty workaround.

I didn't do any research in the code base of LFLiveKit, if they are really using FFmpeg. This is just a guess.