Revision 60a9cc58 qt-faststart.c

View differences:

qt-faststart.c
72 72
    uint64_t atom_size = 0;
73 73
    uint64_t last_offset;
74 74
    unsigned char *moov_atom;
75
    unsigned char *ftyp_atom = 0;
75 76
    uint64_t moov_atom_size;
77
    uint64_t ftyp_atom_size = 0;
76 78
    uint64_t i, j;
77 79
    uint32_t offset_count;
78 80
    uint64_t current_offset;
81
    uint64_t start_offset = 0;
79 82
    unsigned char copy_buffer[COPY_BUFFER_SIZE];
80 83
    int bytes_to_copy;
81 84

  
......
112 115
            break;
113 116
        }
114 117

  
118
        /* keep ftyp atom */
119
        if (atom_type == FTYP_ATOM) {
120
            ftyp_atom_size = atom_size;
121
            ftyp_atom = malloc(ftyp_atom_size);
122
            if (!ftyp_atom) {
123
                printf ("could not allocate 0x%llX byte for ftyp atom\n",
124
                        atom_size);
125
                fclose(infile);
126
                return 1;
127
            }
128
            fseeko(infile, -ATOM_PREAMBLE_SIZE, SEEK_CUR);
129
            if (fread(ftyp_atom, atom_size, 1, infile) != 1) {
130
                perror(argv[1]);
131
                free(ftyp_atom);
132
                fclose(infile);
133
                return 1;
134
            }
135
            start_offset = ftello(infile);
136
            continue;
137
        }
138

  
115 139
        /* 64-bit special case */
116 140
        if (atom_size == 1) {
117 141
            if (fread(atom_bytes, ATOM_PREAMBLE_SIZE, 1, infile) != 1) {
......
214 238
        free(moov_atom);
215 239
        return 1;
216 240
    }
241
    /* seek after ftyp atom if needed */
242
    fseeko(infile, start_offset, SEEK_SET);
243

  
217 244
    outfile = fopen(argv[2], "wb");
218 245
    if (!outfile) {
219 246
        perror(argv[2]);
......
222 249
        return 1;
223 250
    }
224 251

  
252
    /* dump the same ftyp atom */
253
    if (ftyp_atom_size > 0) {
254
        printf (" writing ftyp atom...\n");
255
        if (fwrite(ftyp_atom, ftyp_atom_size, 1, outfile) != 1) {
256
            perror(argv[2]);
257
            goto error_out;
258
        }
259
    }
260

  
225 261
    /* dump the new moov atom */
226 262
    printf (" writing moov atom...\n");
227 263
    if (fwrite(moov_atom, moov_atom_size, 1, outfile) != 1) {

Also available in: Unified diff