From patchwork Sat Sep 21 17:58:20 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rodger Combs X-Patchwork-Id: 15216 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 2DB3F44A5CF for ; Sat, 21 Sep 2019 20:58:34 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 0472D68A9CE; Sat, 21 Sep 2019 20:58:34 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-io1-f43.google.com (mail-io1-f43.google.com [209.85.166.43]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 0B2DF68A92E for ; Sat, 21 Sep 2019 20:58:27 +0300 (EEST) Received: by mail-io1-f43.google.com with SMTP id h144so23580966iof.7 for ; Sat, 21 Sep 2019 10:58:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=vA4ZBLqMIktQlUK8wPhewi4lv7FRGPPadvswX2+diPg=; b=srOaIeVwqcPS6MMlowq2w/uBTtmGziwwq5X3dwJYfMqulOom2/gvLhSVg0MGhSvfPu ehmmVsqTzGR0Ux34N4GnKJV3hrHzR8E5X3uNeCz92BVQPzdZGNpUPjLtFYMfqYtL82fE pEJobJkOGwrT/bx3I8/8WAYOzx82cbdg8BeQJ36P6BybrMcdZ9dF9f5ZG8cHfgiLDBy9 Rw6ZFbJOIuCMODJGCpPdK+eMmga0eQI71u1yx1LyQIJWkHLC8D0/vJxv1+cOmhtEoZWW YzVWumyIiE22moiVN4QTpTTtBbcJyfG34Nl8LcfI4tfOadmZ7SRKrnjOxBRcj4dNulZy kjYQ== 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:mime-version :content-transfer-encoding; bh=vA4ZBLqMIktQlUK8wPhewi4lv7FRGPPadvswX2+diPg=; b=R5qDpw7MBv5LEvtcvLO5h2bOuRm/wrRVfcuyScHxeuYPKBC8Bx094M7do6p622efus XRw/+47Hgx4txf/CXCoDYt88gudzx8QxJMXBZDuDD37VYk7tQTdeVbleAExI2zmaX9XJ JcbzcGF1hJ1HVCTg5uxvDyw8BmyQsK129VQ9bz2FXmRpkviRn9I0nl+Njxs7gvIz+NHM XS91tcADHc0wKyWP3s8VV+Eydoe4bpQNpNomCC8tfyjAGJEIazEfT6HgdnBAQFtxlXS6 ksTI0YjDTz8bg3grfj8OYEcSUVuVztHidvWP63HjwIYuN2sieKgOMlVbb/uClf+nwoUM 1zhA== X-Gm-Message-State: APjAAAUzVxS5+k3rft0i2F8u9ws6qK1bFT2eE983QNv7zGopiAIxpSa3 hydH+5ifNk2Ga9Bt8V1HHodChqDWp2o= X-Google-Smtp-Source: APXvYqzcPfPuc+iv0jRT+JIDu6+rqjaPUeUTe9WnV0bAi5lMyVWDdbCF/bAIq8QzQH9BJ5F+cA4Wgw== X-Received: by 2002:a6b:210:: with SMTP id 16mr23303764ioc.104.1569088705326; Sat, 21 Sep 2019 10:58:25 -0700 (PDT) Received: from MacBook-Pro.localdomain ([24.14.135.13]) by smtp.gmail.com with ESMTPSA id m21sm5736154iob.82.2019.09.21.10.58.24 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sat, 21 Sep 2019 10:58:24 -0700 (PDT) From: Rodger Combs To: ffmpeg-devel@ffmpeg.org Date: Sat, 21 Sep 2019 12:58:20 -0500 Message-Id: <20190921175820.55905-1-rodger.combs@gmail.com> X-Mailer: git-send-email 2.21.0 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH] lavf/movdec: add position_order option 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" This allows reading packets linearly, which prevents large numbers of unnecessary seeks in poorly-interleaved files with consumer software that handles those cases well on its own. --- libavformat/isom.h | 1 + libavformat/mov.c | 11 +++++++---- libavformat/version.h | 2 +- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/libavformat/isom.h b/libavformat/isom.h index 69452cae8e..3e29e9877d 100644 --- a/libavformat/isom.h +++ b/libavformat/isom.h @@ -288,6 +288,7 @@ typedef struct MOVContext { int decryption_key_len; int enable_drefs; int32_t movie_display_matrix[3][3]; ///< display matrix from mvhd + int position_order; } MOVContext; int ff_mp4_read_descr_len(AVIOContext *pb); diff --git a/libavformat/mov.c b/libavformat/mov.c index 675b915906..a1559b8a8f 100644 --- a/libavformat/mov.c +++ b/libavformat/mov.c @@ -7626,8 +7626,10 @@ static int mov_read_header(AVFormatContext *s) static AVIndexEntry *mov_find_next_sample(AVFormatContext *s, AVStream **st) { + MOVContext *mov = s->priv_data; AVIndexEntry *sample = NULL; int64_t best_dts = INT64_MAX; + int use_pos = mov->position_order || !(s->pb->seekable & AVIO_SEEKABLE_NORMAL); int i; for (i = 0; i < s->nb_streams; i++) { AVStream *avst = s->streams[i]; @@ -7636,11 +7638,10 @@ static AVIndexEntry *mov_find_next_sample(AVFormatContext *s, AVStream **st) AVIndexEntry *current_sample = &avst->index_entries[msc->current_sample]; int64_t dts = av_rescale(current_sample->timestamp, AV_TIME_BASE, msc->time_scale); av_log(s, AV_LOG_TRACE, "stream %d, sample %d, dts %"PRId64"\n", i, msc->current_sample, dts); - if (!sample || (!(s->pb->seekable & AVIO_SEEKABLE_NORMAL) && current_sample->pos < sample->pos) || - ((s->pb->seekable & AVIO_SEEKABLE_NORMAL) && - ((msc->pb != s->pb && dts < best_dts) || (msc->pb == s->pb && + if (!sample || (use_pos ? (current_sample->pos < sample->pos) : + (((msc->pb != s->pb && dts < best_dts) || (msc->pb == s->pb && ((FFABS(best_dts - dts) <= AV_TIME_BASE && current_sample->pos < sample->pos) || - (FFABS(best_dts - dts) > AV_TIME_BASE && dts < best_dts)))))) { + (FFABS(best_dts - dts) > AV_TIME_BASE && dts < best_dts))))))) { sample = current_sample; best_dts = dts; *st = avst; @@ -8017,6 +8018,8 @@ static const AVOption mov_options[] = { { "decryption_key", "The media decryption key (hex)", OFFSET(decryption_key), AV_OPT_TYPE_BINARY, .flags = AV_OPT_FLAG_DECODING_PARAM }, { "enable_drefs", "Enable external track support.", OFFSET(enable_drefs), AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, FLAGS }, + { "position_order", "Read packets in position order (rather than timestamp order)", + OFFSET(position_order), AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, FLAGS }, { NULL }, }; diff --git a/libavformat/version.h b/libavformat/version.h index edfa73fb97..2eb14659d0 100644 --- a/libavformat/version.h +++ b/libavformat/version.h @@ -33,7 +33,7 @@ // Also please add any ticket numbers that you believe might be affected here #define LIBAVFORMAT_VERSION_MAJOR 58 #define LIBAVFORMAT_VERSION_MINOR 32 -#define LIBAVFORMAT_VERSION_MICRO 104 +#define LIBAVFORMAT_VERSION_MICRO 105 #define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \ LIBAVFORMAT_VERSION_MINOR, \