Ticket #11312: 0001-libavformat-mov.c-update-the-audio-packet-duration-b.patch

File 0001-libavformat-mov.c-update-the-audio-packet-duration-b.patch, 2.5 KB (added by Thierry, 2 years ago)

Patch which seems to fix the issue

  • libavformat/mov.c

    From 0ccbeaf13cdcfb2eec2cd69efa24aba595614fdf Mon Sep 17 00:00:00 2001
    From: Thierry Foucu <tfoucu@gmail.com>
    Date: Tue, 19 Nov 2024 16:58:25 -0800
    Subject: [PATCH] [libavformat/mov.c] update the audio packet duration based on
     trun
    
    ---
     libavformat/mov.c | 15 ++++++++++++---
     1 file changed, 12 insertions(+), 3 deletions(-)
    
    diff --git a/libavformat/mov.c b/libavformat/mov.c
    index 954ff657a9..6429b0625b 100644
    a b  
    2626#include "config_components.h"
    2727
    2828#include <inttypes.h>
     29#include <libavutil/avutil.h>
    2930#include <limits.h>
    3031#include <stdint.h>
    3132
    … …  
    3738#include "libavutil/intreadwrite.h"
    3839#include "libavutil/intfloat.h"
    3940#include "libavutil/mathematics.h"
     41#include "libavutil/samplefmt.h"
    4042#include "libavutil/avassert.h"
    4143#include "libavutil/avstring.h"
    4244#include "libavutil/dict.h"
    … … static int mov_read_trun(MOVContext *c, AVIOContext *pb, MOVAtom atom)  
    59105912        sti->index_entries[index_entry_pos].flags = index_entry_flags;
    59115913
    59125914        sc->ctts_data[index_entry_pos].count = 1;
    5913         sc->ctts_data[index_entry_pos].duration = ctts_duration;
     5915        if (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) {
     5916            sc->ctts_data[index_entry_pos].duration = sample_duration;
     5917        } else {
     5918            sc->ctts_data[index_entry_pos].duration = ctts_duration;
     5919        }
    59145920        index_entry_pos++;
    59155921
    59165922        av_log(c->fc, AV_LOG_TRACE, "AVIndex stream %d, sample %d, offset %"PRIx64", dts %"PRId64", "
    5917                 "size %u, distance %d, keyframe %d\n", st->index,
    5918                 index_entry_pos, offset, dts, sample_size, distance, keyframe);
     5923                "size %u, distance %d, keyframe %d duration %d\n", st->index,
     5924                index_entry_pos, offset, dts, sample_size, distance, keyframe, sc->ctts_data[index_entry_pos-1].duration);
    59195925        distance++;
    59205926        if (av_sat_add64(dts, sample_duration) != dts + (uint64_t)sample_duration)
    59215927            return AVERROR_INVALIDDATA;
    … … static int mov_finalize_packet(AVFormatContext *s, AVStream *st, AVIndexEntry *s  
    1072210728    }
    1072310729    if (sc->ctts_data && sc->ctts_index < sc->ctts_count) {
    1072410730        pkt->pts = av_sat_add64(pkt->dts, av_sat_add64(sc->dts_shift, sc->ctts_data[sc->ctts_index].duration));
     10731        if (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) {
     10732            pkt->duration = sc->ctts_data[sc->ctts_index].duration;
     10733        }
    1072510734        /* update ctts context */
    1072610735        sc->ctts_sample++;
    1072710736        if (sc->ctts_index < sc->ctts_count &&