From patchwork Fri Mar 12 14:48:46 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Derek Buitenhuis X-Patchwork-Id: 26354 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id 8AD1344ACEB for ; Fri, 12 Mar 2021 16:49:03 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 6516F68AD01; Fri, 12 Mar 2021 16:49:03 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wr1-f48.google.com (mail-wr1-f48.google.com [209.85.221.48]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 7AEA968ACC4 for ; Fri, 12 Mar 2021 16:48:57 +0200 (EET) Received: by mail-wr1-f48.google.com with SMTP id y16so4971354wrw.3 for ; Fri, 12 Mar 2021 06:48:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=PUCJ71rJ7FoLdnjqYo51Am0u6s5oi1AVU4L5syfCWDs=; b=SLHq3z44GxENhLxH/dBek1pg7p5TA/5FeTiD02xkxMWjdbTQfKxKaIruwHgsFEFGur fJ+3H8Hyq3gSFISKv+hxpDocShZ1MfCveXCht7ZV1dNMLLv8ggb2dpHUuV4LgPm2p5CL oAK6qKci0P7K6Me/MQ8V6TMvKw08tPC2U9NY/dU4kh5hi30e0U+SphtRrxW1XxLZ/nK9 lf04KF/aO+Mm8+LD/8bs68GtOkYVXC7HiMIZHD81/87EwGOXukJXV+os0Rtnw45NMd/U sj5NDZI7KQufpec8cGjx77DduvFyNIM+vdph5dc+lZsey9pHt+Qb0rU5ywKwmhxSg7W6 LjLA== 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=PUCJ71rJ7FoLdnjqYo51Am0u6s5oi1AVU4L5syfCWDs=; b=MQf31gYo7hFqpG+3baF8ekyAAuV38FostEJDoSZKoLH6QJlPvI/egJSRx6MJVuNx15 E2L2oH5dpj9nrwRFUQfK3nVvZaNg/BjWvP2jbAOMzk4hGaUvMuT6dbLIMwDENq19a+TN WIPhlV2qYYn+VJclRcHBjMPQIs1fr/MIKpVWuJ2CUbOMAmJEO0uUxp7tCBC3Vo7CzzTg 280qrkyQq0euUxgLhcygtadxTuJeK6AkC9cyVaUPWyf5Xvgx9LxrpXOMTFTnKUi2wFba wIp8ah2lWPpLLPbSr0cQzyOlO6StLPJQGRQZ03UhGQc7V6qZeSH5xfLZHsgM6qOG5bFQ ffaQ== X-Gm-Message-State: AOAM530vVfIyiAiKrdpPcP96NomaKqOWBHiG0awMuKtKAaKUinqflzde 5MrgAlhO2iTSenDwO//HnaYr60rAAbU= X-Google-Smtp-Source: ABdhPJw6amfGUrkBA2ArxMJigp8l3vvo64dV2dj5OC5oRNIZqMeHAl0oitscBAh/bZrYbJKWeGMNdw== X-Received: by 2002:adf:ed46:: with SMTP id u6mr14227481wro.350.1615560536790; Fri, 12 Mar 2021 06:48:56 -0800 (PST) Received: from localhost.localdomain ([82.129.110.36]) by smtp.gmail.com with ESMTPSA id f14sm2398902wmf.7.2021.03.12.06.48.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Mar 2021 06:48:56 -0800 (PST) From: Derek Buitenhuis To: ffmpeg-devel@ffmpeg.org Date: Fri, 12 Mar 2021 14:48:46 +0000 Message-Id: <20210312144846.181794-1-derek.buitenhuis@gmail.com> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20210310160757.59501-1-derek.buitenhuis@gmail.com> References: <20210310160757.59501-1-derek.buitenhuis@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v2] avformat/mov: Properly consider if the file is self-initializing when marking sidx reading complete 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Files with the "dash" major brand are guaranteed to only have a single initialization range for the whole file. We can check this and stop appropriately - which is useful, as the existing check to see if the offset reaches the end of the file is not sufficient. For example, Premiere creates valid self-initializing ISOBMFF files that contain a single 'uuid' box appended at the end, after the last 'moof', and this check does not catch that, which causes, for example, probing to traverse the entire file (every single 'moof'), which is extremely slow over a network, which is the main place these self-initializing fragmented ISOBMFF files would be used. This is the same behavior that was addressed in 2ff3c466eca66bb8eb32bb41a4ce70fe285e3ea0 for live-style fragmented files. Signed-off-by: Derek Buitenhuis --- Updated the commit message too, to reflect that the files are actually a YouTube-muxed file that was opened in Premiere, which appends XMP metadata in a 'uuid' box to files it opens. Gross. --- libavformat/mov.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/libavformat/mov.c b/libavformat/mov.c index 23b0ead01e..0eb52ab6e6 100644 --- a/libavformat/mov.c +++ b/libavformat/mov.c @@ -5052,6 +5052,8 @@ static int mov_read_sidx(MOVContext *c, AVIOContext *pb, MOVAtom atom) AVStream *ref_st = NULL; MOVStreamContext *sc, *ref_sc = NULL; AVRational timescale; + AVDictionaryEntry *major_brand = av_dict_get(c->fc->metadata, "major_brand", NULL, AV_DICT_MATCH_CASE); + AVDictionaryEntry *compatible_brands = av_dict_get(c->fc->metadata, "compatible_brands", NULL, AV_DICT_MATCH_CASE); version = avio_r8(pb); if (version > 1) { @@ -5120,7 +5122,13 @@ static int mov_read_sidx(MOVContext *c, AVIOContext *pb, MOVAtom atom) sc->has_sidx = 1; // See if the remaining bytes are just an mfra which we can ignore. - is_complete = offset == stream_size; + // + // Also check to see if the file is Self-initializing, which guarantees + // only a single initialization range is present for the whole file. + // See: ISO-IEC 23009-1 Section 6.3.5. + is_complete = offset == stream_size || + (major_brand && !strncmp(major_brand->value, "dash", 4)) || + (compatible_brands && strstr(compatible_brands->value, "dash")); if (!is_complete && (pb->seekable & AVIO_SEEKABLE_NORMAL)) { int64_t ret; int64_t original_pos = avio_tell(pb);