switch (atom.size) {
case 1:
if (end - pos < 8) {
- printf("not enough room for 64 bit atom size\n");
+ fprintf(stderr, "not enough room for 64 bit atom size\n");
return -1;
}
}
if (atom.size < atom.header_size) {
- printf("atom size %"PRIu64" too small\n", atom.size);
+ fprintf(stderr, "atom size %"PRIu64" too small\n", atom.size);
return -1;
}
atom.size -= atom.header_size;
if (atom.size > end - pos) {
- printf("atom size %"PRIu64" too big\n", atom.size);
+ fprintf(stderr, "atom size %"PRIu64" too big\n", atom.size);
return -1;
}
printf(" patching stco atom...\n");
if (atom->size < 8) {
- printf("stco atom size %"PRIu64" too small\n", atom->size);
+ fprintf(stderr, "stco atom size %"PRIu64" too small\n", atom->size);
return -1;
}
offset_count = BE_32(atom->data + 4);
if (offset_count > (atom->size - 8) / 4) {
- printf("stco offset count %"PRIu32" too big\n", offset_count);
+ fprintf(stderr, "stco offset count %"PRIu32" too big\n", offset_count);
return -1;
}
printf(" patching co64 atom...\n");
if (atom->size < 8) {
- printf("co64 atom size %"PRIu64" too small\n", atom->size);
+ fprintf(stderr, "co64 atom size %"PRIu64" too small\n", atom->size);
return -1;
}
offset_count = BE_32(atom->data + 4);
if (offset_count > (atom->size - 8) / 8) {
- printf("co64 offset count %"PRIu32" too big\n", offset_count);
+ fprintf(stderr, "co64 offset count %"PRIu32" too big\n", offset_count);
return -1;
}
case STBL_ATOM:
context->depth++;
if (context->depth > 10) {
- printf("atoms too deeply nested\n");
+ fprintf(stderr, "atoms too deeply nested\n");
return -1;
}
new_moov_atom = malloc(upgrade_context.new_moov_size);
if (new_moov_atom == NULL) {
- printf("could not allocate %"PRIu64" bytes for updated moov atom\n",
+ fprintf(stderr, "could not allocate %"PRIu64" bytes for updated moov atom\n",
upgrade_context.new_moov_size);
return -1;
}
*moov_atom_size = upgrade_context.new_moov_size;
if (upgrade_context.dest != *moov_atom + *moov_atom_size) {
- printf("unexpected - wrong number of moov bytes written\n");
+ fprintf(stderr, "unexpected - wrong number of moov bytes written\n");
return -1;
}
int64_t start_offset = 0;
unsigned char *copy_buffer = NULL;
int bytes_to_copy;
+ uint64_t free_size = 0;
+ uint64_t moov_size = 0;
if (argc != 3) {
printf("Usage: qt-faststart <infile.mov> <outfile.mov>\n"
/* keep ftyp atom */
if (atom_type == FTYP_ATOM) {
if (atom_size > MAX_FTYP_ATOM_SIZE) {
- printf("ftyp atom size %"PRIu64" too big\n",
+ fprintf(stderr, "ftyp atom size %"PRIu64" too big\n",
atom_size);
goto error_out;
}
free(ftyp_atom);
ftyp_atom = malloc(ftyp_atom_size);
if (!ftyp_atom) {
- printf("could not allocate %"PRIu64" bytes for ftyp atom\n",
+ fprintf(stderr, "could not allocate %"PRIu64" bytes for ftyp atom\n",
atom_size);
goto error_out;
}
(atom_type != PICT_ATOM) &&
(atom_type != UUID_ATOM) &&
(atom_type != FTYP_ATOM)) {
- printf("encountered non-QT top-level atom (is this a QuickTime file?)\n");
+ fprintf(stderr, "encountered non-QT top-level atom (is this a QuickTime file?)\n");
break;
}
atom_offset += atom_size;
* able to continue scanning sensibly after this atom, so break. */
if (atom_size < 8)
break;
+
+ if (atom_type == MOOV_ATOM)
+ moov_size = atom_size;
+
+ if (moov_size && atom_type == FREE_ATOM) {
+ free_size += atom_size;
+ atom_type = MOOV_ATOM;
+ atom_size = moov_size;
+ }
}
if (atom_type != MOOV_ATOM) {
}
if (atom_size < 16) {
- printf("bad moov atom size\n");
+ fprintf(stderr, "bad moov atom size\n");
goto error_out;
}
/* moov atom was, in fact, the last atom in the chunk; load the whole
* moov atom */
- if (fseeko(infile, -atom_size, SEEK_END)) {
+ if (fseeko(infile, -(atom_size + free_size), SEEK_END)) {
perror(argv[1]);
goto error_out;
}
moov_atom_size = atom_size;
moov_atom = malloc(moov_atom_size);
if (!moov_atom) {
- printf("could not allocate %"PRIu64" bytes for moov atom\n", atom_size);
+ fprintf(stderr, "could not allocate %"PRIu64" bytes for moov atom\n", atom_size);
goto error_out;
}
if (fread(moov_atom, atom_size, 1, infile) != 1) {
/* this utility does not support compressed atoms yet, so disqualify
* files with compressed QT atoms */
if (BE_32(&moov_atom[12]) == CMOV_ATOM) {
- printf("this utility does not support compressed moov atoms yet\n");
+ fprintf(stderr, "this utility does not support compressed moov atoms yet\n");
goto error_out;
}
bytes_to_copy = MIN(COPY_BUFFER_SIZE, last_offset);
copy_buffer = malloc(bytes_to_copy);
if (!copy_buffer) {
- printf("could not allocate %d bytes for copy_buffer\n", bytes_to_copy);
+ fprintf(stderr, "could not allocate %d bytes for copy_buffer\n", bytes_to_copy);
goto error_out;
}
printf(" copying rest of file...\n");