diff mbox

[FFmpeg-devel] tools/qt-faststart: Allow free atoms after moov atom

Message ID CAB0OVGo0592ZEwKGc1gebtCJOWW1eZ95ZdgLN6OXwd_UHbAcqg@mail.gmail.com
State Accepted
Headers show

Commit Message

Carl Eugen Hoyos July 11, 2018, 11:28 p.m. UTC
Hi!

Attached patch allows to fast-start mov files with free atoms after
the moov atom.
Tested with the sample from ticket #7277.

Please comment, Carl Eugen

Comments

Carl Eugen Hoyos July 19, 2018, 9:18 p.m. UTC | #1
2018-07-12 1:28 GMT+02:00, Carl Eugen Hoyos <ceffmpeg@gmail.com>:

> Attached patch allows to fast-start mov files with free atoms after
> the moov atom.
> Tested with the sample from ticket #7277.

Ping.

As this is not trivial to test, I would prefer not to "improve" the patch
until another sample appears.

Carl Eugen
Carl Eugen Hoyos July 25, 2018, 6:37 p.m. UTC | #2
2018-07-19 23:18 GMT+02:00, Carl Eugen Hoyos <ceffmpeg@gmail.com>:
> 2018-07-12 1:28 GMT+02:00, Carl Eugen Hoyos <ceffmpeg@gmail.com>:
>
>> Attached patch allows to fast-start mov files with free atoms after
>> the moov atom.
>> Tested with the sample from ticket #7277.
>
> Ping.
>
> As this is not trivial to test, I would prefer not to "improve" the patch
> until another sample appears.

I will push this patch if nobody objects.

Carl Eugen
Carl Eugen Hoyos July 31, 2018, 11:27 p.m. UTC | #3
2018-07-25 20:37 GMT+02:00, Carl Eugen Hoyos <ceffmpeg@gmail.com>:
> 2018-07-19 23:18 GMT+02:00, Carl Eugen Hoyos <ceffmpeg@gmail.com>:
>> 2018-07-12 1:28 GMT+02:00, Carl Eugen Hoyos <ceffmpeg@gmail.com>:
>>
>>> Attached patch allows to fast-start mov files with free atoms after
>>> the moov atom.
>>> Tested with the sample from ticket #7277.
>>
>> Ping.
>>
>> As this is not trivial to test, I would prefer not to "improve" the patch
>> until another sample appears.
>
> I will push this patch if nobody objects.

Patch applied.

Carl Eugen
diff mbox

Patch

From 8decd60aaae4209f4991c926f058f9370701336e Mon Sep 17 00:00:00 2001
From: Carl Eugen Hoyos <ceffmpeg@gmail.com>
Date: Thu, 12 Jul 2018 01:24:39 +0200
Subject: [PATCH] tools/qt-faststart: Allow free atoms after moov atom.

---
 tools/qt-faststart.c |   13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/tools/qt-faststart.c b/tools/qt-faststart.c
index 5e88c38..46950a5 100644
--- a/tools/qt-faststart.c
+++ b/tools/qt-faststart.c
@@ -443,6 +443,8 @@  int main(int argc, char *argv[])
     int64_t start_offset = 0;
     unsigned char *copy_buffer = NULL;
     int bytes_to_copy;
+    uint64_t free_size = 0;
+    uint64_t moov_size = 0;
 
     if (argc != 3) {
         printf("Usage: qt-faststart <infile.mov> <outfile.mov>\n"
@@ -535,6 +537,15 @@  int main(int argc, char *argv[])
          * able to continue scanning sensibly after this atom, so break. */
         if (atom_size < 8)
             break;
+
+        if (atom_type == MOOV_ATOM)
+            moov_size = atom_size;
+
+        if (moov_size && atom_type == FREE_ATOM) {
+            free_size += atom_size;
+            atom_type = MOOV_ATOM;
+            atom_size = moov_size;
+        }
     }
 
     if (atom_type != MOOV_ATOM) {
@@ -551,7 +562,7 @@  int main(int argc, char *argv[])
 
     /* moov atom was, in fact, the last atom in the chunk; load the whole
      * moov atom */
-    if (fseeko(infile, -atom_size, SEEK_END)) {
+    if (fseeko(infile, -(atom_size + free_size), SEEK_END)) {
         perror(argv[1]);
         goto error_out;
     }
-- 
1.7.10.4