Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
From: Wang Cao via ffmpeg-devel <ffmpeg-devel@ffmpeg.org>
To: ffmpeg-devel@ffmpeg.org
Cc: Wang Cao <wangcao@google.com>
Subject: [FFmpeg-devel] [PATCH] mov.c fix the duration for the last audio frame.
Date: Thu, 30 May 2024 19:38:36 +0000
Message-ID: <20240530193836.2602182-1-wangcao@google.com> (raw)

It is possible that the actual audio data only occupy part of the last audio frame. This can be signaled by duration in the "trun" atom. We should respect the metadata of file and set the duration correctly.
---
 libavformat/mov.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/libavformat/mov.c b/libavformat/mov.c
index 45eca74d1d..caea36b495 100644
--- a/libavformat/mov.c
+++ b/libavformat/mov.c
@@ -5700,11 +5700,16 @@ static int mov_read_trun(MOVContext *c, AVIOContext *pb, MOVAtom atom)
 
         sc->ctts_data[index_entry_pos].count = 1;
         sc->ctts_data[index_entry_pos].duration = ctts_duration;
+        if (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) {
+            sc->ctts_data[index_entry_pos].duration = sample_duration;
+        } else {
+            sc->ctts_data[index_entry_pos].duration = ctts_duration;
+        }
         index_entry_pos++;
 
         av_log(c->fc, AV_LOG_TRACE, "AVIndex stream %d, sample %d, offset %"PRIx64", dts %"PRId64", "
-                "size %u, distance %d, keyframe %d\n", st->index,
-                index_entry_pos, offset, dts, sample_size, distance, keyframe);
+                "size %u, distance %d, keyframe %d duration %d\n", st->index,
+                index_entry_pos, offset, dts, sample_size, distance, keyframe, sc->ctts_data[index_entry_pos-1].duration);
         distance++;
         if (av_sat_add64(dts, sample_duration) != dts + (uint64_t)sample_duration)
             return AVERROR_INVALIDDATA;
@@ -9894,6 +9899,9 @@ static int mov_finalize_packet(AVFormatContext *s, AVStream *st, AVIndexEntry *s
     }
     if (sc->ctts_data && sc->ctts_index < sc->ctts_count) {
         pkt->pts = av_sat_add64(pkt->dts, av_sat_add64(sc->dts_shift, sc->ctts_data[sc->ctts_index].duration));
+        if (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) {
+            pkt->duration = sc->ctts_data[sc->ctts_index].duration;
+        }
         /* update ctts context */
         sc->ctts_sample++;
         if (sc->ctts_index < sc->ctts_count &&
-- 
2.45.1.288.g0e0cd299f1-goog

_______________________________________________
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".

             reply	other threads:[~2024-05-30 19:38 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-05-30 19:38 Wang Cao via ffmpeg-devel [this message]
2024-05-30 23:49 ` Michael Niedermayer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240530193836.2602182-1-wangcao@google.com \
    --to=ffmpeg-devel@ffmpeg.org \
    --cc=wangcao@google.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

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