]> git.sesse.net Git - ffmpeg/blobdiff - qt-faststart.c
simplify
[ffmpeg] / qt-faststart.c
index b4eba7bb56db375e7f24d32522dfe4dd8d104031..f9de435146baecc0b3140206717c2af466f3fef7 100644 (file)
 #include <stdlib.h>
 #include <inttypes.h>
 
+#ifdef __MINGW32__
+#define fseeko(x,y,z)  fseeko64(x,y,z)
+#define ftello(x)      ftello64(x)
+#endif
+
 #define BE_16(x) ((((uint8_t*)(x))[0] << 8) | ((uint8_t*)(x))[1])
 #define BE_32(x) ((((uint8_t*)(x))[0] << 24) | \
                   (((uint8_t*)(x))[1] << 16) | \
@@ -99,7 +104,7 @@ int main(int argc, char *argv[])
         if (fread(atom_bytes, ATOM_PREAMBLE_SIZE, 1, infile) != 1) {
             break;
         }
-        atom_size = BE_32(&atom_bytes[0]);
+        atom_size = (uint32_t)BE_32(&atom_bytes[0]);
         atom_type = BE_32(&atom_bytes[4]);
 
         if ((atom_type != FREE_ATOM) &&
@@ -238,8 +243,11 @@ int main(int argc, char *argv[])
         free(moov_atom);
         return 1;
     }
-    /* seek after ftyp atom if needed */
-    fseeko(infile, start_offset, SEEK_SET);
+
+    if (start_offset > 0) { /* seek after ftyp atom */
+        fseeko(infile, start_offset, SEEK_SET);
+        last_offset -= start_offset;
+    }
 
     outfile = fopen(argv[2], "wb");
     if (!outfile) {
@@ -288,6 +296,8 @@ int main(int argc, char *argv[])
     fclose(infile);
     fclose(outfile);
     free(moov_atom);
+    if (ftyp_atom_size > 0)
+        free(ftyp_atom);
 
     return 0;
 
@@ -295,5 +305,7 @@ error_out:
     fclose(infile);
     fclose(outfile);
     free(moov_atom);
+    if (ftyp_atom_size > 0)
+        free(ftyp_atom);
     return 1;
 }