[FFmpeg-cvslog] qt-faststart: speedup

Jan Ehrhardt git at videolan.org
Sun Sep 30 22:21:04 CEST 2012


ffmpeg | branch: master | Jan Ehrhardt <phpdev at ehrhardt.nl> | Sun Sep 30 21:32:26 2012 +0200| [f4d9148fe282879b9fcc755767c9c04de9ddbcfa] | committer: Michael Niedermayer

qt-faststart: speedup

qt-faststart is terribly slow when the input file and the output file
are on a slow disk like a SD card. By increasing the copy_buffer from
1K to 32M I decreased the processing time on a sample file from
1600 seconds to 4 seconds. The timing difference is during 'copying
rest of file'.

S:\SD_VIDEO\PRG001>e:\utils\qt-faststart 00005.mp4 5.mp4
ftyp          0 32
free         32 8
mdat         40 13744391
moov   13744431 141848
 patching stco atom...
 patching stco atom...
 writing ftyp atom...
 writing moov atom...
 copying rest of file...

Execution time: 1576.259 s

S:\SD_VIDEO\PRG001>s:\utils\qt-faststart 00005.mp4 5.mp4
ftyp          0 32
free         32 8
mdat         40 13744391
moov   13744431 141848
 patching stco atom...
 patching stco atom...
 writing ftyp atom...
 writing moov atom...
 copying rest of file...

Execution time: 3.846 s

Signed-off-by: Michael Niedermayer <michaelni at gmx.at>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=f4d9148fe282879b9fcc755767c9c04de9ddbcfa
---

 tools/qt-faststart.c |   11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/tools/qt-faststart.c b/tools/qt-faststart.c
index ebbe952..bfa6f1a 100644
--- a/tools/qt-faststart.c
+++ b/tools/qt-faststart.c
@@ -77,7 +77,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[])
 {
@@ -96,7 +96,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) {
@@ -293,6 +293,11 @@ int main(int argc, char *argv[])
     }
 
     /* copy the remainder of the infile, from offset 0 -> last_offset - 1 */
+    copy_buffer = malloc(COPY_BUFFER_SIZE);
+    if (!copy_buffer) {
+        printf("could not allocate %"PRIu64" bytes for copy_buffer\n", COPY_BUFFER_SIZE);
+        goto error_out;
+    }
     printf(" copying rest of file...\n");
     while (last_offset) {
         if (last_offset > COPY_BUFFER_SIZE)
@@ -315,6 +320,7 @@ int main(int argc, char *argv[])
     fclose(outfile);
     free(moov_atom);
     free(ftyp_atom);
+    free(copy_buffer);
 
     return 0;
 
@@ -325,5 +331,6 @@ error_out:
         fclose(outfile);
     free(moov_atom);
     free(ftyp_atom);
+    free(copy_buffer);
     return 1;
 }



More information about the ffmpeg-cvslog mailing list