This is an automated email from the git hooks/post-receive script.

Git pushed a commit to branch master
in repository ffmpeg.

commit 7581abdcb1602b9fb7e54ea65868473105ed8ee0
Author:     James Almer <[email protected]>
AuthorDate: Sun Jan 25 23:45:12 2026 -0300
Commit:     James Almer <[email protected]>
CommitDate: Thu Jan 29 21:09:02 2026 -0300

    avformat/cafenc: support writing Packet Table Chunk Header if there are 
priming or remainder frames
    
    If a codec has fixed block_align and frame_size but a given sample has 
either
    priming or remainder frames, a pakt chunk can be written declaring zero 
packets
    and no table, reporting only the samples to be discarded.
    
    Signed-off-by: James Almer <[email protected]>
---
 libavformat/cafenc.c          | 18 ++++++++++--------
 tests/ref/fate/caf-qdm2-remux |  4 ++--
 2 files changed, 12 insertions(+), 10 deletions(-)

diff --git a/libavformat/cafenc.c b/libavformat/cafenc.c
index b1e7555aca..6f44e2a2b0 100644
--- a/libavformat/cafenc.c
+++ b/libavformat/cafenc.c
@@ -263,10 +263,10 @@ static int caf_write_packet(AVFormatContext *s, AVPacket 
*pkt)
             caf_st->frame_size_buffer = pkt_sizes;
             caf_st->frame_size_buffer[caf->packets] = pkt->duration;
         }
-
+    }
         caf->packets++;
         caf->total_duration += pkt->duration;
-    }
+
     avio_write(s->pb, pkt->data, pkt->size);
     return 0;
 }
@@ -281,13 +281,15 @@ static int caf_write_trailer(AVFormatContext *s)
 
     if (pb->seekable & AVIO_SEEKABLE_NORMAL) {
         int64_t file_size = avio_tell(pb);
-
-        avio_seek(pb, caf->data, SEEK_SET);
-        avio_wb64(pb, file_size - caf->data - 8);
-        if (!par->block_align || !caf->frame_size) {
+        int64_t packets = (!par->block_align || !caf->frame_size) ? 
caf->packets : 0;
             int64_t valid_frames = caf->frame_size ? caf->packets * 
caf->frame_size : caf->total_duration;
             unsigned remainder_frames = valid_frames > caf->total_duration
                                       ? valid_frames - caf->total_duration : 0;
+
+        avio_seek(pb, caf->data, SEEK_SET);
+        avio_wb64(pb, file_size - caf->data - 8);
+
+        if (!par->block_align || !caf->frame_size || par->initial_padding || 
remainder_frames) {
             int64_t size = 24;
 
             valid_frames -= par->initial_padding;
@@ -296,11 +298,11 @@ static int caf_write_trailer(AVFormatContext *s)
             avio_seek(pb, file_size, SEEK_SET);
             ffio_wfourcc(pb, "pakt");
             avio_wb64(pb, 0); // size, to be replaced
-            avio_wb64(pb, caf->packets); ///< mNumberPackets
+            avio_wb64(pb, packets); ///< mNumberPackets
             avio_wb64(pb, valid_frames); ///< mNumberValidFrames
             avio_wb32(pb, par->initial_padding); ///< mPrimingFrames
             avio_wb32(pb, remainder_frames); ///< mRemainderFrames
-            for (int i = 0; i < caf->packets; i++) {
+            for (int i = 0; i < packets; i++) {
                 if (!par->block_align) {
                     for (int j = 4; j > 0; j--) {
                         unsigned top = caf_st->byte_size_buffer[i] >> j * 7;
diff --git a/tests/ref/fate/caf-qdm2-remux b/tests/ref/fate/caf-qdm2-remux
index e0e96eaf5e..d14e298d5d 100644
--- a/tests/ref/fate/caf-qdm2-remux
+++ b/tests/ref/fate/caf-qdm2-remux
@@ -1,5 +1,5 @@
-2b71d78aa6c9d13a3c0dbbbebe885227 *tests/data/fate/caf-qdm2-remux.caf
-51228 tests/data/fate/caf-qdm2-remux.caf
+fa896705e19dccfef00734f1e8f614c8 *tests/data/fate/caf-qdm2-remux.caf
+51264 tests/data/fate/caf-qdm2-remux.caf
 #extradata 0:       64, 0x10d20603
 #tb 0: 1/44100
 #media_type 0: audio

_______________________________________________
ffmpeg-cvslog mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to