mpp_enc_data.type = MPP_VIDEO_CodingAVC;
mpp_enc_data.num_frames = 2000;
ret = mpp_buffer_get(NULL, &mpp_enc_data.frm_buf, mpp_enc_data.frame_size);
if (ret)
{
printf("failed to get buffer for input frame ret %d\n", ret);
goto MPP_INIT_OUT;
}
ret = mpp_create(&mpp_enc_data.ctx, &mpp_enc_data.mpi);
if (ret)
{
printf("mpp_create failed ret %d\n", ret);
goto MPP_INIT_OUT;
}
ret = mpp_init(mpp_enc_data.ctx, MPP_CTX_ENC, mpp_enc_data.type);
if (ret)
{
printf("mpp_init failed ret %d\n", ret);
goto MPP_INIT_OUT;
}
ret = mpp_enc_data.mpi->control(mpp_enc_data.ctx, MPP_ENC_SET_RC_CFG, &mpp_enc_data.rc_cfg);
if (ret)
{
printf("mpi control enc set rc cfg failed ret %d\n", ret);
goto MPP_INIT_OUT;
}
ret = mpp_enc_data.mpi->control(mpp_enc_data.ctx, MPP_ENC_SET_CODEC_CFG, &mpp_enc_data.codec_cfg);
if (ret)
{
printf("mpi control enc set codec cfg failed ret %d\n", ret);
goto MPP_INIT_OUT;
}
/* optional */
mpp_enc_data.sei_mode = MPP_ENC_SEI_MODE_ONE_FRAME;
ret = mpp_enc_data.mpi->control(mpp_enc_data.ctx, MPP_ENC_SET_SEI_CFG, &mpp_enc_data.sei_mode);
if (ret)
{
printf("mpi control enc set sei cfg failed ret %d\n", ret);
goto MPP_INIT_OUT;
}
mpp_enc_data.fp_output = fopen(OUTPUTPATH, "wb+");
if (mpp_enc_data.type == MPP_VIDEO_CodingAVC)
{
MppPacket packet = NULL;
ret = mpp_enc_data.mpi->control(mpp_enc_data.ctx, MPP_ENC_GET_EXTRA_INFO, &packet);
if (ret)
{
printf("mpi control enc get extra info failed\n");
goto MPP_INIT_OUT;
}
/* get and write sps/pps for H.264 */
if (packet)
{
void *ptr = mpp_packet_get_pos(packet);
size_t len = mpp_packet_get_length(packet);
if (mpp_enc_data.fp_output)
fwrite(ptr, 1, len, mpp_enc_data.fp_output);
packet = NULL;
}
}
return;
MPP_INIT_OUT:
if (mpp_enc_data.ctx)
{
mpp_destroy(mpp_enc_data.ctx);
mpp_enc_data.ctx = NULL;
}
if (mpp_enc_data.frm_buf)
{
mpp_buffer_put(mpp_enc_data.frm_buf);
mpp_enc_data.frm_buf = NULL;
}