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

📄 multi_dec.c

📁 MPEG4编解码系统代码
💻 C
字号:
/************************************************************************ *                                                                      * *  multi_dec.c    Test opendivx decoding by several frames             * *                                                                      * *  decodes a series of files names frame05%d.divx (starting with zero) * *  to a series of PGMs (YUV in PGM-format) called frame%05d.pgm        * *                                                                      * *  Christoph Lampert, 2001/05/28                                       * *                                                                      * *  compile with: cc -o multi_dec multi_dec.c -ldivxdecore -lm -DLINUX  * *                                                                      * *  call with: ./multi_dec                                              * *                                                                      * *  THIS VERSION IS SUPPOSED TO WORK WITH OPENDIVX RELEASE 4.0ALPHA50!  * *  NO WITH EARLIER VERSIONS, NOT WITH LATER VERSIONS!                  * *                                                                      * ************************************************************************/#include <stdio.h>#include <malloc.h>#include <stdlib.h>
#include <memory.h>#include "decore.h"#define MY_APP_ID 0x0815#define XDIM 320#define YDIM 240#define BUFFERSIZE 512000#define MAXFILENR 200			// number of framesvoid yuv2rgb_24(
				unsigned char *puc_y, int stride_y,
				unsigned char *puc_u, unsigned char *puc_v, int stride_uv,
				unsigned char *puc_out,
				int width_y, int height_y,
				unsigned int stride_out);
int main(){	int i;	FILE* filehandle;	int filenr;    char filename[80];
	unsigned char *bmp_buffer;
	unsigned char *yuv_buffer;	unsigned char *divx_buffer;  	unsigned char *bmp_head;
		double dauer;	int status;	int divx_size;      DEC_MEM_REQS dec_memreqs;   DEC_PARAM dec_param;   DEC_SET   dec_set;   DEC_FRAME dec_frame;	/* ...skip check for malloc failure... don't do this in applications! */	yuv_buffer=(unsigned char*) malloc(XDIM*YDIM*3/2);						//	Y is full-res, U and V subsampled	bmp_buffer=(unsigned char*) malloc(3*XDIM*YDIM);			// RGB is in full-res  
	divx_buffer=(unsigned char*) malloc(BUFFERSIZE);	bmp_head=(unsigned char*) malloc(54);	filehandle=fopen("bmphead.dat","rb");
	divx_size=fread(bmp_head,sizeof(unsigned char),54,filehandle);
	fclose(filehandle);
/*********************************************************************//*                            DIVX PART  Start                       *//*********************************************************************//* Init the decoder, this has become a little complicated... */	   dec_param.x_dim = XDIM;	   dec_param.y_dim = YDIM;	   dec_param.output_format=DEC_RGB24;      // output color format   dec_param.time_incr=0;   status = decore(MY_APP_ID, DEC_OPT_MEMORY_REQS, &dec_param, &dec_memreqs);	fprintf(stderr,"Decore MEM_REQS return %d\n",status);   dec_param.buffers.mp4_edged_ref_buffers = malloc(dec_memreqs.mp4_edged_ref_buffers_size);   dec_param.buffers.mp4_edged_for_buffers = malloc(dec_memreqs.mp4_edged_for_buffers_size);   dec_param.buffers.mp4_display_buffers = malloc(dec_memreqs.mp4_display_buffers_size);   dec_param.buffers.mp4_state = malloc(dec_memreqs.mp4_state_size);   dec_param.buffers.mp4_tables = malloc(dec_memreqs.mp4_tables_size);   memset(dec_param.buffers.mp4_state, 0, dec_memreqs.mp4_state_size);   memset(dec_param.buffers.mp4_tables, 0,dec_memreqs.mp4_tables_size);   dec_param.buffers.mp4_stream = malloc(dec_memreqs.mp4_stream_size);   status = decore(MY_APP_ID, DEC_OPT_INIT, &dec_param, NULL);	fprintf(stderr,"Decore INIT return %d\n",status);	status = decore(MY_APP_ID, DEC_OPT_SETOUT, &dec_param,NULL);	fprintf(stderr,"Decore SETOUT return %d\n",status);	/* Set the postprocessing level:  0 = no PP */   dec_set.postproc_level = 0;   status = decore(MY_APP_ID, DEC_OPT_SETPP, &dec_set, NULL);				fprintf(stderr,"Decore POSTPROC %d return %d\n",dec_set.postproc_level,status);/*********************************************************************//*                            Main Part                              *//*********************************************************************/	for (filenr=1;filenr<MAXFILENR;filenr++)		// Main loop over frames   {	/* read opendivx-encoded frame */	sprintf(filename,"frame%05d.divx",filenr);	filehandle = fopen(filename,"rb");	if (!filehandle)    {	fprintf(stderr,"Error reading file!\n"); return 1; }  	divx_size=fread(divx_buffer,1,BUFFERSIZE,filehandle);	fclose(filehandle);      fprintf(stderr,"Frame %d: Framelength is %d\n",filenr,divx_size);/* Decode the frame */   dec_frame.length      = divx_size;   dec_frame.bitstream   = divx_buffer;   dec_frame.bmp         = (void *) bmp_buffer;   dec_frame.render_flag = 1;   dec_frame.stride      = XDIM;   fprintf(stderr,"Decore FRAME start\n");          status = decore(MY_APP_ID, 0, &dec_frame, NULL);      fprintf(stderr,"Decore FRAME return %d\n",status);					/* write PGM-file output, that is just header + YUV data  */	sprintf(filename,"frame%05d.bmp",filenr);	filehandle = fopen(filename,"wb");	if (!filehandle)    {	fprintf(stderr,"Error writing file!\n"); return 2; }	fwrite(bmp_head,1,54,filehandle);//fprintf(filehandle,"P5\n%3d %3d\n255\n",XDIM,YDIM*3/2); // remove this to get	RAW YUV out	fwrite(bmp_buffer,XDIM,YDIM*3,filehandle);   fclose(filehandle);	}		// end of FOR-loop over all files/* Stop the decoder */   status = decore(MY_APP_ID, DEC_OPT_RELEASE, NULL, NULL);	fprintf(stderr,"Decore RELEASE return %d\n",status);			/*********************************************************************//*                            DIVX PART  End                         *//*********************************************************************/   	free(dec_param.buffers.mp4_edged_ref_buffers);    free(dec_param.buffers.mp4_edged_for_buffers);	free(dec_param.buffers.mp4_display_buffers);	free(dec_param.buffers.mp4_state);	free(dec_param.buffers.mp4_tables);	free(dec_param.buffers.mp4_stream);	free(divx_buffer);	free(yuv_buffer);	free(bmp_buffer);
		return 0;}

⌨️ 快捷键说明

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