Before this patch, when qt-faststart converted stco atoms to co64, it
did so without updating the chunk offsets of pre-existing co64 atoms,
resulting in corrupted tracks. This patch ensures that existing co64
chunk offsets are correctly adjusted when such a conversion occurs.

Signed-off-by: CesarATV <cesaratv...@gmail.com>
---
 tools/qt-faststart.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/tools/qt-faststart.c b/tools/qt-faststart.c
index 46950a5cf4..3c3b0890a8 100644
--- a/tools/qt-faststart.c
+++ b/tools/qt-faststart.c
@@ -218,7 +218,7 @@ static int 
update_stco_offsets(update_chunk_offsets_context_t *context, atom_t *
     return 0;
 }
 
-static int update_co64_offsets(update_chunk_offsets_context_t *context, atom_t 
*atom)
+static int update_co64_offsets(uint64_t offset_increment, atom_t *atom)
 {
     uint64_t current_offset;
     uint32_t offset_count;
@@ -241,7 +241,7 @@ static int 
update_co64_offsets(update_chunk_offsets_context_t *context, atom_t *
         pos < end;
         pos += 8) {
         current_offset = BE_64(pos);
-        current_offset += context->moov_atom_size;
+        current_offset += offset_increment;
         AV_WB64(pos, current_offset);
     }
 
@@ -258,7 +258,7 @@ static int update_chunk_offsets_callback(void *ctx, atom_t 
*atom)
         return update_stco_offsets(context, atom);
 
     case CO64_ATOM:
-        return update_co64_offsets(context, atom);
+        return update_co64_offsets(context->moov_atom_size, atom);
 
     case MOOV_ATOM:
     case TRAK_ATOM:
@@ -359,6 +359,10 @@ static int upgrade_stco_callback(void *ctx, atom_t *atom)
         set_atom_size(start_pos, atom->header_size, context->dest - start_pos);
         break;
 
+    case CO64_ATOM:
+        update_co64_offsets(context->new_moov_size - 
context->original_moov_size, atom);
+        /* fallthrough */
+
     default:
         copy_size = atom->header_size + atom->size;
         memcpy(context->dest, atom->data - atom->header_size, copy_size);
-- 
2.43.0

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Reply via email to