I am trying to encode a video in java. I have access to the separate frames as I420 yuv frames (these come from a different part of the program that I cannot change). I basically have 3 bytebuffers for the different planes of a frame (+ dimensions). As far as I understand, my format has 1 byte for the y-plane, and half a byte for u and v each, per pixel.
What is the best way to encode these into an mp4 video file? I have tried with the xuggler API, but I can't seem to find a way to use the yuv frames directly. Right now, I would convert them to a BufferedImage (TYPE_3BYTE_BGR) first before I can use them with the xuggler api to encode them to a video.
But this creates a huge overhead (I have to convert the yuv data to rgb for each pixel) and is unnecessary, as xuggler encodes them to yuv frames again to store them in a video file? (Not sure about this.)
So is there any easier way to encode raw yuv-frames to a video file directly in java?
Thanks for any pointers.
The way your are planning this seems correct (manual conversion), as long as xuggler didn't re-encode the frame after you.
I have done this conversion with both python and C, the process is still the same as yours (frame by frame, looping the pixels). In Java, this could look like :
Sample code from https://github.com/jyanik/Mocobar/blob/master/Mocobar/src/com/yanik/mocobar/camera/YUV2RGB.java