Android摄像头开发 实时摄像头视频预览帧的编码问题(二)

本文探讨Android摄像头开发中的实时预览帧处理,分析onPreviewFrame()中的转换流程,指出由于预览帧默认格式为NV21,直接用BitmapFactory解析会失败。建议使用YuvImage或自定义转换函数将YUV420SP转RGB。同时,分享了三种常见的转换方法,并邀请读者一起探讨YUV420SP中Y分量的提取。
摘要由CSDN通过智能技术生成
               

Android开发:实时处理摄像头预览帧视频------浅析PreviewCallback,onPreviewFrame,AsyncTask的综合应用 这里将大致框架介绍了,但很多人对onPreviewFrame()里的处理提出质疑。认为下面的转换是多余的:

            final YuvImage image = new YuvImage(mData, ImageFormat.NV21, w, h, null);            ByteArrayOutputStream os = new ByteArrayOutputStream(mData.length);            if(!image.compressToJpeg(new Rect(0, 0, w, h), 100, os)){                return null;            }            byte[] tmp = os.toByteArray();            Bitmap bmp = BitmapFactory.decodeByteArray(tmp, 0,tmp.length); 


因为这个mData是byte[ ]格式,转换流程是:byte[ ]---YuvImage----ByteArrayOutputStream---byte[ ]-----Bitmap。乍一看这个转换还真是多余了。看看看goolge的api:

public abstract void onPreviewFrame (byte[] data, Camera camera)Added in API level 1Called as preview frames are displayed. This callback is invoked on the event thread open(int) was called from.If using the YV12 format, refer to the equations in setPreviewFormat(int) for the arrangement of the pixel data in the preview callback buffers.Parametersdata the contents of the preview frame in the format defined by ImageFormat, which can be queried with getPreviewFormat(). If setPreviewFormat(int) is never called, the default will be the YCbCr_420_SP (NV21) format.camera the Camera service object.


大致意思是:可以用getPreviewFormat()查询支持的预览帧格式。如果setPreviewFormat(INT) 从未被调用,默认将使用YCbCr_420_SP的格式(NV21)。

setPreviewFormat里,它又说:

public void setPreviewFormat (int pixel_format)Added in API level 1Sets the image format for preview pictures.If this is never called, the default format will be NV21, which uses the NV21 encoding format.Use getSupportedPreviewFormats() to get a list of the available preview formats.It is strongly recommended
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值