I want to say no platform, such as tiny210 and x210, their header files are slightly different. This is the code under X210. But all need to pay attention to is nv12t and NV12 problem, the default request input picture is nv12t, after adjusting, can allow to use NV12.
Even so, the NV12 format of the picture is not easy to get AH.
#include <stdio.h> #include <string.h> #include <stdlib.h> #include <unistd.h> #include ". /mfc/ssbsipmfcapi.h "#include". /mfc/mfcconvert.h "#include".
/mm/mmclock.h "int test_enc_mpeg4 () {Mmclock clock; Clock.
Adjust (1000);
Ssbsip_mfc_error_code ret = MFC_RET_OK;
Open unsigned int buf_type = CACHE;
void* handle = Ssbsipmfcencopen ();
if (handle = = NULL) {printf ("Failed to open MFC device!\n");
return-1;
printf ("= = Ssbsipmfcdecopen ok \ \ n");
int img_width = 640;
int img_height = 480;
Initialization of Ssbsip_mfc_enc_mpeg4_param PARAM;
memset (¶m, 0, sizeof (param));
Param.codectype = Mpeg4_enc; Param.
Sourcewidth = Img_width; Param.
Sourceheight = Img_height; Param. Framemap = Nv12_linear; Use linear param. Idrperiod = 20;
can be greater than 3. Param.
Slicemode = 0; Param.
Sliceargument = 1; Param. Randomintrambrefresh = 0;
// ? Do not use the frame based rate control param.
Enablefrmratecontrol = 1; Param.
Timeincreamentres = 1000; Param. Voptimeincreament= 40; Param.
bitrate = 4000000; Param.
FRAMEQP = 1; Param.
Frameqp_p = 1; Param.
Frameqp_b = 1; Param.
Qscodemax = 45; Param.
Qscodemin = 20; Param.
CBRPERIODRF = 2; Do not use custom padding param.
Padcontrolon = 0; Param.
Lumapadval = 0; Param.
Cbpadval = 0; Param.
Crpadval = 0; Param.
PROFILEIDC = 66; Param.
LEVELIDC = 22; Param.
Numberbframes = 0; Param.
Disableqpelme = 0;
if (Ssbsipmfcencinit (handle,¶m)!= mfc_ret_ok) {printf ("Failed to init encoder!\n");
return-1;
/* Get Input buffer address * * Ssbsip_mfc_enc_input_info inbuf;
if (Ssbsipmfcencgetinbuf (handle, &inbuf)!= Mfc_ret_ok) {printf ("failed to get in buf!\n");
return 0; printf ("In Buf:y (addr=%08x, size=%d), Cbcr (addr=%08x, size=%d) \ n", Inbuf. Yviraddr, Inbuf. Ysize, Inbuf. Cviraddr, Inbuf.
CSize);
/* Get Header * * Ssbsip_mfc_enc_output_info outbuf;
ret = SSBSIPMFCENCGETOUTBUF (handle, &OUTBUF);
if (ret!= mfc_ret_ok) {printf ("failed to get output (%d) \ n", ret);
return-1; printf ("SaviNg header:%d bytes \ n ", outbuf.headersize);
if (1) {file* fp = fopen ("A00.MPEG4", "WB"); Fwrite (outbuf.
STRMVIRADDR, 1, outbuf.headersize, FP);
Fclose (FP);
int y_size = Img_width * img_height;
int c_size = Y_SIZE/2;
/* Read image/* file* fp = fopen ("K00.nv12", "RB"); int n1 = Fread (inbuf.
YVIRADDR, 1, y_size, FP); int n2 = Fread (inbuf.
CVIRADDR, 1, c_size, FP);
printf ("read bytes:n1=%d, n2=%d \ n", N1, N2);
int count = 0; while (count + + < 3) {printf (... times:%d, now%d ... \ n), count, (int) clock.
Ptstime ());
/* Encoding/ret = Ssbsipmfcencexe (handle);
if (ret!= mfc_ret_ok) {printf ("Failed encoding (%d) \ n", ret);
return-1;
}/* Output result * * Ssbsip_mfc_enc_output_info outbuf;
ret = SSBSIPMFCENCGETOUTBUF (handle, &OUTBUF);
if (ret!= mfc_ret_ok) {printf ("failed to get output (%d) \ n", ret);
return-1; printf ("Output:frame type=%d, size=%d, header size=%d \ n", Outbuf.frametype, Outbuf.datasize, Outbuf.hea Dersize);
/* Save into a file */char filename[128];
sprintf (filename, "A%02D.MPEG4", count);
file* fp = fopen (filename, "WB"); Fwrite (outbuf.
STRMVIRADDR, 1, outbuf.datasize, FP);
Fclose (FP);
} ssbsipmfcencclose (handle);
return 0;
}