From patchwork Thu May 30 19:38:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wang Cao X-Patchwork-Id: 49411 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a59:9183:0:b0:460:55fa:d5ed with SMTP id s3csp64637vqg; Thu, 30 May 2024 12:38:52 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCWnCMsV08IIh1Tge4qsoN6MPTqWh+g7hz4jmeIF1iZjnYkdDPLBJ6lpMdC88ZW2ja00DbGX2EB+bG4k/nzVL7zNvqiItIu7NQP2wA== X-Google-Smtp-Source: AGHT+IH8jvD6XJqahYd0PjF9fgO1djM5/ga6jTfQC/Gyq7SJEZA3dFEqtW+qTTZiY212/9JyQO6N X-Received: by 2002:a17:907:5013:b0:a65:fbc6:b94a with SMTP id a640c23a62f3a-a65fbc6baa0mr146316266b.40.1717097932262; Thu, 30 May 2024 12:38:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1717097932; cv=none; d=google.com; s=arc-20160816; b=r83gsZN9HQX0k4/ldQVFUDelZTM9Pz48ILmnBshk8sDx1cqt5XighYwT5dmrBEDuK4 xgeHPqz3J9TaeYVCVw/qQNsShXS6raOlIl1DJZTrxC3N/LQDBbx2XaPs8gQhUADyNlD5 srET64xOeOfG0Fyz7jaJwAhbWa38SRDcfq28EF1Va81aRpnghFKjZc7FIOyyWh4G0GCd oV6++gr5LcyhZfnPcOLIRfUQeYLXGWuKmzB5lPDwjleuvy0tRcQ8Gc5rJ52SJmC1SM8j W6NIvZRpkAJDkWDMe7VNwOz5anOR6RG2AYJlarzsg4z+lkrmHGQLRBhXACSGsbDJK0CU mvhA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc:reply-to:from :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:to:message-id:mime-version:date :delivered-to; bh=mzAXqCUCSYw4is2AeHIGZflq9KlZE56rd7332hLsc+s=; fh=Z18/o64rc4tZes3nSTVLKZglumwhljiLdmjurcfLBe8=; b=GnqRPoI+ekl2yg5sZ8LlJABwROdjx1nRb6GqkE0l2wtoQYl1Dr7J+NhCOdNyP4gEPs tQvVwnI84VGPneWHdBcmeN6xbr+nysAeM6l370KjzoPscR+1vT9/Zek+uYn09KWzslEK +APbvEw2nBnoBCvbWr4QNFS373o/hN93AZqgxzqjfZ0d9kWzLKOTvYVI4xxtv4Xynzhb Wbe22AQ/w2lJtzuOR1HHdczyDkQ60mcG2A6YrBGh5+cX7YocB7dXD7D151GreenuaP3i G/XvSzZIbBx6P+x1aYF+BZrAulWGZTDCdaalRqbi88U8TJnUMCpoEEXhGXsTnAeemOsH 2Ctg==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id a640c23a62f3a-a67eaf65300si7780766b.842.2024.05.30.12.38.51; Thu, 30 May 2024 12:38:52 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id CF93F68D363; Thu, 30 May 2024 22:38:48 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org 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-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: , X-Patchwork-Original-From: Wang Cao via ffmpeg-devel From: Wang Cao Reply-To: FFmpeg development discussions and patches Cc: Wang Cao Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: eh2IabthS/a3 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 &&