x264在Android平台上的编译和使用(3)

#include <stdio.h>
#include "x264encoder.h"
 
int main( int argc, char **argv )
{
    X264Encoder x264Encoder;
 
    x264Encoder.setBitrate(512);
    x264Encoder.setResolution(640,480);
    x264Encoder.setFps(20);
 
    FILE *inputFile = NULL;
    FILE *outputFile = NULL;
    inputFile = fopen("yuv_640x480.yuv","rb");
    outputFile = fopen("h264_640x480.h264","wb");
 
    x264_picture_t inputPicture;
    x264_picture_alloc(&inputPicture, X264_CSP_I420, 640, 480);
 
    x264_nal_t *p_nals = NULL;
    int nalsCount = 0;
 
    if(x264Encoder.openX264Encoder())
    {
        for(int j=0; j<20; j++)
        {
            fread(inputPicture.img.plane[0],1,640*480, inputFile);
            fread(inputPicture.img.plane[1],1,640*480/4, inputFile);
            fread(inputPicture.img.plane[2],1,640*480/4, inputFile);
 
            x264Encoder.x264EncoderProcess(&inputPicture,&p_nals,nalsCount);
 
            if(p_nals)
            {
                for(int i=0; i<nalsCount; i++)
                {
                    fwrite(p_nals[i].p_payload, p_nals[i].i_payload, 1, outputFile);
                }
            }
        }
 
    }
 
    fclose(inputFile);
    fclose(outputFile);
 
    x264_picture_clean(&inputPicture);
 
    x264Encoder.closeX264Encoder();
 
    return 0;

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:http://www.heiqu.com/19373.html