Chris@634: //***********************************************************// Chris@634: // Interactive Music Audio Format (IMAF) ENCODER // Chris@634: // Version 2.0 // Chris@634: // // Chris@634: // Eugenio Oñate Hospital // Chris@634: // Jesús Corral García & Costantino Taglialatela // Chris@634: // // Chris@634: // Copyright (c) 2013 Centre for Digital Music (C4DM) // Chris@634: // Queen Mary University of London. All rights reserved. // Chris@634: //***********************************************************// Chris@634: // main.c // Chris@634: //***********************************************************// Chris@634: Chris@634: //File input/output Chris@634: #include Chris@634: //Standard library: numeric conversion, memory allocation... Chris@634: #include Chris@634: //Operations with strings Chris@634: #include Chris@634: //Get the creation time: clock Chris@634: #include Chris@634: #include "IMAFencoder.h" Chris@634: //Qt libraries Chris@634: #include Chris@634: #include Chris@634: #include Chris@634: Chris@634: Chris@634: /*Prototype*/ Chris@634: void filetypebx(FileTypeBox *ftyp); Chris@634: int mdatbox(MediaDataBox *mdat, int, FILE *imf, FILE *song, FILE *text, int, int, u32); Chris@634: void moovheaderbox(MovieBox *moov, int, int, int, int, int, int, int); Chris@634: int trackstructure(MovieBox *moov, int, int, int, int,const char *name); Chris@634: int samplecontainer(MovieBox *moov, int, int, const char *name); Chris@634: int sampledescription(MovieBox *moov, int); Chris@634: int presetcontainer(MovieBox *moov, int, int *vol_values, int type, int fade_in); Chris@634: int rulescontainer(MovieBox *moov, int SelRuleType, int SelRule_PAR1, int SelRule_PAR2, Chris@634: int MixRuleType, int MixRule_PAR1, int MixRule_PAR2, int MixRule_PAR3, int MixRule_PAR4); Chris@636: void writemoovbox(MovieBox moov, int numtrack,int totaltracks, FILE *imf, FILE *text, bool HasTextFile); Chris@634: int readTrack(MovieBox *moov, int,const char *name); Chris@634: Chris@634: // Timed Text Functions Chris@634: int trackstructure_text (MovieBox *moov, int numtrack, int clock, int durationTrack, int sizemdat,const char *textfile,FILE *text,int totaltracks); Chris@634: int samplecontainer_text(MovieBox *moov, int numtrack, int sizemdat, const char *textfiles,int totaltracks); Chris@634: int aux (FILE *text,int num,int num1,int num2,int num3,int *sal); Chris@634: int getTextSize (FILE *text); Chris@634: // Group and Preset functions Chris@634: int groupcontainer(MovieBox *moov, int *group_tracks, int grp_vol, QString grp_name, Chris@634: QString grp_description, int totaltracks); Chris@634: void writepresets(MovieBox moov, int numtrack,int totaltracks, FILE *imf); // NOT YET USED Chris@634: Chris@634: // MetaData and JPEG Image functions Chris@634: int metacontainer (MetaBox *meta); Chris@634: u32 getImageSize(const char *imag); Chris@634: void insertImage (MetaBox *meta, FILE **imf, u32 imagesize, const char *imagedir); Chris@634: void writemetabox(MetaBox meta, FILE *imf); Chris@634: Chris@634: int bytereverse(int num); Chris@634: int bytereverse16(int num); Chris@634: int size_phrase[1000];//the total number of bytes in a phrase including modifiers Chris@634: int phrases;//the number of phrases in the whole text Chris@634: Chris@634: Chris@634: // Qt Widget for the "Exit Window" Chris@634: class ExitWindow : public QWidget Chris@634: { Chris@634: public: Chris@634: ExitWindow(); Chris@634: private: Chris@634: QMessageBox *file_created; Chris@634: }; Chris@634: Chris@634: ExitWindow::ExitWindow() Chris@634: { Chris@634: file_created = new QMessageBox(); Chris@634: file_created->setFixedSize(400,200); // doesn't seem to work Chris@634: file_created->setWindowTitle("IM AF Encoder"); Chris@634: file_created->setText("IM AF file successfully created!"); Chris@634: file_created->show(); Chris@634: } Chris@634: Chris@634: int mainIMAFencoder (int totaltracks, QString files_path[maxtracks],QString outimaf, Chris@634: QString picturefile, QString textfile, int vol_values[maxtracks], bool HasImageFile, Chris@636: bool HasTextFile, int SelRuleType, int SelRule_PAR1, int SelRule_PAR2, Chris@634: int MixRuleType, int MixRule_PAR1, int MixRule_PAR2, int MixRule_PAR3, int MixRule_PAR4, Chris@634: int group_tracks[maxtracks], int group_volume, QString group_name, QString group_description, Chris@634: int pres_type, int fade_in) Chris@634: { Chris@634: //Variables Chris@634: FileTypeBox ftyp; Chris@634: MediaDataBox mdat; Chris@634: MovieBox moov; Chris@634: MetaBox meta; Chris@634: Chris@634: //Media Data Box - Contains the audio Chris@634: FILE *song; //MP3 Chris@634: u32 sizeTRAK = 0; Chris@634: int numtr; Chris@634: //Output File Chris@634: FILE *imf; //IMA Chris@634: int numtrack, sizemdat, durationTrack; Chris@634: //Image Chris@634: u32 imagesize; Chris@634: QTextStream out (stdout); Chris@634: //Timed-Text Chris@634: FILE *text; Chris@634: int sizetext; Chris@634: const char *c_str1[8];//change this value to support more than 8 audio tracks Chris@634: const char *c_str2; Chris@634: Chris@634: //Groups, Presets, Rules and Metadata boxes sizes Chris@634: u32 sizeGRCO, sizePRCO, sizeRUCO, sizeMETA; Chris@634: Chris@634: /* Obtain current time as seconds elapsed since the Epoch. */ Chris@634: time_t clock = time(NULL); Chris@634: Chris@634: Chris@634: //INPUT: Image Chris@634: if (HasImageFile){ Chris@634: c_str2= picturefile.toStdString().c_str(); //convert QString to const char Chris@634: imagesize = getImageSize(c_str2);//calculate the size of the jpeg Chris@634: } else { //if there is no image, the size is 0 Chris@634: imagesize = 0; Chris@634: } Chris@634: Chris@634: //INPUT: Timed-Text Chris@636: if (HasTextFile){ Chris@636: c_str2= textfile.toStdString().c_str(); //convert Qstring to const char Chris@636: text = fopen(c_str2, "rb"); Chris@636: sizetext= getTextSize (text); //calculate the size of the text Chris@636: } Chris@636: else{ Chris@636: sizetext = 0; Chris@636: } Chris@634: //Create OUTPUT file (.ima) Chris@634: imf = fopen (outimaf.toStdString().c_str(),"wb"); Chris@634: Chris@634: //Define the File Type Box Chris@634: filetypebx(&ftyp); Chris@634: fwrite(&ftyp, sizeof(FileTypeBox),1, imf); Chris@634: //AUDIO Chris@634: //Put the tracks in Media Data Box Chris@634: for (numtr=0; numtr enter sizeGRCO instead of 0 Chris@634: Chris@634: //Writes the movie box into the file Chris@636: writemoovbox(moov, numtrack, totaltracks, imf, text, HasTextFile); Chris@634: Chris@634: //Writes the meta box into the IMAF file Chris@634: if (HasImageFile){ Chris@634: writemetabox(meta,imf); Chris@634: } Chris@634: Chris@634: //Close Files and show exit dialog window Chris@634: fclose(imf); Chris@634: fclose (text); Chris@634: ExitWindow *window = new ExitWindow(); Chris@634: } Chris@634: Chris@634: Chris@634: Chris@634: void filetypebx(FileTypeBox *ftyp){ Chris@634: int swap; Chris@634: Chris@634: swap = bytereverse(24);// 24 is the size of the box "ftyp" Chris@634: ftyp->size = swap; Chris@634: swap = bytereverse('ftyp'); Chris@634: ftyp->type = swap; Chris@634: swap = bytereverse('im02'); // Conformance point 3 (see ISO/IEC 23000-12:2010/FDAM 1:2011(E)) Chris@634: ftyp->major_brand = swap; Chris@634: ftyp->minor_version = 0; Chris@634: swap = bytereverse('im02'); // Conformance point 3 (see ISO/IEC 23000-12:2010/FDAM 1:2011(E)) Chris@634: ftyp->compatible_brands[0] = swap; Chris@634: swap = bytereverse('isom'); Chris@634: ftyp->compatible_brands[1] = swap; Chris@634: } Chris@634: Chris@634: int mdatbox(MediaDataBox *mdat, int totaltracks, FILE *imf, FILE *song, FILE *text, int numtr, int sizetext, u32 imagesize){ Chris@634: Chris@634: int d=0, cnt=0, j, find = 0, sizestring = 0, i = 0,cnt2=0,highlight_end_time=0; Chris@634: int dat = 0, dat1 = 0, dat2 = 0, dat3 = 0,k=0; Chris@634: u32 size = 0, swap, sizeMDAT = 0; Chris@634: unsigned char c1=0,c2=0,numwords=0,initposition[3000],endposition[3000]; Chris@634: Chris@634: //Positionate the pointer at the end of the file to know the size of it Chris@634: fseek(song, 0, SEEK_END); Chris@634: size = ftell(song); Chris@634: //Positionate the pointer at first Chris@634: fseek(song, 0, SEEK_SET); Chris@634: Chris@634: initposition[0]=0; // this array saves the position of the first letter of a word in a phrase Chris@634: phrases=0;// this variable saves the number of phrases in the whole text Chris@634: Chris@634: //Find the header of the first frame (the beginning), when find it d=1 and jump out the loop. Chris@634: // The header is 32 bytes. We find in groups of 8 bytes Chris@634: // Contemplate all possible options of headers Chris@634: while (d == 0) { Chris@634: find = 0; Chris@634: fread(&dat, sizeof(unsigned char), 1, song); Chris@634: cnt++; Chris@634: Chris@634: if (dat == 0xFF) { Chris@634: cnt++; // cnt : stores the position of the pointer. Chris@634: fread(&dat1, sizeof(unsigned char), 1, song); Chris@634: cnt++; Chris@634: fread(&dat2, sizeof(unsigned char), 1, song); Chris@634: cnt++; Chris@634: fread(&dat3, sizeof(unsigned char), 1, song); Chris@634: if (dat1 == 0xFB && dat2 == 146 && dat3 == 64 ) { Chris@634: find = 1; // find: if the header is found Chris@634: d=1; // d: jump out the loop Chris@634: } Chris@634: if (dat1 == 0xFB && dat2 == 146 && dat3 == 96 ) { Chris@634: d=1; Chris@634: find = 1; Chris@634: } Chris@634: if (dat1 == 0xFB && dat2 == 144 && dat3 == 64 ) { Chris@634: find = 1; Chris@634: d=1; Chris@634: } Chris@634: if (dat1 == 0xFB && dat2 == 144 && dat3 == 96 ) { Chris@634: find = 1; Chris@634: d=1; Chris@634: } Chris@634: if (dat1 == 0xFB && dat2 == 146 && dat3 == 100 ) { Chris@634: d=1; Chris@634: find = 1; Chris@634: } Chris@634: if (dat1 == 0xFB && dat2 == 144 && dat3 == 100 ) { Chris@634: find = 1; Chris@634: d=1; Chris@634: } Chris@634: if (dat1 == 0xFA && dat2 == 146 && dat3 == 64 ) { Chris@634: find = 1; Chris@634: d=1; Chris@634: } Chris@634: if (dat1 == 0xFA && dat2 == 146 && dat3 == 96 ) { Chris@634: d=1; Chris@634: find = 1; Chris@634: } Chris@634: if (dat1 == 0xFA && dat2 == 144 && dat3 == 64 ) { Chris@634: find = 1; Chris@634: d=1; Chris@634: } Chris@634: if (dat1 == 0xFA && dat2 == 144 && dat3 == 96 ) { Chris@634: find = 1; Chris@634: d=1; Chris@634: } Chris@634: if (dat1 == 0xFA && dat2 == 146 && dat3 == 100 ) { Chris@634: d=1; Chris@634: find = 1; Chris@634: } Chris@634: if (dat1 == 0xFA && dat2 == 144 && dat3 == 100 ) { Chris@634: find = 1; Chris@634: d=1; Chris@634: } Chris@634: if (find == 0) { Chris@634: fseek(song, -3, SEEK_CUR); // if 3 last bytes in the header are not correct Chris@634: cnt = cnt - 3; Chris@634: } Chris@634: } // close if Chris@634: if (cnt == size) { //if we have readen all the bytes in the audio file Chris@634: d = 1; Chris@634: } Chris@634: }//close while Chris@634: size = size - (cnt - 4); // Calculate the size of the samples. size = pos. end of file - pos. first header. Chris@634: if (numtr == 0) { //if it is the first audio track the code writes the mdat size Chris@634: sizeMDAT = size*totaltracks + 8 + sizetext + imagesize; // size of the whole media box -> INCLUDING IMAGE and TEXT SIZE.The text size does not include modifiers Chris@634: swap = bytereverse(sizeMDAT); Chris@634: fwrite(&swap, sizeof(u32), 1, imf); Chris@634: swap = bytereverse('mdat'); Chris@634: mdat->type = swap; Chris@634: fwrite(&mdat->type, sizeof(u32), 1, imf); Chris@634: } Chris@634: fseek(song, cnt - 4, SEEK_SET); Chris@634: for (j=0; jdata, sizeof(char), 1, song); Chris@634: fwrite(&mdat->data, sizeof(char), 1, imf); Chris@634: } Chris@634: Chris@634: // copy the text in the 3gp to the ima and add the text modifiers Chris@636: if (sizetext !=0){ Chris@634: cnt=0;// the total number of bytes of the whole text including modifiers Chris@634: fseek(text,0,SEEK_CUR); Chris@634: sizestring=0;//number of bytes of a phrase (without modifiers) Chris@634: initposition[0]=0;// this array saves the initial position of a word Chris@634: if(numtr==totaltracks-1){ // writes the text after the samples of all the audio tracks Chris@634: j=0;cnt=0; Chris@634: while(jdata,sizeof(char),1,text); Chris@634: fwrite(&mdat->data,sizeof(char),1,imf); Chris@634: j++; Chris@634: cnt=cnt+1; Chris@634: cnt2=cnt2+1; Chris@634: if(mdat->data==0x20){ //a blank space separates two words. 0x20 = blank space Chris@634: Chris@634: numwords++; Chris@634: endposition[k]=i; Chris@634: initposition[k+1]=i+1; Chris@634: k++; Chris@634: } Chris@634: Chris@634: Chris@634: } //close for Chris@634: endposition[k]=sizestring-1;//saves the last position of the last word in a phrase Chris@634: numwords++; Chris@634: Chris@634: Chris@634: mdat->data=0x00; Chris@634: fwrite(&mdat->data,sizeof(char),1,imf);//hclr size Chris@634: fwrite(&mdat->data,sizeof(char),1,imf);//hclr size Chris@634: fwrite(&mdat->data,sizeof(char),1,imf);//hclr size Chris@634: mdat->data=0x0C; Chris@634: fwrite(&mdat->data,sizeof(char),1,imf); //hclr size Chris@634: fwrite("h",sizeof(char),1,imf); Chris@634: fwrite("c",sizeof(char),1,imf); Chris@634: fwrite("l",sizeof(char),1,imf); Chris@634: fwrite("r",sizeof(char),1,imf); Chris@634: mdat->data=0xFF; Chris@634: fwrite(&mdat->data,sizeof(char),1,imf);//highlight color rgba Chris@634: mdat->data=0x62; Chris@634: fwrite(&mdat->data,sizeof(char),1,imf);//highlight color rgba Chris@634: mdat->data=0x04; Chris@634: fwrite(&mdat->data,sizeof(char),1,imf);//highlight color rgba Chris@634: mdat->data=0xFF; Chris@634: fwrite(&mdat->data,sizeof(char),1,imf);//highlight color rgba Chris@634: mdat->data=0x00; Chris@634: fwrite(&mdat->data,sizeof(char),1,imf); //krok size Chris@634: mdat->data=0x00; Chris@634: fwrite(&mdat->data,sizeof(char),1,imf);//krok size Chris@634: mdat->data=0x00; Chris@634: fwrite(&mdat->data,sizeof(char),1,imf);//krok size Chris@634: mdat->data=14+(8*numwords); Chris@634: fwrite(&mdat->data,sizeof(char),1,imf); //krok size Chris@634: fwrite("k",sizeof(char),1,imf); Chris@634: fwrite("r",sizeof(char),1,imf); Chris@634: fwrite("o",sizeof(char),1,imf); Chris@634: fwrite("k",sizeof(char),1,imf); Chris@634: mdat->data=0x00; Chris@634: fwrite(&mdat->data,sizeof(char),1,imf);//highlight-start-time Chris@634: mdat->data=0x00; Chris@634: fwrite(&mdat->data,sizeof(char),1,imf);//highlight-start-time Chris@634: mdat->data=0x00; Chris@634: fwrite(&mdat->data,sizeof(char),1,imf);//highlight-start-time Chris@634: mdat->data=0x00; Chris@634: fwrite(&mdat->data,sizeof(char),1,imf);//highlight-start-time Chris@634: mdat->data=0x00; Chris@634: fwrite(&mdat->data,sizeof(char),1,imf);//entry-count Chris@634: mdat->data=numwords; Chris@634: fwrite(&mdat->data,sizeof(char),1,imf);//entry-count Chris@634: Chris@634: for(i=0;idata=0x00; Chris@634: fwrite(&mdat->data,sizeof(char),1,imf);//highlight-end-time Chris@634: mdat->data=0x00; Chris@634: fwrite(&mdat->data,sizeof(char),1,imf);//highlight-end-time Chris@634: Chris@634: Chris@634: if(i==numwords-1){ //if it is the last word in a phrase we put this value Chris@634: mdat->data=0xFF; Chris@634: fwrite(&mdat->data,sizeof(char),1,imf);//highlight-end-time Chris@634: mdat->data=0xFF; Chris@634: fwrite(&mdat->data,sizeof(char),1,imf);//highlight-end-time Chris@634: Chris@634: } Chris@634: Chris@634: else{ //if it is not the last word in a phrase Chris@634: Chris@634: highlight_end_time = (i+1)*(11/numwords);//change the value '11' in order to increase o decrease the speed of highlight Chris@634: mdat->data= highlight_end_time; Chris@634: fwrite(&mdat->data,sizeof(char),1,imf);//highlight-end-time Chris@634: mdat->data=0xFF; Chris@634: fwrite(&mdat->data,sizeof(char),1,imf);//highlight-end-time Chris@634: Chris@634: Chris@634: } Chris@634: Chris@634: mdat->data=0x00; Chris@634: fwrite(&mdat->data,sizeof(char),1,imf);//startcharoffset Chris@634: mdat->data=initposition[i]; Chris@634: fwrite(&mdat->data,sizeof(char),1,imf);//startcharoffset Chris@634: mdat->data=0x00; Chris@634: fwrite(&mdat->data,sizeof(char),1,imf);//endcharoffset Chris@634: mdat->data=endposition[i]+1; Chris@634: fwrite(&mdat->data,sizeof(char),1,imf);//endcharoffset Chris@634: Chris@634: }//close for Chris@634: Chris@634: cnt=cnt+26+(numwords*8);//cnt is the number of bytes of the whole text including modifiers Chris@634: cnt2=cnt2+26+(numwords*8); //cnt2 is the number of bytes of a phrase including the modifiers Chris@634: Chris@634: size_phrase[phrases-1]=cnt2 ; Chris@634: Chris@634: } //close while Chris@634: Chris@634: sizeMDAT = size*totaltracks + 8 + cnt + imagesize; // size value must include image and text sizes Chris@634: swap = bytereverse(sizeMDAT); Chris@634: fseek(imf,-(sizeMDAT-imagesize),SEEK_CUR); //overwrittes sizeMDAT with the total size (Image is yet to be written in the file at this point) Chris@634: fwrite(&swap, sizeof(u32), 1, imf); Chris@634: fseek(imf,(sizeMDAT-imagesize)-4,SEEK_CUR); // (Image is yet to be written in the file at this point) Chris@634: } // close if (numtr==totaltracks-1) Chris@636: }//close if sizetext Chris@634: fclose(song); Chris@634: Chris@634: return size; Chris@634: } Chris@634: Chris@634: int samplecontainer(MovieBox *moov, int numtrack, int sizemdat, const char *name){ Chris@634: Chris@634: u32 sizeSTSD, sizeSTSZ, swap, num_samples, dat=0; Chris@634: u32 sizetime, sizeSTTS; //Time to Sample Box Chris@634: u32 sizeSTSC = 28; //Sample to Chunck Chris@634: u32 sizeSTCO = 20; //Chunck offset Chris@634: u32 sizeSTBL; //Sample Table Box // Chris@634: Chris@634: //Sample Description Box// Chris@634: sizeSTSD = sampledescription(moov, numtrack); Chris@634: Chris@634: //Sample size box// Chris@634: swap = bytereverse('stsz'); Chris@634: moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox. Chris@634: SampleSizeBox.type = swap; Chris@634: moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox. Chris@634: SampleSizeBox.version = 0; Chris@634: //Read Track: Frame size and Decoder Times Chris@634: num_samples = readTrack(moov, numtrack, name); Chris@634: sizeSTSZ = num_samples*4 + 20; Chris@634: swap = bytereverse(sizeSTSZ); Chris@634: moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox. Chris@634: SampleSizeBox.size = swap; Chris@634: Chris@634: //Time To Sample Box// Chris@634: sizetime = bytereverse(moov->TrackBox[numtrack].MediaBox.MediaInformationBox. Chris@634: SampleTableBox.TimeToSampleBox.entry_count); Chris@634: sizeSTTS = 16 + sizetime*4*2; Chris@634: swap = bytereverse(sizeSTTS); Chris@634: moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox. Chris@634: TimeToSampleBox.size = swap; Chris@634: swap = bytereverse('stts'); Chris@634: moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox. Chris@634: TimeToSampleBox.type = swap; Chris@634: moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox. Chris@634: TimeToSampleBox.version = 0; Chris@634: Chris@634: //Sample To Chunk// Chris@634: swap = bytereverse(sizeSTSC); Chris@634: moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox. Chris@634: SampleToChunk.size = swap; Chris@634: swap = bytereverse('stsc'); Chris@634: moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox. Chris@634: SampleToChunk.type = swap; Chris@634: moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox. Chris@634: SampleToChunk.version = 0; Chris@634: swap = bytereverse(1); Chris@634: moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox. Chris@634: SampleToChunk.entry_count = swap; Chris@634: swap = bytereverse(1); Chris@634: moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox. Chris@634: SampleToChunk.first_chunk = swap; Chris@634: moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox. Chris@634: SampleToChunk.samples_per_chunk = moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.SampleSizeBox.sample_count; Chris@634: swap = bytereverse(1); Chris@634: moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox. Chris@634: SampleToChunk.sample_description_index = swap; Chris@634: Chris@634: //Chunk Offset Box// Chris@634: swap = bytereverse(sizeSTCO); Chris@634: moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox. Chris@634: ChunkOffsetBox.size = swap; Chris@634: swap = bytereverse('stco'); Chris@634: moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox. Chris@634: ChunkOffsetBox.type = swap; Chris@634: moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox. Chris@634: ChunkOffsetBox.version = 0; Chris@634: swap = bytereverse(1); Chris@634: moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox. Chris@634: ChunkOffsetBox.entry_count = swap; Chris@634: dat = 32 + sizemdat*numtrack; Chris@634: swap = bytereverse(dat); Chris@634: moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox. Chris@634: ChunkOffsetBox.chunk_offset[numtrack] = swap; Chris@634: Chris@634: //Sample Table Box // Chris@634: sizeSTBL = 8 + sizeSTSD + sizeSTSZ + sizeSTSC + sizeSTCO + sizeSTTS; Chris@634: swap = bytereverse(sizeSTBL); Chris@634: moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.size = swap; Chris@634: swap = bytereverse('stbl'); Chris@634: moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.type =swap; Chris@634: Chris@634: return sizeSTBL; Chris@634: } Chris@634: Chris@634: int sampledescription(MovieBox *moov, int numtrack){ Chris@634: Chris@634: u32 swap, sizeESD = 35; Chris@634: Chris@634: u32 sizeMP4a; //Audio Sample Entry// Chris@634: u32 sizeSTSD; //Sample description box // Chris@634: Chris@634: Chris@634: swap = bytereverse(sizeESD); Chris@634: moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox. Chris@634: SampleDescriptionBox.AudioSampleEntry.ESbox.size = swap; Chris@634: swap = bytereverse('esds'); Chris@634: moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox. Chris@634: SampleDescriptionBox.AudioSampleEntry.ESbox.type = swap; Chris@634: moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox. Chris@634: SampleDescriptionBox.AudioSampleEntry.ESbox.version = 0; Chris@634: Chris@634: //ES Descriptor// Chris@634: moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox. Chris@634: SampleDescriptionBox.AudioSampleEntry.ESbox.ES_Descriptor.tag = 3; Chris@634: moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox. Chris@634: SampleDescriptionBox.AudioSampleEntry.ESbox.ES_Descriptor.length = 21; Chris@634: moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox. Chris@634: SampleDescriptionBox.AudioSampleEntry.ESbox.ES_Descriptor.ES_ID = 0; Chris@634: moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox. Chris@634: SampleDescriptionBox.AudioSampleEntry.ESbox.ES_Descriptor.mix = 0; Chris@634: Chris@634: //Decoder config descriptor// Chris@634: moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox. Chris@634: SampleDescriptionBox.AudioSampleEntry.ESbox.ES_Descriptor. Chris@634: DecoderConfigDescriptor.tag = 4; Chris@634: moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox. Chris@634: SampleDescriptionBox.AudioSampleEntry.ESbox.ES_Descriptor. Chris@634: DecoderConfigDescriptor.length = 13; Chris@634: moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox. Chris@634: SampleDescriptionBox.AudioSampleEntry.ESbox.ES_Descriptor. Chris@634: DecoderConfigDescriptor.objectProfileInd = 0x6B; Chris@634: swap = bytereverse(0x150036B0); Chris@634: moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox. Chris@634: SampleDescriptionBox.AudioSampleEntry.ESbox.ES_Descriptor. Chris@634: DecoderConfigDescriptor.mix = swap; Chris@634: swap = bytereverse(128); Chris@634: moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox. Chris@634: SampleDescriptionBox.AudioSampleEntry.ESbox.ES_Descriptor. Chris@634: DecoderConfigDescriptor.maxBitRate = swap; Chris@634: swap = bytereverse(128); Chris@634: moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox. Chris@634: SampleDescriptionBox.AudioSampleEntry.ESbox.ES_Descriptor. Chris@634: DecoderConfigDescriptor.avgBitrate = swap; Chris@634: Chris@634: //SLConfig Descriptor// Chris@634: moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox. Chris@634: SampleDescriptionBox.AudioSampleEntry.ESbox.ES_Descriptor. Chris@634: SLConfigDescriptor.tag = 6; Chris@634: moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox. Chris@634: SampleDescriptionBox.AudioSampleEntry.ESbox.ES_Descriptor. Chris@634: SLConfigDescriptor.length = 1; Chris@634: moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox. Chris@634: SampleDescriptionBox.AudioSampleEntry.ESbox.ES_Descriptor. Chris@634: SLConfigDescriptor.predifined = 2; Chris@634: Chris@634: //Audio Sample Entry// Chris@634: sizeMP4a = 36 + sizeESD; Chris@634: swap = bytereverse(sizeMP4a); Chris@634: moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox. Chris@634: SampleDescriptionBox.AudioSampleEntry.size = swap; Chris@634: swap = bytereverse('mp4a'); Chris@634: moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox. Chris@634: SampleDescriptionBox.AudioSampleEntry.type =swap; Chris@634: moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox. Chris@634: SampleDescriptionBox.AudioSampleEntry.reserved[0] = 0; Chris@634: moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox. Chris@634: SampleDescriptionBox.AudioSampleEntry.reserved[1] = 0; Chris@634: moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox. Chris@634: SampleDescriptionBox.AudioSampleEntry.reserved[2] = 0; Chris@634: moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox. Chris@634: SampleDescriptionBox.AudioSampleEntry.reserved[3] = 0; Chris@634: moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox. Chris@634: SampleDescriptionBox.AudioSampleEntry.reserved[4] = 0; Chris@634: moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox. Chris@634: SampleDescriptionBox.AudioSampleEntry.reserved[5] = 0; Chris@634: moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox. Chris@634: SampleDescriptionBox.AudioSampleEntry.data_reference_index = bytereverse16(1); Chris@634: moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox. Chris@634: SampleDescriptionBox.AudioSampleEntry.reserved2[0] = 0; Chris@634: moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox. Chris@634: SampleDescriptionBox.AudioSampleEntry.reserved2[1] = 0; Chris@634: moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox. Chris@634: SampleDescriptionBox.AudioSampleEntry.channelcount = 512; Chris@634: moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox. Chris@634: SampleDescriptionBox.AudioSampleEntry.samplesize = 4096; // 16 bits Chris@634: moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox. Chris@634: SampleDescriptionBox.AudioSampleEntry.reserved3 = 0; Chris@634: swap = 44100 << 16; Chris@634: swap = bytereverse(swap); Chris@634: moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox. Chris@634: SampleDescriptionBox.AudioSampleEntry.samplerate = swap; Chris@634: Chris@634: //Sample description box // Chris@634: sizeSTSD = 16 + sizeMP4a; Chris@634: swap = bytereverse(sizeSTSD); Chris@634: moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox. Chris@634: SampleDescriptionBox.size = swap; Chris@634: swap = bytereverse('stsd'); Chris@634: moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox. Chris@634: SampleDescriptionBox.type = swap; Chris@634: moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox. Chris@634: SampleDescriptionBox.version = 0; Chris@634: swap = bytereverse(1); Chris@634: moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox. Chris@634: SampleDescriptionBox.entry_count = swap; Chris@634: Chris@634: return sizeSTSD; Chris@634: } Chris@634: Chris@634: int readTrack (MovieBox *moov, int numtrack,const char *name){ Chris@634: Chris@634: int t=0,k=1, l =0; Chris@634: Chris@634: FILE *song; Chris@634: int d=0, cnt = 0, i=0, j=0, cnt2 = 0, find = 0, swap, num_entr = 0; Chris@634: int dat = 0, dat1 = 0, dat2 = 0, dat3 = 0, num_frame = 0, end =0, pos = 0; Chris@634: u32 size[9000]; Chris@634: Chris@634: //Open the audio file with the name introduced by the user Chris@634: song = fopen (name,"rb"); Chris@634: if (song == NULL) { Chris@634: printf("Error opening input file\n"); Chris@634: system("pause"); Chris@634: exit(1); Chris@634: } Chris@634: //Calculate the size of the track Chris@634: fseek(song, 0, SEEK_END); Chris@634: end = ftell(song); Chris@634: fseek(song, 0, SEEK_SET); Chris@634: d=0, i=0; Chris@634: //Search for each frame one by one, and extratcs the information Chris@634: while (d == 0) { Chris@634: find = 0; Chris@634: fread(&dat, sizeof(unsigned char), 1, song); Chris@634: cnt++; Chris@634: Chris@634: if (dat == 0xFF) { Chris@634: cnt++; Chris@634: fread(&dat1, sizeof(unsigned char), 1, song); Chris@634: cnt++; Chris@634: fread(&dat2, sizeof(unsigned char), 1, song); Chris@634: cnt++; Chris@634: fread(&dat3, sizeof(unsigned char), 1, song); Chris@634: if (dat1 == 0xFB && dat2 == 146 && dat3 == 64 ) { Chris@634: pos = cnt - 4; //Pos of the beginning of the frame Chris@634: size[num_frame] = pos - cnt2; //Size of one frame Chris@634: cnt2 = pos; //Pos of the next frame Chris@634: find = 1; Chris@634: num_frame ++; //Number of frames Chris@634: } Chris@634: if (dat1 == 0xFB && dat2 == 146 && dat3 == 96 ) { Chris@634: pos = cnt - 4; Chris@634: size[num_frame] = pos - cnt2; Chris@634: cnt2 = pos; Chris@634: find = 1; Chris@634: num_frame ++; Chris@634: } Chris@634: if (dat1 == 0xFB && dat2 == 144 && dat3 == 64 ) { Chris@634: pos = cnt - 4; Chris@634: size[num_frame] = pos - cnt2; Chris@634: cnt2 = pos; Chris@634: find = 1; Chris@634: num_frame ++; Chris@634: } Chris@634: if (dat1 == 0xFB && dat2 == 144 && dat3 == 96 ) { Chris@634: pos = cnt - 4; Chris@634: size[num_frame] = pos - cnt2; Chris@634: cnt2 = pos; Chris@634: find = 1; Chris@634: num_frame ++; Chris@634: } Chris@634: if (dat1 == 0xFB && dat2 == 146 && dat3 == 100 ) { Chris@634: pos = cnt - 4; Chris@634: size[num_frame] = pos - cnt2; Chris@634: cnt2 = pos; Chris@634: find = 1; Chris@634: num_frame ++; Chris@634: } Chris@634: if (dat1 == 0xFB && dat2 == 144 && dat3 == 100 ) { Chris@634: pos = cnt - 4; Chris@634: size[num_frame] = pos - cnt2; Chris@634: cnt2 = pos; Chris@634: find = 1; Chris@634: num_frame ++; Chris@634: } Chris@634: if (dat1 == 0xFA && dat2 == 146 && dat3 == 64 ) { Chris@634: pos = cnt - 4; Chris@634: size[num_frame] = pos - cnt2; Chris@634: cnt2 = pos; Chris@634: find = 1; Chris@634: num_frame ++; Chris@634: } Chris@634: if (dat1 == 0xFA && dat2 == 146 && dat3 == 96 ) { Chris@634: pos = cnt - 4; Chris@634: size[num_frame] = pos - cnt2; Chris@634: cnt2 = pos; Chris@634: find = 1; Chris@634: num_frame ++; Chris@634: } Chris@634: if (dat1 == 0xFA && dat2 == 144 && dat3 == 64 ) { Chris@634: pos = cnt - 4; Chris@634: size[num_frame] = pos - cnt2; Chris@634: cnt2 = pos; Chris@634: find = 1; Chris@634: num_frame ++; Chris@634: } Chris@634: if (dat1 == 0xFA && dat2 == 144 && dat3 == 96 ) { Chris@634: pos = cnt - 4; Chris@634: size[num_frame] = pos - cnt2; Chris@634: cnt2 = pos; Chris@634: find = 1; Chris@634: num_frame ++; Chris@634: } Chris@634: if (dat1 == 0xFA && dat2 == 146 && dat3 == 100 ) { Chris@634: pos = cnt - 4; Chris@634: size[num_frame] = pos - cnt2; Chris@634: cnt2 = pos; Chris@634: find = 1; Chris@634: num_frame ++; Chris@634: } Chris@634: if (dat1 == 0xFA && dat2 == 144 && dat3 == 100 ) { Chris@634: pos = cnt - 4; Chris@634: size[num_frame] = pos - cnt2; Chris@634: cnt2 = pos; Chris@634: find = 1; Chris@634: num_frame ++; Chris@634: } Chris@634: if (find == 0) { //In case it does not find the header. Chris@634: //It keeps reading next data without jump any position Chris@634: fseek(song, -3, SEEK_CUR); Chris@634: cnt = cnt - 3; Chris@634: } Chris@634: } Chris@634: Chris@634: if (cnt == end) { Chris@634: pos = cnt; Chris@634: size[num_frame] = pos - cnt2; Chris@634: d = 1; Chris@634: } Chris@634: } Chris@634: Chris@634: //Save Samples size// Chris@634: swap = bytereverse(num_frame); Chris@634: moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox. Chris@634: SampleSizeBox.sample_count = swap; Chris@634: moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox. Chris@634: SampleSizeBox.sample_size = 0; Chris@634: Chris@634: for (i=0; i< num_frame; i++) { Chris@634: swap = bytereverse(size[i+1]); Chris@634: moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox. Chris@634: SampleSizeBox.entry_size[i] = swap; Chris@634: } Chris@634: Chris@634: //Save Decoding Times// Chris@634: //Writes manually the duration of each frame. Chris@634: //Follows the following structure: Chris@634: // 7 frames of 26 ms Chris@634: // 1 frame of 27 ms Chris@634: // ... Chris@634: // And each 13 rows it writes Chris@634: // 8 frames of 26 ms Chris@634: // 1 frame of 27 ms Chris@634: //It is done for adjusting the different durations of each frame. Chris@634: // as they vary between 26.125 ms and 26.075 ms Chris@634: Chris@634: swap = bytereverse(1); Chris@634: moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox. Chris@634: TimeToSampleBox.sample_count[0] = swap; Chris@634: moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox. Chris@634: TimeToSampleBox.sample_delta[0] =0; Chris@634: // int t=0,k=1, l =0; Chris@634: num_entr = 1; Chris@634: j = 0; Chris@634: for (i = 1; i< num_frame; i++) { Chris@634: if (j == 8 && l == 0) { Chris@634: swap = bytereverse(7); Chris@634: moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox. Chris@634: TimeToSampleBox.sample_count[num_entr] = swap; Chris@634: swap = bytereverse(26); Chris@634: moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox. Chris@634: TimeToSampleBox.sample_delta[num_entr] =swap; Chris@634: num_entr ++; Chris@634: Chris@634: swap = bytereverse(1); Chris@634: moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox. Chris@634: TimeToSampleBox.sample_count[num_entr] = swap; Chris@634: swap = bytereverse(27); Chris@634: moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox. Chris@634: TimeToSampleBox.sample_delta[num_entr] =swap; Chris@634: num_entr++; Chris@634: j=0; Chris@634: dat = i; Chris@634: if (k == 6 && t == 0) { Chris@634: l = 1; Chris@634: t = 1; Chris@634: k = 1; Chris@634: } Chris@634: if (k == 6 && t ==1) { Chris@634: l = 1; Chris@634: k = 1; Chris@634: } Chris@634: k++; Chris@634: } Chris@634: Chris@634: if (j == 9 && l == 1) { Chris@634: Chris@634: swap = bytereverse(8); Chris@634: moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox. Chris@634: TimeToSampleBox.sample_count[num_entr] = swap; Chris@634: swap = bytereverse(26); Chris@634: moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox. Chris@634: TimeToSampleBox.sample_delta[num_entr] =swap; Chris@634: num_entr ++; Chris@634: Chris@634: swap = bytereverse(1); Chris@634: moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox. Chris@634: TimeToSampleBox.sample_count[num_entr] = swap; Chris@634: swap = bytereverse(27); Chris@634: moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox. Chris@634: TimeToSampleBox.sample_delta[num_entr] =swap; Chris@634: num_entr++; Chris@634: j=0; Chris@634: dat = i; Chris@634: l = 0; Chris@634: } Chris@634: j++; Chris@634: } Chris@634: Chris@634: dat = num_frame - dat; Chris@634: Chris@634: swap = bytereverse(dat); Chris@634: moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox. Chris@634: TimeToSampleBox.sample_count[num_entr] = swap; Chris@634: swap = bytereverse(26); Chris@634: moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox. Chris@634: TimeToSampleBox.sample_delta[num_entr] =swap; Chris@634: num_entr++; Chris@634: swap = bytereverse(num_entr); Chris@634: moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox. Chris@634: TimeToSampleBox.entry_count = swap; Chris@634: Chris@634: fclose(song); Chris@634: return num_frame; Chris@634: Chris@634: } Chris@634: Chris@634: int trackstructure (MovieBox *moov, int numtrack, int clock, Chris@634: int durationTrack, int sizemdat,const char *name){ Chris@634: int swap; Chris@634: Chris@634: int sizeSTBL; //Sample Table Box Chris@634: u32 sizeURL; //Data Entry Url Box Chris@634: u32 sizeDREF; //Data Reference Chris@634: u32 sizeSMHD; //Sound Header Box Chris@634: u32 sizeDINF; //Data information Box Chris@634: u32 sizeMINF; //Media Information Box// Chris@634: u32 sizeHDLR; //Handler Box// Chris@634: u32 sizeMDHD; //Media Header Box// Chris@634: u32 sizeMDIA; //Media Box// Chris@634: u32 sizeTKHD; //Track Header// Chris@634: u32 sizeTRAK; //Track container Chris@634: Chris@634: //Sample Table Box Chris@634: sizeSTBL = 0; Chris@634: sizeSTBL = samplecontainer(moov, numtrack,sizemdat, name); Chris@634: Chris@634: //Data Entry Url Box Chris@634: sizeURL = 12; Chris@634: swap = bytereverse(sizeURL); Chris@634: moov->TrackBox[numtrack].MediaBox.MediaInformationBox.DataInformationBox. Chris@634: DataReferenceBox.DataEntryUrlBox.size = swap; Chris@634: swap = bytereverse('url '); Chris@634: moov->TrackBox[numtrack].MediaBox.MediaInformationBox.DataInformationBox. Chris@634: DataReferenceBox.DataEntryUrlBox.type = swap; Chris@634: swap = bytereverse(1); Chris@634: moov->TrackBox[numtrack].MediaBox.MediaInformationBox.DataInformationBox. Chris@634: DataReferenceBox.DataEntryUrlBox.flags = swap; // =1 Track in same file as movie atom. Chris@634: Chris@634: //Data Reference Chris@634: sizeDREF = sizeURL+ 16; Chris@634: swap = bytereverse(sizeDREF); Chris@634: moov->TrackBox[numtrack].MediaBox.MediaInformationBox.DataInformationBox. Chris@634: DataReferenceBox.size = swap; Chris@634: swap = bytereverse('dref'); Chris@634: moov->TrackBox[numtrack].MediaBox.MediaInformationBox.DataInformationBox. Chris@634: DataReferenceBox.type = swap; Chris@634: moov->TrackBox[numtrack].MediaBox.MediaInformationBox.DataInformationBox. Chris@634: DataReferenceBox.flags = 0; Chris@634: swap = bytereverse(1); Chris@634: moov->TrackBox[numtrack].MediaBox.MediaInformationBox.DataInformationBox. Chris@634: DataReferenceBox.entry_count = swap; Chris@634: Chris@634: //Data information Box// Chris@634: sizeDINF = sizeDREF + 8; Chris@634: swap = bytereverse(sizeDINF); Chris@634: moov->TrackBox[numtrack].MediaBox.MediaInformationBox.DataInformationBox.size = swap; Chris@634: swap = bytereverse('dinf'); Chris@634: moov->TrackBox[numtrack].MediaBox.MediaInformationBox.DataInformationBox.type = swap; Chris@634: Chris@634: //Sound Header Box // Chris@634: sizeSMHD = 16; Chris@634: swap = bytereverse(sizeSMHD); Chris@634: moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SoundMediaHeaderBox.size = swap; Chris@634: swap = bytereverse('smhd'); Chris@634: moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SoundMediaHeaderBox.type = swap; Chris@634: moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SoundMediaHeaderBox.version = 0; Chris@634: moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SoundMediaHeaderBox.balance = 0; Chris@634: moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SoundMediaHeaderBox.reserved = 0; Chris@634: Chris@634: //Media Information Box// Chris@634: sizeMINF = sizeDINF + sizeSMHD + sizeSTBL + 8; Chris@634: swap = bytereverse(sizeMINF); Chris@634: moov->TrackBox[numtrack].MediaBox.MediaInformationBox.size = swap; Chris@634: swap = bytereverse('minf'); Chris@634: moov->TrackBox[numtrack].MediaBox.MediaInformationBox.type = swap; Chris@634: Chris@634: //Handler Box// Chris@634: sizeHDLR = 37; Chris@634: swap = bytereverse(sizeHDLR); Chris@634: moov->TrackBox[numtrack].MediaBox.HandlerBox.size = swap; Chris@634: swap = bytereverse('hdlr'); Chris@634: moov->TrackBox[numtrack].MediaBox.HandlerBox.type = swap; Chris@634: moov->TrackBox[numtrack].MediaBox.HandlerBox.version = 0; Chris@634: moov->TrackBox[numtrack].MediaBox.HandlerBox.pre_defined = 0; Chris@634: swap = bytereverse('soun'); Chris@634: moov->TrackBox[numtrack].MediaBox.HandlerBox.handler_type = swap; Chris@634: moov->TrackBox[numtrack].MediaBox.HandlerBox.reserved[0] = 0; Chris@634: moov->TrackBox[numtrack].MediaBox.HandlerBox.reserved[1] = 0; Chris@634: moov->TrackBox[numtrack].MediaBox.HandlerBox.reserved[2] = 0; Chris@634: //swap = bytereverse('soun'); Chris@634: //moov->TrackBox[numtrack].MediaBox.HandlerBox.data = swap; Chris@634: moov->TrackBox[numtrack].MediaBox.HandlerBox.data[0] = 's'; Chris@634: moov->TrackBox[numtrack].MediaBox.HandlerBox.data[1] = 'o'; Chris@634: moov->TrackBox[numtrack].MediaBox.HandlerBox.data[2] = 'u'; Chris@634: moov->TrackBox[numtrack].MediaBox.HandlerBox.data[3] = 'n'; Chris@634: moov->TrackBox[numtrack].MediaBox.HandlerBox.data[4] = '\0'; Chris@634: Chris@634: //Media Header Box// Chris@634: sizeMDHD = 32; Chris@634: swap = bytereverse(sizeMDHD); Chris@634: moov->TrackBox[numtrack].MediaBox.MediaHeaderBox.size = swap; Chris@634: swap = bytereverse('mdhd'); Chris@634: moov->TrackBox[numtrack].MediaBox.MediaHeaderBox.type = swap; Chris@634: moov->TrackBox[numtrack].MediaBox.MediaHeaderBox.version = 0; Chris@634: swap = bytereverse(clock); Chris@634: moov->TrackBox[numtrack].MediaBox.MediaHeaderBox.creation_time = swap; Chris@634: moov->TrackBox[numtrack].MediaBox.MediaHeaderBox.modification_time = swap; Chris@634: swap = bytereverse(1000); Chris@634: moov->TrackBox[numtrack].MediaBox.MediaHeaderBox.timescale = swap; Chris@634: swap = bytereverse(durationTrack); Chris@634: moov->TrackBox[numtrack].MediaBox.MediaHeaderBox.duration = swap; Chris@634: moov->TrackBox[numtrack].MediaBox.MediaHeaderBox.language = 0xC455; Chris@634: moov->TrackBox[numtrack].MediaBox.MediaHeaderBox.pre_defined = 0; Chris@634: Chris@634: //Media Box// Chris@634: sizeMDIA = sizeMDHD + sizeHDLR + sizeMINF + 8; Chris@634: swap = bytereverse(sizeMDIA); Chris@634: moov->TrackBox[numtrack].MediaBox.size = swap; Chris@634: swap = bytereverse('mdia'); Chris@634: moov->TrackBox[numtrack].MediaBox.type = swap; Chris@634: Chris@634: //Track Header// Chris@634: sizeTKHD = 92; Chris@634: swap = bytereverse (sizeTKHD); Chris@634: moov->TrackBox[numtrack].TrackHeaderBox.size = swap; Chris@634: swap = bytereverse ('tkhd'); Chris@634: moov->TrackBox[numtrack].TrackHeaderBox.type = swap ; Chris@634: swap = bytereverse (0x00000006); Chris@634: moov->TrackBox[numtrack].TrackHeaderBox.version = swap; Chris@634: swap = bytereverse (clock); Chris@634: moov->TrackBox[numtrack].TrackHeaderBox.creation_time = swap; Chris@634: moov->TrackBox[numtrack].TrackHeaderBox.modification_time = swap; Chris@634: swap = bytereverse (numtrack+1); Chris@634: moov->TrackBox[numtrack].TrackHeaderBox.track_ID = swap; //From 0x00000001 - 0x7FFFFFFF (dec 2147483647) Chris@634: moov->TrackBox[numtrack].TrackHeaderBox.reserved = 0; Chris@634: swap = bytereverse (durationTrack); Chris@634: moov->TrackBox[numtrack].TrackHeaderBox.duration = swap; Chris@634: moov->TrackBox[numtrack].TrackHeaderBox.reserved2[0] = 0; Chris@634: moov->TrackBox[numtrack].TrackHeaderBox.reserved2[1] = 0; Chris@634: moov->TrackBox[numtrack].TrackHeaderBox.layer = 0; Chris@634: moov->TrackBox[numtrack].TrackHeaderBox.alternate_group = 0; Chris@634: moov->TrackBox[numtrack].TrackHeaderBox.volume = 0x1; Chris@634: moov->TrackBox[numtrack].TrackHeaderBox.reserved3 = 0; Chris@634: swap = bytereverse (0x00010000); Chris@634: moov->TrackBox[numtrack].TrackHeaderBox.matrix[0] = swap; Chris@634: moov->TrackBox[numtrack].TrackHeaderBox.matrix[1] = 0; Chris@634: moov->TrackBox[numtrack].TrackHeaderBox.matrix[2] = 0; Chris@634: moov->TrackBox[numtrack].TrackHeaderBox.matrix[3] = 0; Chris@634: moov->TrackBox[numtrack].TrackHeaderBox.matrix[4] = swap; Chris@634: moov->TrackBox[numtrack].TrackHeaderBox.matrix[5] = 0; Chris@634: moov->TrackBox[numtrack].TrackHeaderBox.matrix[6] = 0; Chris@634: moov->TrackBox[numtrack].TrackHeaderBox.matrix[7] = 0; Chris@634: swap = bytereverse(0x40000000); Chris@634: moov->TrackBox[numtrack].TrackHeaderBox.matrix[8] = swap; Chris@634: moov->TrackBox[numtrack].TrackHeaderBox.width = 0; //just for video Chris@634: moov->TrackBox[numtrack].TrackHeaderBox.height = 0; //just for video Chris@634: Chris@634: //Track container Chris@634: sizeTRAK = sizeTKHD + sizeMDIA + 8; Chris@634: swap = bytereverse (sizeTRAK); // Size of one track Chris@634: moov->TrackBox[numtrack].size = swap; Chris@634: swap = bytereverse ('trak'); Chris@634: moov->TrackBox[numtrack].type = swap; Chris@634: return sizeTRAK; Chris@634: Chris@634: } Chris@634: Chris@634: int groupcontainer(MovieBox *moov, int *group_tracks, int grp_vol, QString grp_name, Chris@634: QString grp_description, int totaltracks) { Chris@634: Chris@634: int i, j, k, numgroups, sizeCont; Chris@634: int numel = 0; Chris@634: int sizeBox = 0; Chris@634: int tempsize = 0; Chris@634: int active, activenum, addsize; Chris@634: Chris@634: // ADDED FOR SV Chris@634: for (j=0; jGroupContainerBox.num_groups = bytereverse16(numgroups); Chris@634: Chris@634: for (i=0; iGroupContainerBox.GroupBox[i].group_ID = bytereverse(2147483649+i+1); // group_ID shall be represented from 0x80000000 to 0xFFFFFFFF Chris@634: strcpy(moov->GroupContainerBox.GroupBox[i].group_name, grp_name.toStdString().c_str()); Chris@634: strcpy(moov->GroupContainerBox.GroupBox[i].group_description, grp_description.toStdString().c_str()); Chris@634: Chris@634: // numel = 0; // uncomment for more than one group and remove initial "for" with numel Chris@634: k = 0; Chris@634: for (j=0; jGroupContainerBox.GroupBox[i].groupElemId[k].element_ID = bytereverse(j+1); Chris@634: // numel++; // uncomment for more than one group and remove initial "for" with numel Chris@634: addsize += 4; Chris@634: k++; Chris@634: } Chris@634: } Chris@634: moov->GroupContainerBox.GroupBox[i].num_elements = bytereverse16(numel); Chris@634: Chris@634: // printf("Choose the activation mode: "); Chris@634: // printf("Activation mode\n"); Chris@634: // printf(" - Switch on the MINIMUN number of elements (0, if no Min/Max rule) [0]\n"); Chris@634: // printf(" - Switch on the MAXIMUM number of elements (All tracks, if no Min/Max rule) [1]\n"); Chris@634: // printf(" - Switch on the defined number of elements (ONLY IF there is Min/Max rule) [2]\n"); Chris@634: // scanf("%d",&active); Chris@634: // fflush(stdin); Chris@634: Chris@634: active = 1; // ADDED FOR SV, All tracks enabled Chris@634: Chris@634: moov->GroupContainerBox.GroupBox[i].group_activation_mode = active; Chris@634: activenum = 0; Chris@634: moov->GroupContainerBox.GroupBox[i].group_activation_elements_number = activenum; Chris@634: if (active==2){ Chris@634: printf("Activation elements number: "); Chris@634: scanf("%d",&activenum); Chris@634: moov->GroupContainerBox.GroupBox[i].group_activation_elements_number = bytereverse16(activenum); Chris@634: addsize += 2; Chris@634: } Chris@634: Chris@634: moov->GroupContainerBox.GroupBox[i].group_reference_volume = bytereverse16(grp_vol*256/100); // define 8.8 fixed point Chris@634: Chris@634: tempsize = 75 + addsize; // ---> before was 66 + addsize; Chris@634: moov->GroupContainerBox.GroupBox[i].size = bytereverse(tempsize); Chris@634: moov->GroupContainerBox.GroupBox[i].type = bytereverse('grup'); Chris@634: moov->GroupContainerBox.GroupBox[i].version = bytereverse(0x02); // flags = Display enable, Edit disable Chris@634: Chris@634: sizeBox += tempsize; Chris@634: Chris@634: } // close for (numgroups) Chris@634: Chris@634: sizeCont = sizeBox + 10; Chris@634: Chris@634: moov->GroupContainerBox.size = bytereverse(sizeCont); Chris@634: moov->GroupContainerBox.type = bytereverse('grco'); Chris@634: Chris@634: return sizeCont; Chris@634: } Chris@634: Chris@634: int presetcontainer(MovieBox *moov, int totaltracks, int *vol_values, int prestype, int fade_in){ Chris@634: Chris@634: int temp, i, j, k, m, t, vol; Chris@634: int numpres, eq; Chris@634: //char name[50]; Chris@634: u32 sizePRST = 0; Chris@634: u32 sizePRCO = 0; Chris@634: u32 sizeEQ; Chris@634: u32 addsize = 0; Chris@634: int updates = 0; Chris@634: Chris@634: numpres = 1; // ADDED FOR SV Chris@634: Chris@634: //Preset Box// Chris@634: for (i=0; iPresetContainerBox.PresetBox[i].type = bytereverse('prst'); Chris@634: moov->PresetContainerBox.PresetBox[i].flags = bytereverse(0x02); // Display Enable Edit Disable Chris@634: moov->PresetContainerBox.PresetBox[i].preset_ID = i+1; Chris@634: moov->PresetContainerBox.PresetBox[i].num_preset_elements = totaltracks; // All the tracks are involved in the preset Chris@634: for (j=0; jPresetContainerBox.PresetBox[i].presElemId[j].preset_element_ID = bytereverse(j+1); Chris@634: } Chris@634: moov->PresetContainerBox.PresetBox[i].preset_global_volume = 100; Chris@634: Chris@634: // prestype = 0; // ADDED FOR SV Chris@634: Chris@634: switch (prestype) { Chris@634: case 0: moov->PresetContainerBox.PresetBox[i].preset_type = 0; Chris@634: strcpy(moov->PresetContainerBox.PresetBox[i].preset_name, "Static track volume preset"); Chris@634: Chris@634: for (j=0; jPresetContainerBox.PresetBox[i].StaticTrackVolume.presVolumElem[j].preset_volume_element = vol/2; //*0.02 Chris@634: } Chris@634: Chris@634: addsize = totaltracks; Chris@634: break; Chris@634: case 1: moov->PresetContainerBox.PresetBox[i].preset_type = 1; Chris@634: strcpy(moov->PresetContainerBox.PresetBox[i].preset_name, "Static object volume preset"); Chris@634: Chris@634: for (j=0; jPresetContainerBox.PresetBox[i].StaticObjectVolume.InputCH[j].num_input_channel = num_ch; Chris@634: } Chris@634: moov->PresetContainerBox.PresetBox[i].StaticObjectVolume.output_channel_type = 1; // STEREO (2 output channels) Chris@634: for (j=0; jPresetContainerBox.PresetBox[i].StaticObjectVolume.presElVol[j]. Chris@634: Input[k].Output[m].preset_volume_element = (100-(20*m))/2; // INPUT BY USER Chris@634: } Chris@634: } Chris@634: } Chris@634: Chris@634: addsize = totaltracks + 1+ totaltracks*num_ch*num_ch; Chris@634: break; Chris@634: case 2: moov->PresetContainerBox.PresetBox[i].preset_type = 2; Chris@634: strcpy(moov->PresetContainerBox.PresetBox[i].preset_name, "Dynamic track volume preset"); Chris@634: Chris@634: updates = 2; // volume changes Chris@634: moov->PresetContainerBox.PresetBox[i].DynamicTrackVolume.num_updates = bytereverse16(updates); Chris@634: for (j=0; jPresetContainerBox.PresetBox[i].DynamicTrackVolume. Chris@634: DynamicChange[j].updated_sample_number = bytereverse16(100+(j*100)); // *0.026 = time in seconds Chris@634: for (k=0; kPresetContainerBox.PresetBox[i].DynamicTrackVolume. Chris@634: DynamicChange[j].presVolumElem[k].preset_volume_element = (50*j)/2; // INPUT BY USER Chris@634: } Chris@634: } Chris@634: Chris@634: addsize = 2 + updates*(2 + totaltracks); Chris@634: break; Chris@634: case 3: moov->PresetContainerBox.PresetBox[i].preset_type = 3; Chris@634: strcpy(moov->PresetContainerBox.PresetBox[i].preset_name, "Dynamic object volume preset"); Chris@634: Chris@634: updates = 2; // volume changes Chris@634: moov->PresetContainerBox.PresetBox[i].DynamicObjectVolume.num_updates = bytereverse16(updates); // INPUT BY USER (maybe...) Chris@634: for (j=0; jPresetContainerBox.PresetBox[i].DynamicObjectVolume.InputCH[j].num_input_channel = 2; Chris@634: } Chris@634: moov->PresetContainerBox.PresetBox[i].DynamicObjectVolume.output_channel_type = 1; // STEREO (2 output channels) Chris@634: for (j=0; jPresetContainerBox.PresetBox[i].DynamicObjectVolume. Chris@634: DynamicChange[j].updated_sample_number = bytereverse16(0+(j*500)); // *0.026 = time in seconds Chris@634: for (k=0; kPresetContainerBox.PresetBox[i].DynamicObjectVolume.DynamicChange[j]. Chris@634: presElVol[k].Input[m].Output[t].preset_volume_element = (25*(j+1)); // INPUT BY USER Chris@634: } Chris@634: } Chris@634: } Chris@634: } Chris@634: Chris@634: addsize = 2 + totaltracks + 1 + updates*(2 + totaltracks*num_ch*num_ch); Chris@634: break; Chris@634: case 4: moov->PresetContainerBox.PresetBox[i].preset_type = 4; Chris@634: strcpy(moov->PresetContainerBox.PresetBox[i].preset_name, "Dynamic track approximated volume"); Chris@634: Chris@634: updates = 2; // volume changes Chris@634: moov->PresetContainerBox.PresetBox[i].DynamicTrackApproxVolume.num_updates = bytereverse16(updates); Chris@634: for (j=0; jPresetContainerBox.PresetBox[i].DynamicTrackApproxVolume. Chris@634: DynamicChange[j].start_sample_number = bytereverse16(100); // *0.026 = time in seconds - INPUT BY USER Chris@634: moov->PresetContainerBox.PresetBox[i].DynamicTrackApproxVolume. Chris@634: DynamicChange[j].duration_update = bytereverse16(500); // *0.026 = time in seconds -INPUT BY USER Chris@634: for (k=0; kPresetContainerBox.PresetBox[i].DynamicTrackApproxVolume.DynamicChange[j]. Chris@634: presElVol[k].end_preset_volume_element = (50*j); // Fade IN Chris@634: } else { Chris@634: moov->PresetContainerBox.PresetBox[i].DynamicTrackApproxVolume.DynamicChange[j]. Chris@634: presElVol[k].end_preset_volume_element = (100-(100*j))/2; // Fade OUT Chris@634: } Chris@634: } Chris@634: } Chris@634: Chris@634: /* // some code for test Chris@634: moov->PresetContainerBox.PresetBox[i].DynamicTrackApproxVolume.DynamicChange[2].start_sample_number = bytereverse16(1100); Chris@634: moov->PresetContainerBox.PresetBox[i].DynamicTrackApproxVolume.DynamicChange[2].duration_update = bytereverse16(250); Chris@634: moov->PresetContainerBox.PresetBox[i].DynamicTrackApproxVolume.DynamicChange[2].presElVol[0].end_preset_volume_element = 50; Chris@634: moov->PresetContainerBox.PresetBox[i].DynamicTrackApproxVolume.DynamicChange[2].presElVol[1].end_preset_volume_element = 50; Chris@634: moov->PresetContainerBox.PresetBox[i].DynamicTrackApproxVolume.DynamicChange[3].start_sample_number = bytereverse16(1100); Chris@634: moov->PresetContainerBox.PresetBox[i].DynamicTrackApproxVolume.DynamicChange[3].duration_update = bytereverse16(250); Chris@634: moov->PresetContainerBox.PresetBox[i].DynamicTrackApproxVolume.DynamicChange[3].presElVol[0].end_preset_volume_element = 1; Chris@634: moov->PresetContainerBox.PresetBox[i].DynamicTrackApproxVolume.DynamicChange[3].presElVol[1].end_preset_volume_element = 1; Chris@634: */ Chris@634: Chris@634: addsize = 2 + updates*(2 + 2 + totaltracks); Chris@634: break; Chris@634: case 5: moov->PresetContainerBox.PresetBox[i].preset_type = 5; // NOT YET IMPLEMENTED INTO THE PLAYER! Chris@634: strcpy(moov->PresetContainerBox.PresetBox[i].preset_name, "Dynamic object approximated volume"); Chris@634: Chris@634: printf("\n\nTHIS PRESET IS NOT YET IMPLEMENTED INTO THE PLAYER!!! PLAYER MAY CRASH WITH THIS FILE!!!\n\n"); Chris@634: Chris@634: updates = 2; // volume changes Chris@634: moov->PresetContainerBox.PresetBox[i].DynamicObjectApproxVolume.num_updates = bytereverse16(updates); Chris@634: for (j=0; jPresetContainerBox.PresetBox[i].DynamicObjectApproxVolume.InputCH[j].num_input_channel = 2; Chris@634: } Chris@634: moov->PresetContainerBox.PresetBox[i].DynamicObjectApproxVolume.output_channel_type = 1; // STEREO (2 output channels) Chris@634: for (j=0; jPresetContainerBox.PresetBox[i].DynamicObjectApproxVolume. Chris@634: DynamicChange[j].start_sample_number = bytereverse16(100); // *0.026 = time in seconds - INPUT BY USER Chris@634: moov->PresetContainerBox.PresetBox[i].DynamicObjectApproxVolume. Chris@634: DynamicChange[j].duration_update = bytereverse16(250); // *0.026 = time in seconds - INPUT BY USER Chris@634: for (k=0; kPresetContainerBox.PresetBox[i].DynamicObjectApproxVolume.DynamicChange[j]. Chris@634: presElVol[k].Input[m].Output[t].preset_volume_element = (100*j)/2; // INPUT BY USER Chris@634: } Chris@634: } Chris@634: } Chris@634: } Chris@634: Chris@634: addsize = 2 + totaltracks + 1 + updates*( 2 + 2 + totaltracks*num_ch*num_ch); Chris@634: break; Chris@634: case 6: moov->PresetContainerBox.PresetBox[i].preset_type = 8; Chris@634: strcpy(moov->PresetContainerBox.PresetBox[i].preset_name, "Static track volume with Equalization"); Chris@634: Chris@634: eq = 0; addsize = 0; Chris@634: for (j=0; jPresetContainerBox.PresetBox[i].StaticTrackVolume.presVolumElem[j].preset_volume_element = vol/2; //*0.02 Chris@634: Chris@634: // Equalization Chris@634: printf("EQ Filter on this element? [1] Yes - [0] No : "); Chris@634: scanf("%d",&eq); Chris@634: fflush(stdin); Chris@634: Chris@634: if (eq == 1){ Chris@634: moov->PresetContainerBox.PresetBox[i].StaticTrackVolume.presVolumElem[j].EQ.num_eq_filters = 1; Chris@634: for (k=0; kPresetContainerBox.PresetBox[i].StaticTrackVolume.presVolumElem[j].EQ.num_eq_filters; k++){ Chris@634: moov->PresetContainerBox.PresetBox[i].StaticTrackVolume.presVolumElem[j].EQ.Filter[k].filter_type = 4; // HPF Chris@634: moov->PresetContainerBox.PresetBox[i].StaticTrackVolume.presVolumElem[j].EQ.Filter[k]. Chris@634: filter_reference_frequency = bytereverse16(5000); // 10kHz Chris@634: moov->PresetContainerBox.PresetBox[i].StaticTrackVolume.presVolumElem[j].EQ.Filter[k].filter_gain = -10; Chris@634: moov->PresetContainerBox.PresetBox[i].StaticTrackVolume.presVolumElem[j].EQ.Filter[k].filter_bandwidth = 4; Chris@634: addsize += 5; Chris@634: } //close for Chris@634: }else{ Chris@634: moov->PresetContainerBox.PresetBox[i].StaticTrackVolume.presVolumElem[j].EQ.num_eq_filters = 0; Chris@634: } //close if/else Chris@634: } //close for Chris@634: Chris@634: addsize += totaltracks + totaltracks; //add preset_volume and num_eq_filters size Chris@634: break; Chris@634: case 7: moov->PresetContainerBox.PresetBox[i].preset_type = 9; // NOT YET IMPLEMENTED INTO THE PLAYER! Chris@634: strcpy(moov->PresetContainerBox.PresetBox[i].preset_name, "Static object volume with Equalization"); Chris@634: printf("\n\nTHIS PRESET IS NOT YET IMPLEMENTED INTO THE PLAYER!!! PLAYER MAY CRASH WITH THIS FILE!!!\n\n"); Chris@634: break; Chris@634: case 8: moov->PresetContainerBox.PresetBox[i].preset_type = 10; // NOT YET IMPLEMENTED INTO THE PLAYER! Chris@634: strcpy(moov->PresetContainerBox.PresetBox[i].preset_name, "Dynamic track volume with Equalization"); Chris@634: printf("\n\nTHIS PRESET IS NOT YET IMPLEMENTED INTO THE PLAYER!!! PLAYER MAY CRASH WITH THIS FILE!!!\n\n"); Chris@634: break; Chris@634: case 9: moov->PresetContainerBox.PresetBox[i].preset_type = 11; // NOT YET IMPLEMENTED INTO THE PLAYER! Chris@634: strcpy(moov->PresetContainerBox.PresetBox[i].preset_name, "Dynamic object volume with Equalization"); Chris@634: break; Chris@634: case 10: moov->PresetContainerBox.PresetBox[i].preset_type = 12; // NOT YET IMPLEMENTED INTO THE PLAYER! Chris@634: strcpy(moov->PresetContainerBox.PresetBox[i].preset_name, "Dynamic track approximated with Equalization"); Chris@634: printf("\n\nTHIS PRESET IS NOT YET IMPLEMENTED INTO THE PLAYER!!! PLAYER MAY CRASH WITH THIS FILE!!!\n\n"); Chris@634: Chris@634: eq = 0; addsize = 0; Chris@634: updates = 2; // volume changes Chris@634: moov->PresetContainerBox.PresetBox[i].DynamicTrackApproxVolume.num_updates = bytereverse16(updates); Chris@634: for (j=0; jPresetContainerBox.PresetBox[i].DynamicTrackApproxVolume. Chris@634: DynamicChange[j].start_sample_number = bytereverse16(100); // *0.026 = time in seconds - INPUT BY USER Chris@634: moov->PresetContainerBox.PresetBox[i].DynamicTrackApproxVolume. Chris@634: DynamicChange[j].duration_update = bytereverse16(500); // *0.026 = time in seconds -INPUT BY USER Chris@634: for (k=0; kPresetContainerBox.PresetBox[i].DynamicTrackApproxVolume.DynamicChange[j]. Chris@634: presElVol[k].end_preset_volume_element = (50*j); // Fade IN, change in (100-(100*j))/2 for Fade OUT -INPUT BY USER Chris@634: Chris@634: // Equalization Chris@634: //printf("EQ Filter on %s ? [1] Yes - [0] No : ",namet[k].title); Chris@634: scanf("%d",&eq); Chris@634: fflush(stdin); Chris@634: Chris@634: if (eq == 1){ Chris@634: moov->PresetContainerBox.PresetBox[i].DynamicTrackApproxVolume. Chris@634: DynamicChange[j].presElVol[k].EQ.num_eq_filters = 1; Chris@634: for (t=0; tPresetContainerBox.PresetBox[i].DynamicTrackApproxVolume. Chris@634: DynamicChange[j].presElVol[k].EQ.num_eq_filters; t++){ Chris@634: moov->PresetContainerBox.PresetBox[i].DynamicTrackApproxVolume. Chris@634: DynamicChange[j].presElVol[k].EQ.Filter[t].filter_type = 4; // HPF Chris@634: moov->PresetContainerBox.PresetBox[i].DynamicTrackApproxVolume. Chris@634: DynamicChange[j].presElVol[k].EQ.Filter[t].filter_reference_frequency = bytereverse16(5000); // 10kHz Chris@634: moov->PresetContainerBox.PresetBox[i].DynamicTrackApproxVolume. Chris@634: DynamicChange[j].presElVol[k].EQ.Filter[t].end_filter_gain = -10; Chris@634: moov->PresetContainerBox.PresetBox[i].DynamicTrackApproxVolume. Chris@634: DynamicChange[j].presElVol[k].EQ.Filter[t].filter_bandwidth = 4; Chris@634: addsize += 5; Chris@634: } //close for Chris@634: }else{ Chris@634: moov->PresetContainerBox.PresetBox[i].DynamicTrackApproxVolume. Chris@634: DynamicChange[j].presElVol[k].EQ.num_eq_filters = 0; Chris@634: } //close if/else Chris@634: } //close for (k) Chris@634: } //close for (j) Chris@634: Chris@634: addsize += 2 + updates*(2 + 2 + totaltracks*(1+1)); Chris@634: break; Chris@634: case 11: moov->PresetContainerBox.PresetBox[i].preset_type = 13; // NOT YET IMPLEMENTED INTO THE PLAYER! Chris@634: strcpy(moov->PresetContainerBox.PresetBox[i].preset_name, "Dynamic object approximated with Equalization"); Chris@634: printf("\n\nTHIS PRESET IS NOT YET IMPLEMENTED INTO THE PLAYER!!! PLAYER MAY CRASH WITH THIS FILE!!!\n\n"); Chris@634: break; Chris@634: default: printf("ERROR in PRESET CONTAINER"); Chris@634: system("pause"); Chris@634: exit(1); Chris@634: break; Chris@634: Chris@634: } //close switch Chris@634: Chris@634: temp = 16 + 50 + 4*totaltracks + addsize; // size PresetBox[i] Chris@634: moov->PresetContainerBox.PresetBox[i].size = bytereverse(temp); Chris@634: Chris@634: sizePRST += temp; // size of all Preset Boxes Chris@634: Chris@634: } //close for Chris@634: Chris@634: //Preset Container// Chris@634: sizePRCO += sizePRST + 10; Chris@634: moov->PresetContainerBox.size = bytereverse(sizePRCO); Chris@634: moov->PresetContainerBox.type = bytereverse('prco'); Chris@634: moov->PresetContainerBox.default_preset_ID = 1; // Indicates initial preset activated. Chris@634: moov->PresetContainerBox.num_preset = numpres; Chris@634: Chris@634: return sizePRCO; Chris@634: Chris@634: } //close function Chris@634: Chris@634: int rulescontainer(MovieBox *moov, int SelRuleType, int SelRule_PAR1, int SelRule_PAR2, Chris@634: int MixRuleType, int MixRule_PAR1, int MixRule_PAR2, Chris@634: int MixRule_PAR3, int MixRule_PAR4) { Chris@634: Chris@634: int swap; Chris@634: u32 add_size = 0; //for SelectionRulesBox Chris@634: u32 sizeRUSC, sizeRUCO, sizeRUMX; Chris@634: Chris@634: Chris@634: //Selection Rules Chris@634: moov->RulesContainer.num_selection_rules = bytereverse16(1); Chris@634: moov->RulesContainer.SelectionRules.selection_rule_ID = bytereverse16(1); Chris@634: Chris@634: switch (SelRuleType) { Chris@634: Chris@634: case 0: moov->RulesContainer.SelectionRules.selection_rule_type = 0; Chris@634: moov->RulesContainer.SelectionRules.element_ID = bytereverse(2147483649+1); // Must be the same ID of the group Chris@634: moov->RulesContainer.SelectionRules.min_num_elements = bytereverse16(SelRule_PAR1); Chris@634: moov->RulesContainer.SelectionRules.max_num_elements = bytereverse16(SelRule_PAR2); Chris@634: strcpy(moov->RulesContainer.SelectionRules.rule_description,"Min/Max Rule"); Chris@634: add_size = 4; Chris@634: break; Chris@634: case 1: moov->RulesContainer.SelectionRules.selection_rule_type = 1; Chris@634: moov->RulesContainer.SelectionRules.element_ID = bytereverse(SelRule_PAR1); Chris@634: moov->RulesContainer.SelectionRules.key_element_ID =bytereverse(SelRule_PAR2); Chris@634: strcpy(moov->RulesContainer.SelectionRules.rule_description,"Exclusion Rule"); Chris@634: add_size = 4; Chris@634: break; Chris@634: case 2: moov->RulesContainer.SelectionRules.selection_rule_type = 2; Chris@634: moov->RulesContainer.SelectionRules.element_ID = bytereverse(SelRule_PAR1); Chris@634: strcpy(moov->RulesContainer.SelectionRules.rule_description,"Not mute Rule"); Chris@634: add_size = 0; Chris@634: break; Chris@634: case 3: moov->RulesContainer.SelectionRules.selection_rule_type = 3; Chris@634: moov->RulesContainer.SelectionRules.element_ID = bytereverse(SelRule_PAR1); Chris@634: moov->RulesContainer.SelectionRules.key_element_ID =bytereverse(SelRule_PAR2); Chris@634: strcpy(moov->RulesContainer.SelectionRules.rule_description,"Implication Rule"); Chris@634: add_size = 4; Chris@634: break; Chris@634: default: printf("ERROR in RULES CONTAINER/Selection Rules"); Chris@634: system("pause"); Chris@634: break; Chris@634: } Chris@634: Chris@634: sizeRUSC = 19 + 20 + add_size; Chris@634: moov->RulesContainer.SelectionRules.size = bytereverse(sizeRUSC); Chris@634: moov->RulesContainer.SelectionRules.type = bytereverse('rusc'); Chris@634: moov->RulesContainer.SelectionRules.version = 0; Chris@634: Chris@634: //Mixing Rule Chris@634: moov->RulesContainer.num_mixing_rules = bytereverse16(1); Chris@634: moov->RulesContainer.MixingRules.mixing_rule_ID = bytereverse16(1); Chris@634: Chris@634: switch (MixRuleType) { Chris@634: Chris@634: case 0: moov->RulesContainer.MixingRules.mixing_type = 0; Chris@634: moov->RulesContainer.MixingRules.element_ID = bytereverse(MixRule_PAR1); Chris@634: moov->RulesContainer.MixingRules.key_elem_ID = bytereverse(MixRule_PAR2); Chris@634: strcpy(moov->RulesContainer.MixingRules.mix_description, "Equivalence rule"); Chris@634: break; Chris@634: case 1: moov->RulesContainer.MixingRules.mixing_type = 1; Chris@634: moov->RulesContainer.MixingRules.element_ID = bytereverse(MixRule_PAR2); Chris@634: moov->RulesContainer.MixingRules.key_elem_ID = bytereverse(MixRule_PAR1); Chris@634: strcpy(moov->RulesContainer.MixingRules.mix_description, "Upper rule"); Chris@634: break; Chris@634: case 2: moov->RulesContainer.MixingRules.mixing_type = 2; Chris@634: moov->RulesContainer.MixingRules.element_ID = bytereverse(MixRule_PAR2); Chris@634: moov->RulesContainer.MixingRules.key_elem_ID = bytereverse(MixRule_PAR1); Chris@634: strcpy(moov->RulesContainer.MixingRules.mix_description, "Lower rule"); Chris@634: break; Chris@634: case 3: moov->RulesContainer.MixingRules.mixing_type = 3; Chris@634: moov->RulesContainer.MixingRules.element_ID = bytereverse(MixRule_PAR1); Chris@634: moov->RulesContainer.MixingRules.min_volume = bytereverse16(1 + MixRule_PAR3*2.5); // 8.8 fixed point Chris@634: moov->RulesContainer.MixingRules.max_volume = bytereverse16(1 + MixRule_PAR4*2.5); // 8.8 fixed point Chris@634: strcpy(moov->RulesContainer.MixingRules.mix_description, "Limit rule"); Chris@634: break; Chris@634: default: printf("ERROR in RULES CONTAINER/Mixing Rules"); Chris@634: system("pause"); Chris@634: exit(1); Chris@634: break; Chris@634: } Chris@634: Chris@634: sizeRUMX = 23 + 17; Chris@634: moov->RulesContainer.MixingRules.size = bytereverse(sizeRUMX); Chris@634: moov->RulesContainer.MixingRules.type = bytereverse('rumx'); Chris@634: moov->RulesContainer.MixingRules.version = 0; Chris@634: Chris@634: //Rule container Chris@634: sizeRUCO = 12 + sizeRUSC + sizeRUMX; Chris@634: swap = bytereverse(sizeRUCO); Chris@634: moov->RulesContainer.size = swap; Chris@634: swap = bytereverse('ruco'); Chris@634: moov->RulesContainer.type = swap; Chris@634: Chris@634: return sizeRUCO; Chris@634: Chris@634: } // close function Chris@634: Chris@634: void moovheaderbox (MovieBox *moov, int clock, int sizeTRAK, int sizePRCO, int totaltracks, Chris@634: int durationTrack, int sizeRUCO, int sizeGRCO) { Chris@634: int swap; Chris@634: u32 sizeMOOV; //MovieBox Chris@634: Chris@634: //MovieHeader Chris@634: u32 sizeMVHD = 108; Chris@634: swap = bytereverse (sizeMVHD); Chris@634: moov->MovieHeaderBox.size = swap; Chris@634: swap = bytereverse ('mvhd'); Chris@634: moov->MovieHeaderBox.type = swap; Chris@634: moov->MovieHeaderBox.version = 0; Chris@634: swap = bytereverse (clock); Chris@634: moov->MovieHeaderBox.creation_time = swap; Chris@634: moov->MovieHeaderBox.modification_time = swap; Chris@634: swap = bytereverse (1000); Chris@634: moov->MovieHeaderBox.timescale = swap; Chris@634: swap = bytereverse (durationTrack); Chris@634: moov->MovieHeaderBox.duration = swap; Chris@634: swap = bytereverse (0x00010000); Chris@634: moov->MovieHeaderBox.rate = swap; Chris@634: swap = bytereverse (1); Chris@634: moov->MovieHeaderBox.volume = 1; Chris@634: moov->MovieHeaderBox.reserved=0; Chris@634: moov->MovieHeaderBox.reserved2[0] = 0; Chris@634: moov->MovieHeaderBox.reserved2[1] = 0; Chris@634: swap = bytereverse (0x00010000); Chris@634: moov->MovieHeaderBox.matrix[0] = swap; Chris@634: moov->MovieHeaderBox.matrix[1] = 0; Chris@634: moov->MovieHeaderBox.matrix[2] = 0; Chris@634: moov->MovieHeaderBox.matrix[3] = 0; Chris@634: moov->MovieHeaderBox.matrix[4] = swap; Chris@634: moov->MovieHeaderBox.matrix[5] = 0; Chris@634: moov->MovieHeaderBox.matrix[6] = 0; Chris@634: moov->MovieHeaderBox.matrix[7] = 0; Chris@634: swap = bytereverse (0x40000000); Chris@634: moov->MovieHeaderBox.matrix[8] = 0x40000000; Chris@634: moov->MovieHeaderBox.pre_defined[0] = 0; Chris@634: moov->MovieHeaderBox.pre_defined[1] = 0; Chris@634: moov->MovieHeaderBox.pre_defined[2] = 0; Chris@634: moov->MovieHeaderBox.pre_defined[3] = 0; Chris@634: moov->MovieHeaderBox.pre_defined[4] = 0; Chris@634: moov->MovieHeaderBox.pre_defined[5] = 0; Chris@634: swap = bytereverse (totaltracks + 1); Chris@634: moov->MovieHeaderBox.next_track_ID = swap; Chris@634: Chris@634: //MovieBox Chris@634: sizeMOOV = sizeMVHD + sizeTRAK + sizePRCO + sizeRUCO + sizeGRCO + 8; Chris@634: swap = bytereverse (sizeMOOV); //Size movie: Taking into account number tracks Chris@634: moov->size = swap; Chris@634: swap = bytereverse ('moov'); Chris@634: moov->type = swap; Chris@634: } Chris@634: Chris@634: Chris@636: void writemoovbox(MovieBox moov, int numtrack,int totaltracks, FILE *imf, FILE *text, bool HasTextFile) Chris@634: { Chris@634: int i, j, k, m, t, swap, pos, temp, type; Chris@634: int cnt = 0, cnt2 = 0, d = 0, dat = 0, dat1 = 0, dat2 = 0, dat3 = 0, size = 0; Chris@634: u16 numgroups, numel; Chris@634: Chris@634: Chris@634: //Write movie box// Chris@634: fwrite(&moov.size, sizeof(u32), 1, imf); Chris@634: fwrite(&moov.type, sizeof(u32), 1, imf); Chris@634: //Movie header// Chris@634: fwrite(&moov.MovieHeaderBox, sizeof(moov.MovieHeaderBox), 1, imf); Chris@634: //Track container// Chris@634: for (numtrack = 0; numtrack < totaltracks; numtrack++) { Chris@634: fwrite(&moov.TrackBox[numtrack].size, sizeof(u32), 1, imf); Chris@634: fwrite(&moov.TrackBox[numtrack].type, sizeof(u32), 1, imf); Chris@634: //Trck header// Chris@634: fwrite(&moov.TrackBox[numtrack].TrackHeaderBox, sizeof(moov.TrackBox[numtrack].TrackHeaderBox), 1, imf); Chris@634: //Media Box// Chris@634: fwrite(&moov.TrackBox[numtrack].MediaBox.size, sizeof(u32), 1, imf); Chris@634: fwrite(&moov.TrackBox[numtrack].MediaBox.type, sizeof(u32), 1, imf); Chris@634: //Media Header// Chris@634: fwrite(&moov.TrackBox[numtrack].MediaBox.MediaHeaderBox, Chris@634: sizeof(moov.TrackBox[numtrack].MediaBox.MediaHeaderBox), 1, imf); Chris@634: //Handler Box// Chris@634: fwrite(&moov.TrackBox[numtrack].MediaBox.HandlerBox.size, sizeof(u32), 1, imf); Chris@634: fwrite(&moov.TrackBox[numtrack].MediaBox.HandlerBox.type, sizeof(u32), 1, imf); Chris@634: fwrite(&moov.TrackBox[numtrack].MediaBox.HandlerBox.version, sizeof(u32), 1, imf); Chris@634: fwrite(&moov.TrackBox[numtrack].MediaBox.HandlerBox.pre_defined, sizeof(u32), 1, imf); Chris@634: fwrite(&moov.TrackBox[numtrack].MediaBox.HandlerBox.handler_type, sizeof(u32), 1, imf); Chris@634: fwrite(&moov.TrackBox[numtrack].MediaBox.HandlerBox.reserved[0], sizeof(u32), 1, imf); Chris@634: fwrite(&moov.TrackBox[numtrack].MediaBox.HandlerBox.reserved[1], sizeof(u32), 1, imf); Chris@634: fwrite(&moov.TrackBox[numtrack].MediaBox.HandlerBox.reserved[2], sizeof(u32), 1, imf); Chris@634: fwrite(&moov.TrackBox[numtrack].MediaBox.HandlerBox.data[0], sizeof(unsigned char), 1, imf); Chris@634: fwrite(&moov.TrackBox[numtrack].MediaBox.HandlerBox.data[1], sizeof(unsigned char), 1, imf); Chris@634: fwrite(&moov.TrackBox[numtrack].MediaBox.HandlerBox.data[2], sizeof(unsigned char), 1, imf); Chris@634: fwrite(&moov.TrackBox[numtrack].MediaBox.HandlerBox.data[3], sizeof(unsigned char), 1, imf); Chris@634: fwrite(&moov.TrackBox[numtrack].MediaBox.HandlerBox.data[4], sizeof(unsigned char), 1, imf); Chris@634: //Media inforamtion box// Chris@634: fwrite(&moov.TrackBox[numtrack].MediaBox.MediaInformationBox.size, sizeof(u32), 1, imf); Chris@634: fwrite(&moov.TrackBox[numtrack].MediaBox.MediaInformationBox.type, sizeof(u32), 1, imf); Chris@634: //Sound media header// Chris@634: fwrite(&moov.TrackBox[numtrack].MediaBox.MediaInformationBox.SoundMediaHeaderBox, Chris@634: sizeof(moov.TrackBox[numtrack].MediaBox.MediaInformationBox.SoundMediaHeaderBox), 1, imf); Chris@634: //Data reference// Chris@634: fwrite(&moov.TrackBox[numtrack].MediaBox.MediaInformationBox.DataInformationBox, Chris@634: sizeof(moov.TrackBox[numtrack].MediaBox.MediaInformationBox.DataInformationBox), 1, imf); Chris@634: //Sample table box// Chris@634: fwrite(&moov.TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.size, sizeof(u32), 1, imf); Chris@634: fwrite(&moov.TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.type, sizeof(u32), 1, imf); Chris@634: Chris@634: //Time to sample box// Chris@634: fwrite(&moov.TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox. Chris@634: TimeToSampleBox.size, sizeof(u32), 1, imf); Chris@634: fwrite(&moov.TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox. Chris@634: TimeToSampleBox.type, sizeof(u32), 1, imf); Chris@634: fwrite(&moov.TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox. Chris@634: TimeToSampleBox.version, sizeof(u32), 1, imf); Chris@634: fwrite(&moov.TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox. Chris@634: TimeToSampleBox.entry_count, sizeof(u32), 1, imf); Chris@634: Chris@634: swap = bytereverse(moov.TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox. Chris@634: TimeToSampleBox.entry_count); Chris@634: pos = swap; Chris@634: Chris@634: for (i=0; iIMAF SongEncoderQMULFrank Sinatra2013Electro 0711"; Chris@634: Chris@634: sizeDINF = 8;// + sizeDREF + sizeURL; Chris@634: sizeIINF = 14 + sizeINFE; Chris@634: sizeMETA = 12 + sizeHDLR + sizeDINF + sizeILOC + sizeIINF + sizeXML; Chris@634: Chris@634: meta->size = bytereverse(sizeMETA); Chris@634: meta->type = bytereverse('meta'); Chris@634: meta->version = 0; Chris@634: //HandlerBox Chris@634: meta->theHandler.size = bytereverse(sizeHDLR); Chris@634: meta->theHandler.type = bytereverse('hdlr'); Chris@634: meta->theHandler.version = 0; Chris@634: meta->theHandler.pre_defined = 0; Chris@634: meta->theHandler.handler_type = bytereverse('meta'); Chris@634: meta->theHandler.reserved[0] = 0; Chris@634: meta->theHandler.reserved[1] = 0; Chris@634: meta->theHandler.reserved[2] = 0; Chris@634: meta->theHandler.name[0] = bytereverse('m'); Chris@634: meta->theHandler.name[1] = bytereverse('p'); Chris@634: meta->theHandler.name[2] = bytereverse('7'); Chris@634: meta->theHandler.name[3] = bytereverse('t'); Chris@634: //DataInformationBox Chris@634: meta->file_locations.size = bytereverse(sizeDINF); Chris@634: meta->file_locations.type = bytereverse('dinf'); Chris@634: /* Chris@634: //DataReferenceBox Chris@634: meta->file_locations.DataReferenceBox.size = bytereverse(sizeDREF); Chris@634: meta->file_locations.DataReferenceBox.type = bytereverse('dref'); Chris@634: meta->file_locations.DataReferenceBox.flags = bytereverse(0); // CHECK THIS VALUE Chris@634: meta->file_locations.DataReferenceBox.entry_count = bytereverse(1); Chris@634: //DataEntryUrlBox Chris@634: meta->file_locations.DataReferenceBox.DataEntryUrlBox.size = bytereverse(sizeURL); Chris@634: meta->file_locations.DataReferenceBox.DataEntryUrlBox.type = bytereverse('url '); // 'url ' with blank space Chris@634: meta->file_locations.DataReferenceBox.DataEntryUrlBox.flags = bytereverse(0); // CHECK THIS VALUE Chris@634: */ Chris@634: //item_location Chris@634: meta->item_locations.size = bytereverse(sizeILOC); Chris@634: meta->item_locations.type = bytereverse('iloc'); Chris@634: meta->item_locations.version = 0; Chris@634: meta->item_locations.offset_size = 68; // 0100|0100 offset_size = 4 + lenght_size = 4 Chris@634: //meta->item_locations.lenght_size = 4; //already included Chris@634: meta->item_locations.base_offset_size = 64; // 0100|0000 base_offset_size = 4 + reserved = 0 Chris@634: //meta->item_locations.reserved = 0; //already included Chris@634: meta->item_locations.item_count = bytereverse16(1); Chris@634: meta->item_locations.item_ID = bytereverse16(1); Chris@634: meta->item_locations.data_reference_index = 0; Chris@634: //meta->item_locations.base_offset = bytereverse(); // corresponding to iloc_offset in insertImage function Chris@634: meta->item_locations.extent_count = bytereverse16(1); Chris@634: //meta->item_locations.extent_offset = bytereverse(); // corresponding to iloc_offset in insertImage function Chris@634: //meta->item_locations.extent_length = bytereverse(); // corresponding to imagesize in insertImage function Chris@634: Chris@634: //ItemInfoBox Chris@634: meta->item_infos.size = bytereverse(sizeIINF); Chris@634: meta->item_infos.type = bytereverse('iinf'); Chris@634: meta->item_infos.version = 0; Chris@634: meta->item_infos.entry_count = bytereverse16(1); Chris@634: Chris@634: //info_entry Chris@634: meta->item_infos.info_entry.size = bytereverse(sizeINFE); Chris@634: meta->item_infos.info_entry.type = bytereverse('infe'); Chris@634: meta->item_infos.info_entry.version = 0; Chris@634: meta->item_infos.info_entry.item_ID = bytereverse16(1); Chris@634: meta->item_infos.info_entry.item_protection_index = 0; Chris@634: strcpy(meta->item_infos.info_entry.item_name, name); Chris@634: strcpy(meta->item_infos.info_entry.content_type, type_content); Chris@634: strcpy(meta->item_infos.info_entry.content_encoding, encoding); Chris@634: Chris@634: //XMLBox (MetaData) Chris@634: meta->XMLBox.size = bytereverse(sizeXML); Chris@634: meta->XMLBox.type = bytereverse('xml '); Chris@634: meta->XMLBox.version = 0; Chris@634: strcpy(meta->XMLBox.string, xml); Chris@634: Chris@634: return sizeMETA; Chris@634: } Chris@634: Chris@634: //Read the image's size Chris@634: u32 getImageSize(const char *imagedir){ Chris@634: u32 size; Chris@634: FILE *img; Chris@634: Chris@634: img = fopen(imagedir,"rb"); Chris@634: Chris@634: //Calculate size of the picture Chris@634: fseek(img,0,SEEK_END); Chris@634: size = ftell(img); Chris@634: fclose(img); Chris@634: Chris@634: return size; Chris@634: } Chris@634: //Read the text´s size Chris@634: int getTextSize (FILE *text){ Chris@634: Chris@634: int d=0,sizetext=0,dat=0,dat1=0,dat2=0,dat3=0; Chris@634: Chris@634: //TEXT-FILE Chris@634: //Find mdat in text file in order to know the size of the text file Chris@634: d=0; Chris@634: while(d==0){ Chris@634: Chris@634: fread (&dat,sizeof(unsigned char),1,text); //read a byte and saves it in dat Chris@634: fread (&dat1,sizeof(unsigned char),1,text); Chris@634: fread (&dat2,sizeof(unsigned char),1,text); Chris@634: fread (&dat3,sizeof(unsigned char),1,text); Chris@634: fseek(text,-3,SEEK_CUR); Chris@634: Chris@634: if(dat == 0x6D && dat1 == 0x64 && dat2 == 0x61 && dat3 == 0x74){ // 6D646174 = mdat Chris@634: d=1; Chris@634: } Chris@634: Chris@634: } //close while Chris@634: Chris@634: fseek (text,-5,SEEK_CUR);//positionate the pointer at the first byte of size Chris@634: fread (&dat,sizeof(unsigned char),1,text); //first byte of size Chris@634: fread (&dat1,sizeof(unsigned char),1,text);//second byte of size Chris@634: fread (&dat2,sizeof(unsigned char),1,text);//third byte of size Chris@634: fread (&dat3,sizeof(unsigned char),1,text);//fourth byte of size Chris@634: Chris@634: sizetext = (dat<<24) | (dat1<<16) | (dat2<<8) | (dat3); Chris@634: sizetext = sizetext-8-16; //4 bytes of size and 4 bytes of type and 16 bytes of padding Chris@634: Chris@634: fseek (text,20,SEEK_CUR);//Advance 20 bytes, because the pointer must advance 20 bytes to read the size of the first string.This is because of the way that Quicktime creates the 3gp Chris@634: Chris@634: return sizetext; Chris@634: Chris@634: Chris@634: } Chris@634: Chris@634: //Read the JPEG file Chris@634: Chris@634: void insertImage (MetaBox *meta, FILE **imf, u32 imagesize, const char *imagedir) { Chris@634: Chris@634: FILE *img; Chris@634: u64 iloc_offset = 0; Chris@634: unsigned char *imgbuffer; Chris@634: Chris@634: img = fopen(imagedir,"rb"); Chris@634: Chris@634: // Binary reading Chris@634: fseek(img,0,SEEK_SET); Chris@634: imgbuffer= (unsigned char*)malloc(sizeof(unsigned char)*imagesize); Chris@634: fread(imgbuffer, 1, imagesize, img); Chris@634: fclose(img); Chris@634: Chris@634: // Find position in the IMAF file and write the image Chris@634: iloc_offset = ftell(*imf); Chris@634: fwrite(imgbuffer,1,imagesize, *imf); Chris@634: Chris@634: // Set image size and offset values Chris@634: meta->item_locations.base_offset = bytereverse(iloc_offset); Chris@634: meta->item_locations.extent_length = bytereverse(imagesize); Chris@634: meta->item_locations.extent_offset = bytereverse(iloc_offset); Chris@634: Chris@634: } Chris@634: Chris@634: Chris@634: void writemetabox(MetaBox meta, FILE *imf) { Chris@634: Chris@634: int i=0; Chris@634: Chris@634: //MetaBox Chris@634: fwrite(&meta.size, sizeof(u32), 1, imf); Chris@634: fwrite(&meta.type, sizeof(u32), 1, imf); Chris@634: fwrite(&meta.version, sizeof(u32), 1, imf); Chris@634: //Handler Chris@634: fwrite(&meta.theHandler.size, sizeof(u32), 1, imf); Chris@634: fwrite(&meta.theHandler.type, sizeof(u32), 1, imf); Chris@634: fwrite(&meta.theHandler.version, sizeof(u32), 1, imf); Chris@634: fwrite(&meta.theHandler.pre_defined, sizeof(u32), 1, imf); Chris@634: fwrite(&meta.theHandler.handler_type, sizeof(u32), 1, imf); Chris@634: fwrite(&meta.theHandler.reserved[0], sizeof(u32), 1, imf); Chris@634: fwrite(&meta.theHandler.reserved[1], sizeof(u32), 1, imf); Chris@634: fwrite(&meta.theHandler.reserved[2], sizeof(u32), 1, imf); Chris@634: fwrite(&meta.theHandler.name[0], sizeof(unsigned char), 1, imf); Chris@634: fwrite(&meta.theHandler.name[1], sizeof(unsigned char), 1, imf); Chris@634: fwrite(&meta.theHandler.name[2], sizeof(unsigned char), 1, imf); Chris@634: fwrite(&meta.theHandler.name[3], sizeof(unsigned char), 1, imf); Chris@634: //Data Information Box Chris@634: fwrite(&meta.file_locations.size, sizeof(u32), 1, imf); Chris@634: fwrite(&meta.file_locations.type, sizeof(u32), 1, imf); Chris@634: /* Chris@634: //Data Reference Chris@634: fwrite(&meta.file_locations.DataReferenceBox.size, sizeof(u32), 1, imf); Chris@634: fwrite(&meta.file_locations.DataReferenceBox.type, sizeof(u32), 1, imf); Chris@634: fwrite(&meta.file_locations.DataReferenceBox.flags, sizeof(u32), 1, imf); Chris@634: fwrite(&meta.file_locations.DataReferenceBox.entry_count, sizeof(u32), 1, imf); Chris@634: Chris@634: fwrite(&meta.file_locations.DataReferenceBox.DataEntryUrlBox.size, sizeof(u32), 1, imf); Chris@634: fwrite(&meta.file_locations.DataReferenceBox.DataEntryUrlBox.type, sizeof(u32), 1, imf); Chris@634: fwrite(&meta.file_locations.DataReferenceBox.DataEntryUrlBox.flags, sizeof(u32), 1, imf); Chris@634: */ Chris@634: //Item Location Box Chris@634: fwrite(&meta.item_locations.size, sizeof(u32), 1, imf); Chris@634: fwrite(&meta.item_locations.type, sizeof(u32), 1, imf); Chris@634: fwrite(&meta.item_locations.version, sizeof(u32), 1, imf); Chris@634: fwrite(&meta.item_locations.offset_size, sizeof(unsigned char), 1, imf); Chris@634: //fwrite(&meta.item_locations.lenght_size, sizeof(unsigned char), 1, imf); Chris@634: fwrite(&meta.item_locations.base_offset_size, sizeof(unsigned char), 1, imf); Chris@634: //fwrite(&meta.item_locations.reserved, sizeof(unsigned char), 1, imf); Chris@634: fwrite(&meta.item_locations.item_count, sizeof(u16), 1, imf); Chris@634: fwrite(&meta.item_locations.item_ID, sizeof(u16), 1, imf); Chris@634: fwrite(&meta.item_locations.data_reference_index, sizeof(u16), 1, imf); Chris@634: fwrite(&meta.item_locations.base_offset, sizeof(u32), 1, imf); Chris@634: fwrite(&meta.item_locations.extent_count, sizeof(u16), 1, imf); Chris@634: fwrite(&meta.item_locations.extent_offset, sizeof(u32), 1, imf); Chris@634: fwrite(&meta.item_locations.extent_length, sizeof(u32), 1, imf); Chris@634: //Item Info Chris@634: fwrite(&meta.item_infos.size, sizeof(u32), 1, imf); Chris@634: fwrite(&meta.item_infos.type, sizeof(u32), 1, imf); Chris@634: fwrite(&meta.item_infos.version, sizeof(u32), 1, imf); Chris@634: fwrite(&meta.item_infos.entry_count, sizeof(u16), 1, imf); Chris@634: //Info Entry Chris@634: fwrite(&meta.item_infos.info_entry.size, sizeof(u32), 1, imf); Chris@634: fwrite(&meta.item_infos.info_entry.type, sizeof(u32), 1, imf); Chris@634: fwrite(&meta.item_infos.info_entry.version, sizeof(u32), 1, imf); Chris@634: fwrite(&meta.item_infos.info_entry.item_ID, sizeof(u16), 1, imf); Chris@634: fwrite(&meta.item_infos.info_entry.item_protection_index, sizeof(u16), 1, imf); Chris@634: for (i=0; i<6; i++){ Chris@634: fwrite(&meta.item_infos.info_entry.item_name[i], sizeof(char), 1, imf); Chris@634: } Chris@634: for (i=0; i<18; i++){ Chris@634: fwrite(&meta.item_infos.info_entry.content_type[i], sizeof(char), 1, imf); Chris@634: } Chris@634: for (i=0; i<4; i++){ Chris@634: fwrite(&meta.item_infos.info_entry.content_encoding[i], sizeof(char), 1, imf); Chris@634: } Chris@634: //XML for metadata Chris@634: fwrite(&meta.XMLBox.size, sizeof(u32), 1, imf); Chris@634: fwrite(&meta.XMLBox.type, sizeof(u32), 1, imf); Chris@634: fwrite(&meta.XMLBox.version, sizeof(u32), 1, imf); Chris@634: for(i=0; i<2000; i++){ Chris@634: fwrite(&meta.XMLBox.string[i], sizeof(char), 1, imf); Chris@634: } Chris@634: Chris@634: } Chris@634: Chris@634: //TIMED-TEXT's funcionts Chris@634: int trackstructure_text (MovieBox *moov, int numtrack, int clock, Chris@634: int durationTrack, int sizemdat, const char *textfile,FILE *text,int totaltracks ) { // creates the text trak structure Chris@634: int swap; Chris@634: u32 sizeURL; Chris@634: u32 sizeDREF; Chris@634: u32 sizeDINF; Chris@634: u32 sizeSMHD; Chris@634: u32 sizeMINF; Chris@634: u32 sizeHDLR; Chris@634: u32 sizeMDHD; Chris@634: u32 sizeMDIA; Chris@634: u32 sizeTKHD; Chris@634: u32 sizeTRAK; Chris@634: Chris@634: Chris@634: //Sample Table Box Chris@634: int sizeSTBL = 0; Chris@634: Chris@634: sizeSTBL = samplecontainer_text(moov, numtrack,sizemdat, textfile,totaltracks); Chris@634: Chris@634: //Data Entry Url Box Chris@634: sizeURL = 12; Chris@634: swap = bytereverse(sizeURL); Chris@634: moov->TrackBox[numtrack].MediaBox.MediaInformationBox.DataInformationBox. Chris@634: DataReferenceBox.DataEntryUrlBox.size = swap; Chris@634: swap = bytereverse('url '); Chris@634: moov->TrackBox[numtrack].MediaBox.MediaInformationBox.DataInformationBox. Chris@634: DataReferenceBox.DataEntryUrlBox.type = swap; Chris@634: swap = bytereverse(1); Chris@634: moov->TrackBox[numtrack].MediaBox.MediaInformationBox.DataInformationBox. Chris@634: DataReferenceBox.DataEntryUrlBox.flags = swap; // =1 Track in same file as movie atom. Chris@634: Chris@634: //Data Reference Chris@634: sizeDREF = sizeURL+ 16; Chris@634: swap = bytereverse(sizeDREF); Chris@634: moov->TrackBox[numtrack].MediaBox.MediaInformationBox.DataInformationBox. Chris@634: DataReferenceBox.size = swap; Chris@634: swap = bytereverse('dref'); Chris@634: moov->TrackBox[numtrack].MediaBox.MediaInformationBox.DataInformationBox. Chris@634: DataReferenceBox.type = swap; Chris@634: moov->TrackBox[numtrack].MediaBox.MediaInformationBox.DataInformationBox. Chris@634: DataReferenceBox.flags = 0; Chris@634: swap = bytereverse(1); Chris@634: moov->TrackBox[numtrack].MediaBox.MediaInformationBox.DataInformationBox. Chris@634: DataReferenceBox.entry_count = swap; Chris@634: Chris@634: //Data information Box// Chris@634: sizeDINF = sizeDREF + 8; Chris@634: swap = bytereverse(sizeDINF); Chris@634: moov->TrackBox[numtrack].MediaBox.MediaInformationBox.DataInformationBox.size = swap; Chris@634: swap = bytereverse('dinf'); Chris@634: moov->TrackBox[numtrack].MediaBox.MediaInformationBox.DataInformationBox.type = swap; Chris@634: Chris@634: Chris@634: //Null Media Header Box Chris@634: swap = bytereverse(12); Chris@634: moov->TrackBox[numtrack].MediaBox.MediaInformationBox.NullMediaHeaderBox.size = swap ; Chris@634: swap = bytereverse ('nmhd'); Chris@634: moov->TrackBox[numtrack].MediaBox.MediaInformationBox.NullMediaHeaderBox.type = swap; Chris@634: moov->TrackBox[numtrack].MediaBox.MediaInformationBox.NullMediaHeaderBox.flags = 0; Chris@634: Chris@634: //Media Information Box// Chris@634: sizeMINF = sizeDINF + sizeSTBL + 8 + 12; Chris@634: swap = bytereverse(sizeMINF); Chris@634: moov->TrackBox[numtrack].MediaBox.MediaInformationBox.size = swap; Chris@634: swap = bytereverse('minf'); Chris@634: moov->TrackBox[numtrack].MediaBox.MediaInformationBox.type = swap; Chris@634: Chris@634: //Handler Box// Chris@634: sizeHDLR = 37; Chris@634: swap = bytereverse(sizeHDLR); Chris@634: moov->TrackBox[numtrack].MediaBox.HandlerBox.size = swap; Chris@634: swap = bytereverse('hdlr'); Chris@634: moov->TrackBox[numtrack].MediaBox.HandlerBox.type = swap; Chris@634: moov->TrackBox[numtrack].MediaBox.HandlerBox.version = 0; Chris@634: moov->TrackBox[numtrack].MediaBox.HandlerBox.pre_defined = 0; Chris@634: swap = bytereverse('text'); Chris@634: moov->TrackBox[numtrack].MediaBox.HandlerBox.handler_type = swap; Chris@634: moov->TrackBox[numtrack].MediaBox.HandlerBox.reserved[0] = 0; Chris@634: moov->TrackBox[numtrack].MediaBox.HandlerBox.reserved[1] = 0; Chris@634: moov->TrackBox[numtrack].MediaBox.HandlerBox.reserved[2] = 0; Chris@634: moov->TrackBox[numtrack].MediaBox.HandlerBox.data[0] = 't'; Chris@634: moov->TrackBox[numtrack].MediaBox.HandlerBox.data[1] = 'e'; Chris@634: moov->TrackBox[numtrack].MediaBox.HandlerBox.data[2] = 'x'; Chris@634: moov->TrackBox[numtrack].MediaBox.HandlerBox.data[3] = 't'; Chris@634: moov->TrackBox[numtrack].MediaBox.HandlerBox.data[4] = '\0'; Chris@634: Chris@634: //Media Header Box// Chris@634: sizeMDHD = 32; Chris@634: swap = bytereverse(sizeMDHD); Chris@634: moov->TrackBox[numtrack].MediaBox.MediaHeaderBox.size = swap; Chris@634: swap = bytereverse('mdhd'); Chris@634: moov->TrackBox[numtrack].MediaBox.MediaHeaderBox.type = swap; Chris@634: moov->TrackBox[numtrack].MediaBox.MediaHeaderBox.version = 0; Chris@634: swap = bytereverse(clock); Chris@634: moov->TrackBox[numtrack].MediaBox.MediaHeaderBox.creation_time = swap; Chris@634: moov->TrackBox[numtrack].MediaBox.MediaHeaderBox.modification_time = swap; Chris@634: swap = bytereverse(1000); Chris@634: moov->TrackBox[numtrack].MediaBox.MediaHeaderBox.timescale = swap; Chris@634: swap = bytereverse(durationTrack); Chris@634: moov->TrackBox[numtrack].MediaBox.MediaHeaderBox.duration = swap; Chris@634: moov->TrackBox[numtrack].MediaBox.MediaHeaderBox.language = 0xC455; Chris@634: moov->TrackBox[numtrack].MediaBox.MediaHeaderBox.pre_defined = 0; Chris@634: Chris@634: //Media Box// Chris@634: sizeMDIA = sizeMDHD + sizeHDLR + sizeMINF + 8; Chris@634: swap = bytereverse(sizeMDIA); Chris@634: moov->TrackBox[numtrack].MediaBox.size = swap; Chris@634: swap = bytereverse('mdia'); Chris@634: moov->TrackBox[numtrack].MediaBox.type = swap; Chris@634: Chris@634: //Track Header// Chris@634: sizeTKHD = 92; Chris@634: swap = bytereverse (sizeTKHD); Chris@634: moov->TrackBox[numtrack].TrackHeaderBox.size = swap; Chris@634: swap = bytereverse ('tkhd'); Chris@634: moov->TrackBox[numtrack].TrackHeaderBox.type = swap ; Chris@634: swap = bytereverse (0x00000007); Chris@634: moov->TrackBox[numtrack].TrackHeaderBox.version = swap; Chris@634: swap = bytereverse (clock); Chris@634: moov->TrackBox[numtrack].TrackHeaderBox.creation_time = swap; Chris@634: moov->TrackBox[numtrack].TrackHeaderBox.modification_time = swap; Chris@634: moov->TrackBox[numtrack].TrackHeaderBox.track_ID = bytereverse(12345678); Chris@634: moov->TrackBox[numtrack].TrackHeaderBox.reserved = 0; Chris@634: swap = bytereverse (durationTrack); Chris@634: moov->TrackBox[numtrack].TrackHeaderBox.duration = swap; Chris@634: moov->TrackBox[numtrack].TrackHeaderBox.reserved2[0] = 0; Chris@634: moov->TrackBox[numtrack].TrackHeaderBox.reserved2[1] = 0; Chris@634: moov->TrackBox[numtrack].TrackHeaderBox.layer = 0; Chris@634: moov->TrackBox[numtrack].TrackHeaderBox.alternate_group = 0; Chris@634: moov->TrackBox[numtrack].TrackHeaderBox.volume = 0; Chris@634: moov->TrackBox[numtrack].TrackHeaderBox.reserved3 = 0; Chris@634: swap = bytereverse (0x00010000); Chris@634: moov->TrackBox[numtrack].TrackHeaderBox.matrix[0] = swap; Chris@634: moov->TrackBox[numtrack].TrackHeaderBox.matrix[1] = 0; Chris@634: moov->TrackBox[numtrack].TrackHeaderBox.matrix[2] = 0; Chris@634: moov->TrackBox[numtrack].TrackHeaderBox.matrix[3] = 0; Chris@634: moov->TrackBox[numtrack].TrackHeaderBox.matrix[4] = swap; Chris@634: moov->TrackBox[numtrack].TrackHeaderBox.matrix[5] = 0; Chris@634: moov->TrackBox[numtrack].TrackHeaderBox.matrix[6] = 0; Chris@634: moov->TrackBox[numtrack].TrackHeaderBox.matrix[7] = 0; Chris@634: swap = bytereverse(0x40000000); Chris@634: moov->TrackBox[numtrack].TrackHeaderBox.matrix[8] = swap; Chris@634: moov->TrackBox[numtrack].TrackHeaderBox.width =0; Chris@634: moov->TrackBox[numtrack].TrackHeaderBox.height = 0; Chris@634: Chris@634: //Track container Chris@634: sizeTRAK = sizeTKHD + sizeMDIA + 8; Chris@634: swap = bytereverse (sizeTRAK); // Size of one track Chris@634: moov->TrackBox[numtrack].size = swap; Chris@634: swap = bytereverse ('trak'); Chris@634: moov->TrackBox[numtrack].type = swap; Chris@634: Chris@634: return sizeTRAK; Chris@634: } Chris@634: Chris@634: Chris@634: int aux (FILE *text,int num,int num1,int num2,int num3,int *sal) { Chris@634: int dat=0,dat1=0,dat2=0,dat3=0,size=0,d=0,cnt=0,i=0; Chris@634: fseek(text,0,SEEK_SET); Chris@634: d=0; Chris@634: while(d==0){ Chris@634: Chris@634: fread (&dat,sizeof(unsigned char),1,text); Chris@634: cnt++; Chris@634: fread (&dat1,sizeof(unsigned char),1,text); Chris@634: cnt++; Chris@634: fread (&dat2,sizeof(unsigned char),1,text); Chris@634: cnt++; Chris@634: fread (&dat3,sizeof(unsigned char),1,text); Chris@634: cnt++; Chris@634: fseek(text, -3 ,SEEK_CUR); Chris@634: if(dat == num && dat1 == num1 && dat2 == num2 && dat3 == num3){ Chris@634: Chris@634: d=1; Chris@634: } Chris@634: Chris@634: else{ Chris@634: Chris@634: cnt=cnt-3; Chris@634: } Chris@634: Chris@634: } //end while Chris@634: Chris@634: Chris@634: fseek (text,0,SEEK_SET);//positionate the pointer at first Chris@634: Chris@634: cnt=cnt-7;//size is located 7 bytes before type Chris@634: for (d=1;d<=cnt;d++){ Chris@634: Chris@634: fread (&dat,sizeof(unsigned char),1,text); Chris@634: Chris@634: } Chris@634: fread (&dat1,sizeof(unsigned char),1,text); Chris@634: fread (&dat2,sizeof(unsigned char),1,text); Chris@634: fread (&dat3,sizeof(unsigned char),1,text); Chris@634: Chris@634: size = (dat<<24) | (dat1<<16) | (dat2<<8) | (dat3); Chris@634: Chris@634: for (i=1;i<=8;i++) { //advance sample_size Chris@634: fread (&dat,sizeof(unsigned char),1,text); Chris@634: } Chris@634: fread(&dat,1,1,text); Chris@634: fread(&dat1,1,1,text); Chris@634: fread(&dat2,1,1,text); Chris@634: fread(&dat3,1,1,text); Chris@634: Chris@634: *sal = (dat<<24) | (dat1<<16) | (dat2<<8) | (dat3); Chris@634: Chris@634: Chris@634: return size; Chris@634: Chris@634: } Chris@634: Chris@634: int samplecontainer_text(MovieBox *moov, int numtrack, int sizemdat,const char *textfiles,int totaltracks) { Chris@634: Chris@634: u32 sizeSTSD, sizeSTSZ, swap,i=0; Chris@634: u32 sizeSTTS; Chris@634: u32 sizeSTSC = 0; Chris@634: u32 sizeSTCO = 0; Chris@634: u32 sizeSTBL=0; Chris@634: int dat=0,dat1=0,dat2=0,dat3=0,sal=0, samplecount=0; Chris@634: Chris@634: //Sample Description Box// Chris@634: FILE *text; Chris@634: Chris@634: text=fopen ( textfiles,"rb"); Chris@634: fseek(text,0,SEEK_CUR); Chris@634: Chris@634: //stsd Chris@634: Chris@634: sizeSTSD =16+64; Chris@634: swap = bytereverse(sizeSTSD); Chris@634: moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox. Chris@634: SampleDescriptionBox.size = swap; Chris@634: swap = bytereverse('stsd'); Chris@634: moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox. Chris@634: SampleDescriptionBox.type = swap; Chris@634: moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox. Chris@634: SampleDescriptionBox.version = 0; Chris@634: swap = bytereverse(1); Chris@634: moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox. Chris@634: SampleDescriptionBox.entry_count = swap; Chris@634: Chris@634: Chris@634: //tx3g Chris@634: swap = bytereverse(64); Chris@634: moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.SampleDescriptionBox.TextSampleEntry.size=swap; Chris@634: swap = bytereverse('tx3g'); Chris@634: moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.SampleDescriptionBox.TextSampleEntry.type=swap; Chris@634: moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.SampleDescriptionBox.TextSampleEntry.a=0; Chris@634: swap=bytereverse(1); Chris@634: moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.SampleDescriptionBox.TextSampleEntry.b=swap; Chris@634: swap = bytereverse(0x00000800);//continuous karaoke Chris@634: moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.SampleDescriptionBox.TextSampleEntry.displayFlags = swap; Chris@634: moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.SampleDescriptionBox.TextSampleEntry.horizontaljustification=0x01; Chris@634: moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.SampleDescriptionBox.TextSampleEntry.verticaljustification=0x01; Chris@634: moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.SampleDescriptionBox.TextSampleEntry.backgroundcolorrgba[0]= 0x00; Chris@634: moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.SampleDescriptionBox.TextSampleEntry.backgroundcolorrgba[1]= 0x00; Chris@634: moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.SampleDescriptionBox.TextSampleEntry.backgroundcolorrgba[2]= 0x00; Chris@634: moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.SampleDescriptionBox.TextSampleEntry.backgroundcolorrgba[3]= 0xFF; Chris@634: moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.SampleDescriptionBox.TextSampleEntry.top=0; Chris@634: moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.SampleDescriptionBox.TextSampleEntry.left=0; Chris@634: moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.SampleDescriptionBox.TextSampleEntry.bottom=0x6400; Chris@634: moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.SampleDescriptionBox.TextSampleEntry.right=0x2C01; Chris@634: moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.SampleDescriptionBox.TextSampleEntry.startChar=0; Chris@634: moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.SampleDescriptionBox.TextSampleEntry.endChar=0; Chris@634: moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.SampleDescriptionBox.TextSampleEntry.fontID=0x0100; Chris@634: moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.SampleDescriptionBox.TextSampleEntry.facestyleflags=0x01; Chris@634: moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.SampleDescriptionBox.TextSampleEntry.fontsize=0x0A; Chris@634: moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.SampleDescriptionBox.TextSampleEntry.textcolorrgba[0]=0xFF; Chris@634: moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.SampleDescriptionBox.TextSampleEntry.textcolorrgba[1]=0xFF; Chris@634: moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.SampleDescriptionBox.TextSampleEntry.textcolorrgba[2]=0xFF; Chris@634: moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.SampleDescriptionBox.TextSampleEntry.textcolorrgba[3]=0xFF; Chris@634: moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.SampleDescriptionBox.TextSampleEntry.FontTableBox.size =0x12000000; Chris@634: swap =bytereverse('ftab'); Chris@634: moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.SampleDescriptionBox.TextSampleEntry.FontTableBox.type =swap; Chris@634: moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.SampleDescriptionBox.TextSampleEntry.FontTableBox.entrycount=0x0100; Chris@634: moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.SampleDescriptionBox.TextSampleEntry.FontTableBox.fontID =0x0200; Chris@634: moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.SampleDescriptionBox.TextSampleEntry.FontTableBox.fontnamelenght =0x05; Chris@634: moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.SampleDescriptionBox.TextSampleEntry.FontTableBox.font[0] =0x53; Chris@634: moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.SampleDescriptionBox.TextSampleEntry.FontTableBox.font[1] =0x65; Chris@634: moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.SampleDescriptionBox.TextSampleEntry.FontTableBox.font[2] =0x72; Chris@634: moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.SampleDescriptionBox.TextSampleEntry.FontTableBox.font[3] =0x69; Chris@634: moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.SampleDescriptionBox.TextSampleEntry.FontTableBox.font[4] =0x66; Chris@634: Chris@634: //stsz Chris@634: Chris@634: sizeSTSZ=aux(text,0x73,0x74,0x73,0x7A,&sal)+4; // the function aux looks for the box stsz in 3gp file and returns the size Chris@634: swap = bytereverse('stsz'); Chris@634: moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox. Chris@634: SampleSizeBox.type = swap; Chris@634: moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox. Chris@634: SampleSizeBox.version = 0; Chris@634: moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.SampleSizeBox.sample_size=0; Chris@634: Chris@634: fseek(text,0,SEEK_CUR); Chris@634: Chris@634: fread(&dat,1,1,text); //read sample_count Chris@634: fread(&dat1,1,1,text); Chris@634: fread(&dat2,1,1,text); Chris@634: fread(&dat3,1,1,text); Chris@634: Chris@634: samplecount = (dat<<24) | (dat1<<16) | (dat2<<8) | (dat3); Chris@634: Chris@634: swap= bytereverse(samplecount); Chris@634: moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.SampleSizeBox.sample_count=swap; Chris@634: Chris@634: for (i=1;i<=samplecount;i++){ Chris@634: Chris@634: swap = bytereverse(size_phrase[i-1]); Chris@634: moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.SampleSizeBox.entry_size[i-1]=swap; Chris@634: } Chris@634: Chris@634: sizeSTSZ= 20 + bytereverse(moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.SampleSizeBox.sample_count)*4; Chris@634: swap = bytereverse(sizeSTSZ); Chris@634: moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox. Chris@634: SampleSizeBox.size = swap; Chris@634: Chris@634: Chris@634: //Time To Sample Box// Chris@634: Chris@634: fseek (text,0,SEEK_SET);//positionate the pointer at first Chris@634: sizeSTTS=aux(text,0x73,0x74,0x74,0x73,&sal); Chris@634: Chris@634: swap = bytereverse(sizeSTTS); Chris@634: moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox. Chris@634: TimeToSampleBox.size = swap; Chris@634: swap = bytereverse('stts'); Chris@634: moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox. Chris@634: TimeToSampleBox.type = swap; Chris@634: moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox. Chris@634: TimeToSampleBox.version = 0; Chris@634: swap = bytereverse(sal); Chris@634: moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.TimeToSampleBox.entry_count=swap; Chris@634: fseek(text,0,SEEK_CUR); Chris@634: for(i=1;i<=sal;i++){ Chris@634: Chris@634: fread(&dat,1,1,text);//read count Chris@634: fread(&dat1,1,1,text); Chris@634: fread(&dat2,1,1,text); Chris@634: fread(&dat3,1,1,text); Chris@634: Chris@634: dat = (dat<<24) | (dat1<<16) | (dat2<<8) | (dat3); Chris@634: Chris@634: Chris@634: swap = bytereverse(dat); Chris@634: moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.TimeToSampleBox.sample_count[i-1]=swap; Chris@634: fread(&dat,1,1,text);//read delta Chris@634: Chris@634: fread(&dat1,1,1,text); Chris@634: Chris@634: fread(&dat2,1,1,text); Chris@634: Chris@634: fread(&dat3,1,1,text); Chris@634: Chris@634: Chris@634: dat = (dat<<24) | (dat1<<16) | (dat2<<8) | (dat3); Chris@634: Chris@634: swap = bytereverse(dat/0.6);// the input text file has time_scale = 600 but the audio has time scale=1000 Chris@634: moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.TimeToSampleBox.sample_delta[i-1]=swap; Chris@634: } Chris@634: Chris@634: //Sample To Chunk// Chris@634: Chris@634: dat=0; Chris@634: fseek (text,0,SEEK_SET);//positionate the pointer at first Chris@634: sizeSTSC = aux(text,0x73,0x74,0x73,0x63,&sal); Chris@634: dat=sal; Chris@634: swap = bytereverse(sizeSTSC); Chris@634: moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox. Chris@634: SampleToChunk.size = swap; Chris@634: swap = bytereverse('stsc'); Chris@634: moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox. Chris@634: SampleToChunk.type = swap; Chris@634: moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox. Chris@634: SampleToChunk.version = 0; Chris@634: moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox. Chris@634: SampleToChunk.entry_count = bytereverse(1); Chris@634: moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.SampleToChunk.first_chunk=bytereverse(1); Chris@634: moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.SampleToChunk.samples_per_chunk=moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.SampleSizeBox.sample_count; Chris@634: moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.SampleToChunk.sample_description_index = bytereverse(1); Chris@634: Chris@634: //Chunk Offset Box// Chris@634: sizeSTCO=24; Chris@634: swap = bytereverse(sizeSTCO); Chris@634: moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox. Chris@634: ChunkOffsetBox.size = swap; Chris@634: swap = bytereverse('co64'); Chris@634: moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox. Chris@634: ChunkOffsetBox.type = swap; Chris@634: moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox. Chris@634: ChunkOffsetBox.version = 0; Chris@634: moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox. Chris@634: ChunkOffsetBox.entry_count = bytereverse(1); Chris@634: dat=32+sizemdat*totaltracks; Chris@634: swap=bytereverse(dat); Chris@634: moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox. Chris@634: ChunkOffsetBox.chunk_offset [0]= swap; Chris@634: Chris@634: //Sample Table Box // Chris@634: sizeSTBL = 8 + sizeSTSD + sizeSTSZ + sizeSTSC + sizeSTCO + sizeSTTS; Chris@634: swap = bytereverse(sizeSTBL); Chris@634: moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.size = swap; Chris@634: swap = bytereverse('stbl'); Chris@634: moov->TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox.type =swap; Chris@634: return sizeSTBL; Chris@634: } Chris@634: Chris@634: //AUX Functions for endianness Chris@634: Chris@634: int bytereverse(int num) { Chris@634: int swapped; Chris@634: swapped = ((num>>24)&0xff) | // move byte 3 to byte 0 Chris@634: ((num<<8)&0xff0000) | // move byte 1 to byte 2 Chris@634: ((num>>8)&0xff00) | // move byte 2 to byte 1 Chris@634: ((num<<24)&0xff000000); // byte 0 to byte 3 Chris@634: return swapped; Chris@634: } Chris@634: int bytereverse16(int num) { Chris@634: int swapped; Chris@634: swapped = ( ((num<<8)&0xff00) | // move byte 1 to byte 2 Chris@634: ((num>>8)&0x00ff) ); // byte 2 to byte 1 Chris@634: return swapped; Chris@634: }