From patchwork Fri Feb 18 23:19:57 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?b?Q2zDqW1lbnQgQsWTc2No?= X-Patchwork-Id: 34396 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6838:d078:0:0:0:0 with SMTP id x24csp1378053nkx; Fri, 18 Feb 2022 15:20:27 -0800 (PST) X-Google-Smtp-Source: ABdhPJxzIrjakMpTx93kFsoyED2b2ggLXa4uAq92xol6s9cnK7YsTyEL5btrHkiTBPfR6cao22Cu X-Received: by 2002:a05:6402:440d:b0:412:9e8a:5e51 with SMTP id y13-20020a056402440d00b004129e8a5e51mr10366200eda.362.1645226427434; Fri, 18 Feb 2022 15:20:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1645226427; cv=none; d=google.com; s=arc-20160816; b=Oko/SExTPNzZVJX2aPVGao5bWVI8qCQLMIdEjqXaiV8LGiyF6FUg+pPC3YnjVPbHz1 PFUIzcDqXSseBD2zpQZm1dISpgrGKFFkN+yBg6rQJ5idPAlHntLeXEWG/gQ14mR0h1oc d4uTGFXHFvZ3hfJ07s0UuWeOVIL+UT5CZ+nK3YYRbTz7BmI1MGq4fOFCssoaGERftdtq 54LHB09tDweF6pFKwj7ukTUmY2M3pyvK2SBp3zNic08StzF6Raf/ap/W7WCFcxd5OyOQ BaLWYYDIjERGM+RP8HNDYEtKud/r9l/1i7Y4ujEzqbGLDhvYFt/ZumVE98zGTJNwhHhs DX9A== 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:references:in-reply-to :message-id:date:to:from:dkim-signature:delivered-to; bh=yZ0DrCiS7NbTYn22y3norhJVzM3anTlEGC4SYOgEFYE=; b=09ZGmnHutqvACqjtAyoBjfqbxkOvUSZfhx0pYEdkh8p/liYjsCMQFBaZq9g6HUI/lc dRhRV+YNN/xbNEj0PQ7X2jJe4nC1lSXOeH0EOGJ+VGEDPsJT1bJZstcAylY42G0jUmAE /I92RTEumdXCYWZx4SAKImH5/eAJ7B0N4a4PNBcMdMusYek1rXBFMXGShuu7oDGhMqo7 xvwmmFeko+SBFsgPdCiNqI990qRjDH+KW9J4ZzUGj7dWsdRKNE06rCLZVg/VRc//9TgT L4bBIhAgVuJDvIarnlVXWLukrdvGnKCUWphgilxU7aAJIFvAUZGnMAArgsqcH9L/h+Ac u7Nw== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@pkh.me header.s=selector1 header.b=dczMyyxh; 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=NONE dis=NONE) header.from=pkh.me Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id hc42si4807088ejc.369.2022.02.18.15.20.27; Fri, 18 Feb 2022 15:20:27 -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=@pkh.me header.s=selector1 header.b=dczMyyxh; 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=NONE dis=NONE) header.from=pkh.me Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id D049168B0E4; Sat, 19 Feb 2022 01:20:15 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from ssq0.pkh.me (laubervilliers-656-1-228-164.w92-154.abo.wanadoo.fr [92.154.28.164]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 3F5DC68AF2A for ; Sat, 19 Feb 2022 01:20:09 +0200 (EET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pkh.me; s=selector1; t=1645226403; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=aHcJ9E6Czagwq12x8X7Rivq/nVJEMd0c0ePANwkLqwc=; b=dczMyyxhhESmQx9TuHfsFDzqUraGBqgIu082XInmvCXFUW04EoYeopvhk/g2D0MP3iViI6 GHHGtMwDUACGy1k8QMcGlHQm0nBBmMnV2SIU0tVLhDGkVrWQ7KNKIwvx5caAO4oAnD7sjk ZwPilsEVCpQqoLmiHJ2ZmOcvlSmTkNA= Received: from localhost (ssq0.pkh.me [local]) by ssq0.pkh.me (OpenSMTPD) with ESMTPA id 6b23e1df; Fri, 18 Feb 2022 23:20:03 +0000 (UTC) From: =?utf-8?b?Q2zDqW1lbnQgQsWTc2No?= To: ffmpeg-devel@ffmpeg.org Date: Sat, 19 Feb 2022 00:19:57 +0100 Message-Id: <20220218232001.345826-2-u@pkh.me> X-Mailer: git-send-email 2.34.0 In-Reply-To: <20220218232001.345826-1-u@pkh.me> References: <20220218232001.345826-1-u@pkh.me> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 1/5] avformat/mov: prepare sbgp parsing for other grouping types 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: =?utf-8?b?Q2zDqW1lbnQgQsWTc2No?= Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: HUamrxQeqImB --- libavformat/mov.c | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/libavformat/mov.c b/libavformat/mov.c index 5e26267810..aade052b7a 100644 --- a/libavformat/mov.c +++ b/libavformat/mov.c @@ -3137,6 +3137,8 @@ static int mov_read_sbgp(MOVContext *c, AVIOContext *pb, MOVAtom atom) unsigned int i, entries; uint8_t version; uint32_t grouping_type; + MOVSbgp *table, **tablep; + int *table_count; if (c->fc->nb_streams < 1) return 0; @@ -3146,28 +3148,34 @@ static int mov_read_sbgp(MOVContext *c, AVIOContext *pb, MOVAtom atom) version = avio_r8(pb); /* version */ avio_rb24(pb); /* flags */ grouping_type = avio_rl32(pb); - if (grouping_type != MKTAG( 'r','a','p',' ')) - return 0; /* only support 'rap ' grouping */ + + if (grouping_type == MKTAG('r','a','p',' ')) { + tablep = &sc->rap_group; + table_count = &sc->rap_group_count; + } else { + return 0; + } + if (version == 1) avio_rb32(pb); /* grouping_type_parameter */ entries = avio_rb32(pb); if (!entries) return 0; - if (sc->rap_group) - av_log(c->fc, AV_LOG_WARNING, "Duplicated SBGP atom\n"); - av_free(sc->rap_group); - sc->rap_group_count = 0; - sc->rap_group = av_malloc_array(entries, sizeof(*sc->rap_group)); - if (!sc->rap_group) + if (*tablep) + av_log(c->fc, AV_LOG_WARNING, "Duplicated SBGP %s atom\n", av_fourcc2str(grouping_type)); + av_freep(tablep); + table = av_malloc_array(entries, sizeof(*table)); + if (!table) return AVERROR(ENOMEM); + *tablep = table; for (i = 0; i < entries && !pb->eof_reached; i++) { - sc->rap_group[i].count = avio_rb32(pb); /* sample_count */ - sc->rap_group[i].index = avio_rb32(pb); /* group_description_index */ + table[i].count = avio_rb32(pb); /* sample_count */ + table[i].index = avio_rb32(pb); /* group_description_index */ } - sc->rap_group_count = i; + *table_count = i; if (pb->eof_reached) { av_log(c->fc, AV_LOG_WARNING, "reached eof, corrupted SBGP atom\n"); From patchwork Fri Feb 18 23:19:58 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?b?Q2zDqW1lbnQgQsWTc2No?= X-Patchwork-Id: 34397 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6838:d078:0:0:0:0 with SMTP id x24csp1378139nkx; Fri, 18 Feb 2022 15:20:36 -0800 (PST) X-Google-Smtp-Source: ABdhPJyv9VtK+HpdV0ZMOUSJxJLx+OaJC3jxhNRwX3RF1h9bHrvl/PnkYTtAwsLA+ggMilyVLXZb X-Received: by 2002:a05:6402:2744:b0:404:ba60:fec6 with SMTP id z4-20020a056402274400b00404ba60fec6mr10465195edd.235.1645226436121; Fri, 18 Feb 2022 15:20:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1645226436; cv=none; d=google.com; s=arc-20160816; b=v5TWa96epYXI6W5t/uSrnUs0QVPQ+qwl2hKzvWpmjZIzHL2LqFVawppF4HxMQwo2zy 98fuEObb3psy90yMYtahu7bow6GYX+jGc4H3lOdnLQvPqw+6WcXcv2vJA3A4sBDGM/nq TpWqsi59vGdCLcQ8MwdWG/RGZpTW55xuuFns7CsWLQcM5CeEEHDzkJJ27iuQmukAo4X8 Z/adfsyj0bAb3jGag/o//8Z9S1rDH+Z7q0UxPt6JibMu7l7HGccSMJbveIggd2PfOVtW M726ESZljNrRc6yJfI/C/7t1Hgr2Eg94VBMD1cTqKfIGelVPZea1FC3RsxDjiyYmAiAr 9cBg== 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:references:in-reply-to :message-id:date:to:from:dkim-signature:delivered-to; bh=nfsBPE4VyMJkJ1iEe2Io22SQ10odDfR+OYyEoRw7IL8=; b=vJQsKs1ToJR5UeE+H9pv5KgDLTtsdFOAfi4iqoFKWHWt7/n+HCz5Ysc9SOlDygM9wT STwSukdhO+0fbOzFvVmIrp2zFNMskVhtC5mLDMOhXaV2HKZ62X1zQYP3gJaCPjF9qNNj 0JSkpJhBZLmHEltrUvuXx2N9iI3I3SQXaT948/B+9KfapHhi2aqhOB/+dg/YL7TTBMYt LKIxX5+OiDRi7v8rhUQ8O4Mi305eXF9MhEMJknPDXkbxYgQs1xjzpW/03noUP3f31jTi sYkoYI72VEj6IteoGPHNO0MuV3KRbuORBGUkol4obj7GVrDjYNEeRXepy3SXfwWWJBmZ E8+w== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@pkh.me header.s=selector1 header.b=kuqnjnmU; 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=NONE dis=NONE) header.from=pkh.me Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id eq18si6401894edb.640.2022.02.18.15.20.35; Fri, 18 Feb 2022 15:20:36 -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=@pkh.me header.s=selector1 header.b=kuqnjnmU; 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=NONE dis=NONE) header.from=pkh.me Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id DA7B968B10A; Sat, 19 Feb 2022 01:20:16 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from ssq0.pkh.me (laubervilliers-656-1-228-164.w92-154.abo.wanadoo.fr [92.154.28.164]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 0E46068AF5C for ; Sat, 19 Feb 2022 01:20:10 +0200 (EET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pkh.me; s=selector1; t=1645226403; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=2rFUjeAYkxRG68Z7RjVeRyq+gS2vrjL2QLJv8LT5wg8=; b=kuqnjnmUxXUH/8AfH3wxZ4rC8vC+rX0k79aBaRi5dRPEYcwzUxo1Uc1ThwVd1OehQnv3Zz MFVPR1yc1S7sae0eNNnEu1pIVAGWKOAuFiKjx/6CoDtlH28boP8g8RnxAmRYegbS3IjzbN MQ0ooINboAA35eidB6i6USgL5JXe4CQ= Received: from localhost (ssq0.pkh.me [local]) by ssq0.pkh.me (OpenSMTPD) with ESMTPA id 9d84cd86; Fri, 18 Feb 2022 23:20:03 +0000 (UTC) From: =?utf-8?b?Q2zDqW1lbnQgQsWTc2No?= To: ffmpeg-devel@ffmpeg.org Date: Sat, 19 Feb 2022 00:19:58 +0100 Message-Id: <20220218232001.345826-3-u@pkh.me> X-Mailer: git-send-email 2.34.0 In-Reply-To: <20220218232001.345826-1-u@pkh.me> References: <20220218232001.345826-1-u@pkh.me> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 2/5] avformat/mov: add support for sync group in sbgp box 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: =?utf-8?b?Q2zDqW1lbnQgQsWTc2No?= Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: JnMtoVszeOOb --- libavformat/isom.h | 2 ++ libavformat/mov.c | 5 +++++ 2 files changed, 7 insertions(+) diff --git a/libavformat/isom.h b/libavformat/isom.h index 625dea8421..e326f4f27f 100644 --- a/libavformat/isom.h +++ b/libavformat/isom.h @@ -218,6 +218,8 @@ typedef struct MOVStreamContext { int start_pad; ///< amount of samples to skip due to enc-dec delay unsigned int rap_group_count; MOVSbgp *rap_group; + unsigned int sync_group_count; + MOVSbgp *sync_group; int nb_frames_for_fps; int64_t duration_for_fps; diff --git a/libavformat/mov.c b/libavformat/mov.c index aade052b7a..ebc397e573 100644 --- a/libavformat/mov.c +++ b/libavformat/mov.c @@ -3152,6 +3152,9 @@ static int mov_read_sbgp(MOVContext *c, AVIOContext *pb, MOVAtom atom) if (grouping_type == MKTAG('r','a','p',' ')) { tablep = &sc->rap_group; table_count = &sc->rap_group_count; + } else if (grouping_type == MKTAG('s','y','n','c')) { + tablep = &sc->sync_group; + table_count = &sc->sync_group_count; } else { return 0; } @@ -4371,6 +4374,7 @@ static int mov_read_trak(MOVContext *c, AVIOContext *pb, MOVAtom atom) av_freep(&sc->stps_data); av_freep(&sc->elst_data); av_freep(&sc->rap_group); + av_freep(&sc->sync_group); return 0; } @@ -7708,6 +7712,7 @@ static int mov_read_close(AVFormatContext *s) av_freep(&sc->stps_data); av_freep(&sc->elst_data); av_freep(&sc->rap_group); + av_freep(&sc->sync_group); av_freep(&sc->display_matrix); av_freep(&sc->index_ranges); From patchwork Fri Feb 18 23:19:59 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?b?Q2zDqW1lbnQgQsWTc2No?= X-Patchwork-Id: 34398 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6838:d078:0:0:0:0 with SMTP id x24csp1378240nkx; Fri, 18 Feb 2022 15:20:45 -0800 (PST) X-Google-Smtp-Source: ABdhPJxZ2dBJK5uPGF8y6QU76uPZVmnSLe8Yt+1rN0a9DcYb05LIA51bc+qC7F7IU10VVc3x1lI7 X-Received: by 2002:a05:6402:1cae:b0:410:d3ae:3c8a with SMTP id cz14-20020a0564021cae00b00410d3ae3c8amr10280769edb.215.1645226445353; Fri, 18 Feb 2022 15:20:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1645226445; cv=none; d=google.com; s=arc-20160816; b=hos+9R4/Te1IJeM6v0mbqxD8x2JV7/KcUyPVJ2CYeA1NA2hhqDQP8MEG0GmBebd/MT u+9myyWNNurB3oX5AIrTxBc3SpvWSy59ya/imby2VFZCdgaJrVahNGLlGfBpZgqSKmr/ S0G9pKhXfTfvz1KOBIwkf8g+cbSpA0/dxc/AmbCUIDidlHVbgLvqDKZ+UE8P58wuFcBA Ad2NJZG/Rgj0DKMZy1gGhibbMs+b5zxnXQvguKQtOvidr1B2EsdEh5hfh2uTaFkpw608 /BKVaSk6Ww06cj38CS3ci05J0qry+yhwzJE1QclozxPTKIMSNkX797SdY9/1u19ncSjo zfxA== 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:references:in-reply-to :message-id:date:to:from:dkim-signature:delivered-to; bh=TjNuiRlVBwlpTyMTLkDHajkfOkcmbb5pz9QkZh8jQsU=; b=0oJW6F1I2OtHowjm5e67tzBrVBwwNhn2FYUh5pOYNE4K+JyStqVMqFByXtH1pzg73M IFL/GGDC0kyr70+Be9hTXuxLZECj2JWMJRVECkQ+6zZrvIZl2FGvhfShLhnHGY2fXVF9 SumU+0uBHOsOLTgyCTVwLg9GP3n6+E18TB+ksquXdQndOX+bBYB4aTkXfjIxyyVWAm6G 6SIZNOnN69EY1YMx8riBDg0Ij4y+Jym4VnWJDeAP2JLAycamrN0mR3F798LtOavihDFa ba81Ocd5oCSmmUTcLNe/nDUamTNV8WjwQXqAmnMXzR4cdA/WbIBbiDnTw8xCYUqdwn3Z e25w== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@pkh.me header.s=selector1 header.b=lLh5kHzU; 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=NONE dis=NONE) header.from=pkh.me Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id f10si4193529ejl.292.2022.02.18.15.20.44; Fri, 18 Feb 2022 15:20:45 -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=@pkh.me header.s=selector1 header.b=lLh5kHzU; 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=NONE dis=NONE) header.from=pkh.me Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id CD2A768B143; Sat, 19 Feb 2022 01:20:20 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from ssq0.pkh.me (laubervilliers-656-1-228-164.w92-154.abo.wanadoo.fr [92.154.28.164]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 44F3468AF2A for ; Sat, 19 Feb 2022 01:20:14 +0200 (EET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pkh.me; s=selector1; t=1645226404; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=nl+4XVzTmTo77XAK67uh2ID1j6bvmH6Zc3NKIvrvxik=; b=lLh5kHzUX4E6PD0oK+Lo1O8OdxkL8BlcL8CEQw5X7d4ymiTZWc7oYJuWKh2kFCVVJsflIj l0yYAUR3IO5s69z2rf+gdK0fASRkmmcqINCb9rWwBVomVShECSPavOwuGTEE0lajTXJvf9 TslFwZbYjEBUQ1YKxOhsdQ8sUU2jVZU= Received: from localhost (ssq0.pkh.me [local]) by ssq0.pkh.me (OpenSMTPD) with ESMTPA id 1244174b; Fri, 18 Feb 2022 23:20:04 +0000 (UTC) From: =?utf-8?b?Q2zDqW1lbnQgQsWTc2No?= To: ffmpeg-devel@ffmpeg.org Date: Sat, 19 Feb 2022 00:19:59 +0100 Message-Id: <20220218232001.345826-4-u@pkh.me> X-Mailer: git-send-email 2.34.0 In-Reply-To: <20220218232001.345826-1-u@pkh.me> References: <20220218232001.345826-1-u@pkh.me> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 3/5] avformat/mov: add parsing for the sgpd sync box 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: =?utf-8?b?Q2zDqW1lbnQgQsWTc2No?= Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: lyBD5ETq+IzK sgpd means Sample Group Description Box. For now, only the sync grouping type is parsed, but the function can easily be adjusted to support other flavours. The sbgp (Sample to Group Box) sync_group table built in previous commit contains references to this table through the group_description_index field. --- libavformat/isom.h | 2 ++ libavformat/mov.c | 59 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+) diff --git a/libavformat/isom.h b/libavformat/isom.h index e326f4f27f..bbe395ee4b 100644 --- a/libavformat/isom.h +++ b/libavformat/isom.h @@ -220,6 +220,8 @@ typedef struct MOVStreamContext { MOVSbgp *rap_group; unsigned int sync_group_count; MOVSbgp *sync_group; + uint8_t *sgpd_sync; + uint32_t sgpd_sync_count; int nb_frames_for_fps; int64_t duration_for_fps; diff --git a/libavformat/mov.c b/libavformat/mov.c index ebc397e573..6b22d8c5f8 100644 --- a/libavformat/mov.c +++ b/libavformat/mov.c @@ -3130,6 +3130,62 @@ static int mov_read_ctts(MOVContext *c, AVIOContext *pb, MOVAtom atom) return 0; } +static int mov_read_sgpd(MOVContext *c, AVIOContext *pb, MOVAtom atom) +{ + AVStream *st; + MOVStreamContext *sc; + uint8_t version; + uint32_t grouping_type; + uint32_t default_length; + av_unused uint32_t default_group_description_index; + uint32_t entry_count; + + if (c->fc->nb_streams < 1) + return 0; + st = c->fc->streams[c->fc->nb_streams - 1]; + sc = st->priv_data; + + version = avio_r8(pb); /* version */ + avio_rb24(pb); /* flags */ + grouping_type = avio_rl32(pb); + + /* + * This function only supports "sync" boxes, but the code is able to parse + * other boxes (such as "tscl", "tsas" and "stsa") + */ + if (grouping_type != MKTAG('s','y','n','c')) + return 0; + + default_length = version >= 1 ? avio_rb32(pb) : 0; + default_group_description_index = version >= 2 ? avio_rb32(pb) : 0; + entry_count = avio_rb32(pb); + + av_freep(&sc->sgpd_sync); + sc->sgpd_sync_count = entry_count; + sc->sgpd_sync = av_calloc(entry_count, sizeof(*sc->sgpd_sync)); + if (!sc->sgpd_sync) + return AVERROR(ENOMEM); + + for (uint32_t i = 0; i < entry_count && !pb->eof_reached; i++) { + uint32_t description_length = default_length; + if (version >= 1 && default_length == 0) + description_length = avio_rb32(pb); + if (grouping_type == MKTAG('s','y','n','c')) { + const uint8_t nal_unit_type = avio_r8(pb) & 0x3f; + sc->sgpd_sync[i] = nal_unit_type; + description_length -= 1; + } + avio_skip(pb, description_length); + } + + if (pb->eof_reached) { + av_log(c->fc, AV_LOG_WARNING, "reached eof, corrupted SGPD atom\n"); + return AVERROR_EOF; + } + + return 0; +} + static int mov_read_sbgp(MOVContext *c, AVIOContext *pb, MOVAtom atom) { AVStream *st; @@ -4375,6 +4431,7 @@ static int mov_read_trak(MOVContext *c, AVIOContext *pb, MOVAtom atom) av_freep(&sc->elst_data); av_freep(&sc->rap_group); av_freep(&sc->sync_group); + av_freep(&sc->sgpd_sync); return 0; } @@ -7253,6 +7310,7 @@ static const MOVParseTableEntry mov_default_parse_table[] = { { MKTAG('c','m','o','v'), mov_read_cmov }, { MKTAG('c','h','a','n'), mov_read_chan }, /* channel layout */ { MKTAG('d','v','c','1'), mov_read_dvc1 }, +{ MKTAG('s','g','p','d'), mov_read_sgpd }, { MKTAG('s','b','g','p'), mov_read_sbgp }, { MKTAG('h','v','c','C'), mov_read_glbl }, { MKTAG('u','u','i','d'), mov_read_uuid }, @@ -7713,6 +7771,7 @@ static int mov_read_close(AVFormatContext *s) av_freep(&sc->elst_data); av_freep(&sc->rap_group); av_freep(&sc->sync_group); + av_freep(&sc->sgpd_sync); av_freep(&sc->display_matrix); av_freep(&sc->index_ranges); From patchwork Fri Feb 18 23:20:00 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?Q2zDqW1lbnQgQsWTc2No?= X-Patchwork-Id: 34399 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6838:d078:0:0:0:0 with SMTP id x24csp1378318nkx; Fri, 18 Feb 2022 15:20:55 -0800 (PST) X-Google-Smtp-Source: ABdhPJwjK4BPsvdn/W1IsRC+eto0FpiJuCNG9vyyJfUSbplcN4xY5lkVqWeVwA4mgMm+WGh+itlV X-Received: by 2002:aa7:c04e:0:b0:400:4daf:bab1 with SMTP id k14-20020aa7c04e000000b004004dafbab1mr10508881edo.101.1645226455252; Fri, 18 Feb 2022 15:20:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1645226455; cv=none; d=google.com; s=arc-20160816; b=P4eo81nSU8EsVRztBDi89aTbI/Pp5TxGNVndykY/yZh9m2vBtiLdZ+uPCa+/VtvgQA xUJBd4L4GH6x+tld5uhrjzgpS1OnWZt0xx2EPdMtYrzYndcY0kaLjDJpbIMkHNoOnbPI Q/Vo5B/8NWQqfmE3g/n3ifOwVAdgQPUpppi2wl1Ut+c25SwXRLF/eSthCCsu5igwVZvr N6Qi9HyIrIASi+welzN+DGXYuIpg+CqGfwf29N3qzVI/BQr4/4gWaUFmrZ3eKJ3a65H8 wNbn0FEXW+wLpg5ckMQ64/Kelgyc1fbbx0vwCAqIXAQxPIQmlu9mzof6mZ2Tc17DcXas +p0g== 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:references:in-reply-to :message-id:date:to:from:dkim-signature:delivered-to; bh=Y66Mmq8SbI7IbGUDcDGGfnegjpNEV5NLr2jtwm/+oT0=; b=vJGk7ZCV/mxDIS71KaGgbHGIdwFOOvfzJ+CjCH+PNss4y5Hfw7Ax8kfjloDphqKPfY ZFEMAyB3UlpVnKDpyKrD4J8dPeqpsjMzd7RNqJq5KqTq33mDLMw/mdbzft6oTgtiWY4n iYp+AHpNM3P32d96IUylrqM+G24STGkfvDs6hZ4meXnOZuqPOWnhTkuuDFkRAT8nZcXx mIRmhEaDz0+7ujeJ5gDmsicwe7ZdldLA+jEnmpCFeMiJ73hZVcXOZUzm2SY1yPXu5Ppy oUJpHPQtpiIEIVqlwDGP3MDxQCMMDC9fRRN6gjVJnwoJwDWr4D9HpTCL9ZSFLM4hzU/L WjQA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@pkh.me header.s=selector1 header.b=X0tN3PJn; 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=NONE dis=NONE) header.from=pkh.me Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id ej5si5536721edb.224.2022.02.18.15.20.54; Fri, 18 Feb 2022 15:20: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=@pkh.me header.s=selector1 header.b=X0tN3PJn; 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=NONE dis=NONE) header.from=pkh.me Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 13B7168B0A8; Sat, 19 Feb 2022 01:20:22 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from ssq0.pkh.me (laubervilliers-656-1-228-164.w92-154.abo.wanadoo.fr [92.154.28.164]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 6979768AF5C for ; Sat, 19 Feb 2022 01:20:14 +0200 (EET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pkh.me; s=selector1; t=1645226404; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=l9Za0JINjBRSoj6uWFbTpDBrrc956210d2bZXawEEeo=; b=X0tN3PJnaVjlc5BMV0hoWQtS6r+4CcIAQql1QhuHI5iTG+lwdYjeY3K7mRf8GXtiXKAimT 7ZM8035IGkHG7sLnhuOFbMOaxeM0spKNu+/rAaPnq6D3Lg6d7DYpei1v0p9ioP3OxOEzvD fPFMj0gQw16bM+KcSOEHyjfnD/1uz/Q= Received: from localhost (ssq0.pkh.me [local]) by ssq0.pkh.me (OpenSMTPD) with ESMTPA id aacdbe36; Fri, 18 Feb 2022 23:20:04 +0000 (UTC) From: =?utf-8?b?Q2zDqW1lbnQgQsWTc2No?= To: ffmpeg-devel@ffmpeg.org Date: Sat, 19 Feb 2022 00:20:00 +0100 Message-Id: <20220218232001.345826-5-u@pkh.me> X-Mailer: git-send-email 2.34.0 In-Reply-To: <20220218232001.345826-1-u@pkh.me> References: <20220218232001.345826-1-u@pkh.me> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 4/5] avformat/mov: fix seeking with HEVC open GOP files 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: =?utf-8?b?Q2zDqW1lbnQgQsWTc2No?= Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: 5ej0ar1bA87H This was tested with medias recorded from an iPhone XR and an iPhone 13. Here is how a typical stream looks like in coding order: ┌────────┬─────┬─────┬──────────┐ │ sample | PTS | DTS | keyframe | ├────────┼─────┼─────┼──────────┤ ┊ ┊ ┊ ┊ ┊ │ 53 │ 560 │ 510 │ No │ │ 54 │ 540 │ 520 │ No │ │ 55 │ 530 │ 530 │ No │ │ 56 │ 550 │ 540 │ No │ │ 57 │ 600 │ 550 │ Yes │ │ * 58 │ 580 │ 560 │ No │ │ * 59 │ 570 │ 570 │ No │ │ * 60 │ 590 │ 580 │ No │ │ 61 │ 640 │ 590 │ No │ │ 62 │ 620 │ 600 │ No │ ┊ ┊ ┊ ┊ ┊ In composition/display order: ┌────────┬─────┬─────┬──────────┐ │ sample | PTS | DTS | keyframe | ├────────┼─────┼─────┼──────────┤ ┊ ┊ ┊ ┊ ┊ │ 55 │ 530 │ 530 │ No │ │ 54 │ 540 │ 520 │ No │ │ 56 │ 550 │ 540 │ No │ │ 53 │ 560 │ 510 │ No │ │ * 59 │ 570 │ 570 │ No │ │ * 58 │ 580 │ 560 │ No │ │ * 60 │ 590 │ 580 │ No │ │ 57 │ 600 │ 550 │ Yes │ │ 63 │ 610 │ 610 │ No │ │ 62 │ 620 │ 600 │ No │ ┊ ┊ ┊ ┊ ┊ Sample/frame 58, 59 and 60 are B-frames which actually depends on the key frame (57). Here the key frame is not an IDR but a "CRA" (Clean Random Access). Initially, I thought I could rely on the sdtp box (independent and disposable samples), but unfortunately: sdtp[54] is_leading:0 sample_depends_on:1 sample_is_depended_on:0 sample_has_redundancy:0 sdtp[55] is_leading:0 sample_depends_on:1 sample_is_depended_on:2 sample_has_redundancy:0 sdtp[56] is_leading:0 sample_depends_on:1 sample_is_depended_on:2 sample_has_redundancy:0 sdtp[57] is_leading:0 sample_depends_on:2 sample_is_depended_on:0 sample_has_redundancy:0 sdtp[58] is_leading:0 sample_depends_on:1 sample_is_depended_on:0 sample_has_redundancy:0 sdtp[59] is_leading:0 sample_depends_on:1 sample_is_depended_on:2 sample_has_redundancy:0 sdtp[60] is_leading:0 sample_depends_on:1 sample_is_depended_on:2 sample_has_redundancy:0 sdtp[61] is_leading:0 sample_depends_on:1 sample_is_depended_on:0 sample_has_redundancy:0 sdtp[62] is_leading:0 sample_depends_on:1 sample_is_depended_on:0 sample_has_redundancy:0 The information that might have been useful here would have been is_leading, but all the samples are set to 0 so this was unusable. Instead, we need to rely on sgpd/sbgp tables. In my case the video track contained 3 sgpd tables with the following grouping types: tscl, sync and tsas. In the sync table we have the following 2 entries (only): sgpd.sync[1]: sync nal_unit_type:0x14 sgpd.sync[2]: sync nal_unit_type:0x15 (The count starts at 1 because 0 carries the undefined semantic, we'll see that later in the reference table). The NAL unit types presented here correspond to: libavcodec/hevc.h: HEVC_NAL_IDR_N_LP = 20, libavcodec/hevc.h: HEVC_NAL_CRA_NUT = 21, In parallel, the sbgp sync table contains the following: ┌────┬───────┬─────┐ │ id │ count │ gdi │ ├────┼───────┼─────┤ │ 0 │ 1 │ 1 │ │ 1 │ 56 │ 0 │ │ 2 │ 1 │ 2 │ │ 3 │ 59 │ 0 │ │ 4 │ 1 │ 2 │ │ 5 │ 59 │ 0 │ │ 6 │ 1 │ 2 │ │ 7 │ 59 │ 0 │ │ 8 │ 1 │ 2 │ │ 9 │ 59 │ 0 │ │ 10 │ 1 │ 2 │ │ 11 │ 11 │ 0 │ └────┴───────┴─────┘ The gdi column (group description index) directly refers to the index in the sgpd.sync table. This means the first frame is an IDR, then we have batches of undefined frames interlaced with CRA frames. No IDR ever appears again (tried on a 30+ seconds sample). With that information, we can build an heuristic using the presentation order. A few things needed to be introduced in this commit: 1. min_sample_duration is extracted from the stts: we need the minimal step between sample in order to PTS-step backward to a valid point 2. In order to avoid a loop over the ctts table systematically during a seek, we build an expanded list of sample offsets which will be used to translate from DTS to PTS 3. An open_key_samples index to keep track of all the non-IDR key frames; for now it only supports HEVC CRA frames. We should probably add BLA frames as well, but I don't have any sample so I prefered to leave that for later It is entirely possible I missed something obvious in my approach, but I couldn't come up with a better solution. Also, as mentioned in the diff, we could optimize is_open_key_sample(), but the linear scaling overhead should be fine for now since it only happens in seek events. Fixing this issue prevents sending broken packets to the decoder. With FFmpeg hevc decoder the frames are skipped, with VideoToolbox the frames are glitching. --- libavformat/isom.h | 5 ++ libavformat/mov.c | 121 ++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 124 insertions(+), 2 deletions(-) diff --git a/libavformat/isom.h b/libavformat/isom.h index bbe395ee4b..7362c876be 100644 --- a/libavformat/isom.h +++ b/libavformat/isom.h @@ -169,11 +169,14 @@ typedef struct MOVStreamContext { int64_t *chunk_offsets; unsigned int stts_count; MOVStts *stts_data; + uint32_t min_sample_duration; unsigned int sdtp_count; uint8_t *sdtp_data; unsigned int ctts_count; unsigned int ctts_allocated_size; MOVCtts *ctts_data; + int32_t *sample_offsets; + int sample_offsets_count; unsigned int stsc_count; MOVStsc *stsc_data; unsigned int stsc_index; @@ -222,6 +225,8 @@ typedef struct MOVStreamContext { MOVSbgp *sync_group; uint8_t *sgpd_sync; uint32_t sgpd_sync_count; + int *open_key_samples; + int open_key_samples_count; int nb_frames_for_fps; int64_t duration_for_fps; diff --git a/libavformat/mov.c b/libavformat/mov.c index 6b22d8c5f8..919dd940c0 100644 --- a/libavformat/mov.c +++ b/libavformat/mov.c @@ -50,6 +50,7 @@ #include "libavutil/dovi_meta.h" #include "libavcodec/ac3tab.h" #include "libavcodec/flac.h" +#include "libavcodec/hevc.h" #include "libavcodec/mpegaudiodecheader.h" #include "libavcodec/mlp_parse.h" #include "avformat.h" @@ -2948,6 +2949,7 @@ static int mov_read_stts(MOVContext *c, AVIOContext *pb, MOVAtom atom) if (entries >= INT_MAX / sizeof(*sc->stts_data)) return AVERROR(ENOMEM); + sc->min_sample_duration = INT_MAX; for (i = 0; i < entries && !pb->eof_reached; i++) { unsigned int sample_duration; unsigned int sample_count; @@ -2967,6 +2969,7 @@ static int mov_read_stts(MOVContext *c, AVIOContext *pb, MOVAtom atom) sc->stts_data[i].count= sample_count; sc->stts_data[i].duration= sample_duration; + sc->min_sample_duration = FFMIN(sc->min_sample_duration, sample_duration); av_log(c->fc, AV_LOG_TRACE, "sample_count=%u, sample_duration=%u\n", sample_count, sample_duration); @@ -3069,6 +3072,7 @@ static int mov_read_ctts(MOVContext *c, AVIOContext *pb, MOVAtom atom) AVStream *st; MOVStreamContext *sc; unsigned int i, entries, ctts_count = 0; + int32_t *sample_offsets; if (c->fc->nb_streams < 1) return 0; @@ -3090,6 +3094,7 @@ static int mov_read_ctts(MOVContext *c, AVIOContext *pb, MOVAtom atom) if (!sc->ctts_data) return AVERROR(ENOMEM); + sc->sample_offsets_count = 0; for (i = 0; i < entries && !pb->eof_reached; i++) { int count = avio_rb32(pb); int duration = avio_rb32(pb); @@ -3101,8 +3106,9 @@ static int mov_read_ctts(MOVContext *c, AVIOContext *pb, MOVAtom atom) continue; } - add_ctts_entry(&sc->ctts_data, &ctts_count, &sc->ctts_allocated_size, - count, duration); + if (add_ctts_entry(&sc->ctts_data, &ctts_count, &sc->ctts_allocated_size, + count, duration) >= 0) + sc->sample_offsets_count += count; av_log(c->fc, AV_LOG_TRACE, "count=%d, duration=%d\n", count, duration); @@ -3127,6 +3133,15 @@ static int mov_read_ctts(MOVContext *c, AVIOContext *pb, MOVAtom atom) av_log(c->fc, AV_LOG_TRACE, "dts shift %d\n", sc->dts_shift); + av_freep(&sc->sample_offsets); + sc->sample_offsets = av_calloc(sc->sample_offsets_count, sizeof(*sc->sample_offsets)); + if (!sc->sample_offsets) + return AVERROR(ENOMEM); + sample_offsets = sc->sample_offsets; + for (int i = 0; i < sc->ctts_count; i++) + for (int j = 0; j < sc->ctts_data[i].count; j++) + *sample_offsets++ = sc->ctts_data[i].duration; + return 0; } @@ -3882,6 +3897,52 @@ static void mov_fix_index(MOVContext *mov, AVStream *st) msc->current_index = msc->index_ranges[0].start; } +static uint32_t get_sgpd_sync_index(const MOVStreamContext *sc, int nal_unit_type) +{ + for (uint32_t i = 0; i < sc->sgpd_sync_count; i++) + if (sc->sgpd_sync[i] == HEVC_NAL_CRA_NUT) + return i + 1; + return 0; +} + +static int build_open_gop_key_points(AVStream *st) +{ + int k = 0; + int sample_id = 0; + int open_sample_count = 0; + uint32_t cra_index; + MOVStreamContext *sc = st->priv_data; + + if (st->codecpar->codec_id != AV_CODEC_ID_HEVC || !sc->sync_group_count) + return 0; + + /* The following HEVC NAL type reveal the use of open GOP sync points + * (TODO: BLA types may also be concerned) */ + cra_index = get_sgpd_sync_index(sc, HEVC_NAL_CRA_NUT); /* Clean Random Access */ + if (!cra_index) + return 0; + + for (uint32_t i = 0; i < sc->sync_group_count; i++) + if (sc->sync_group[i].index == cra_index) + open_sample_count += sc->sync_group[i].count; + + av_freep(&sc->open_key_samples); + sc->open_key_samples_count = open_sample_count; + sc->open_key_samples = av_calloc(open_sample_count, sizeof(*sc->open_key_samples)); + if (!sc->open_key_samples) + return AVERROR(ENOMEM); + + for (uint32_t i = 0; i < sc->sync_group_count; i++) { + const MOVSbgp *sg = &sc->sync_group[i]; + if (sg->index == cra_index) + for (uint32_t j = 0; j < sg->count; j++) + sc->open_key_samples[k++] = sample_id; + sample_id += sg->count; + } + + return 0; +} + static void mov_build_index(MOVContext *mov, AVStream *st) { MOVStreamContext *sc = st->priv_data; @@ -3897,6 +3958,10 @@ static void mov_build_index(MOVContext *mov, AVStream *st) MOVCtts *ctts_data_old = sc->ctts_data; unsigned int ctts_count_old = sc->ctts_count; + int ret = build_open_gop_key_points(st); + if (ret < 0) + return; + if (sc->elst_count) { int i, edit_start_index = 0, multiple_edits = 0; int64_t empty_duration = 0; // empty duration of the first edit list entry @@ -7772,6 +7837,8 @@ static int mov_read_close(AVFormatContext *s) av_freep(&sc->rap_group); av_freep(&sc->sync_group); av_freep(&sc->sgpd_sync); + av_freep(&sc->open_key_samples); + av_freep(&sc->sample_offsets); av_freep(&sc->display_matrix); av_freep(&sc->index_ranges); @@ -8444,6 +8511,49 @@ static int mov_seek_fragment(AVFormatContext *s, AVStream *st, int64_t timestamp return 0; } +static int is_open_key_sample(const MOVStreamContext *sc, int sample) +{ + // TODO: a bisect search would scale much better + for (int i = 0; i < sc->open_key_samples_count; i++) { + const int oks = sc->open_key_samples[i]; + if (oks == sample) + return 1; + if (oks > sample) /* list is monotically increasing so we can stop early */ + break; + } + return 0; +} + +/* + * Some key sample may be key frames but not IDR frames, so a random access to + * them may not be allowed. + */ +static int can_seek_to_key_sample(AVStream *st, int sample, int64_t requested_pts) +{ + MOVStreamContext *sc = st->priv_data; + FFStream *const sti = ffstream(st); + int64_t key_sample_dts, key_sample_pts; + + if (st->codecpar->codec_id != AV_CODEC_ID_HEVC) + return 1; + + if (sample >= sc->sample_offsets_count) + return 1; + + key_sample_dts = sti->index_entries[sample].timestamp; + key_sample_pts = key_sample_dts + sc->sample_offsets[sample] + sc->dts_shift; + + /* + * If the sample needs to be presented before an open key sample, they may + * not be decodable properly, even though they come after in decoding + * order. + */ + if (is_open_key_sample(sc, sample) && key_sample_pts > requested_pts) + return 0; + + return 1; +} + static int mov_seek_stream(AVFormatContext *s, AVStream *st, int64_t timestamp, int flags) { MOVStreamContext *sc = st->priv_data; @@ -8459,12 +8569,19 @@ static int mov_seek_stream(AVFormatContext *s, AVStream *st, int64_t timestamp, if (ret < 0) return ret; + for (;;) { sample = av_index_search_timestamp(st, timestamp, flags); av_log(s, AV_LOG_TRACE, "stream %d, timestamp %"PRId64", sample %d\n", st->index, timestamp, sample); if (sample < 0 && sti->nb_index_entries && timestamp < sti->index_entries[0].timestamp) sample = 0; if (sample < 0) /* not sure what to do */ return AVERROR_INVALIDDATA; + + if (!sample || can_seek_to_key_sample(st, sample, timestamp)) + break; + timestamp -= FFMAX(sc->min_sample_duration, 1); + } + mov_current_sample_set(sc, sample); av_log(s, AV_LOG_TRACE, "stream %d, found sample %d\n", st->index, sc->current_sample); /* adjust ctts index */ From patchwork Fri Feb 18 23:20:01 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?b?Q2zDqW1lbnQgQsWTc2No?= X-Patchwork-Id: 34400 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6838:d078:0:0:0:0 with SMTP id x24csp1378443nkx; Fri, 18 Feb 2022 15:21:07 -0800 (PST) X-Google-Smtp-Source: ABdhPJwYDxb9g0umpTqIa96dcDdLIG2tnRqAO9D0zelo4uYQo7Cr2hmyJIOz+3CbeVEbWIZ4Mv7w X-Received: by 2002:a50:e004:0:b0:410:a39b:e30c with SMTP id e4-20020a50e004000000b00410a39be30cmr10333809edl.198.1645226467417; Fri, 18 Feb 2022 15:21:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1645226467; cv=none; d=google.com; s=arc-20160816; b=xtHXU0F0ZdCQVNQSTG4TwOPYAsHEZWU0XApnFar8eveHjqb/zG7VL+S3zc+C8uIviP UHxfHlPpvqf9MMqDo2iEHhrMEANlrFBnCRrI13nolz8gKZOPPBKMcNzoh7cAi9nNCvOl S43ZetPJ0K1kiOgeke7UAdB7s9BCh2NKiTUOv00kh3J1HUblB+vuGnnk5GxVC2vuiLVi 5rsV0TEvGPDvltOFILLJgTKV9hxaE1BX5Sh1zIV6vS/1k98ESWevzoCu5ApJGTyauI3x cdAN6c+2mxAhC90p5zHixcjDLfXgT0NXhhTrjPwsciGf4FgE/i9ZMQr5JnuwRw6RgRtX wRSQ== 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:references:in-reply-to :message-id:date:to:from:dkim-signature:delivered-to; bh=RN9Mpv6SlMVubBUtpL0XNv6Y3++/dqS4r/C2XtEsRMQ=; b=uwByDO3/dyQJ4DGDFcBze/+dc7mblovry2XuiKMx2stOZIFzxTEiFAKn1I87vO4Xja tZTsYVV7lzSBJy8A6FCwKCF5s9KyabxlfaxKhAVofC7z/IDy6+DBrrsqn2U9/omLILtf 6yVzr28KqWJMUyVpzujo9fsKaQdculu6m+dcahqiSzdzkGzXNtO297Q/lPSpDvn8fvY0 5Yj1tBA+fwnUiMxuaA0rPBv9KhTyB6f3PlbGOryBj4gfHMj0nYriCh4KpHUgmolmyCAh Bycrhumlm6euuDIG3H/xILFlgK3Rdg4K0lN0K9TEXSf3ONWMOxiP6RjAU6htGsUtTRHs 1GdQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@pkh.me header.s=selector1 header.b=TGjvxcS6; 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=NONE dis=NONE) header.from=pkh.me Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id wn10si1184687ejb.0.2022.02.18.15.21.05; Fri, 18 Feb 2022 15:21:07 -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=@pkh.me header.s=selector1 header.b=TGjvxcS6; 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=NONE dis=NONE) header.from=pkh.me Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 3D6F068B14C; Sat, 19 Feb 2022 01:20:23 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from ssq0.pkh.me (laubervilliers-656-1-228-164.w92-154.abo.wanadoo.fr [92.154.28.164]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 430CE68B124 for ; Sat, 19 Feb 2022 01:20:15 +0200 (EET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pkh.me; s=selector1; t=1645226404; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=mNwdWUInrOFD9PVHZcTlAgUvolUM0bS7OWEtd6ew0+4=; b=TGjvxcS6hlcQbKjJxx77BEnHZ6SS6BGALsR7vbkmeNCtFeG81eI4Efe+z/+rN1ejklmzNB zCguGkqHK4e1I+lVLu5xNRwH1H4oV/kynmh3ZDuRmOp47RpTaKItwXYXOoVJWVfxkZvmT7 UnkeHkEd3No+Hn/buVYmAcg21qJ0EGc= Received: from localhost (ssq0.pkh.me [local]) by ssq0.pkh.me (OpenSMTPD) with ESMTPA id 2801152d; Fri, 18 Feb 2022 23:20:04 +0000 (UTC) From: =?utf-8?b?Q2zDqW1lbnQgQsWTc2No?= To: ffmpeg-devel@ffmpeg.org Date: Sat, 19 Feb 2022 00:20:01 +0100 Message-Id: <20220218232001.345826-6-u@pkh.me> X-Mailer: git-send-email 2.34.0 In-Reply-To: <20220218232001.345826-1-u@pkh.me> References: <20220218232001.345826-1-u@pkh.me> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 5/5] avformat/mov: reindent after previous commit 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: =?utf-8?b?Q2zDqW1lbnQgQsWTc2No?= Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: g3stJCkJNmwp --- libavformat/mov.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/libavformat/mov.c b/libavformat/mov.c index 919dd940c0..09cc4e8ad7 100644 --- a/libavformat/mov.c +++ b/libavformat/mov.c @@ -8570,12 +8570,12 @@ static int mov_seek_stream(AVFormatContext *s, AVStream *st, int64_t timestamp, return ret; for (;;) { - sample = av_index_search_timestamp(st, timestamp, flags); - av_log(s, AV_LOG_TRACE, "stream %d, timestamp %"PRId64", sample %d\n", st->index, timestamp, sample); - if (sample < 0 && sti->nb_index_entries && timestamp < sti->index_entries[0].timestamp) - sample = 0; - if (sample < 0) /* not sure what to do */ - return AVERROR_INVALIDDATA; + sample = av_index_search_timestamp(st, timestamp, flags); + av_log(s, AV_LOG_TRACE, "stream %d, timestamp %"PRId64", sample %d\n", st->index, timestamp, sample); + if (sample < 0 && sti->nb_index_entries && timestamp < sti->index_entries[0].timestamp) + sample = 0; + if (sample < 0) /* not sure what to do */ + return AVERROR_INVALIDDATA; if (!sample || can_seek_to_key_sample(st, sample, timestamp)) break;