We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
这是编码过程中的代码,希望有大佬有时间可以讨论下,看到会回复。 int t_hor_stride =(MPP_ALIGN(my_def_width, 16)); int t_ver_stride =(MPP_ALIGN(my_def_height, 16));
//printf("encode\n"); if(set_bps == 0){ if(webrtc_bps123!=bps){ bps = webrtc_bps123; SetRate(bps); } } if(set_bps>0){ if(set_bps!=bps){ bps = set_bps; SetRate(bps); } } MppFrame src_frame = NULL; MppMeta meta = NULL; MppPacket packet = NULL; RK_S32 cam_frm_idx = -1; MppBuffer cam_buf = NULL; int ret = 0; //从相机中取数据 if(!cam_ctx){ return nullptr; } cam_frm_idx = camera_source_get_frame(cam_ctx); //耗时17ms //mpp_assert(cam_frm_idx >= 0); camera_source_put_frame(cam_ctx, cam_frm_idx); cam_buf = camera_frame_to_buf(cam_ctx, cam_frm_idx); //mpp_assert(cam_buf); //从参数中取数据 //========================================= test rga // std::cerr << "55555555555555555555555555555555555555555 " << std::endl; // print_current_time(); //MppFrame dest_frame = scale_frame_custom(src_frame,cam_buf); //MppFrame dest_frame = scale_frame(src_frame); MppFrame dest_frame = NULL; // std::cerr << "66666666666666666666666666666666666666666 " << std::endl; // print_current_time(); //========================================= //rga转化 dst_size = my_width*my_height*3/2; if (mpp_buffer_get(mbuf_grp, &dst_buf, dst_size) != MPP_OK) { perror("failed to allocate destination buffer\n"); } char* src_buf = (char*) mpp_buffer_get_ptr(cam_buf); size_t msrc_size = mpp_buffer_get_size(cam_buf); printf("msrc_size = %d\n",msrc_size); size_t mdst_size = mpp_buffer_get_size(dst_buf); printf("mdst_size = %d\n",mdst_size); char* dst_buf_char = (char*) mpp_buffer_get_ptr(dst_buf); memset(dst_buf_char,0,dst_size); rga_buffer_t src; rga_buffer_t dst; src = wrapbuffer_virtualaddr(src_buf, my_def_width, my_def_height, RK_FORMAT_YCbCr_420_SP); dst = wrapbuffer_virtualaddr(dst_buf_char, my_width, my_height, RK_FORMAT_YCbCr_420_SP); src.fd = mpp_buffer_get_fd(cam_buf); dst.fd = mpp_buffer_get_fd(dst_buf); print_expected(src,dst); printf(" phy_addr: %p, vir_addr: %p, fd: %d, src_width: %d\n", src.phy_addr, src.vir_addr, src.fd, src.width); printf(" phy_addr: %p, vir_addr: %p, fd: %d, dst_width: %d\n", dst.phy_addr, dst.vir_addr, dst.fd, dst.width); ret = imresize(src, dst); if (ret != IM_STATUS_SUCCESS) { printf("RGA resize failed! %s\n", imStrError((IM_STATUS)ret)); return nullptr; } // //保存到文件 // FILE* file = fopen("test.yuv", "wb"); // size_t written = fwrite(dst_buf_char, 1, dst_size, file); // if (written != dst_size) { // std::cerr << "written size: " << written << std::endl; // perror("Failed to write buffer to file"); // } else { // printf("Successfully saved %zu bytes to file %s\n", written, "test.yuv"); // } // fclose(file); // for(;;); //========================================= ret = mpp_frame_init(&dest_frame); if (ret) { perror("mpp_frame_init failed\n"); return nullptr; } mpp_frame_set_width(dest_frame, my_width); mpp_frame_set_height(dest_frame, my_height); mpp_frame_set_hor_stride(dest_frame, my_width); mpp_frame_set_ver_stride(dest_frame, my_height); mpp_frame_set_fmt(dest_frame, mfmt); mpp_frame_set_eos(dest_frame, mEos); mpp_frame_set_buffer(dest_frame, dst_buf); std::cerr << "dest_frame size: " << mpp_buffer_get_size(mpp_frame_get_buffer(dest_frame)) << std::endl; meta = mpp_frame_get_meta(dest_frame); std::cerr << "mpkt_buf size: " << mpp_buffer_get_size(mpkt_buf) << std::endl; mpp_packet_init_with_buffer(&packet, mpkt_buf); /* NOTE: It is important to clear output packet length!! */ mpp_packet_set_length(packet, 0); mpp_meta_set_packet(meta, KEY_OUTPUT_PACKET, packet); std::cerr << "md_info size: " << mpp_buffer_get_size(md_info) << std::endl; mpp_meta_set_buffer(meta, KEY_MOTION_INFO,md_info); ret = mApi->encode_put_frame(mCtx, dest_frame); //耗时操作 16ms if (ret) { perror("encode put frame failed\n"); mpp_frame_deinit(&dest_frame); return nullptr; } mpp_frame_deinit(&dest_frame); ret = mApi->encode_get_packet(mCtx, &packet); //耗时操作 6ms if (ret) { perror("encode get packet failed\n"); return nullptr; } mpp_assert(packet); if (packet) { auto data = (uint8_t*)mpp_packet_get_pos(packet); size = mpp_packet_get_length(packet); //printf("[encode size:%d\n",size); mpp_packet_deinit(&packet); mpp_buffer_put(dst_buf); fps_calc_inc(cfps); camera_source_put_frame(cam_ctx, cam_frm_idx); return data; }
The text was updated successfully, but these errors were encountered:
解决了,通过将画布设置为目标分辨率,然后使用一个中间变量接收dst_buf,最后将内容拷贝到mpp_buffer中
Sorry, something went wrong.
No branches or pull requests
这是编码过程中的代码,希望有大佬有时间可以讨论下,看到会回复。
int t_hor_stride =(MPP_ALIGN(my_def_width, 16));
int t_ver_stride =(MPP_ALIGN(my_def_height, 16));
The text was updated successfully, but these errors were encountered: