keep ftyp first

Originally committed as revision 5170 to svn://svn.ffmpeg.org/ffmpeg/trunk
This commit is contained in:
Baptiste Coudurier 2006-03-16 16:37:05 +00:00
parent c03395995a
commit 60a9cc5879

View File

@ -72,10 +72,13 @@ int main(int argc, char *argv[])
uint64_t atom_size = 0;
uint64_t last_offset;
unsigned char *moov_atom;
unsigned char *ftyp_atom = 0;
uint64_t moov_atom_size;
uint64_t ftyp_atom_size = 0;
uint64_t i, j;
uint32_t offset_count;
uint64_t current_offset;
uint64_t start_offset = 0;
unsigned char copy_buffer[COPY_BUFFER_SIZE];
int bytes_to_copy;
@ -112,6 +115,27 @@ int main(int argc, char *argv[])
break;
}
/* keep ftyp atom */
if (atom_type == FTYP_ATOM) {
ftyp_atom_size = atom_size;
ftyp_atom = malloc(ftyp_atom_size);
if (!ftyp_atom) {
printf ("could not allocate 0x%llX byte for ftyp atom\n",
atom_size);
fclose(infile);
return 1;
}
fseeko(infile, -ATOM_PREAMBLE_SIZE, SEEK_CUR);
if (fread(ftyp_atom, atom_size, 1, infile) != 1) {
perror(argv[1]);
free(ftyp_atom);
fclose(infile);
return 1;
}
start_offset = ftello(infile);
continue;
}
/* 64-bit special case */
if (atom_size == 1) {
if (fread(atom_bytes, ATOM_PREAMBLE_SIZE, 1, infile) != 1) {
@ -214,6 +238,9 @@ int main(int argc, char *argv[])
free(moov_atom);
return 1;
}
/* seek after ftyp atom if needed */
fseeko(infile, start_offset, SEEK_SET);
outfile = fopen(argv[2], "wb");
if (!outfile) {
perror(argv[2]);
@ -222,6 +249,15 @@ int main(int argc, char *argv[])
return 1;
}
/* dump the same ftyp atom */
if (ftyp_atom_size > 0) {
printf (" writing ftyp atom...\n");
if (fwrite(ftyp_atom, ftyp_atom_size, 1, outfile) != 1) {
perror(argv[2]);
goto error_out;
}
}
/* dump the new moov atom */
printf (" writing moov atom...\n");
if (fwrite(moov_atom, moov_atom_size, 1, outfile) != 1) {