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

📄 test.cpp

📁 H.263的编码程序,加了CPU指令优化,VC版.
💻 CPP
字号:
// testencoder.cpp : Defines the entry point for the console application.
//


#include <time.h>
#include <afxwin.h>
#include <afxext.h>         // MFC extensions

#include "H263Encoder/H263PEncode.h"

#define VC_EXTRALEAN

#define CIF

#define BUFF_SIZE 100000

#ifdef CIF
#define PIC_SIZE  352*288*3/2
#else
#define PIC_SIZE  176*144*3/2
#endif

FILE *out_file1;
FILE *out_file2;

void EncodeThread1(LPVOID *dummy);
void EncodeThread2(LPVOID *dummy);
long writestrm1(unsigned char*pData, int len, long time, unsigned long type, void* context);
long writestrm2(unsigned char*pData, int len, long time, unsigned long type, void* context);

int main(int argc, char* argv[])
{
	DWORD dummy;

	HANDLE hThread[2];

	hThread[0] = CreateThread(NULL, 2*PIC_SIZE, (LPTHREAD_START_ROUTINE) EncodeThread2,
		                      NULL, 0, &dummy);
	WaitForSingleObject(hThread[0], -1);
	return 0; 
}

long writestrm1(unsigned char*pData, int len, long time, unsigned long type, void* context)
{
	fwrite(pData, 1, len, out_file1);
	return len;
}

long writestrm2(unsigned char*pData, int len, long time, unsigned long type, void* context)
{
	fwrite(pData, 1, len, out_file2);
	return len;
}

void EncodeThread1(LPVOID *dummy)
{
	BYTE src_pic[352*288*3];
	FILE *src_file;
	CH263Encoder encoder;
	Enc_Option option;
	int frame = 0;
	UINT nTime = 0;

	
	src_file = fopen("foreman.cif", "rb");
	out_file1 = fopen("out.263", "wb");
	encoder.GetOption(option);
	option.m_iPicFormat = _CIF;
	option.m_iVideoFormat = YUV420;
	option.m_EncoderCallBack = writestrm1;
    encoder.EncOpen(option);
 //   while (1)
//	{
//		if(PIC_SIZE != fread(src_pic, 1, PIC_SIZE, src_file))
//			break;
	fread(src_pic, 1, 352*288*3, src_file);
	    encoder.EncOneFrame(src_pic, nTime);
		frame++;
		nTime = (unsigned int)frame;
	
//	}
    encoder.EncClose();

	fclose(out_file1);
	fclose(src_file);
	printf("File1 encoded!\n");
    ExitThread(0);
}

void EncodeThread2(LPVOID *dummy)
{
	BYTE src_pic[PIC_SIZE];
	FILE *src_file;
	CH263Encoder encoder;
	Enc_Option option;
	int frame = 0;
	UINT nTime = 0;
	clock_t start;
	clock_t end;
	float total_time;
	int frame_type;
	
    src_file = fopen("in.yuv", "rb");
	out_file2 = fopen("out.263", "wb");
	encoder.GetOption(option);
	option.m_iPicFormat = _CIF;
//	option.m_iUseAIC = 1;
	option.m_iQuantI = 11;
	option.m_iPRate = 500;
//	option.m_iPicFormat = _CPFMT;
//	option.m_iPicWidth = 1024;
//	option.m_iPicHeight = 768;
//	option.m_iQuantI = 11;
//	option.m_iQuantB = 12;
	option.m_iQuantP = 12;
//	option.m_iPRate = 100;
//	option.m_iUseAIC = 1;
//	option.m_iUseAP = 1;
//	option.m_iUseDF = 1;
//	option.m_iUseBFrame = 1;
//	option.m_iUseRPS = 1;
//	option.m_iUseBlock = 2000;
	option.m_iFrameRate = 30;
	option.m_iUseRC = 512;

	option.m_EncoderCallBack = writestrm2;
    encoder.EncOpen(option);

	start = clock();	
    while (1)
	{
		if(PIC_SIZE != fread(src_pic, 1, PIC_SIZE, src_file))
			break;
	    frame_type = encoder.EncOneFrame(src_pic, nTime);
//		if(frame_type)
			frame++;
		nTime = (unsigned int)frame;
		//printf("%d\n", frame);
		
	}
	end = clock();
	total_time = (float)((end - start)/CLOCKS_PER_SEC);
	
	printf("encode %d frames\n", frame);
	printf("average coding speed: %f frames per second.\n", (float)(frame/total_time));
	
    encoder.EncClose();

	fclose(out_file2);
	fclose(src_file);

	printf("File2 encoded!\n");

	ExitThread(0);
}

⌨️ 快捷键说明

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