From patchwork Sun Mar 29 21:27:38 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Stebbins X-Patchwork-Id: 18497 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 27FCA44B025 for ; Mon, 30 Mar 2020 00:27:50 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 07E1468B50A; Mon, 30 Mar 2020 00:27:50 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail.jetheaddev.com (mail.jetheaddev.com [70.164.99.34]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 7E9E068AFA0 for ; Mon, 30 Mar 2020 00:27:43 +0300 (EEST) Received: from dionysus.jetheaddev.com (10.13.8.112) by cas.jetheaddev.com (192.168.13.27) with Microsoft SMTP Server (TLS) id 14.3.351.0; Sun, 29 Mar 2020 14:27:40 -0700 Received: from dionysus.jetheaddev.com (localhost [127.0.0.1]) by dionysus.jetheaddev.com (8.15.2/8.14.7) with ESMTP id 02TLReIx226922 for ; Sun, 29 Mar 2020 14:27:40 -0700 Received: (from jstebbins@localhost) by dionysus.jetheaddev.com (8.15.2/8.15.2/Submit) id 02TLReI9226921 for ffmpeg-devel@ffmpeg.org; Sun, 29 Mar 2020 14:27:40 -0700 From: John Stebbins To: Date: Sun, 29 Mar 2020 14:27:38 -0700 Message-ID: <20200329212738.226876-1-jstebbins@jetheaddev.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-Originating-IP: [10.13.8.112] Subject: [FFmpeg-devel] [PATCH] libavformat/mov: fix multiple trun per traf 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" dts would start over at the beginning of each trun when they should be computed contiguously for each trun in a traf Fixes ticket 8070 --- libavformat/isom.h | 1 + libavformat/mov.c | 12 +++++++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/libavformat/isom.h b/libavformat/isom.h index 4943b80ccf..41a9c64c11 100644 --- a/libavformat/isom.h +++ b/libavformat/isom.h @@ -129,6 +129,7 @@ typedef struct MOVFragmentStreamInfo { int64_t sidx_pts; int64_t first_tfra_pts; int64_t tfdt_dts; + int64_t next_trun_dts; int index_entry; MOVEncryptionIndex *encryption_index; } MOVFragmentStreamInfo; diff --git a/libavformat/mov.c b/libavformat/mov.c index 8ed8b7f6e9..f96a7d8e39 100644 --- a/libavformat/mov.c +++ b/libavformat/mov.c @@ -1335,6 +1335,7 @@ static int update_frag_index(MOVContext *c, int64_t offset) frag_stream_info[i].id = c->fc->streams[i]->id; frag_stream_info[i].sidx_pts = AV_NOPTS_VALUE; frag_stream_info[i].tfdt_dts = AV_NOPTS_VALUE; + frag_stream_info[i].next_trun_dts = AV_NOPTS_VALUE; frag_stream_info[i].first_tfra_pts = AV_NOPTS_VALUE; frag_stream_info[i].index_entry = -1; frag_stream_info[i].encryption_index = NULL; @@ -4609,6 +4610,7 @@ static int mov_read_tfhd(MOVContext *c, AVIOContext *pb, MOVAtom atom) MOVFragment *frag = &c->fragment; MOVTrackExt *trex = NULL; int flags, track_id, i; + MOVFragmentStreamInfo * frag_stream_info; avio_r8(pb); /* version */ flags = avio_rb24(pb); @@ -4642,6 +4644,10 @@ static int mov_read_tfhd(MOVContext *c, AVIOContext *pb, MOVAtom atom) avio_rb32(pb) : trex->flags; av_log(c->fc, AV_LOG_TRACE, "frag flags 0x%x\n", frag->flags); + frag_stream_info = get_current_frag_stream_info(&c->frag_index); + if (frag_stream_info) + frag_stream_info->next_trun_dts = AV_NOPTS_VALUE; + return 0; } @@ -4795,7 +4801,9 @@ static int mov_read_trun(MOVContext *c, AVIOContext *pb, MOVAtom atom) frag_stream_info = get_current_frag_stream_info(&c->frag_index); if (frag_stream_info) { - if (frag_stream_info->first_tfra_pts != AV_NOPTS_VALUE && + if (frag_stream_info->next_trun_dts != AV_NOPTS_VALUE) { + dts = frag_stream_info->next_trun_dts - sc->time_offset; + } else if (frag_stream_info->first_tfra_pts != AV_NOPTS_VALUE && c->use_mfra_for == FF_MOV_FLAG_MFRA_PTS) { pts = frag_stream_info->first_tfra_pts; av_log(c->fc, AV_LOG_DEBUG, "found mfra time %"PRId64 @@ -4950,6 +4958,8 @@ static int mov_read_trun(MOVContext *c, AVIOContext *pb, MOVAtom atom) sc->nb_frames_for_fps ++; } } + if (frag_stream_info) + frag_stream_info->next_trun_dts = dts + sc->time_offset; if (i < entries) { // EOF found before reading all entries. Fix the hole this would // leave in index_entries and ctts_data