|
我yuv编码jpeg出现 jpege_api: jpege: hardware return error status 40 。存下来的图底部是花的,是哪里出了问题?代码如下
- void doCodec(){
- MppCtx ctx;
- MppApi *mpi;
- MpiCmd cmd = MPP_SET_OUTPUT_BLOCK;
- MppParam param = NULL;
- MppPollType block = MPP_POLL_BLOCK;
- MppCodingType type = MPP_VIDEO_CodingMJPEG;
- int MPI_ENC_LOOP_COUNT = 1;
- __android_log_print(ANDROID_LOG_DEBUG, "JNI","mpp_create");
- if(MPP_OK != mpp_create(&ctx, &mpi)){
- __android_log_print(ANDROID_LOG_DEBUG, "JNI","mpp_create failed");
- goto MPP_TEST_FAILED;
- }
- __android_log_print(ANDROID_LOG_DEBUG, "JNI","mpp_init");
- if(MPP_OK != mpp_init(ctx, MPP_CTX_ENC, type)){
- __android_log_print(ANDROID_LOG_DEBUG, "JNI","mpp_init failed");
- goto MPP_TEST_FAILED;
- }
- MppEncRcCfg rcCfg;
- __android_log_print(ANDROID_LOG_DEBUG, "JNI","rcCfg");
- rcCfg.change = MPP_ENC_RC_CFG_CHANGE_ALL;
- rcCfg.rc_mode = (MppEncRcMode) MPP_ENC_RC_MODE_CBR;
- rcCfg.quality = (MppEncRcQuality)MPP_ENC_RC_QUALITY_BEST;
- rcCfg.bps_target = bps;
- rcCfg.bps_max = bps * 17 / 16;
- rcCfg.bps_min = bps * 15 / 16;
- rcCfg.fps_in_flex = 0;
- rcCfg.fps_in_num = 24;
- rcCfg.fps_in_denorm = 1;
- rcCfg.fps_out_flex = 0;
- rcCfg.fps_out_num = 24;
- rcCfg.fps_out_denorm = 1;
- rcCfg.gop = 50;
- if(MPP_OK != mpi->control(ctx, MPP_ENC_SET_RC_CFG, &rcCfg)){
- __android_log_print(ANDROID_LOG_DEBUG, "JNI","rcCfg failed");
- goto MPP_TEST_FAILED;
- }
- __android_log_print(ANDROID_LOG_DEBUG, "JNI","prepCfg");
- MppEncPrepCfg prepCfg;
- prepCfg.change = MPP_ENC_PREP_CFG_CHANGE_INPUT | MPP_ENC_PREP_CFG_CHANGE_FORMAT;
- prepCfg.width = 1920;
- prepCfg.height = YUV_HEIGHT;
- prepCfg.hor_stride = MPP_ALIGN(1920, 8);
- prepCfg.ver_stride = MPP_ALIGN(YUV_HEIGHT, 8);
- prepCfg.format = MPP_FMT_YUV420P;
- if(MPP_OK != mpi->control(ctx, MPP_ENC_SET_PREP_CFG, &prepCfg)){
- __android_log_print(ANDROID_LOG_DEBUG, "JNI","rcCfg failed");
- goto MPP_TEST_FAILED;
- }
-
- __android_log_print(ANDROID_LOG_DEBUG, "JNI","codecCfg");
- MppEncCodecCfg codecCfg;
- if(MPP_OK != mpi->control(ctx, MPP_ENC_SET_CODEC_CFG, &codecCfg)){
- __android_log_print(ANDROID_LOG_DEBUG, "JNI","codecCfg failed");
- goto MPP_TEST_FAILED;
- }
-
- MppPacket enc_out;
- MppFrame enc_in;
- param = █
- MppBuffer frm_buf;
- unsigned char *buf2;
- mpp_buffer_get(NULL, &frm_buf, MPP_ALIGN(1920, 8) * MPP_ALIGN(YUV_HEIGHT, 8) * 3 / 2);
- FILE *file;
- file = fopen("/sdcard/single_frame.yuv", "rb");
- buf2 = (unsigned char *)malloc(YUV_SIZE);
- memset(buf2, 0, YUV_SIZE);
- fread(buf2, 1, YUV_SIZE, file);
- if(MPP_OK != mpi->control(ctx, MPP_SET_OUTPUT_BLOCK, param)){
- __android_log_print(ANDROID_LOG_DEBUG, "JNI","control failed");
- goto MPP_TEST_FAILED;
- }
- // interface with both input and output
- for (int i = 0; i < MPI_ENC_LOOP_COUNT; i++) {
- unsigned char *buf;
- buf = (unsigned char *)mpp_buffer_get_ptr(frm_buf);
- memcpy(buf, buf2, YUV_SIZE);
- mpp_frame_init(&enc_in);
- mpp_frame_set_width(enc_in, 1920);
- mpp_frame_set_height(enc_in, YUV_HEIGHT);
- mpp_frame_set_hor_stride(enc_in, MPP_ALIGN(1920, 8));
- mpp_frame_set_ver_stride(enc_in, MPP_ALIGN(YUV_HEIGHT, 8));
- mpp_frame_set_fmt(enc_in, MPP_FMT_YUV420P);
- mpp_frame_set_buffer(enc_in, frm_buf);
- mpp_frame_set_eos(enc_in, 0);
- if (MPP_OK != mpi->encode_put_frame(ctx, enc_in)) {
- __android_log_print(ANDROID_LOG_DEBUG, "JNI","encode_put_frame failed");
- goto MPP_TEST_FAILED;
- } else{
- if (MPP_OK != mpi->encode_get_packet(ctx, &enc_out)) {
- __android_log_print(ANDROID_LOG_DEBUG, "JNI","encode_get_packet failed");
- goto MPP_TEST_FAILED;
- } else{
- if(enc_out){
- __android_log_print(ANDROID_LOG_DEBUG, "JNI","enc_out!");
- void *ptr = mpp_packet_get_pos(enc_out);
- size_t len = mpp_packet_get_length(enc_out);
- RK_U32 eos = mpp_packet_get_eos(enc_out);
- unsigned char* out_buf = new unsigned char[len];
- memcpy(out_buf, ptr, len);
- FILE *outfile = fopen("/sdcard/output.jpeg", "wb+");
- fwrite(out_buf, 1, len, outfile);
- fclose(outfile);
- mpp_packet_deinit(&enc_out);
- }
- }
- }
- mpp_frame_deinit(&enc_in);
- }
- mpi->reset(ctx);
- if (enc_in){
- mpp_frame_deinit(&enc_in);
- }
- mpp_destroy(ctx);
- free(buf2);
- __android_log_print(ANDROID_LOG_DEBUG, "JNI","mpi_test success");
- return;
- MPP_TEST_FAILED:
- if (enc_in){
- mpp_frame_deinit(&enc_in);
- }
- if (ctx){
- mpp_destroy(ctx);
- }
- if (buf2){
- free(buf2);
- }
- }
|
|