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

Git pushed a commit to branch master
in repository ffmpeg.

commit d151c904dfffcffb2a55c6184fdedeac90a9be73
Author:     James Almer <[email protected]>
AuthorDate: Fri Jan 30 21:27:41 2026 -0300
Commit:     James Almer <[email protected]>
CommitDate: Mon Feb 2 12:52:02 2026 -0300

    avformat/cafdec: take into account priming samples in timestamps
    
    Signed-off-by: James Almer <[email protected]>
---
 libavformat/cafdec.c | 18 ++++++++++++------
 1 file changed, 12 insertions(+), 6 deletions(-)

diff --git a/libavformat/cafdec.c b/libavformat/cafdec.c
index d00b39adf0..300e661dfc 100644
--- a/libavformat/cafdec.c
+++ b/libavformat/cafdec.c
@@ -263,6 +263,7 @@ static int read_pakt_chunk(AVFormatContext *s, int64_t size)
     priming        = avio_rb32(pb); /* priming frames */
     caf->remainder = avio_rb32(pb); /* remainder frames */
 
+    caf->frame_cnt = -(int64_t)priming;
     st->codecpar->initial_padding = priming;
     st->nb_frames += priming;
     st->nb_frames += caf->remainder;
@@ -273,10 +274,10 @@ static int read_pakt_chunk(AVFormatContext *s, int64_t 
size)
                 return AVERROR_INVALIDDATA;
             num_packets = caf->data_size / caf->bytes_per_packet;
         }
-        st->duration = caf->frames_per_packet * num_packets;
+        st->duration = caf->frames_per_packet * num_packets - priming;
         pos          = caf-> bytes_per_packet * num_packets;
     } else {
-        st->duration = 0;
+        st->duration = caf->frame_cnt;
         for (i = 0; i < num_packets; i++) {
             if (avio_feof(pb))
                 return AVERROR_INVALIDDATA;
@@ -455,7 +456,7 @@ static int read_packet(AVFormatContext *s, AVPacket *pkt)
     FFStream *const sti = ffstream(st);
     CafContext *caf   = s->priv_data;
     int res, pkt_size = 0, pkt_frames = 0;
-    unsigned remainder = 0;
+    unsigned priming = 0, remainder = 0;
     int64_t left      = CAF_MAX_PKT_SIZE;
 
     if (avio_feof(pb))
@@ -500,13 +501,18 @@ static int read_packet(AVFormatContext *s, AVPacket *pkt)
     if (res < 0)
         return res;
 
-    if (remainder > 0) {
+    if (!caf->packet_cnt)
+        priming = st->codecpar->initial_padding;
+
+    if (priming > 0 || remainder > 0) {
         uint8_t* side_data = av_packet_new_side_data(pkt,
                                                      AV_PKT_DATA_SKIP_SAMPLES,
                                                      10);
         if (!side_data)
             return AVERROR(ENOMEM);
-        AV_WL32(side_data + 4, caf->remainder);
+
+        AV_WL32A(side_data, priming);
+        AV_WL32A(side_data + 4, remainder);
     }
 
     pkt->duration       = pkt_frames;
@@ -536,7 +542,7 @@ static int read_seek(AVFormatContext *s, int stream_index,
         if (caf->data_size > 0)
             pos = FFMIN(pos, caf->data_size);
         packet_cnt = pos / caf->bytes_per_packet;
-        frame_cnt  = caf->frames_per_packet * packet_cnt;
+        frame_cnt  = caf->frames_per_packet * packet_cnt - 
st->codecpar->initial_padding;
     } else if (sti->nb_index_entries) {
         packet_cnt = av_index_search_timestamp(st, timestamp, flags);
         frame_cnt  = sti->index_entries[packet_cnt].timestamp;

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

Reply via email to