Problems when scaling a YUV image using libyuv library

前端 未结 5 859
滥情空心
滥情空心 2021-01-07 17:12

I\'m developing a camera app based on Camera API 2 and I have found several problems using the libyuv. I want to convert YUV_420_888 images retriev

5条回答
  •  礼貌的吻别
    2021-01-07 17:35

    You are trying to scale your YUV422 image as if it was YUV420, no wonder the colors are all messed up. First of all you need to figure out what exactly format of your YUV input buffer. From documentation of YUV_422_888 it looks like it may represent planar as well as interleaved formats (if pixel stride is not 1). From your results it looks like your source is planar and processing of Y plane is ok, but your error is in handling U and V planes. To get scaling right:

    • You have to figure out if your U and V planes are interleaved or planar. Most likely they are planar as well.
    • Use ScalePlane from libyuv to scale U and V separately. Perhaps if you step into I420Scale it calls ScalePlane for individual planes. Do the same, but use correct linesizes for your U and V planes (each is twice larger than what I420Scale expects).

    Some tips how to figure out if you have planar or interleaved U and V: try to skip scaling of your image and saving it, to ensure that you get correct result (identical to the source). Then try to zero out U frame or V frame and see what you get. If U and V are planar and you memset U plane to zero you should see entire picture changing color. If they are interleaved you'll get half of picture changing and the other one staying the same. Same way you can check your assumptions about sizes, linesizes, and offsets of your planes. Once you are sure about your YUV format and layout you can scale individual planes if your input is planar, or if you have interleaved input first you need to deinterleave planes and then scale them.

    Alternatively, you can use libswscale from ffmpeg/libav and try different formats to find correct one and then use libyuv.

提交回复
热议问题