[FFmpeg-devel] qt-faststart update

Frank Barchard fbarchard
Thu Jun 25 13:32:22 CEST 2009


On Wed, Jun 24, 2009 at 6:54 AM, Diego Biurrun <diego at biurrun.de> wrote:

> On Wed, Jun 24, 2009 at 05:14:39AM -0700, Frank Barchard wrote:
> >
> > --------------------------------------------------
> > From: "Diego Biurrun" <diego at biurrun.de>
> > Sent: Wednesday, June 24, 2009 2:54 AM
> > To: "FFmpeg development discussions and patches" <
> ffmpeg-devel at mplayerhq.hu>
> > Subject: Re: [FFmpeg-devel] qt-faststart update
>
> You will extra good karma if you remove these ugly headers..


Done.


>
>
> > >On Wed, Jun 24, 2009 at 01:52:36AM -0700, Frank Barchard wrote:
> > >>
> > >>> On Tue, Jun 23, 2009 at 07:39:55PM -0700, Frank Barchard wrote:
> > >>--- tools/qt-faststart.orig.c 2009-05-07 21:41:30.000000000 -0700
> > >>+++ tools/qt-faststart.c 2009-06-24 01:04:39.804309200 -0700
> > >>@@ -26,7 +27,15 @@
> > >>
> > >> #include <stdio.h>
> > >> #include <stdlib.h>
> > >>+#ifndef _MSC_VER
> > >> #include <inttypes.h>
> > >>+#else
> > >>+#define uint64_t unsigned __int64
> > >>+#define uint32_t unsigned int
> > >>+#define uint8_t unsigned char
> > >>+#define ftello _ftelli64
> > >>+#define fseeko _fseeki64
> > >>+#endif
> > >
> > >We do not support Visual Studio, get rid of this.  In any case, it would
> > >have to be a separate patch.
> >
> > I'm needing VC for debugging.  It also produces faster code if built with
> > Intel C or VC for Windows.
>
> This is irrelevant, VC workarounds have no place in this patch.  Send one
> issue per patch.


Done.  All bug fixes/improvements removed, including uuid support.  The
patch is limited to 'free' atom removal.
To be clear, the original patch contained the following:
printf's for information
cleanup/error handling
larger size copy for performance
visual c / intel c compatibility
uuid support
removal of 'free' at end of file
The new patch contains only the 'free' removal.  There are 2 distinct
versions of the free removal and the patch contains both:
1. 'free' atom at end of file, but 'moov' does not precede it.  The 'free'
atom will be truncated from the file.
2. 'moov' atom is last non-'free' atom and may have a 'free' atom before
and/or after it.  The 'moov' atom is moved to the start of file, and the
'free' atom(s) are truncated


>
>
> > Keep in mind this is a stand alone tool, not linked into ffmpeg
> libraries.
> > I'll submit a separate patch to the original for VC support.
>
> Don't bother, VC workarounds are rejected.


Done.  Removed icl/cl ifdefs.

>
>
> > >Also, please set a correct content-type for your attachments.
> >
> > I'm not sure how to do that?  The previous attachments were thru gmail.
> > For this one I've switched to Live Mail in plain text format.
>
> It's equally bad, plus Live Mail mimics Outlook formattting, which looks
> horrible.  Some people do manage to set correct mime-type even when
> using webmail...


Done - base64 encoded the diff.

>
>
>
> The patch looks much better.  Can we now have the factorization as a
> separate patch please?


I'll do that as a follow up patch, if the basic 'free' atom support fix is
good.

Patch attached as base64.  Use base64 -d to extract it.

Since its fairly small now, here is the diff

