MeiCam SDK For iOS
3.9.0
|
When users are shooting a video, the virtual live broadcast function is realized by image matting and later applying the virtual scene package (.capturescene) of Meishe SDk to the video.
The specific steps are as follows:
Initialize the StreamingContext. There are two ways to create a NvsStreamingContext singleton object. Here we choose to create singleton object without the flags.
m_streamingContext = [NvsStreamingContext sharedInstance];
Set the callback and connects the capture preview output to the NvsLiveWindow control.
//Sets the callback interface to the streaming context. m_streamingContext.delegate = self; m_streamingContext.assetPackageManager.delegate = self;
//Connects capture preview output to the NvsLiveWindow control. [m_streamingContext connectCapturePreviewWithLiveWindow:self.liveWindow];
Add image matting capture Fx.
NvsCaptureVideoFx *keyerFx = [m_streamingContext appendBuiltinCaptureVideoFx:"Master Keyer"]; if (keyerFx) { //Opens the overflow color removal. [keyerFx setBooleanVal:"Spill Removal" val:YES]; //Set the intensity of the overflow removal to the lowest. [keyerFx setFloatVal:"Spill Removal Intensity" val:0]; //Set the boundary shrinking strength. [keyerFx setFloatVal:"Shrink Intensity" val:0.4]; }
Start the capture preview.
//Color pick is needed on the captured video. So Users need to use NvsStreamingEngineCaptureFlag_GrabCapturedVideoFrame flag. [m_streamingContext startCapturePreview:deviceIndex videoResGrade:NvsVideoCaptureResolutionGradeHigh flags:NvsStreamingEngineCaptureFlag_GrabCapturedVideoFrame aspectRatio:nil];
Click to pick color and pass the extracted background image color value to the key effect.
NvsColor sampledColor = [m_streamingContext sampleColorFromCapturedVideoFrame:sampleRect];
//Passes the extracted background image color value to the key effect. NvsCaptureVideoFx *keyerFx = [m_streamingContext getCaptureVideoFxByIndex:0]; if(keyerFx) [keyerFx setColorVal:"Key Color" val:&sampledColor];
Use the virtual scene package, and the virtual live scene will appear.
[m_streamingContext applyCaptureScene:sceneId];