From patchwork Thu Dec 29 23:04:07 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sasi Inguva X-Patchwork-Id: 1988 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.103.89.21 with SMTP id n21csp2613710vsb; Thu, 29 Dec 2016 15:05:00 -0800 (PST) X-Received: by 10.194.172.42 with SMTP id az10mr39195961wjc.145.1483052700763; Thu, 29 Dec 2016 15:05:00 -0800 (PST) Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id ek8si59697562wjd.74.2016.12.29.15.04.59; Thu, 29 Dec 2016 15:05:00 -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; 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 AC8AA689B23; Fri, 30 Dec 2016 01:04:53 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pg0-f53.google.com (mail-pg0-f53.google.com [74.125.83.53]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 7CD5B689ACB for ; Fri, 30 Dec 2016 01:04:47 +0200 (EET) Received: by mail-pg0-f53.google.com with SMTP id i5so105916205pgh.2 for ; Thu, 29 Dec 2016 15:04:51 -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; bh=+OHY50wro4ylVR31kEDDhzIa3aN1YDiQ+y5TtfQOMgs=; b=Dm0OoDht6Lj+vbwskKlQmzk4mTozXZxrGCkQxL05cfBglrmv4e0sXQwT7H+CL8XsSu QelfaHxLfxadQaArmH4g00ic5YRxKSZc5B8g/jxo2/F0OkN4k6AinD957amuWsCA7iV8 PkQxYqUJBQg8y5EKeN8OGJiPfIdTag/b55oOL2crfltzBQY/QJb+WWG8xs1yzYJloXEC eCwUzobeziqDN5K87eoJWTJ5dLDQXglTqhgdG8PeTKSUXsT9N23d6VSaKscLbKyAzfu8 63aAIPocIFuiecgVX4I6pMn5mHF+8myGkutBbw1Gk4FRtVHLcYooo0UGWeZWa3CJjnOC 8aQQ== 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; bh=+OHY50wro4ylVR31kEDDhzIa3aN1YDiQ+y5TtfQOMgs=; b=csRS5EypypWXdZRfVrwnF36QlLVigk0pVjlyL/eDQwBEr1CwVOUSzowVFg6IiBnqpK 60YjjPU8WUGbhsPc/t4c2u4tO1S5Ydgcp5HroUqkcf9jOTZoaOpVfVACKNucKBfSDuAy 8lymsCnD5ePkH8mOQ3/U4KKXLmiABFB/4B2uIfrx8mIg7WJ1Dx02ZwDT4BCD64PRCn+r KSMJHpdu9DmmXLPtnDVaHnhQKSR1IMK0JdpyR4hVh/qbJbcPYz+IfhUeXQStcmbRN6MB GBtojeO3tZ0xSJvdxYrKaP4rDx6Dw3BOMt7nJg3JoMHlP8HsgGResYmQUw+jh/nkxc9m EwzA== X-Gm-Message-State: AIkVDXJE16F7HvoCq4sf23xIy2UOaSVvEYmaKvpiSs9JJl36KFJJ8GkCIFuC/VBWx2kmrCN4 X-Received: by 10.98.219.5 with SMTP id f5mr41540851pfg.131.1483052689011; Thu, 29 Dec 2016 15:04:49 -0800 (PST) Received: from isasi.mtv.corp.google.com ([172.27.82.89]) by smtp.gmail.com with ESMTPSA id e6sm88862738pgf.4.2016.12.29.15.04.48 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 29 Dec 2016 15:04:48 -0800 (PST) From: Sasi Inguva To: ffmpeg-devel@ffmpeg.org Date: Thu, 29 Dec 2016 15:04:07 -0800 Message-Id: <1483052647-9767-1-git-send-email-isasi@google.com> X-Mailer: git-send-email 2.8.0.rc3.226.g39d4020 Subject: [FFmpeg-devel] [PATCH] lavf/mov.c: Add -editlist_fix_index option for mov format. 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" Signed-off-by: Sasi Inguva --- libavformat/isom.h | 1 + libavformat/mov.c | 23 ++++++++++++++++++++--- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/libavformat/isom.h b/libavformat/isom.h index 12cefc9..ff3a234 100644 --- a/libavformat/isom.h +++ b/libavformat/isom.h @@ -225,6 +225,7 @@ typedef struct MOVContext { unsigned int nb_chapter_tracks; int use_absolute_path; int ignore_editlist; + int editlist_fix_index; int ignore_chapters; int seek_individually; int64_t next_root_atom; ///< offset of the next root atom diff --git a/libavformat/mov.c b/libavformat/mov.c index d1b9291..98f8c4c 100644 --- a/libavformat/mov.c +++ b/libavformat/mov.c @@ -3227,7 +3227,7 @@ static void mov_build_index(MOVContext *mov, AVStream *st) uint64_t stream_size = 0; if (sc->elst_count) { - int i, edit_start_index = 0; + int i, edit_start_index = 0, multiple_edits = 0; int64_t empty_duration = 0; // empty duration of the first edit list entry int64_t start_time = 0; // start time of the media @@ -3240,15 +3240,28 @@ static void mov_build_index(MOVContext *mov, AVStream *st) edit_start_index = 1; } else if (i == edit_start_index && e->time >= 0) { start_time = e->time; + } else { + multiple_edits = 1; } } + if (multiple_edits && !mov->editlist_fix_index) + av_log(mov->fc, AV_LOG_WARNING, "multiple edit list entries, " + "Use -editlist_fix_index to correctly decode otherwise " + "a/v desync might occur\n"); + /* adjust first dts according to edit list */ if ((empty_duration || start_time) && mov->time_scale > 0) { if (empty_duration) empty_duration = av_rescale(empty_duration, sc->time_scale, mov->time_scale); sc->time_offset = start_time - empty_duration; + if (!mov->editlist_fix_index) + current_dts = -sc->time_offset; } + + if (!multiple_edits && !mov->editlist_fix_index && + st->codecpar->codec_id == AV_CODEC_ID_AAC && start_time > 0) + sc->start_pad = start_time; } /* only use old uncompressed audio chunk demuxing when stts specifies it */ @@ -3482,8 +3495,10 @@ static void mov_build_index(MOVContext *mov, AVStream *st) } } - // Fix index according to edit lists. - mov_fix_index(mov, st); + if (!mov->ignore_editlist && mov->editlist_fix_index) { + // Fix index according to edit lists. + mov_fix_index(mov, st); + } } static int test_same_origin(const char *src, const char *ref) { @@ -6349,6 +6364,8 @@ static const AVOption mov_options[] = { 0, 1, FLAGS}, {"ignore_editlist", "", OFFSET(ignore_editlist), AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, FLAGS}, + {"editlist_fix_index", "", OFFSET(editlist_fix_index), AV_OPT_TYPE_BOOL, {.i64 = 1}, + 0, 1, FLAGS}, {"ignore_chapters", "", OFFSET(ignore_chapters), AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, FLAGS}, {"use_mfra_for",