You can use v4l2 to successfully collect the yuyv video and encode it into H. 264 file, because yuv420 was previously encoded as H. 264 program, so I think yuv422 is encoded into H. 264 is also similar and should be quite simple.
So I am very happy to write the encoding function. Encoding yuv420 I am referring to this article and this blog post. I am now ready to start. I feel that Maria is waving to me, I think I'm about to succeed.
Pai_^
However, I know that, as a programmer, I will be embarrassed if I don't encounter any problems or difficulties.
Yes, I have encountered difficulties. The videos I coded are flowers, red, green, and like spring!
Because the YUV code of yuv420 is also scanned by line, its YUV sequence is as follows:
Yyyy
Yyyy
Uvuv
So I naively thought that the yuv422 stored the same sequence, because they all had an interline scan.
Later, we learned that the YV scan sequence is not like this. The yuv422 sequence should be like the following:
Yu YV
That is to say, UV is indeed cross-storage, but it must be crossed with Y.
Once you know the storage sequence, it's easy to encode it into H.264.
See my code below:
Char * Y = en-> picture-> IMG. plane [0]; char * u = en-> picture-> IMG. plane [1]; char * V = en-> picture-> IMG. plane [2]; int is_y = 1, is_u = 1; int y_index = 0, u_index = 0, v_index = 0; int yuv422_length = 2 * En-> param-> I _width * En-> param-> I _height; // The sequence is Yu YV, length width * height * 2 bytes of A yuv422 frame for (I = 0; I <yuv422_length; ++ I) {If (is_y) {* (Y + y_index) = * (in + I); ++ y_index; is_y = 0;} else {If (is_u) {* (U + u_index) = * (in + I ); ++ u_index; is_u = 0;} else {* (V + v_index) = * (in + I); ++ v_index; is_u = 1;} is_y = 1 ;}}
Note: In is the pointer to the yuv422 sequence, that is, the starting address of yuv422.
We only need
Y is assigned to plane [0].
U assigned to plane [1]
V is assigned to plane [2] to encode it.