Mercurial > hg > sonic-visualiser
comparison main/IMAFencoder.c @ 636:767789a78984 imaf_enc
Fix from Jesus Corral Garcia (for crashes etc)
author | Chris Cannam |
---|---|
date | Mon, 04 Nov 2013 17:17:09 +0000 |
parents | ba338234c001 |
children |
comparison
equal
deleted
inserted
replaced
635:8e64cebd38c0 | 636:767789a78984 |
---|---|
34 int samplecontainer(MovieBox *moov, int, int, const char *name); | 34 int samplecontainer(MovieBox *moov, int, int, const char *name); |
35 int sampledescription(MovieBox *moov, int); | 35 int sampledescription(MovieBox *moov, int); |
36 int presetcontainer(MovieBox *moov, int, int *vol_values, int type, int fade_in); | 36 int presetcontainer(MovieBox *moov, int, int *vol_values, int type, int fade_in); |
37 int rulescontainer(MovieBox *moov, int SelRuleType, int SelRule_PAR1, int SelRule_PAR2, | 37 int rulescontainer(MovieBox *moov, int SelRuleType, int SelRule_PAR1, int SelRule_PAR2, |
38 int MixRuleType, int MixRule_PAR1, int MixRule_PAR2, int MixRule_PAR3, int MixRule_PAR4); | 38 int MixRuleType, int MixRule_PAR1, int MixRule_PAR2, int MixRule_PAR3, int MixRule_PAR4); |
39 void writemoovbox(MovieBox moov, int numtrack,int totaltracks, FILE *imf, FILE *text); | 39 void writemoovbox(MovieBox moov, int numtrack,int totaltracks, FILE *imf, FILE *text, bool HasTextFile); |
40 int readTrack(MovieBox *moov, int,const char *name); | 40 int readTrack(MovieBox *moov, int,const char *name); |
41 | 41 |
42 // Timed Text Functions | 42 // Timed Text Functions |
43 int trackstructure_text (MovieBox *moov, int numtrack, int clock, int durationTrack, int sizemdat,const char *textfile,FILE *text,int totaltracks); | 43 int trackstructure_text (MovieBox *moov, int numtrack, int clock, int durationTrack, int sizemdat,const char *textfile,FILE *text,int totaltracks); |
44 int samplecontainer_text(MovieBox *moov, int numtrack, int sizemdat, const char *textfiles,int totaltracks); | 44 int samplecontainer_text(MovieBox *moov, int numtrack, int sizemdat, const char *textfiles,int totaltracks); |
79 file_created->show(); | 79 file_created->show(); |
80 } | 80 } |
81 | 81 |
82 int mainIMAFencoder (int totaltracks, QString files_path[maxtracks],QString outimaf, | 82 int mainIMAFencoder (int totaltracks, QString files_path[maxtracks],QString outimaf, |
83 QString picturefile, QString textfile, int vol_values[maxtracks], bool HasImageFile, | 83 QString picturefile, QString textfile, int vol_values[maxtracks], bool HasImageFile, |
84 int SelRuleType, int SelRule_PAR1, int SelRule_PAR2, | 84 bool HasTextFile, int SelRuleType, int SelRule_PAR1, int SelRule_PAR2, |
85 int MixRuleType, int MixRule_PAR1, int MixRule_PAR2, int MixRule_PAR3, int MixRule_PAR4, | 85 int MixRuleType, int MixRule_PAR1, int MixRule_PAR2, int MixRule_PAR3, int MixRule_PAR4, |
86 int group_tracks[maxtracks], int group_volume, QString group_name, QString group_description, | 86 int group_tracks[maxtracks], int group_volume, QString group_name, QString group_description, |
87 int pres_type, int fade_in) | 87 int pres_type, int fade_in) |
88 { | 88 { |
89 //Variables | 89 //Variables |
122 } else { //if there is no image, the size is 0 | 122 } else { //if there is no image, the size is 0 |
123 imagesize = 0; | 123 imagesize = 0; |
124 } | 124 } |
125 | 125 |
126 //INPUT: Timed-Text | 126 //INPUT: Timed-Text |
127 c_str2= textfile.toStdString().c_str(); //convert Qstring to const char | 127 if (HasTextFile){ |
128 text = fopen(c_str2, "rb"); | 128 c_str2= textfile.toStdString().c_str(); //convert Qstring to const char |
129 sizetext= getTextSize (text); //calculate the size of the text | 129 text = fopen(c_str2, "rb"); |
130 if((text)==NULL) { | 130 sizetext= getTextSize (text); //calculate the size of the text |
131 // do something | 131 } |
132 } | 132 else{ |
133 | 133 sizetext = 0; |
134 } | |
134 //Create OUTPUT file (.ima) | 135 //Create OUTPUT file (.ima) |
135 imf = fopen (outimaf.toStdString().c_str(),"wb"); | 136 imf = fopen (outimaf.toStdString().c_str(),"wb"); |
136 | 137 |
137 //Define the File Type Box | 138 //Define the File Type Box |
138 filetypebx(&ftyp); | 139 filetypebx(&ftyp); |
177 //Rules | 178 //Rules |
178 sizeRUCO = rulescontainer(&moov, SelRuleType, SelRule_PAR1, SelRule_PAR2, | 179 sizeRUCO = rulescontainer(&moov, SelRuleType, SelRule_PAR1, SelRule_PAR2, |
179 MixRuleType, MixRule_PAR1, MixRule_PAR2, MixRule_PAR3, MixRule_PAR4); // Creates the rules, returns the size of the box. | 180 MixRuleType, MixRule_PAR1, MixRule_PAR2, MixRule_PAR3, MixRule_PAR4); // Creates the rules, returns the size of the box. |
180 | 181 |
181 //Text track | 182 //Text track |
182 c_str2= textfile.toStdString().c_str(); //convert Qstring to const char | 183 if (HasTextFile){ |
183 sizeTRAK = trackstructure_text (&moov, numtrack, clock, durationTrack, sizemdat, c_str2, text, totaltracks) + sizeTRAK; | 184 c_str2= textfile.toStdString().c_str(); //convert Qstring to const char |
184 | 185 sizeTRAK = trackstructure_text (&moov, numtrack, clock, durationTrack, sizemdat, c_str2, text, totaltracks) + sizeTRAK; |
186 } | |
185 //Movie Header - Overall declarations | 187 //Movie Header - Overall declarations |
186 moovheaderbox(&moov, clock, sizeTRAK, sizePRCO, totaltracks, durationTrack, sizeRUCO, sizeGRCO); // -> enter sizeGRCO instead of 0 | 188 moovheaderbox(&moov, clock, sizeTRAK, sizePRCO, totaltracks, durationTrack, sizeRUCO, sizeGRCO); // -> enter sizeGRCO instead of 0 |
187 | 189 |
188 //Writes the movie box into the file | 190 //Writes the movie box into the file |
189 writemoovbox(moov, numtrack, totaltracks, imf, text); | 191 writemoovbox(moov, numtrack, totaltracks, imf, text, HasTextFile); |
190 | 192 |
191 //Writes the meta box into the IMAF file | 193 //Writes the meta box into the IMAF file |
192 if (HasImageFile){ | 194 if (HasImageFile){ |
193 writemetabox(meta,imf); | 195 writemetabox(meta,imf); |
194 } | 196 } |
319 fread(&mdat->data, sizeof(char), 1, song); | 321 fread(&mdat->data, sizeof(char), 1, song); |
320 fwrite(&mdat->data, sizeof(char), 1, imf); | 322 fwrite(&mdat->data, sizeof(char), 1, imf); |
321 } | 323 } |
322 | 324 |
323 // copy the text in the 3gp to the ima and add the text modifiers | 325 // copy the text in the 3gp to the ima and add the text modifiers |
324 | 326 if (sizetext !=0){ |
325 cnt=0;// the total number of bytes of the whole text including modifiers | 327 cnt=0;// the total number of bytes of the whole text including modifiers |
326 fseek(text,0,SEEK_CUR); | 328 fseek(text,0,SEEK_CUR); |
327 sizestring=0;//number of bytes of a phrase (without modifiers) | 329 sizestring=0;//number of bytes of a phrase (without modifiers) |
328 initposition[0]=0;// this array saves the initial position of a word | 330 initposition[0]=0;// this array saves the initial position of a word |
329 if(numtr==totaltracks-1){ // writes the text after the samples of all the audio tracks | 331 if(numtr==totaltracks-1){ // writes the text after the samples of all the audio tracks |
455 swap = bytereverse(sizeMDAT); | 457 swap = bytereverse(sizeMDAT); |
456 fseek(imf,-(sizeMDAT-imagesize),SEEK_CUR); //overwrittes sizeMDAT with the total size (Image is yet to be written in the file at this point) | 458 fseek(imf,-(sizeMDAT-imagesize),SEEK_CUR); //overwrittes sizeMDAT with the total size (Image is yet to be written in the file at this point) |
457 fwrite(&swap, sizeof(u32), 1, imf); | 459 fwrite(&swap, sizeof(u32), 1, imf); |
458 fseek(imf,(sizeMDAT-imagesize)-4,SEEK_CUR); // (Image is yet to be written in the file at this point) | 460 fseek(imf,(sizeMDAT-imagesize)-4,SEEK_CUR); // (Image is yet to be written in the file at this point) |
459 } // close if (numtr==totaltracks-1) | 461 } // close if (numtr==totaltracks-1) |
460 | 462 }//close if sizetext |
461 fclose(song); | 463 fclose(song); |
462 | 464 |
463 return size; | 465 return size; |
464 } | 466 } |
465 | 467 |
1589 swap = bytereverse ('moov'); | 1591 swap = bytereverse ('moov'); |
1590 moov->type = swap; | 1592 moov->type = swap; |
1591 } | 1593 } |
1592 | 1594 |
1593 | 1595 |
1594 void writemoovbox(MovieBox moov, int numtrack,int totaltracks, FILE *imf, FILE *text) | 1596 void writemoovbox(MovieBox moov, int numtrack,int totaltracks, FILE *imf, FILE *text, bool HasTextFile) |
1595 { | 1597 { |
1596 int i, j, k, m, t, swap, pos, temp, type; | 1598 int i, j, k, m, t, swap, pos, temp, type; |
1597 int cnt = 0, cnt2 = 0, d = 0, dat = 0, dat1 = 0, dat2 = 0, dat3 = 0, size = 0; | 1599 int cnt = 0, cnt2 = 0, d = 0, dat = 0, dat1 = 0, dat2 = 0, dat3 = 0, size = 0; |
1598 u16 numgroups, numel; | 1600 u16 numgroups, numel; |
1599 | 1601 |
2073 fwrite(&moov.RulesContainer.MixingRules.mix_description[i], | 2075 fwrite(&moov.RulesContainer.MixingRules.mix_description[i], |
2074 sizeof(char), 1, imf); | 2076 sizeof(char), 1, imf); |
2075 } | 2077 } |
2076 | 2078 |
2077 //TIMED TEXT | 2079 //TIMED TEXT |
2080 | |
2081 if (HasTextFile){ | |
2078 fwrite(&moov.TrackBox[numtrack].size, sizeof(u32), 1, imf); | 2082 fwrite(&moov.TrackBox[numtrack].size, sizeof(u32), 1, imf); |
2079 fwrite(&moov.TrackBox[numtrack].type, sizeof(u32), 1, imf); | 2083 fwrite(&moov.TrackBox[numtrack].type, sizeof(u32), 1, imf); |
2080 //Track header// | 2084 //Track header// |
2081 fwrite(&moov.TrackBox[numtrack].TrackHeaderBox, | 2085 fwrite(&moov.TrackBox[numtrack].TrackHeaderBox, |
2082 sizeof(moov.TrackBox[numtrack].TrackHeaderBox), 1, imf); | 2086 sizeof(moov.TrackBox[numtrack].TrackHeaderBox), 1, imf); |
2275 ChunkOffsetBox.entry_count);i++){ | 2279 ChunkOffsetBox.entry_count);i++){ |
2276 | 2280 |
2277 fwrite(&moov.TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox. | 2281 fwrite(&moov.TrackBox[numtrack].MediaBox.MediaInformationBox.SampleTableBox. |
2278 ChunkOffsetBox.chunk_offset[i], sizeof(u32), 1, imf); | 2282 ChunkOffsetBox.chunk_offset[i], sizeof(u32), 1, imf); |
2279 } | 2283 } |
2280 | 2284 } // end if HasTextFile |
2281 //Song Image// | 2285 //Song Image// |
2282 /* Go to function "writemeta" */ | 2286 /* Go to function "writemeta" */ |
2283 | 2287 |
2284 } | 2288 } |
2285 | 2289 |