⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 app_y264_enc.cpp

📁 ti的Davinic平台的DM6446的ARM测例子程序
💻 CPP
字号:
#include <stdio.h>
#include <stdlib.h>
#include "ceapp_y264_enc.h"

/*
 *  ======== main function========
 */
int main(int argc, char *argv[])
{
#define ONE_FRAME_Y_SIZE	(352*288)
#define OUT_BITS_BUF_SIZE   (20000)
#define ONE_FRAME_SIZE      (ONE_FRAME_Y_SIZE*3/2)

	ceapp_Handle ceappHandle;
    char *inFileName, *outFileName;
	FILE *inFile = NULL, *outFile = NULL;
    int  *pNalS, status, n, iBitLoc, iNalLen;
	char *inBufyuv[3];
	int inBufSize[3];
	char *encodedBuf;
	int encodedBufSize; 

	inFileName  = "forman_cif.yuv";
	outFileName = "forman_cif.264";

	
    /* open file streams for input and output */
    if ((inFile = fopen(inFileName, "rb")) == NULL) 
	{
#ifdef  LOG_MY_CE
        printf("App-> ERROR: can't read file %s\n", inFileName);
#endif
        goto MAIN_END;
    }
    if ((outFile = fopen(outFileName, "wb")) == NULL)
	{
#ifdef  LOG_MY_CE
        printf("App-> ERROR: can't write to file %s\n", outFileName);
#endif
        goto MAIN_END;
    }
	
    /* initialize the ceapp which in turns initializes Codec Engine */
    if (ceapp_init(&ceappHandle) != 0) 
	{
#ifdef  LOG_MY_CE
		printf("App-> ceapp_init failed.\n");
#endif
        goto MAIN_END;
    }

	inBufSize[0] = ONE_FRAME_Y_SIZE; inBufSize[0] = ONE_FRAME_Y_SIZE/4;inBufSize[0] = ONE_FRAME_Y_SIZE/4;
	encodedBufSize = OUT_BITS_BUF_SIZE; 

	inBufyuv[0] = ceapp_allocContigBuf(inBufSize[0]+inBufSize[1]+inBufSize[2], 0x80);
    encodedBuf = ceapp_allocContigBuf(encodedBufSize, 0x80);
	inBufyuv[1] = inBufyuv[0] + ONE_FRAME_Y_SIZE; inBufyuv[2] = inBufyuv[0] + ONE_FRAME_Y_SIZE*5/4;
	if (inBufyuv[0]==NULL || encodedBuf==NULL)
	{
#ifdef  LOG_MY_CE
		printf("App-> ceapp_allocContigBuf failed.\n");
#endif
        goto MAIN_END;
    }

	///////////////////////////////////start to encode...////////////////////////////////
#ifdef  LOG_MY_CE
    printf("App-> Application started.\n");
#endif

	for (n = 0 ;; n++) 
	{
        printf("App-> Processing frame %d...\n", n);
		
        if (fread(inBufyuv[0], ONE_FRAME_SIZE, 1, inFile) == 0) 
		{	/* until EOF */
            break;
        }
		
        status = ceapp_encodeoneframe(&ceappHandle, inBufyuv, inBufSize, encodedBuf, encodedBufSize);
        if(status != 0) 
		{
            printf("App-> ERROR: Encoding frame %d FAILED\n", n);
            goto MAIN_END;
        }
		
        /* write bits to file */
		iBitLoc = 0;
		pNalS = (int *)encodedBuf;
		iNalLen = *pNalS;
		while (iNalLen > 0)
		{
			fwrite(encodedBuf+iBitLoc+4, iNalLen-4, 1, outFile);
			iBitLoc += iNalLen;
			pNalS = (int *)(encodedBuf + iBitLoc);
			iNalLen = *pNalS;
		}
    }

MAIN_END:
	if (inFile != NULL)
	{
		fclose(inFile);
		inFile = NULL;//not needed
	}
    if (outFile != NULL)
	{
		fclose(outFile);
		outFile = NULL;//not needed
	}

	if (inBufyuv[0] != NULL) 
	{
        ceapp_freeContigBuf(inBufyuv[0], inBufSize[0]+inBufSize[1]+inBufSize[2]);
    }
    if (encodedBuf != NULL) 
	{
        ceapp_freeContigBuf(encodedBuf, encodedBufSize);
    }

	ceapp_exit(&ceappHandle);

    return 0;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -