From patchwork Mon Oct 7 12:54:55 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: just.one.man@yandex.ru X-Patchwork-Id: 15541 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 476AE44A066 for ; Mon, 7 Oct 2019 15:55:03 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 24668687FEB; Mon, 7 Oct 2019 15:55:03 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from forward500p.mail.yandex.net (forward500p.mail.yandex.net [77.88.28.110]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id E99C16803CA for ; Mon, 7 Oct 2019 15:54:56 +0300 (EEST) Received: from mxback15g.mail.yandex.net (mxback15g.mail.yandex.net [IPv6:2a02:6b8:0:1472:2741:0:8b7:94]) by forward500p.mail.yandex.net (Yandex) with ESMTP id E59AB940418 for ; Mon, 7 Oct 2019 15:54:55 +0300 (MSK) Received: from localhost (localhost [::1]) by mxback15g.mail.yandex.net (nwsmtp/Yandex) with ESMTP id DO7Z1WDo8Q-st8mGc0B; Mon, 07 Oct 2019 15:54:55 +0300 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex.ru; s=mail; t=1570452895; bh=YK99P10jN3OT8EUSFYyWT2ikJhJG/CyWsR30CWBDmLM=; h=Message-Id:Subject:In-Reply-To:Date:References:To:From; b=PZgXfWYkE9wHxiaZBl1sPhYDFtPArVdfUIJWnJ6bWYQ2wzvVYT9CQbwWzAn3TRxQJ FEHBnMd2ejnfPs3jFW0cBF0IwKBzMCk3RpPNHaLcKj3RGDhYXZXHLBV41LK+xWrDiq +Uvxp68kspnJsic+muyiuJ4jFTiXSa9wblyEjwwY= Authentication-Results: mxback15g.mail.yandex.net; dkim=pass header.i=@yandex.ru Received: by iva5-58d151f416d2.qloud-c.yandex.net with HTTP; Mon, 07 Oct 2019 15:54:55 +0300 From: just.one.man@yandex.ru Envelope-From: just-one-man@yandex.ru To: FFmpeg development discussions and patches In-Reply-To: <20191007121444.v75yjs2f6qvieuva@phare.normalesup.org> References: <1570015325-19116-1-git-send-email-just.one.man@yandex.ru> <33758211570015419@iva5-58d151f416d2.qloud-c.yandex.net> <14058761570101997@sas2-5edf99ef3846.qloud-c.yandex.net> <17749581570450366@myt6-4218ece6190d.qloud-c.yandex.net> <20191007121444.v75yjs2f6qvieuva@phare.normalesup.org> MIME-Version: 1.0 X-Mailer: Yamail [ http://yandex.ru ] 5.0 Date: Mon, 07 Oct 2019 15:54:55 +0300 Message-Id: <59884611570452895@iva5-58d151f416d2.qloud-c.yandex.net> Subject: Re: [FFmpeg-devel] [PATCH] Fix segment muxer 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" When incoming media has non-zero start PTS, segment muxer would fail to correctly calculate the point where to chunk segments, as it always assumed that media starts with PTS==0. This change removes this assumption by remembering the PTS of the very first frame passed through the muxer. Also fix starting points of first segment --- libavformat/segment.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) -- 1.7.9.5 Now I tried to re-format as Nicolas George said, hopefully this is okay and won't make a third entry in patchwork (if it does - how do I stop it from doing so?) 07.10.2019, 15:15, "Nicolas George" : > just.one.man@yandex.ru (12019-10-07): >>  Updated patch > > This should be after the triple dash, because it does not belong in the > commit message. > >>  --- >> >>  When incoming media has non-zero start PTS, >>  segment muxer would fail to correctly calculate >>  the point where to chunk segments, as it always >>  assumed that media starts with PTS==0. >> >>  This change removes this assumption by remembering >>  the PTS of the very first frame passed through the muxer. >> >>  Also fix starting points of first segment >>  --- > > This should be before the triple dash, because it does belong in the > commit message. > > I did not look at the code. > > Regards, > > -- >   Nicolas George > , > > _______________________________________________ > ffmpeg-devel mailing list > ffmpeg-devel@ffmpeg.org > https://ffmpeg.org/mailman/listinfo/ffmpeg-devel > > To unsubscribe, visit link above, or email > ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe". diff --git a/libavformat/segment.c b/libavformat/segment.c index e308206..8b985df 100644 --- a/libavformat/segment.c +++ b/libavformat/segment.c @@ -87,6 +87,7 @@ typedef struct SegmentContext { int64_t last_val; ///< remember last time for wrap around detection int cut_pending; int header_written; ///< whether we've already called avformat_write_header + int64_t start_pts; ///< pts of the very first packet processed, used to compute correct segment length char *entry_prefix; ///< prefix to add to list entry filenames int list_type; ///< set the list type @@ -702,6 +703,7 @@ static int seg_init(AVFormatContext *s) if ((ret = parse_frames(s, &seg->frames, &seg->nb_frames, seg->frames_str)) < 0) return ret; } else { + seg->start_pts = AV_NOPTS_VALUE; /* set default value if not specified */ if (!seg->time_str) seg->time_str = av_strdup("2"); @@ -914,7 +916,15 @@ calc_times: seg->cut_pending = 1; seg->last_val = wrapped_val; } else { - end_pts = seg->time * (seg->segment_count + 1); + if (seg->start_pts != AV_NOPTS_VALUE) { + end_pts = seg->start_pts + seg->time * (seg->segment_count + 1); + } else if (pkt->stream_index == seg->reference_stream_index && pkt->pts != AV_NOPTS_VALUE) { + // this is the first packet of the reference stream we see, initialize start point + seg->start_pts = av_rescale_q(pkt->pts, st->time_base, AV_TIME_BASE_Q); + seg->cur_entry.start_time = (double)pkt->pts * av_q2d(st->time_base); + seg->cur_entry.start_pts = seg->start_pts; + end_pts = seg->start_pts + seg->time * (seg->segment_count + 1); + } } }