fprintf(out,"%c %010I64X",
qfprintf(out,"%c %010I64X",
uint8_t indexMpeg(char *mpeg,char *file,uint8_t audioid){	static const char Type[5]={'X','I','P','B','D'};	FILE *out=NULL;	uint32_t val;	uint32_t hnt;;//	uint32_t in;	uint64_t pos;	uint64_t abspos;	uint32_t w,h,fps ;	uint32_t nb_iframe=0;//	uint32_t nb_pframe=0;//	uint32_t nb_bframe=0;//	uint32_t first=0;	uint32_t total_frame=0;	uint32_t seq_found=0;	uint64_t lastPic=0;	uint32_t update=0;	uint8_t  gop_seen=0;	uint64_t lastGop=0;	uint64_t lastAbsGop=0;	    	uint8_t streamid,audiostreamid=0x00;	mParser *parser;	ADM_mpegDemuxer *demuxer;	uint8_t token;		char *realname=PathCanonize(mpeg);		audiostreamid=audioid;	parser=new mParser();	if(!parser->open(realname))		{				GUI_Alert("Error reading mpeg !");				delete parser;				delete [] realname;				return 0;		}	token=parser->read8i();		if(token==0x47)	{		delete parser;		parser=NULL;		//demuxer=new ADM_mpegDemuxerTransportStream(0xe0,audiostreamid);;		//GUI_Alert("This is mpeg TS, no supported !\n");		//return 0;		printf("Mpeg TS detected\n");		uint32_t apid,vpid;		if(! ADM_matchPid(mpeg, audiostreamid,&vpid, &apid))		{			GUI_Alert("Problem with that file");			return 0;		}		if(!vpid) 			{				GUI_Alert("No video track found");				return 0;			}		if(!apid)		{			printf("MMm no matching audio pid found...\n");			apid=0xff;		}		//audiostreamid=apid;		demuxer=new ADM_mpegDemuxerTransportStream(vpid,apid);			}	else	{	parser->setpos(0);		parser->sync(&token);	// first identify stream type (ES/PS)	delete parser;	switch(token)		{				case 0xb3: // video es						printf("Video Elementary stream");						demuxer=new ADM_mpegDemuxerElementaryStream;						break;				case 0xba : // program stream ?	(vob/mpeg/VCD)						printf("Program stream");						demuxer=new  ADM_mpegDemuxerProgramStream(0xe0,audiostreamid);						break;				default:						printf("\n unrecognized stream\n");						return 0;			}	}		// ok now we have it.	demuxer->open(realname);	out=fopen(file,"wt");	if(!out)	{			printf("\n Error : cannot open index !");			delete demuxer;			delete [] realname;			return 0;	}	fprintf(out,"IDXM ");	switch(token)	{		case 0xb3: fprintf(out,"E XX\n");break;		case 0x47: fprintf(out,"T XX\n");break;		case 0xba: fprintf(out,"P XX\n");break;		default:			printf("Unknown token / mpeg type\n");			return 0;	}			fprintf(out,"000000000000\n");	fprintf(out,"1\n");	fprintf(out,"%s\n",realname);	DIA_working 	*work;	uint32_t	gop_forward=0;	uint64_t	image_length,image_start,image_absStart;;	uint32_t    pic_progressive=0,pic_interlaced=0,pic_unknown=0;	work=new DIA_working("Indexing mpeg");	while(1)	{				val=0;				hnt=0;				// sync on the video stream is done by demuxer, now get on the infos				//				if(!demuxer->sync(&streamid)) break;				demuxer->getpos(&pos);				abspos=demuxer->getAbsPos();				update++;			//	printf("\n sync found : %d",streamid);				if(update>100)					{						if(work->update(demuxer->getAbsPos()>>16,demuxer->getSize()>>16))						{							// abort;							goto stop_found;						}						update=0;					}				switch(streamid)					{					/* Useless apparently						  	case 0xB9: // sequence end                                        		printf("\n End seq\n");                                        		goto stop_found;                                        		break;					*/#if 0										case 0xB5:  // Extension start code, used to check if interlaced or not					          {					              uint16_t a,b;					                                 a=demuxer->read16i(); // Fw & Bw reference code					                                 if((a&0xf)==8)  // coding Id correct ?					                                 {                                                       b=demuxer->read16i(); // back 4, Dc 2, pict stuct 2					                                   b=(b>>6)&3;					                                   if(3==b) pic_progressive++;					                                    else if(!b) pic_unknown++;  					                                      else pic_interlaced++;                                                       }                                                                   					          }                                  break;#endif                              					case 0xB3: // sequence start						gop_seen=1;						// Memorize gop position						// as it will be the real start of the						// next I Frame						lastGop=pos;						lastAbsGop=abspos;						if(seq_found)						{						 	demuxer->forward(8);							break;						}						seq_found=1;					        val=demuxer->read32i();						w=val>>20;					       	w=((w+15)&~15);					        h= (((val>>8) & 0xfff)+15)& ~15;					      	fps= FPS[val & 0xf];						demuxer->forward(4);						printf("\n %ld x %ld at %ld fps\n",w,h,fps);						fprintf(out,"%ld %ld %ld\n",w,h,fps);						break;					case 0xb8: // GOP						//	printf("GOP\n");						if(!seq_found) continue;						uint32_t gop;							demuxer->forward(3);							gop=demuxer->read8i();						// x Gop broken x x x x x 						gop>>=6; // skip padding						gop&=1;						// take this as marker						if(!gop_seen)						{							gop_seen=1;							// Memorize gop position							// as it will be the real start of the							// next I Frame							lastGop=pos;							lastAbsGop=abspos;						}						// 25 bits = time code#if 0						if(gop)						{							printf("** Closed gop***\n");							// we will change B frame to P frame							// until we reach the next I/P							gop_forward=2;						}#endif						// 						break;					case 0x00 : // picture				                //  printf("PIC\n");						uint8_t ftype;						uint8_t temporal_ref;												if(!seq_found) continue;						total_frame++;						val=demuxer->read16i();						temporal_ref=val>>6;						ftype=7 & (val>>3);#if 0						if(gop_forward==2 && temporal_ref!=0 && ftype==1)						{							printf("Fake closed gop!\n");							gop_forward=0;						}						if(ftype==1 || ftype==2) // I or P							if(gop_forward) gop_forward--;						if(ftype==3 && gop_forward)							ftype=2; // change B frame to P frame#endif						switch(ftype)						{						case 2:// P 						case 3:// B						case 4:							// clear last memorized one							gop_seen=0;							if(total_frame==1)							{								// Skip until we met a I frame								total_frame=0;								continue;							}						case 1:// printf(" Pic : I\n");								//	printf("\n%c",Type[ftype]);															// We conclude the previous frame							// by indicating its length							// that is the current post - last pic							// Or the lastGop - last pic							if(total_frame!=1)							{								if(gop_seen)									image_length=lastGop-4-lastPic;								else									image_length=pos-4-lastPic;																fprintf(out," %llu\n",image_length);							}														// Now set image type and start							if(!gop_seen)							{								image_start=pos-4;								image_absStart=abspos-4;							}							else							{								image_start=lastGop-4;								image_absStart=lastAbsGop-4;							}#ifndef CYG_MANGLING														fprintf(out,"%c %010llX",#else							fprintf(out,"%c %010I64X",#endif															Type[ftype],image_start);							if(ftype==1) // I frame							{#ifndef CYG_MANGLING																fprintf(out," %010llX %10lx",#else								fprintf(out," %I64X %10lx",#endif																image_absStart,demuxer->getOtherSize()); 								}							if(gop_seen)							{								lastPic=lastGop-4;								gop_seen=0;							}							else															lastPic=pos-4;							nb_iframe++;							break;						}						break;					default:					   break;					}		}stop_found://	 	fprintf(out," %d\n\n",demuxer->getSize()-lastPic-4);	 	fprintf(out," 0 \n\n");		printf("\n end of stream...\n");		// update # of frames		fseek(out,0,SEEK_SET);		printf("Progressive :%lu, interlaced :%lu unknown :%lu\n",		    pic_progressive,pic_interlaced,pic_unknown);		fprintf(out,"IDXM ");				switch(token)		{			case 0xb3: fprintf(out,"E %02x\n",audiostreamid);;break;			case 0x47: fprintf(out,"T %02x\n",audiostreamid);break;			case 0xba: fprintf(out,"P %02x\n",audiostreamid);;break;			default:				printf("Unknown token / mpeg type\n");				return 0;		}		fprintf(out,"%012lX\n",nb_iframe);		fclose(out);		delete work;	  printf("\n Total : %lu frames\n",total_frame);	  if(demuxer->getPTSDelta()!=0)	  {	  	char string[1000];		sprintf(string,"We have a shift of %d ms between audio and video\n",demuxer->getPTSDelta());	  	GUI_Alert(string);	  }	  delete demuxer;	  delete [] realname;	  return 1;}