Use the Samsung source code to compress videos and images at the same time. The source code

Source: Internet
Author: User

Use the Samsung source code to compress videos and images at the same time. The source code

Some time ago, the video was compressed using Samsung to generate H264 files and captured and compressed them to generate JPG images. The core steps are as follows:

    /* Codec set */    /* Get capability */    ret = ioctl(cam_c_fp , VIDIOC_QUERYCAP, &cap);

One-side video compression:

if(frame_count == 1)                    encoded_buf = mfc_encoder_exe(handle, g_yuv, YUV_FRAME_BUFFER_SIZE, 1, &encoded_size);                else                    encoded_buf = mfc_encoder_exe(handle, g_yuv, YUV_FRAME_BUFFER_SIZE, 0, &encoded_size);          

2. Get the data of a certain frame in the video:

 if (read(cam_c_fp, g_yuv_cc, g_YUV420_Frame_Buffer_Size) < 0) {        perror("read()");}

3. After reading the data, because the format before Image Compression must be yuv422, and the data format of the camera is yuv420, the conversion is required:

convert_yuv420p_to_yuv422_my( g_yuv_cc,g_yuv_c,g_codec_Width,g_codec_Height);

The specific implementation of conversion is:

// Plane YUV420 to plane YUV422static void trim (unsigned char * src, unsigned char * dst, int width, int height) {int I, j; unsigned char * pY420_0 = src; unsigned char * pY420_1 = src + width; unsigned char * pU420 = src + width * height; unsigned char * pV420 = src + width * height * 5/4; unsigned char * pY422_0 = dst; unsigned char * pY422_1 = dst + width * 2; for (I = 0; I 

4. After the conversion is complete, it is a simple compression process:

/* JPEG encoding */    /* JPEG Handle initialization */    jpg_handle = SsbSipJPEGEncodeInit();    if (jpg_handle < 0)        return;    /* Set encoding configs */    if((ret = SsbSipJPEGSetConfig(JPEG_SET_SAMPING_MODE, JPG_422)) != JPEG_OK)        return;        if((ret = SsbSipJPEGSetConfig(JPEG_SET_ENCODE_WIDTH, g_codec_Width)) != JPEG_OK)        return;        if((ret = SsbSipJPEGSetConfig(JPEG_SET_ENCODE_HEIGHT, g_codec_Height)) != JPEG_OK)        return;    if((ret = SsbSipJPEGSetConfig(JPEG_SET_ENCODE_QUALITY, JPG_QUALITY_LEVEL_2)) != JPEG_OK)        return;    if((ret = SsbSipJPEGSetConfig(JPEG_SET_ENCODE_THUMBNAIL, TRUE)) != JPEG_OK)        return;        //if((ret = SsbSipJPEGSetConfig(JPEG_SET_THUMBNAIL_WIDTH, 160)) != JPEG_OK)        //  return;        //   Main JPEG have to be multiple of Thumbnail resolution        if((ret = SsbSipJPEGSetConfig(JPEG_SET_THUMBNAIL_WIDTH, g_Thumbnail_Width)) != JPEG_OK)                return;        //if((ret = SsbSipJPEGSetConfig(JPEG_SET_THUMBNAIL_HEIGHT, 120)) != JPEG_OK)                //return;       //   Main JPEG have to be multiple of Thumbnail resolution        if((ret = SsbSipJPEGSetConfig(JPEG_SET_THUMBNAIL_HEIGHT, g_Thumbnail_Height)) != JPEG_OK)                return;    /* Get input buffer address */        in_buf = SsbSipJPEGGetEncodeInBuf(jpg_handle, g_YUV422_Frame_Buffer_Size);    if(in_buf == NULL)        return;    /* Copy YUV data from camera to JPEG driver */        memcpy(in_buf, g_yuv_c, g_YUV422_Frame_Buffer_Size);    /* Make Exif info parameters */    memset(&ExifInfo, 0x00, sizeof(ExifFileInfo));    makeExifParam(&ExifInfo);    /* Encode YUV stream */    ret = SsbSipJPEGEncodeExe(jpg_handle, &ExifInfo, JPEG_USE_HW_SCALER);    //with Exif    /* Get output buffer address */    out_buf = SsbSipJPEGGetEncodeOutBuf(jpg_handle, &jpg_size);    if(out_buf == NULL)        return;    fwrite(out_buf, 1, jpg_size, jpg_fp);    fclose(jpg_fp);    SsbSipJPEGEncodeDeInit(jpg_handle);    printf("CAPTURE SUCCESS\n");

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.