From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTP id 59EC34B1DF for ; Thu, 30 May 2024 19:38:50 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 7F97768D494; Thu, 30 May 2024 22:38:48 +0300 (EEST) Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.202]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id EB0A768BFFF for ; Thu, 30 May 2024 22:38:41 +0300 (EEST) Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-62a3dec382eso13498157b3.1 for ; Thu, 30 May 2024 12:38:41 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717097920; x=1717702720; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=q2rtu2bR7VFA8xGaqWvrTx729W4eNqXk2mzG3m0OC2U=; b=YUJSylOQX3Wss9yNa/p2y6rwvHOA7WQ7AEfDu9vlQbPIS94jGwRe0vC3VFe0ahk/iQ 7d+DFeMGnXVLXPW7HmCFqtyuFdF7JBfG4OFsR58VMoDnQG6cR3Qi1+GBfKNiHu34QRN/ +O8ExhBdGd1Df7GeqhiCxpQxMbTAUuMseuWqMbA9bs+aLGeQ7LJoCfZ5io1ynjHju5W3 A7eeOFCdMTkyHCe/H9VldeJNOW3RGj3JF2A4Lt6dUo54zHxAmy8lk9TTxrm793BQIB/q J2ctxAGw3zLkhr4ZHzIyWIIFVFzXE7JEst77bFNKhgPbhVB3aR23IWviumyLjMplafoT X5sA== X-Gm-Message-State: AOJu0YyAbimtBqGaN3Lf/fWlg/MLfOIAaHO9DVeA595HFxOrJQpBORMR GbNYQJaPCJaoDh73yagfDisSKLyOns8lFRjFYuvek3zQadYJyVtYkWvUUEfUz8sb+p6fquWDi5H m37IwjFXsEI7j22p63GKlyWtAT8SHOnR6m6/D4QN6IYFL/Hf7ke+5/M+9SlFQJHQWyoJCYVpZb6 7HQ70bYvJxYlGBY6r/BshmWWysQw7X3nTzqFdse7Q= X-Google-Smtp-Source: AGHT+IEavd0zl2oDdAwgGTOCY0KVlIlouqkgcbP35f+vtX0awjjHGegzFzWw5dQFQUVgjGbAZU8aW8IdUhMv X-Received: from wangcao.c.googlers.com ([fda3:e722:ac3:cc00:28:9cb1:c0a8:109c]) (user=wangcao job=sendgmr) by 2002:a05:690c:f8e:b0:61b:32dc:881d with SMTP id 00721157ae682-62c6cb54bbamr9189917b3.3.1717097920032; Thu, 30 May 2024 12:38:40 -0700 (PDT) Date: Thu, 30 May 2024 19:38:36 +0000 Mime-Version: 1.0 X-Mailer: git-send-email 2.45.1.288.g0e0cd299f1-goog Message-ID: <20240530193836.2602182-1-wangcao@google.com> To: ffmpeg-devel@ffmpeg.org Subject: [FFmpeg-devel] [PATCH] mov.c fix the duration for the last audio frame. X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: Wang Cao via ffmpeg-devel Reply-To: FFmpeg development discussions and patches Cc: Wang Cao Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: 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".