--- tools/qt-faststart.orig.c   2009-05-07 21:41:30.000000000 -0700
+++ tools/qt-faststart.c        2009-06-25 04:03:55.890861500 -0700
@@ -1,6 +1,7 @@
 /*
- * qt-faststart.c, v0.1
+ * qt-faststart.c, v0.21
  * by Mike Melanson (melanson at pcisys.net)
+ * patch by Frank Barchard, to remove last FREE atom.
  * This file is placed in the public domain. Use the program however you
  * see fit.
  *
@@ -90,6 +91,11 @@ int main(int argc, char *argv[])
     uint64_t start_offset = 0;
     unsigned char copy_buffer[COPY_BUFFER_SIZE];
     int bytes_to_copy;
+    uint32_t last_atom_type = 0;
+    uint64_t last_atom_size = 0;
+    uint64_t last_atom_offset = 0;
+    uint64_t atom_offset;
+    int just_remove_free = 0;

     if (argc != 3) {
         printf ("Usage: qt-faststart <infile.mov> <outfile.mov>\n");
@@ -110,6 +116,7 @@ int main(int argc, char *argv[])
         }
         atom_size = (uint32_t)BE_32(&atom_bytes[0]);
         atom_type = BE_32(&atom_bytes[4]);
+        atom_offset = ftello(infile) - ATOM_PREAMBLE_SIZE;

         if ((atom_type != FREE_ATOM) &&
             (atom_type != JUNK_ATOM) &&
@@ -155,19 +162,30 @@ int main(int argc, char *argv[])
         } else {
             fseeko(infile, atom_size - ATOM_PREAMBLE_SIZE, SEEK_CUR);
         }
+
+        if ((atom_type != FREE_ATOM)) {
+            last_atom_size = atom_size;
+            last_atom_type = atom_type;
+            last_atom_offset = ftello(infile) - last_atom_size;
+        }
+        if ((atom_type != FREE_ATOM) && (atom_type != MOOV_ATOM))
+            last_offset = ftello(infile);
     }

-    if (atom_type != MOOV_ATOM) {
+    if (atom_type == FREE_ATOM) {
+        printf ("free atom at %llu removed.\n", (unsigned long long )
last_offs
et);
+        just_remove_free = 1;
+    } else if (atom_type != MOOV_ATOM) {
         printf ("last atom in file was not a moov atom\n");
         fclose(infile);
         return 0;
     }

+    if (last_atom_type == MOOV_ATOM) {
     /* moov atom was, in fact, the last atom in the chunk; load the whole
      * moov atom */
-    fseeko(infile, -atom_size, SEEK_END);
-    last_offset = ftello(infile);
-    moov_atom_size = atom_size;
+    fseeko(infile, last_atom_offset, SEEK_SET);
+    moov_atom_size = last_atom_size;
     moov_atom = malloc(moov_atom_size);
     if (!moov_atom) {
         printf ("could not allocate 0x%llX byte for moov atom\n",
@@ -175,7 +193,7 @@ int main(int argc, char *argv[])
         fclose(infile);
         return 1;
     }
-    if (fread(moov_atom, atom_size, 1, infile) != 1) {
+    if (fread(moov_atom, moov_atom_size, 1, infile) != 1) {
         perror(argv[1]);
         free(moov_atom);
         fclose(infile);
@@ -239,6 +257,7 @@ int main(int argc, char *argv[])
             i += atom_size - 4;
         }
     }
+    }

     /* re-open the input file and open the output file */
     infile = fopen(argv[1], "rb");
@@ -270,12 +289,14 @@ int main(int argc, char *argv[])
         }
     }

+    if (!just_remove_free) {
     /* dump the new moov atom */
     printf (" writing moov atom...\n");
     if (fwrite(moov_atom, moov_atom_size, 1, outfile) != 1) {
         perror(argv[2]);
         goto error_out;
     }
+    }

     /* copy the remainder of the infile, from offset 0 -> last_offset - 1
*/
     printf (" copying rest of file...\n");




>
>
> Diego
>

Thanks for reviewing it Diego.  I'll try to make it easier in the future.

>
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel at mplayerhq.hu
> https://lists.mplayerhq.hu/mailman/listinfo/ffmpeg-devel
>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: qt-faststart_base64.diff
Type: application/octet-stream
Size: 4494 bytes
Desc: not available
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20090625/5f4b48a8/attachment.obj>



More information about the ffmpeg-devel mailing list