From patchwork Mon Apr 23 15:46:55 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Derek Buitenhuis X-Patchwork-Id: 8603 Delivered-To: ffmpegpatchwork@gmail.com Received: by 2002:a02:155:0:0:0:0:0 with SMTP id c82-v6csp847655jad; Mon, 23 Apr 2018 08:53:02 -0700 (PDT) X-Google-Smtp-Source: AIpwx4+QFBUgZmAq/oK3U1leOHD3091Sav8THiEpuE6j3Fu/b2F8s/e7t33QvFNfUXP/ZM83fzXh X-Received: by 2002:adf:a556:: with SMTP id j22-v6mr16418874wrb.155.1524498782788; Mon, 23 Apr 2018 08:53:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524498782; cv=none; d=google.com; s=arc-20160816; b=0EtzldEMAkZdg0IuTIp7hg3oOHCOnKILYSdFKAj/EU3bBsNONQ6xm0IfBhp74dDAIb GYUFJ2prUEzLcLhUu1azKCPshuuGAM4lc94RZbi2IRtzCUhyKmKvDcmQ3oMNFlCbO+Fj AHJpq1IpGdgCxUiQ/SBaFohrnJga1bm+wrmr9m7OHFdF1Sqxm/wU6TtunVvN3UZA43qu KJ8taFUMfmFMzltu4mR5dyvm4wudkv+V7GcJ3vo/0m75W/7g3QNtUdhAMfHAwHdQKE68 rSJoIz+x4GrJkMyzaAAJJatW++IOSwyO3Sk5TafP00BpUKiAS8MriruRdluUxc+vonG7 nJJw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:message-id:date:to:from:dkim-signature :delivered-to:arc-authentication-results; bh=3jmRFSk7ejGYeo0jfPgqXV9P2Xkdd1cBG3lLwmOCmlo=; b=u9SufZWtM7HaiVL3bXqxwyyyvxWPh5hhI7MF/o7KmKlUDw59Pwt00I3nM8gpUzfna3 n5Pt9ML3js++od2nVdgmfLSMVDVcu9hjbwBjBbSqV0ItLQGUYSveVIxMfLCg6oGcEeAI NZK0rxpev1nFq1MB7uu0RfSH2cufme2vq0rqgLW0dNvnet1hliHk1SuUuyxFAFMlnDdu /RvRHhNal0aFbHmqWGpPjqvWL+ORiYqTTIqaiBJCZoCzWCwjAOyd+EoT0Amly0ed6AbI O5m9HdQG1+NWuXVuaBz+mtW5TJyEbd4HthYlDyfm8tSp6fj4rmK6GmX4kpmq1ZUFEt1J rL0Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=ahHMUiBn; 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; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id 60-v6si8328069wrs.361.2018.04.23.08.53.01; Mon, 23 Apr 2018 08:53:02 -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; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=ahHMUiBn; 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; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id F394368A106; Mon, 23 Apr 2018 18:52:30 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wr0-f196.google.com (mail-wr0-f196.google.com [209.85.128.196]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 92D4E6898D4 for ; Mon, 23 Apr 2018 18:52:24 +0300 (EEST) Received: by mail-wr0-f196.google.com with SMTP id g21-v6so15203033wrb.8 for ; Mon, 23 Apr 2018 08:52:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id; bh=GQz6qp9BpWLYSjGnAcZ604SBKghQMoA1BgeQOYzLTLM=; b=ahHMUiBnlSWD8XO2XCmxlzxy5SjXQdLKPFy40a466A/rV0WNLoe9I7XvymiAL+KGGz UYioWKhxBoBeSzcGw8xoXfTQbVgUHZhZilnzNSo0+5sm4YwV/vQHgmGEso5L9dXEPNtg NtTIg4uVwXV7ngQjb8X9+ZSr4d9DEI9hYMiP0v92+aeQdyeYDcaSsyxipxhs2+qO6XMU ixA+J5IwQOyADHQ+jfb85zXJGLcRC4H5fRKbGNFHVgyyBigQPHIGDbuuuTYOUVBpW9uP iFIt20fDNTg749ryDdHdAjypIjC3N1jphItpQ7srEnAe5KvNkrgkQNLl6kqCC60vgYzE IjCg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id; bh=GQz6qp9BpWLYSjGnAcZ604SBKghQMoA1BgeQOYzLTLM=; b=UfowABENuz8lgvnbNOz3z/ZnYAbw6URXrRwkqspomvZeiobXmnG3wQfztrdtfmDTG9 uvm7LJGbvlme+tCbwXW2VaIrpEF3kciJ5bxZdh1ovwRleVEyWUpY0fszvhP2biOOWEAh F2wPPdHWpHNJwgLC5yaZ7Mnv7SjsuWdW2KpxjVnOguBYoa4EPbywDNXAZtHaLfkGHme5 oqjWSCSCaTErFK2gcjD9NdNEWBTOzy3Yzf4zrCbUP0hrKZYIN9sGFEgno9E6SmXecow7 PjIR0yRGy66XKUNmavdGmDMXftL6vuyYK4rcbC+CiRmZNgjNA9PIU+ZTewMrxwZ2rONL WKVQ== X-Gm-Message-State: ALQs6tCL2apy4+7TAFOHotAWyrAJbVNPHKrMrPY+HJSjKYRnpp/wWMDI Xy7KSMYBS+hfLOdHnHx5DKxL9Aq8 X-Received: by 10.28.12.129 with SMTP id 123mr9680664wmm.75.1524498452022; Mon, 23 Apr 2018 08:47:32 -0700 (PDT) Received: from vimeo-vm.localdomain ([81.2.156.226]) by smtp.gmail.com with ESMTPSA id n14-v6sm15048453wrj.16.2018.04.23.08.47.30 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 23 Apr 2018 08:47:31 -0700 (PDT) From: Derek Buitenhuis To: ffmpeg-devel@ffmpeg.org Date: Mon, 23 Apr 2018 16:46:55 +0100 Message-Id: <1524498415-23141-1-git-send-email-derek.buitenhuis@gmail.com> X-Mailer: git-send-email 1.8.3.1 Subject: [FFmpeg-devel] [PATCH v2] mov: Properly abide by the track's media duration X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" The track's media duration from the mdhd atom takes precedence over both the stts and elst atom for calculating and setting the track's total duraion. Technically, we shouldn't be using the stts atom at all for calculating stream durations. This fixes incorrect stream and final packet durations on files with edit lists that are longer than the media duration. The FATE changes are expected, and output is more correct (the AAC frame is not 1028 samples). Signed-off-by: Derek Buitenhuis --- libavformat/mov.c | 6 +++--- tests/ref/fate/adtstoasc_ticket3715 | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/libavformat/mov.c b/libavformat/mov.c index 8fea670..1975011 100644 --- a/libavformat/mov.c +++ b/libavformat/mov.c @@ -2932,7 +2932,7 @@ static int mov_read_stts(MOVContext *c, AVIOContext *pb, MOVAtom atom) st->nb_frames= total_sample_count; if (duration) - st->duration= duration; + st->duration= FFMIN(st->duration, duration); sc->track_end = duration; return 0; } @@ -3671,8 +3671,8 @@ static void mov_fix_index(MOVContext *mov, AVStream *st) } } - // Update av stream length - st->duration = edit_list_dts_entry_end - start_dts; + // Update av stream length, if it ends up shorter than the track's media duration + st->duration = FFMIN(st->duration, edit_list_dts_entry_end - start_dts); msc->start_pad = st->skip_samples; // Free the old index and the old CTTS structures diff --git a/tests/ref/fate/adtstoasc_ticket3715 b/tests/ref/fate/adtstoasc_ticket3715 index 96795a2..c5f03e4 100644 --- a/tests/ref/fate/adtstoasc_ticket3715 +++ b/tests/ref/fate/adtstoasc_ticket3715 @@ -92,4 +92,4 @@ 0, 83968, 83968, 1024, 465, 0xeb3ce0af 0, 84992, 84992, 1024, 326, 0x7be4a667 0, 86016, 86016, 1024, 339, 0x2cf4a71f -0, 87040, 87040, 1028, 258, 0xd4007ad4 +0, 87040, 87040, 1024, 258, 0xd4007ad4