Embedded topic: s5pv210-MPEG4 Encoding

Source: Internet
Author: User

I would like to say that the header files of platforms such as tiny210 and x210 are slightly different. This is the code under x210. However, you must pay attention to the nv12t and nv12 problems. By default, the input image is nv12t. After adjustment, you can use nv12.

Even so, the nv12 format is hard to get.


# 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; // enable 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; // initialize ssbsip_mfc_enc_mpeg4_param Param; memset (memory M, 0, sizeof (PARAM); Param. codectype = mpeg4_enc; Param. sourcewidth = img_width; Param. sourceheight = img_height; Param. framemap = nv12_linear; // use linearparam. idrperiod = 20; // can it be greater than 3? Param. slicemode = 0; Param. sliceargument = 1; Param. randomintrambrefresh = 0 ;//? // Frame based rate controlparam is not used. 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 paddingparam. 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, limit m )! = Mfc_ret_ OK) {printf ("failed to init encoder! \ N "); Return-1;}/* Get the 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 the 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 (INB Uf. 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 */outputs 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. headersize);/* save it as 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 ;}


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.