X-Git-Url: http://git.ffmpeg.org/gitweb/ffmpeg.git/blobdiff_plain/c07ed8c8a22c1427323dccb7722b2b094f95e728..497559ec90bf9b81d09fe1a89875d0a1d98b2cbe:/tools/qt-faststart.c diff --git a/tools/qt-faststart.c b/tools/qt-faststart.c index 2cbf12b1d9..5c1d850462 100644 --- a/tools/qt-faststart.c +++ b/tools/qt-faststart.c @@ -1,5 +1,5 @@ /* - * qt-faststart.c, v0.1 + * qt-faststart.c, v0.2 * by Mike Melanson (melanson@pcisys.net) * This file is placed in the public domain. Use the program however you * see fit. @@ -7,8 +7,12 @@ * This utility rearranges a Quicktime file such that the moov atom * is in front of the data, thus facilitating network streaming. * - * Compile this program using: - * make qt-faststart + * To compile this program, start from the base directory from which you + * are building FFmpeg and type: + * make tools/qt-faststart + * The qt-faststart program will be built in the tools/ directory. If you + * do not build the program in this manner, correct results are not + * guaranteed, particularly on 64-bit platforms. * Invoke the program with: * qt-faststart * @@ -60,6 +64,7 @@ #define WIDE_ATOM QT_ATOM('w', 'i', 'd', 'e') #define PICT_ATOM QT_ATOM('P', 'I', 'C', 'T') #define FTYP_ATOM QT_ATOM('f', 't', 'y', 'p') +#define UUID_ATOM QT_ATOM('u', 'u', 'i', 'd') #define CMOV_ATOM QT_ATOM('c', 'm', 'o', 'v') #define STCO_ATOM QT_ATOM('s', 't', 'c', 'o') @@ -75,6 +80,7 @@ int main(int argc, char *argv[]) unsigned char atom_bytes[ATOM_PREAMBLE_SIZE]; uint32_t atom_type = 0; uint64_t atom_size = 0; + uint64_t atom_offset = 0; uint64_t last_offset; unsigned char *moov_atom; unsigned char *ftyp_atom = 0; @@ -107,25 +113,12 @@ int main(int argc, char *argv[]) atom_size = (uint32_t)BE_32(&atom_bytes[0]); atom_type = BE_32(&atom_bytes[4]); - if ((atom_type != FREE_ATOM) && - (atom_type != JUNK_ATOM) && - (atom_type != MDAT_ATOM) && - (atom_type != MOOV_ATOM) && - (atom_type != PNOT_ATOM) && - (atom_type != SKIP_ATOM) && - (atom_type != WIDE_ATOM) && - (atom_type != PICT_ATOM) && - (atom_type != FTYP_ATOM)) { - printf ("encountered non-QT top-level atom (is this a Quicktime file?)\n"); - 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", + printf ("could not allocate %"PRIu64" byte for ftyp atom\n", atom_size); fclose(infile); return 1; @@ -138,8 +131,7 @@ int main(int argc, char *argv[]) return 1; } start_offset = ftello(infile); - continue; - } + } else { /* 64-bit special case */ if (atom_size == 1) { @@ -152,6 +144,28 @@ int main(int argc, char *argv[]) fseeko(infile, atom_size - ATOM_PREAMBLE_SIZE, SEEK_CUR); } } + printf("%c%c%c%c %10"PRIu64" %"PRIu64"\n", + (atom_type >> 24) & 255, + (atom_type >> 16) & 255, + (atom_type >> 8) & 255, + (atom_type >> 0) & 255, + atom_offset, + atom_size); + if ((atom_type != FREE_ATOM) && + (atom_type != JUNK_ATOM) && + (atom_type != MDAT_ATOM) && + (atom_type != MOOV_ATOM) && + (atom_type != PNOT_ATOM) && + (atom_type != SKIP_ATOM) && + (atom_type != WIDE_ATOM) && + (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"); + break; + } + atom_offset += atom_size; + } if (atom_type != MOOV_ATOM) { printf ("last atom in file was not a moov atom\n"); @@ -166,7 +180,7 @@ int main(int argc, char *argv[]) moov_atom_size = atom_size; moov_atom = malloc(moov_atom_size); if (!moov_atom) { - printf ("could not allocate 0x%llX byte for moov atom\n", + printf ("could not allocate %"PRIu64" byte for moov atom\n", atom_size); fclose(infile); return 1;