From patchwork Thu Nov 9 00:13:46 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sasi Inguva X-Patchwork-Id: 5927 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.2.161.90 with SMTP id m26csp1392451jah; Wed, 8 Nov 2017 16:20:47 -0800 (PST) X-Google-Smtp-Source: ABhQp+SEHhYM7NYIf0trgulmykokwKpSyeetKhlNWRYGhWiH3B2pon1CvWgXKjaGZwN+T95SDDuu X-Received: by 10.28.17.66 with SMTP id 63mr1586766wmr.66.1510186847648; Wed, 08 Nov 2017 16:20:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1510186847; cv=none; d=google.com; s=arc-20160816; b=Haf3b8ny5ym3aJntMoyaJK7kJP4lZ5Bgv0kRYTDEcMa/lB5+OC+YVewqkZue/TKYy6 T+LtVxlL+7CIzrjJ9p1kfhTOt8ycnt2TtumuIFdwak9cQjRBOq7YyEtBJ7uQ70Dtbqse Vivmegx/fuG6VP3A0vh5pS4ECwFKcyMSrMFSslNswbte8wI5L7IdACYOSjrQcObseXCz ejz0YquBnkGrQpPVxD+HOdOntZ4V3XM0u9zATDdyYQ+GtajYMFlkPGMjwSknSLIDsRTa dA2p/XioK15zmZ9iaVe5UheRBPZp2LgKNseciaVWO5YaTqltv5mQirewHBjbCZyQ2KQG gUPQ== 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:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:references:in-reply-to:message-id:date :to:from:dkim-signature:delivered-to:arc-authentication-results; bh=TAy54gcdZj2LhjOQF3MFOfZF7NDxHSG2uZxZgnO3ETc=; b=Y4CZ6AwiIvVCRGqyPp45Cw8QmsQzWmYX46FZ8M0mDuuQ+x/luTXmcYuShEskh1C948 maS83wT5UhgNQKgdRXEGtnKHvuqnzrMytZNcnIxK2m17FG7P3yieCPGZfEayqxWxiTY+ D6R6Y7yQyqr/qd3SguEUZy6sdAYa2gjtHw7KCrxh2my8IMXIonbo1oLI7cOSQ6P9PsAl zeXuv5rpAATyC7XcKpvKU7nJqpKO8Up+A6u2JmRolrBtqJbYQlHf30DqGNwkI+bBzmYh A9eJZg7ltENDYd7yu5enOOIzi94ZyILkDUsgc7llhLgSBtn+byVMv/urFHiYDxxXo/Dt 57rA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@google.com header.s=20161025 header.b=R1EmiIac; 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 j97si4684481wrj.386.2017.11.08.16.20.47; Wed, 08 Nov 2017 16:20:47 -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=@google.com header.s=20161025 header.b=R1EmiIac; 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 90FD2689B3A; Thu, 9 Nov 2017 02:20:33 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-io0-f193.google.com (mail-io0-f193.google.com [209.85.223.193]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 37833687EC8 for ; Thu, 9 Nov 2017 02:20:27 +0200 (EET) Received: by mail-io0-f193.google.com with SMTP id m16so7954468iod.1 for ; Wed, 08 Nov 2017 16:20:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=hP4z8+udgN/P80i9znMcPdl8p+/EM6zvNV8nNRonSpc=; b=R1EmiIactlGdEqYQvH/3q18VpUQ/D43Pkcc1xtL0elc+UapXVnmhBzZbtDae4Q15k9 aCroA3NjrjHQAw7unsi06NYFn3nwl3gB0TdFdNyQcgAEpr9IpAF32Vq3gMG4M6ovYThQ mxHQTJHvOYxTCzZek+5rLiAC+X01QyL0z2BmrZla7tfg2vOSTmuPMOjBLWFgKk+94pW8 huJsnLvVdEa56k4ORfAcQpyw+G/71Zxzsus2uSQYY8SKl5p8nyt34P4YaOfxa9anyZbM ezQL5bEOEiwiSL6xTB2bSAhBsLYgVNTygdvzI6drDYqrfj+gz+aghBl0I0MYzyrMT2px 0wrA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=hP4z8+udgN/P80i9znMcPdl8p+/EM6zvNV8nNRonSpc=; b=rvcl3O/r1ne3028x/GfXP40KGTLFKtiG7V9AFg9ex+bYbG10g3FIFFiE+KO5Dx0fSn 3bF5xR+iCsTgoEFtzX13jzOuGXVp80F9rrMFbwFMK6223pB351QBAwngkrr2v7tK/Zj2 WXK8Src2A5ANUO3SzW7hEu1m/6jJGjebNunO+Zr3UQ2nOu8tvEDKdx9mRW3fEoz2LMEA 3fd6r9Mtlo/ILTcUK+Qj1pM07APsEeu8mTGnrgUSUh5U+K+w1T1htbMRCJia4DjHrdda lpYhtcWLiDLrB5xq5o0SKbYG0YZeJD8q6G3oBOZ/qXDzwcRlRxYrakwW/VK/gIN7D8lO 9DDw== X-Gm-Message-State: AJaThX6ueqE2DF8pl7bcwflFQ/dZhRalxYK7hHa12evHae6WIeqYZuC2 bEd1ruAdh50aseNdowO+hh3hxkk2Cw4= X-Received: by 10.107.11.92 with SMTP id v89mr2964832ioi.25.1510186494098; Wed, 08 Nov 2017 16:14:54 -0800 (PST) Received: from isasi.mtv.corp.google.com ([172.27.82.28]) by smtp.gmail.com with ESMTPSA id e95sm2521583iod.41.2017.11.08.16.14.53 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 08 Nov 2017 16:14:53 -0800 (PST) From: Sasi Inguva To: ffmpeg-devel@ffmpeg.org Date: Wed, 8 Nov 2017 16:13:46 -0800 Message-Id: <20171109001346.8458-1-isasi@google.com> X-Mailer: git-send-email 2.15.0.448.gf294e3d99a-goog In-Reply-To: References: Subject: [FFmpeg-devel] [PATCH] lavf/mov.c: Parse upto 2 keyframes after the edit list end in mov_fix_index. 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 Cc: Sasi Inguva MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Partially fixes t/6699. --- libavformat/mov.c | 32 ++++++++++++++++++++----------- tests/fate/mov.mak | 4 ++++ tests/ref/fate/mov-elst-ends-betn-b-and-i | 31 ++++++++++++++++++++++++++++++ 3 files changed, 56 insertions(+), 11 deletions(-) create mode 100644 tests/ref/fate/mov-elst-ends-betn-b-and-i diff --git a/libavformat/mov.c b/libavformat/mov.c index 7954db6e47..436ae42cbb 100644 --- a/libavformat/mov.c +++ b/libavformat/mov.c @@ -3295,6 +3295,7 @@ static void mov_fix_index(MOVContext *mov, AVStream *st) int packet_skip_samples = 0; MOVIndexRange *current_index_range; int i; + int found_keyframe_after_edit = 0; if (!msc->elst_data || msc->elst_count <= 0 || nb_old <= 0) { return; @@ -3390,6 +3391,7 @@ static void mov_fix_index(MOVContext *mov, AVStream *st) // Iterate over index and arrange it according to edit list edit_list_start_encountered = 0; + found_keyframe_after_edit = 0; for (; current < e_old_end; current++, index++) { // check if frame outside edit list mark it for discard frame_duration = (current + 1 < e_old_end) ? @@ -3502,18 +3504,26 @@ static void mov_fix_index(MOVContext *mov, AVStream *st) } // Break when found first key frame after edit entry completion - if (((curr_cts + frame_duration) >= (edit_list_duration + edit_list_media_time)) && + if ((curr_cts + frame_duration >= (edit_list_duration + edit_list_media_time)) && ((flags & AVINDEX_KEYFRAME) || ((st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO)))) { - - if (ctts_data_old && ctts_sample_old != 0) { - if (add_ctts_entry(&msc->ctts_data, &msc->ctts_count, - &msc->ctts_allocated_size, - ctts_sample_old - edit_list_start_ctts_sample, - ctts_data_old[ctts_index_old].duration) == -1) { - av_log(mov->fc, AV_LOG_ERROR, "Cannot add CTTS entry %"PRId64" - {%"PRId64", %d}\n", - ctts_index_old, ctts_sample_old - edit_list_start_ctts_sample, - ctts_data_old[ctts_index_old].duration); - break; + if (ctts_data_old) { + // If we have CTTS and this is the the first keyframe after edit elist, + // wait for one more, because there might be trailing B-frames after this I-frame + // that do belong to the edit. + if (st->codecpar->codec_type != AVMEDIA_TYPE_AUDIO && found_keyframe_after_edit == 0) { + found_keyframe_after_edit = 1; + continue; + } + if (ctts_sample_old != 0) { + if (add_ctts_entry(&msc->ctts_data, &msc->ctts_count, + &msc->ctts_allocated_size, + ctts_sample_old - edit_list_start_ctts_sample, + ctts_data_old[ctts_index_old].duration) == -1) { + av_log(mov->fc, AV_LOG_ERROR, "Cannot add CTTS entry %"PRId64" - {%"PRId64", %d}\n", + ctts_index_old, ctts_sample_old - edit_list_start_ctts_sample, + ctts_data_old[ctts_index_old].duration); + break; + } } } break; diff --git a/tests/fate/mov.mak b/tests/fate/mov.mak index 01893a0767..76f66ff498 100644 --- a/tests/fate/mov.mak +++ b/tests/fate/mov.mak @@ -10,6 +10,7 @@ FATE_MOV = fate-mov-3elist \ fate-mov-gpmf-remux \ fate-mov-440hz-10ms \ fate-mov-ibi-elst-starts-b \ + fate-mov-elst-ends-betn-b-and-i \ FATE_MOV_FFPROBE = fate-mov-aac-2048-priming \ fate-mov-zombie \ @@ -42,6 +43,9 @@ fate-mov-1elist-ends-last-bframe: CMD = framemd5 -i $(TARGET_SAMPLES)/mov/mov-1e # Makes sure that we handle timestamps of packets in case of multiple edit lists with one of them ending on a B-frame correctly. fate-mov-2elist-elist1-ends-bframe: CMD = framemd5 -i $(TARGET_SAMPLES)/mov/mov-2elist-elist1-ends-bframe.mov +# Makes sure that if edit list ends on a B-frame but before the I-frame, then we output the B-frame but discard the I-frame. +fate-mov-elst-ends-betn-b-and-i: CMD = framemd5 -i $(TARGET_SAMPLES)/mov/elst_ends_betn_b_and_i.mp4 + # Makes sure that we handle edit lists and start padding correctly. fate-mov-440hz-10ms: CMD = framemd5 -i $(TARGET_SAMPLES)/mov/440hz-10ms.m4a diff --git a/tests/ref/fate/mov-elst-ends-betn-b-and-i b/tests/ref/fate/mov-elst-ends-betn-b-and-i new file mode 100644 index 0000000000..ee7c6389ad --- /dev/null +++ b/tests/ref/fate/mov-elst-ends-betn-b-and-i @@ -0,0 +1,31 @@ +#format: frame checksums +#version: 2 +#hash: MD5 +#tb 0: 1/25 +#media_type 0: video +#codec_id 0: rawvideo +#dimensions 0: 320x240 +#sar 0: 1/1 +#stream#, dts, pts, duration, size, hash +0, 0, 0, 1, 115200, 4e5dc2b806e394cd666c968f736fecd0 +0, 1, 1, 1, 115200, 7a3c7473d44c5f60c07655f6fc0c2ac3 +0, 2, 2, 1, 115200, 038254422a603a3270c09cdcd149707b +0, 3, 3, 1, 115200, 7553b6b4547cb23ef8f0392ed5a5d4b0 +0, 4, 4, 1, 115200, 6d017ede7f446124af7308667cb0dc41 +0, 5, 5, 1, 115200, 77752f0288ae64f857732b8e62e47457 +0, 6, 6, 1, 115200, d656833951af99330625f7c6de7685c4 +0, 7, 7, 1, 115200, 14338b833e431e566ac98da841600bfe +0, 8, 8, 1, 115200, 07ea95d1659f3c4424a470a546d0df6e +0, 9, 9, 1, 115200, fd05b8cc83072f813e89d394d1f6efc6 +0, 10, 10, 1, 115200, 750b82ca5c7e901545e7b1aa69692426 +0, 11, 11, 1, 115200, 7347679ab09bc936047368b8caebcaff +0, 12, 12, 1, 115200, 63a23fdd57ac8462b9ffbcb12ab717b3 +0, 13, 13, 1, 115200, 705257a1c99693db233e2a3ee027adcf +0, 14, 14, 1, 115200, df861a2ec7a4ef70e82b1c28025e5a48 +0, 15, 15, 1, 115200, 2a8b403c077b6b43aa71eaf7d1537713 +0, 16, 16, 1, 115200, 973b5cd3ce473e3970dfa96045553172 +0, 17, 17, 1, 115200, fc612c0afeae3b6576b5ee2f3f119832 +0, 18, 18, 1, 115200, 97074fe5a0b6e7e8470729654092e56c +0, 19, 19, 1, 115200, 8cf9337201065335b3aa4da21dc9b37a +0, 20, 20, 1, 115200, 93ff3589294cc0673af3daee1e7fe42a +0, 21, 21, 1, 115200, c0b6fd870a022f374f9d6c697e8e293d