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

📄 svp_encoder.c

📁 mpeg-4 SVP程序
💻 C
字号:
#include <stdio.h>
#include <stdlib.h>
//#include <iostream.h>
//#include <string.h>
#include "dsp_mp4svp_type.h"

#define _GLOBAL_

#include "dsp_mp4svp_global.h"
#include "dsp_mp4svp_stream.h"
#include "dsp_mp4svp_vop.h"
#include "dsp_mp4svp_dct.h"

void main()
{
	short x_dim, y_dim, startFrame,endFrame, search_range;
	short time_increment_resolution, frame,i,j;
	char QP,prev_rounding_type;
	unsigned int area,returnsize;

//del del del del del del del del del del del del del del del del del del
	char inYUVfilename[100];
	char recYUVfilename[100];
	char streamfilename[100];
	FILE *pfsrcYUV;	 //sorce input  YUV file
	FILE *pfrecYUV;  //rec  output YUV file
	FILE *pfStrm;    //output stream  file

//del del del del del del del del del del del del del del del del del del
	unsigned char *current, *reference, *reconstruct,*voptmp;
	unsigned int malloc_size;

	x_dim=176;  // default image width 176, can be changed to other value
	y_dim =144; // default 144, can be changed to other value
	area = x_dim * y_dim;
	QP=2;// quant step size
	search_range=14;// for motion estimation 
	time_increment_resolution=30;
	prev_rounding_type=0;
	startFrame = 0;
	endFrame=1;// default is 1, so the default video sequence only has two frames,


	malloc_size= area * 3/2 ;//38016 for 176 and 144;
	current = (unsigned char *) malloc(malloc_size*(endFrame - startFrame + 1));
	if(current == NULL) return;
	
	malloc_size = (x_dim+2*16) * (y_dim+2*16)*3/2 ;//54912 for 176 and 144;
	reference = (unsigned char *) malloc(malloc_size);
	reconstruct = (unsigned char *) malloc(malloc_size);
	if(reference == NULL || reconstruct == NULL) return;

	stream = (unsigned char *) malloc(area * (endFrame - startFrame + 1)/2);
	if(stream == NULL) return;
	pstream = stream;

//	
	sprintf (inYUVfilename, "e:\\mpeg4test\\sunflower2.yuv");// raw video sequence in 4:2:0 yuv format
	sprintf (recYUVfilename, "e:\\mpeg4test\\sunflower2_rec.yuv");// reconstructed video
	// sequence during the encoding , the restructed image is padded, so its size is bigger than the source,
	// rec width= 16+width+16, rec height = 16+ heigh +16
	sprintf (streamfilename, "e:\\mpeg4test\\sunflower2.cmp");// compressed stream
	// default path for the files, just change it to whatever path you want 

	if ((pfsrcYUV = fopen (inYUVfilename, "rb")) == NULL )
		printf("open yuv file wrong!");
//		exit(fprintf (stderr, "Can't open source YUV file\n")); 

	returnsize = (unsigned int) fread (current, sizeof (unsigned char), 
								(endFrame - startFrame + 1)*area * 3/2, pfsrcYUV);
//	if (returnsize == 0)	
//		cout<<"can not read source yuv from file to current buffer";
	fclose (pfsrcYUV);

	if ((pfrecYUV = fopen (recYUVfilename, "wb")) == NULL );
	if ((pfStrm   = fopen (streamfilename, "wb")) == NULL );
//del del del del del del del del del del del del del del del del del del

	g_motion_x = (char *)malloc(x_dim/MB_SIZE * (y_dim/MB_SIZE) * 4 * sizeof(char));   //mot
	g_motion_y = (char *)malloc(x_dim/MB_SIZE * (y_dim/MB_SIZE) * 4 * sizeof(char));   //mot
	g_MB_Mode = (char *)malloc(x_dim/MB_SIZE * (y_dim/MB_SIZE) * sizeof(char));   //mot
	
	if(g_motion_x == NULL || g_motion_y==NULL || g_MB_Mode==NULL) return;

	g_DC_store[0] = (short ***)malloc(x_dim/MB_SIZE * sizeof(short **));
	for (i = 0; i < x_dim/MB_SIZE; i++)
	{
		g_DC_store[0][i] = (short **)malloc(6 * sizeof(short *));
		for (j = 0; j < 6; j++)
			g_DC_store[0][i][j] = (short *)malloc(15 * sizeof(short));
	}

	 
	g_DC_store[1] = (short ***)malloc(x_dim/MB_SIZE * sizeof(short **));
	for (i = 0; i < x_dim/MB_SIZE; i++)
	{
		g_DC_store[1][i] = (short **)malloc(6 * sizeof(short *));
		for (j = 0; j < 6; j++)
			g_DC_store[1][i][j] = (short *)malloc(15 * sizeof(short));
	}

	idct_int32_init();
	
	initBuffer();
	p_par = &vop_par;
	initVopPar();
	p_par->width=x_dim;
	p_par->height=y_dim;
	p_par->quantizer=QP;
	p_par->intra_quantizer=QP;
	p_par->sr_for=search_range;
	p_par->time_increment_resolution=time_increment_resolution;
	p_par->rounding_type = prev_rounding_type;
	p_par->fcode_for = get_fcode(search_range);

	CodeVOVOLHeader();
	stuffingBitstrm();

	for( frame=startFrame;frame<=endFrame;frame++)
	{
		if (frame == startFrame) 	p_par->prediction_type=I_VOP;
		else p_par->prediction_type= P_VOP;
		
		if(p_par->prediction_type == P_VOP)
		{
			prev_rounding_type = 1-prev_rounding_type;
			p_par->rounding_type = prev_rounding_type;
		}

		CodeVop(current+ frame * area * 3/2,
				reference,
				reconstruct,
				frame);
		
		voptmp = reference;
		reference = reconstruct;
		reconstruct = voptmp;

//del del del del del del del del del del del del del del del del del del
		//dump rec data(including the padded 16pxl eges)
		//returnsize = (unsigned int)fwrite (reference, sizeof (unsigned char), (x_dim+2*16)*(y_dim+2*16)*3/2, pfrecYUV);
		//if (returnsize == 0) ;
//			exit(fprintf (stderr, "Can't write to rec YUV file\n")); 
//del del del del del del del del del del del del del del del del del del	
		stuffingBitstrm();

	}

	memcpy (pstream, buffer, bytecnt%256);//dma ,dump the buffer

//del del del del del del del del del del del del del del del del del del
	returnsize = (unsigned int)fwrite(stream, 1, bytecnt, pfStrm);
	if (returnsize == 0) ;
		//exit(fprintf (stderr, "Can't write to file\n")); 

	fclose (pfStrm);
	fclose (pfrecYUV);
//	cout<<"closing all...";

//del del del del del del del del del del del del del del del del del del
}

⌨️ 快捷键说明

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