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
|
|
| 26 | 26 | #include "config_components.h" |
| 27 | 27 | |
| 28 | 28 | #include <inttypes.h> |
| | 29 | #include <libavutil/avutil.h> |
| 29 | 30 | #include <limits.h> |
| 30 | 31 | #include <stdint.h> |
| 31 | 32 | |
| … |
… |
|
| 37 | 38 | #include "libavutil/intreadwrite.h" |
| 38 | 39 | #include "libavutil/intfloat.h" |
| 39 | 40 | #include "libavutil/mathematics.h" |
| | 41 | #include "libavutil/samplefmt.h" |
| 40 | 42 | #include "libavutil/avassert.h" |
| 41 | 43 | #include "libavutil/avstring.h" |
| 42 | 44 | #include "libavutil/dict.h" |
| … |
… |
static int mov_read_trun(MOVContext *c, AVIOContext *pb, MOVAtom atom)
|
| 5910 | 5912 | sti->index_entries[index_entry_pos].flags = index_entry_flags; |
| 5911 | 5913 | |
| 5912 | 5914 | 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 | } |
| 5914 | 5920 | index_entry_pos++; |
| 5915 | 5921 | |
| 5916 | 5922 | 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); |
| 5919 | 5925 | distance++; |
| 5920 | 5926 | if (av_sat_add64(dts, sample_duration) != dts + (uint64_t)sample_duration) |
| 5921 | 5927 | return AVERROR_INVALIDDATA; |
| … |
… |
static int mov_finalize_packet(AVFormatContext *s, AVStream *st, AVIndexEntry *s
|
| 10722 | 10728 | } |
| 10723 | 10729 | if (sc->ctts_data && sc->ctts_index < sc->ctts_count) { |
| 10724 | 10730 | 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 | } |
| 10725 | 10734 | /* update ctts context */ |
| 10726 | 10735 | sc->ctts_sample++; |
| 10727 | 10736 | if (sc->ctts_index < sc->ctts_count && |