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

📄 test_enc.c

📁 MPEG4视频编解码内有divx(编码)
💻 C
字号:
/************************************************************************

 测试编码:一帧数据编码测试                                                                     *
 ************************************************************************/

#include <stdio.h>
#include <malloc.h>
#include <stdlib.h>

#include "encore.h"
#include "rgb2yuv.h"

#define MY_APP_ID 0x0815			// doesn't matter

#define XDIM 600
#define YDIM 400
#define BUFFERSIZE 512000		// This should be more than enough for 1 frame

int RGB2YUV (int x_dim, int y_dim, void *bmp, void *y_out, void *u_out, void *v_out);

int main()
{
	char *in_buffer[3];
	char *bmp_buffer;
	char *divx_buffer;  
	char *yuv_buffer;
  
   int status;
   int frame_size;
   FILE *f_in;
   FILE *f_out;
   ENC_PARAM enc_param;
   ENC_FRAME enc_frame;
   ENC_RESULT enc_result;

   frame_size = XDIM*YDIM + XDIM/2*YDIM/2 + XDIM/2*YDIM/2;		// full Y, subsamples U,V

/* ...skip check for malloc failure... don't do that in application!!! */

   yuv_buffer=(char*) malloc(frame_size);
   bmp_buffer=(char*) malloc(3*XDIM*YDIM);
   divx_buffer=(char*) malloc(BUFFERSIZE);	

/*********************************************************************/
/*                            DIVX PART  Start                       */
/*********************************************************************/

/* Init the encoder */

    enc_param.x_dim = XDIM; 
    enc_param.y_dim = YDIM;
    enc_param.framerate = 24.0;
    enc_param.bitrate = 900000;

    enc_param.rc_period = 2000; 
    enc_param.rc_reaction_period = 10;
    enc_param.rc_reaction_ratio = 20;
//    enc_param.search_range = 128;				

    enc_param.max_quantizer = 15;
    enc_param.min_quantizer = 1;    		// these setting are not
    						// important for a single file	

    status = encore(MY_APP_ID, ENC_OPT_INIT, &enc_param, NULL);
	 fprintf(stderr,"Encore INIT return %d\n",status);

/*********************************************************************/
/*                            Main Part                              */
/*********************************************************************/

/* read raw RGB from stdin */
	 //我自己加上的

	f_in=fopen("win2k.raw","rb");
	if (f_in==0)
	{
	 printf("Can't open file: raw!\n");
	 exit(0);
	}
	fread(bmp_buffer,XDIM,3*YDIM,f_in);
	fclose(f_in);
	
/* convert raw RGB to YUV 4:2:0, that encore()-input format */

	in_buffer[0]=yuv_buffer;
	in_buffer[1]=yuv_buffer + XDIM*YDIM;
	in_buffer[2]=yuv_buffer + XDIM*YDIM + XDIM/2*YDIM/2;
  
  	RGB2YUV(XDIM,YDIM,bmp_buffer,in_buffer[0],in_buffer[1],in_buffer[2]) ; 

/* Encode one frame */

   enc_frame.image       = (void *) yuv_buffer;
   enc_frame.bitstream   = (void *) divx_buffer;
   enc_frame.length      = 0;							// will be filled by routine

   status = encore(MY_APP_ID, ENC_OPT_WRITE, &enc_frame, &enc_result);				

   fprintf(stderr,"Encore ENCODE return %d, divx-stream length=%ld bytes\n",status,enc_frame.length);
   fprintf(stderr,"Encore RESULT IsKeyFrame=%d\n",enc_result.isKeyFrame);

/* Write encoded data to stdout */
   //我自己加上的
   if((f_out=fopen("win2k.div","wb"))==NULL)
   {
	   printf("Can't creat file to write!\n");
	   exit(0);
   }
	fwrite(divx_buffer,1,enc_frame.length,f_out);
	fclose(f_out);

/*********************************************************************/
/*                            DIVX PART  Stop                        */
/*********************************************************************/

/* Stop the encoder */

   status = encore(MY_APP_ID, ENC_OPT_RELEASE, &enc_frame, NULL);							// END Encoding
	fprintf(stderr,"Encore RELEASE return %d\n",status);
	
	free(divx_buffer);
 	free(bmp_buffer);
	free(yuv_buffer);
	//scanf("Wait for a moment!");	//用来观察输出信息

   
	return 0;
}

⌨️ 快捷键说明

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