]> git.sesse.net Git - ffmpeg/blobdiff - tools/qt-faststart.c
nutenc: use 1/sample rate as timebase for audio instead of framesize/sample rate
[ffmpeg] / tools / qt-faststart.c
index bb8e02eac9986adc54d9e7abfe04f6624a47cd33..b9dbdfdb6aed11586b65c192ba6d2d146d550731 100644 (file)
 #ifdef __MINGW32__
 #define fseeko(x, y, z) fseeko64(x, y, z)
 #define ftello(x)       ftello64(x)
+#elif defined(_WIN32)
+#define fseeko(x, y, z) _fseeki64(x, y, z)
+#define ftello(x)       _ftelli64(x)
 #endif
 
+#define FFMIN(a,b) ((a) > (b) ? (b) : (a))
+
 #define BE_16(x) ((((uint8_t*)(x))[0] <<  8) | ((uint8_t*)(x))[1])
 
 #define BE_32(x) ((((uint8_t*)(x))[0] << 24) |  \
@@ -74,7 +79,7 @@
 #define CO64_ATOM QT_ATOM('c', 'o', '6', '4')
 
 #define ATOM_PREAMBLE_SIZE    8
-#define COPY_BUFFER_SIZE   1024
+#define COPY_BUFFER_SIZE   33554432
 
 int main(int argc, char *argv[])
 {
@@ -93,7 +98,7 @@ int main(int argc, char *argv[])
     uint32_t offset_count;
     uint64_t current_offset;
     uint64_t start_offset = 0;
-    unsigned char copy_buffer[COPY_BUFFER_SIZE];
+    unsigned char *copy_buffer = NULL;
     int bytes_to_copy;
 
     if (argc != 3) {
@@ -290,12 +295,15 @@ int main(int argc, char *argv[])
     }
 
     /* copy the remainder of the infile, from offset 0 -> last_offset - 1 */
+    bytes_to_copy = FFMIN(COPY_BUFFER_SIZE, last_offset);
+    copy_buffer = malloc(bytes_to_copy);
+    if (!copy_buffer) {
+        printf("could not allocate %"PRIu64" bytes for copy_buffer\n", bytes_to_copy);
+        goto error_out;
+    }
     printf(" copying rest of file...\n");
     while (last_offset) {
-        if (last_offset > COPY_BUFFER_SIZE)
-            bytes_to_copy = COPY_BUFFER_SIZE;
-        else
-            bytes_to_copy = last_offset;
+        bytes_to_copy = FFMIN(bytes_to_copy, last_offset);
 
         if (fread(copy_buffer, bytes_to_copy, 1, infile) != 1) {
             perror(argv[1]);
@@ -312,6 +320,7 @@ int main(int argc, char *argv[])
     fclose(outfile);
     free(moov_atom);
     free(ftyp_atom);
+    free(copy_buffer);
 
     return 0;
 
@@ -322,5 +331,6 @@ error_out:
         fclose(outfile);
     free(moov_atom);
     free(ftyp_atom);
+    free(copy_buffer);
     return 1;
 }