Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
* [FFmpeg-devel] [PATCH] qt-faststart: update co64 chunk offsets when converting stco to co64
@ 2025-05-21 14:00 CesarATV
  0 siblings, 0 replies; only message in thread
From: CesarATV @ 2025-05-21 14:00 UTC (permalink / raw)
  To: ffmpeg-devel; +Cc: CesarATV

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 <cesaratvgit@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-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2025-05-21 14:00 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-05-21 14:00 [FFmpeg-devel] [PATCH] qt-faststart: update co64 chunk offsets when converting stco to co64 CesarATV

Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
		ffmpegdev@gitmailbox.com
	public-inbox-index ffmpegdev

Example config snippet for mirrors.


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git