[Libav-user] how to convert NV21 to YUV420P with swscale
Peter Pan
hawkwithwind at gmail.com
Tue Sep 30 09:54:47 CEST 2014
Hello
I'm trying to convert NV21 image to YUV420P,
for x264 encoder to encode it.
my code is:
static int scale(char* lin, x264_picture_t* pic,
int in_width, int in_height, int out_width, int out_height){
if(convertCtx == NULL){
convertCtx = sws_getContext(in_width, in_height, PIX_FMT_NV21,
out_width, out_height, PIX_FMT_YUV420P,
SWS_FAST_BILINEAR, NULL, NULL, NULL);
}
AVPicture src;
avpicture_fill(&src, lin, PIX_FMT_NV21, in_width, in_height);
int h = sws_scale(convertCtx,
(const uint8_t **)(&lin), src.linesize,
0, in_height,
(uint8_t * const*)(pic->img.plane), pic->img.i_stride);
return h;
}
the images are recorded from android camera with such code:
params = mCamera.getParameters();
params.setPreviewFormat(ImageFormat.NV21);
mCamera.setParameters(params);
And I will get the video buffer from onPreviewFrame callback.
the code works well if the src image is PIX_FMT_YUYV422,
with android camera set to
params.setPreviewFormat(ImageFormat.YUY2);
but when I try to convert NV21 images on some other devices,
the image broke. the image looks like its purple and green part
of the pixels are separated.
please help me with this convert code. thank you.
Thanks,
Peter
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://ffmpeg.org/pipermail/libav-user/attachments/20140930/e682129d/attachment.html>
More information about the Libav-user
mailing list