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

📄 main.c~

📁 linux 或者arm动态连接库的调用
💻 C~
字号:
#include <stdlib.h>#include <stdio.h>#include <errno.h>#include <string.h>#include <fcntl.h>#include <math.h>#include <time.h>#include <dlfcn.h>#include "encore.h"  int (*encore)(unsigned long,unsigned long,void*,void*); ENC_PARAM encParams;ENC_FRAME encFrame;ENC_RESULT encResult;unsigned int frameWidth = 320;			/* --width=<uint> */unsigned int frameHeight = 240;int main(){    void *encorehandle=NULL;    char* rawFileName = "./video1.yuv";	char* mpeg4FileName = "./video1.divx";	FILE* rawFile = NULL;	FILE* mpeg4File = NULL;	FILE* frameinfo=NULL;	u_int32_t yuvSize;	u_int8_t encVopBuffer[128 * 1024];	u_int32_t frameNumber = 0;	void* myHandle = NULL;		//save length of  frame to file	frameinfo=fopen("newframeinfo-1.txt","w");	fflush(frameinfo);		/* variables controlable from command line */	unsigned int bitRate = 500000;			/* --bitrate=<uint> */			/* --height=<uint> */	float frameRate = 30.0;			/* --rate=<float> */	unsigned int iFrameFrequency = 10;		/* --ifrequency=<uint> */				// initialize encoder 	encParams.x_dim = 320;	encParams.y_dim = 240;	encParams.framerate = frameRate;	encParams.bitrate = bitRate;	encParams.rc_period = 2000;	encParams.rc_reaction_period = 10;	encParams.rc_reaction_ratio = 20;	encParams.max_key_interval = iFrameFrequency;		if((encorehandle=dlopen("./libencore.so",RTLD_LAZY))==NULL)	{	    printf("open lib error!\n");	    exit(1);	}	encore=dlsym(encorehandle,"encore");		rawFile = fopen(rawFileName, "rb");	if (rawFile == NULL) {		// error, file doesn't exist or we can't read it 		printf(" error opening %s: %s\n",			 rawFileName, strerror(errno));		exit(2);	}		// open the MPEG-4 file for writing 	mpeg4File = fopen(mpeg4FileName, "wb");	if (mpeg4File == NULL) {		printf(": error %s: %s\n", mpeg4FileName, strerror(errno));		fclose(rawFile);		exit(4);	}	if (encore(myHandle, ENC_OPT_INIT, &encParams, NULL) != ENC_OK) {		printf(" error: can't initialize encoder\n");		exit(5);	}yuvSize = (frameWidth * frameHeight * 3) / 2;	encFrame.image = (u_int8_t *)malloc(yuvSize);	encFrame.bitstream = encVopBuffer;	while (!feof(rawFile))	{	    int rc1;	frameNumber++;	// read yuv data 	rc1 = fread(encFrame.image, sizeof(u_int8_t), yuvSize, rawFile);		if (rc1 == 0) 		    break;		encFrame.length = sizeof(encVopBuffer);	rc1 = encore(myHandle, ENC_OPT_ENCODE, &encFrame, &encResult);//------		if (rc1 != ENC_OK)		{			break;		}		// write results to output file 	rc1 = fwrite(encFrame.bitstream, 1, encFrame.length, mpeg4File);		if (rc1 != encFrame.length) 		{		printf(" write error %s: %s\n", mpeg4FileName, strerror(errno));		break;		}		// -----test-----		printf("Encoding frame %u to %lu bytes\n", frameNumber,		       encFrame.length);		fprintf(frameinfo,"encoding frame %u to %lu bytes\n",frameNumber,			encFrame.length);		encore(myHandle, ENC_OPT_RELEASE, NULL, NULL);		if (encore(myHandle, ENC_OPT_INIT, &encParams, NULL) != ENC_OK) 		{		printf(" error: can't initialize encoder\n");		break;	               }	}		// cleanup��ͷ�	encore(myHandle, ENC_OPT_RELEASE, NULL, NULL);	if(encFrame.image!=NULL)	{		free(encFrame.image);		encFrame.image=NULL;	}	//---	fclose(frameinfo);	fclose(rawFile);	fclose(mpeg4File);	dlclose(encorehandle);	return 0;}

⌨️ 快捷键说明

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