From patchwork Wed Dec 28 16:28:44 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Derek Buitenhuis X-Patchwork-Id: 39801 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:bc95:b0:ad:ade2:bfd2 with SMTP id fx21csp4247163pzb; Wed, 28 Dec 2022 08:28:56 -0800 (PST) X-Google-Smtp-Source: AMrXdXscz46ls84EW1Kmaofql/690ksCXuuLbBRHSGWAkNTUi+CJsHSSS1F7gy0DU5gOmWTOcNlT X-Received: by 2002:a17:906:684b:b0:7c1:2fc2:6740 with SMTP id a11-20020a170906684b00b007c12fc26740mr22167112ejs.46.1672244935914; Wed, 28 Dec 2022 08:28:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672244935; cv=none; d=google.com; s=arc-20160816; b=lvGgFt/mSPXFJRr1wRG+JWTXp3ikdIadAf2glIsD9FvvyRgs4sD4Y43JqVsjwrgbaL bJZmejHaq0a7YEQ4bcfppjl4T5FKgOsh4ZtQ6gRNBBFmxaBxUYi8AJITPHeNr7T+Lyyr SAfixwB2E11rXrqCP+76lgg0jcuLn70Rznx520rrcQC320c0xkkyvg44DT7S2mps+r+R eavcNPOMVFLzoil8Q0gGbjvss1CKssbYsjs6Y+9Gb/P7j9Wj1JKJNpm5106p/0eM8jxw ceB/QrHkfeptBHk37TRaJtMyWi/Aqa8ZQjVBhgOlWwHPmYe48IK3KkYqeykwscaES0bg LLVQ== 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 :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:mime-version:message-id:date:to:from :dkim-signature:delivered-to; bh=sKUG5rIx7IJk524eV/MDKd5lrHIcKem1sEF8eIm0e5U=; b=KEt/hF5WMhdyQolVAYWS1dbRsI+Oibb0317mwZFooWkX89+k/ANJwdMeWVc5OQlieN muSbFXc13SNPdlbSPxxR2daIZ0OHe/fsBv/bD2ROt3F6ERWXHPfKMADSn+tj3L1JTlhv eJilUxL6+eyfA04/Y8rNT4wbOV9AehhSJ4xbocuhg4BL+e18sThpa7prgkdO6KGaXWQc 0njlxAec18J3I0N824kQoAKYYlvyeC3Dk1Rdt5YxB6mAb4B/gpMYnB5SkSXiLFyBR6OL BcrQ7IxDWsigR25KVRyFqseeZIzykUeoctACEQ9WakSYVhEeTRRwftNDZzc4T4NF40vK qwGw== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=LQOI1gPL; 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 y99-20020a50bb6c000000b0046b1ffb7211si14278885ede.423.2022.12.28.08.28.55; Wed, 28 Dec 2022 08:28:55 -0800 (PST) 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=20210112 header.b=LQOI1gPL; 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 C6EEE68B9EC; Wed, 28 Dec 2022 18:28:53 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm1-f51.google.com (mail-wm1-f51.google.com [209.85.128.51]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 8D600680C51 for ; Wed, 28 Dec 2022 18:28:47 +0200 (EET) Received: by mail-wm1-f51.google.com with SMTP id bg10so11549259wmb.1 for ; Wed, 28 Dec 2022 08:28:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=D2earPvzPy+0eYLp7dFXGyxU0ERgzXPL74nCRPPlq6s=; b=LQOI1gPLyBXK1iUczaAASfYA+6vraIKP4sZdIkBA+l4SyUcv9b2Y8phXozbcpGS2hE suIqbZLbdm9TyXGu46rLsoYA/JAiolKah+AWPjiSWVeKDYj7zH/vLw4aEMxcJKeXC8Zl l79t7T9mek0NbrHUfji++yCOZtrqUBDwwAN4/mXPjUis8Ye34xnyMHyb2KebLDqM25l6 425wdkxvh+bSdmVoRfoh4oxEMdeI8M6hZYmtA9zXGqP1j8m/D0Obq+cKc7KqX42dquLx p1ab0mtuP0HPZ538jTyf5pdi3wWGzCCjmSP5kj3Q5vPDQQbnb82UCxznheV8wk26ZUlg RJVw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=D2earPvzPy+0eYLp7dFXGyxU0ERgzXPL74nCRPPlq6s=; b=AL0OOT/gPu5XUmSWwQrmbogOPoHOodZuLLRtl55lVZYATYMtyseak3fqqfPtk5xrw/ /PmPq2+7s0S+aadE0V3dvlduAya4rJuq+Rtm3/Um18K+0cDPK9BHWmuAa4W0Mk4PMQGm dbrK+1W7L79qrzN9sFeIYfUQDay1WzEaouZZoocGpI6S0rQxkuHj4DxbNxJehiUEkTvy SMRFdSTYXHqiEih2uAvWdJ8qnFmVoQTa/qrb1CYjKmnI8lI3yXr6ViOIKa0p9mue+CGv 0br/KjeA9anjVHYUa+nNRngVJxbGMrWew1xSdkNjfA2mz7giC3fntaSbYkSBW9nXxzWB OIkw== X-Gm-Message-State: AFqh2krgHuG68ouBR5C5561gJAJRJhqfft2fsESPl3+8k9Q6NX7MhcH5 XMHqQJLrmBaVj9RSb06wFcbwcfsRPcY= X-Received: by 2002:a05:600c:512a:b0:3cf:8957:a441 with SMTP id o42-20020a05600c512a00b003cf8957a441mr18443829wms.12.1672244926572; Wed, 28 Dec 2022 08:28:46 -0800 (PST) Received: from localhost.localdomain (33bf250e.skybroadband.com. [51.191.37.14]) by smtp.gmail.com with ESMTPSA id s16-20020a1cf210000000b003c6bd12ac27sm21190643wmc.37.2022.12.28.08.28.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Dec 2022 08:28:45 -0800 (PST) From: Derek Buitenhuis To: ffmpeg-devel@ffmpeg.org Date: Wed, 28 Dec 2022 16:28:44 +0000 Message-Id: <20221228162844.197098-1-derek.buitenhuis@gmail.com> X-Mailer: git-send-email 2.39.0 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH][RFC][CURSED] mov: Disable advanced_editlist for fragmented MP4 input 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: , Reply-To: FFmpeg development discussions and patches Cc: isasi@google.com Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: Y9hePGH+f+tF Advanced edit list support is entirely broken for fragmented MP4s, currently. mov_fix_index is never run in mov_build_index, since in fragmented MP4s the stco, stsz, stts, and stsc boxes have zero entries, with the index being filled in as each fragment's trun box is seen. The result of this is that the skip samples is never set properly, since half the code thinks it doesn't need to, as advanced_editlist is enabled, but as mov_fix_index is never called, it doesnt get set. This means that any edits for e.g. priming are not properly applied as skip samples side data. This also means remuxing to fragmented MP4 from progressive MP4 with lavf will quietly drop the edit list, currently. Example: $ ffmpeg -loglevel quiet -advanced_editlist 1 -i non_fragmented.mp4 -f md5 - MD5=d02d929f8eb4edef624758a298d5f7c6 $ ffmpeg -loglevel quiet -advanced_editlist 0 -i non_fragmented.mp4 -f md5 - MD5=d02d929f8eb4edef624758a298d5f7c6 $ ffmpeg -loglevel quiet -advanced_editlist 1 -i fragmented.mp4 -f md5 - MD5=e38b110f586fa886ff94e0ca98a95d59 <-- wrong, extra samples are output instead of being skipped $ ffmpeg -loglevel quiet -advanced_editlist 0 -i fragmented.mp4 -f md5 - MD5=d02d929f8eb4edef624758a298d5f7c6 We cannot call mov_fix_index after reading a trun box since mov_fix_index seems to assume it is only called once, on a fully complete index, an multiple calls to it don't seem like they'd work, so the "best" option seems to be disabling advanced edit list support entirely for the time being, as it is broken for these types of files. Signed-off-by: Derek Buitenhuis --- Obviously, I think this is a pretty gross 'fix', but short of a rewrite(-ish) of advanced edit list support, I don't know a better option. Ideas welcome. I've CCed the authors of advanced edit list support, although I am not sure if they're still around or involved in FFmpeg. Files from example above: * https://www.dropbox.com/s/zw626kck6d9eist/non_fragmented.mp4?dl=0 * https://www.dropbox.com/s/c46ajkqewqurdrz/fragmented.mp4?dl=0 --- libavformat/mov.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/libavformat/mov.c b/libavformat/mov.c index 29bd3103e3..e0b7df2815 100644 --- a/libavformat/mov.c +++ b/libavformat/mov.c @@ -4499,6 +4499,20 @@ static int mov_read_trak(MOVContext *c, AVIOContext *pb, MOVAtom atom) avpriv_set_pts_info(st, 64, 1, sc->time_scale); + /* + * Advanced edit list support does not work with fragemented MP4s, which + * have stsc, stsz, stco, and stts with zero entries in the moov atom. + * In these files, trun atoms may be streamed in. + * + * It cannot be used with use_mfra_for = {pts,dts} either, as the index + * is not complete, but filled in as more trun atoms are read, as well. + */ + if (!sc->stts_count || c->use_mfra_for != FF_MOV_FLAG_MFRA_AUTO) { + av_log(c->fc, AV_LOG_WARNING, "advanced_editlist does not work with fragmented " + "MP4. disabling.\n"); + c->advanced_editlist = 0; + } + mov_build_index(c, st); if (sc->dref_id-1 < sc->drefs_count && sc->drefs[sc->dref_id-1].path) {