This example demonstrates passing custom video data into the R5Stream.
To view this example, you simply need to open the example and subscribe to your stream from a second device. All audio will be recorded, and instead of camera input, a simply plasma style effect is rendered.
Instead of using an R5Camera, this example uses a custom video source, the CustomVideoSource. This device
CustomVideoSource source = new CustomVideoSource();
publish.attachCamera(source);PublishCustomSourceTest.java #54
This device automatically polls and pushes to the encoder when new pixels are ready to be published. There are several steps that are needed to properly feed data to the encoder.
- Make sure all bytes are in the YUV420 or YV12 pixel format.
CustomVideoSourceuses RGBA data, so it has a special functionencodeYUV420which converts RGB data to this format. This method can be seen at CustomVideoSource.java #47. - Call
prepareFrame. This method will convert the YUV data into the proper format for the encoder.CustomVideoSourcehas two buffers, and copies the properly prepared frames to the output buffer at CustomVideoSource.java #183. - Get the timestamp. The timestamp can be gotten from the AudioEngine if you are publishing audio, or can be localled tracked. CustomVideoSource.java #187.
- Encode the data! This last call to
encodewill send the data to the encoder and pass to the stream when ready. CustomVideoSource.java #192.