- mpp_enc_data.fmt = MPP_FMT_YUV420P;
- if (mpp_enc_data.fmt <= MPP_FMT_YUV420SP_VU)
- mpp_enc_data.frame_size = mpp_enc_data.hor_stride * mpp_enc_data.ver_stride * 3 / 2;
- else if (mpp_enc_data.fmt <= MPP_FMT_YUV422_UYVY) {
- // NOTE: yuyv and uyvy need to double stride
- mpp_enc_data.hor_stride *= 2;
- mpp_enc_data.frame_size = mpp_enc_data.hor_stride * mpp_enc_data.ver_stride;
- } else
- mpp_enc_data.frame_size = mpp_enc_data.hor_stride * mpp_enc_data.ver_stride * 4;
复制代码
调用mpp的代码:(其中image2是mat格式的)- unsigned char *buf = mpp_buffer_get_ptr(mpp_enc_data.frm_buf);
- cvtColor(image2, dstimage,CV_RGB2YUV_I420);
- memcpy(buf, dstimage.data,Image_Width*Image_High*3/2*sizeof(unsigned char));
- ret = mpp_frame_init(&frame);
- mpp_frame_set_width(frame, mpp_enc_data.width);
- mpp_frame_set_height(frame, mpp_enc_data.height);
- mpp_frame_set_hor_stride(frame, mpp_enc_data.hor_stride);
- mpp_frame_set_ver_stride(frame, mpp_enc_data.ver_stride);
- mpp_frame_set_fmt(frame, mpp_enc_data.fmt);
- mpp_frame_set_buffer(frame, mpp_enc_data.frm_buf);
- ret = mpp_enc_data.mpi->encode_put_frame(mpp_enc_data.ctx, frame);
- ret = mpp_enc_data.mpi->encode_get_packet(mpp_enc_data.ctx, &packet);
复制代码
相当于先把opencv的mat转成yuv格式的,再编码,是可以的。- //cvtColor(image2, dstimage,CV_RGB2YUV_I420);
- memcpy(buf, image2.data,Image_Width*Image_High*4*sizeof(unsigned char));
复制代码
编码出来的就是花屏,欢迎光临 Toybrick (https://t.rock-chips.com/) | Powered by Discuz! X3.3 |