Last active
March 17, 2021 18:27
-
-
Save icywind/92053d0983e713515c64d5c532ebee21 to your computer and use it in GitHub Desktop.
How to push external video source frame with a coroutine
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Push frame to the remote client | |
IEnumerator PushFrame(byte[] bytes, int width, int height, System.Action onFinish) | |
{ | |
if (bytes == null || bytes.Length == 0) | |
{ | |
Debug.LogError("Zero bytes found!!!!"); | |
yield break; | |
} | |
IRtcEngine rtc = IRtcEngine.QueryEngine(); | |
//if the engine is present | |
if (rtc != null) | |
{ | |
//Create a new external video frame | |
ExternalVideoFrame externalVideoFrame = new ExternalVideoFrame(); | |
//Set the buffer type of the video frame | |
externalVideoFrame.type = ExternalVideoFrame.VIDEO_BUFFER_TYPE.VIDEO_BUFFER_RAW_DATA; | |
// Set the video pixel format | |
//externalVideoFrame.format = ExternalVideoFrame.VIDEO_PIXEL_FORMAT.VIDEO_PIXEL_BGRA; // V.2.9.x | |
externalVideoFrame.format = ExternalVideoFrame.VIDEO_PIXEL_FORMAT.VIDEO_PIXEL_RGBA; // V.3.x.x | |
//apply raw data you are pulling from the rectangle you created earlier to the video frame | |
externalVideoFrame.buffer = bytes; | |
//Set the width of the video frame (in pixels) | |
externalVideoFrame.stride = width; | |
//Set the height of the video frame | |
externalVideoFrame.height = height; | |
//Remove pixels from the sides of the frame | |
externalVideoFrame.cropLeft = 10; | |
externalVideoFrame.cropTop = 10; | |
externalVideoFrame.cropRight = 10; | |
externalVideoFrame.cropBottom = 10; | |
//Rotate the video frame (0, 90, 180, or 270) | |
externalVideoFrame.rotation = 90; | |
// increment i with the video timestamp | |
externalVideoFrame.timestamp = i++; | |
//Push the external video frame with the frame we just created | |
int a = rtc.PushVideoFrame(externalVideoFrame); | |
Debug.Log(" pushVideoFrame(" + i + ") size:" + bytes.Length + " => " + a); | |
} | |
yield return null; | |
onFinish(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment