From patchwork Thu Jun 16 09:09:11 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gyan Doshi X-Patchwork-Id: 36254 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:1a22:b0:84:42e0:ad30 with SMTP id cj34csp824533pzb; Thu, 16 Jun 2022 02:09:50 -0700 (PDT) X-Google-Smtp-Source: AGRyM1ti4EK7JvvfYOYJsABGfs+W3fRRns+WeLVpww+qKDZsiC2kWMN7DRjm808/2HjAOwGUJqTX X-Received: by 2002:a17:906:1d5:b0:712:3952:afc6 with SMTP id 21-20020a17090601d500b007123952afc6mr3649587ejj.564.1655370589906; Thu, 16 Jun 2022 02:09:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655370589; cv=none; d=google.com; s=arc-20160816; b=Up9BNXk+9KEaVwrXJYl7zl8tZtThhLYBdAnyGnj+uVjyEOx4Ii96WtjSJXZoEJIRFW rC3lHqLEuMjGvidHK5Ylco8WeXIBoFjUkNYwAaNL0sZ+JbO0ZtOHlrD3Ikoqwu4+pyZr MaaJrjyj7UFTjtMFquhkA38Bc/6XflLaHmWxprIDrPBMYd7GExVwd5vc8fUwCBksTeyY o2zIo0eETMrkhvrmObuUeqCmbvjLXgUf79fIHsw2tRYrbWXlooI/Nw7qYhAElhsTohsy Y4RmOdB1a3jI7KGIiuWZiLDmTysjthMkBX8gIKpVfVhRfX0bHFBkjEIuiLYkEJZi8pjD hdMg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:reply-to:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:subject:mime-version:message-id:date:to:from :delivered-to; bh=8Duu8xOajFQ5g8GAPlRJRzq8ss37LGusWJAtwd4gzQ4=; b=AE08/snCXc3JDrCbeM4Pf5Z2wbFbHwI/aTxfGotVJcv/l1Wlgo3o4kt0UT+ZgtzUmo 3JrNMlRNehlgnWFlRlvcg+za2H+Ze/tj0s+LBLkjeqADYqj0CMLyxYFwCD0ayGhjBmPw CKI21NpDqK52o0Ou9ufU5IDyjG6K9MvDfJbt0YohGrONmPUioVXNgyNdr+LcsXAmpC+U Nh2bQvHvvIPmaZ6w7wdtmP8GsheT/2VrflCk+pRpNgL4id8tb1yfX/5alzKZK/Cwj0k0 PjJS+pxszHhseCf1CBmHX3xVYYectRt8Q4aDn7LETd+Ag0XoBStDabrZwc/Iz3oCNZek lZww== ARC-Authentication-Results: i=1; mx.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 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id cw22-20020a170906479600b00706b9787b43si1381576ejc.319.2022.06.16.02.09.49; Thu, 16 Jun 2022 02:09:49 -0700 (PDT) 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; 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 7CBB868B74F; Thu, 16 Jun 2022 12:09:46 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mout-p-202.mailbox.org (mout-p-202.mailbox.org [80.241.56.172]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 3BFA168B657 for ; Thu, 16 Jun 2022 12:09:40 +0300 (EEST) Received: from smtp202.mailbox.org (smtp202.mailbox.org [10.196.197.202]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-384) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-p-202.mailbox.org (Postfix) with ESMTPS id 4LNxFZ0RFwz9sQx for ; Thu, 16 Jun 2022 11:09:38 +0200 (CEST) From: Gyan Doshi To: ffmpeg-devel@ffmpeg.org Date: Thu, 16 Jun 2022 14:39:11 +0530 Message-Id: <20220616090911.5357-1-ffmpeg@gyani.pro> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH] avformat: add AVFormatContext.first_pts_wallclock X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 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" X-TUID: bkuGCn22/GtG Stores wallclock time for the first packet received with a pts. --- doc/APIchanges | 3 +++ libavformat/avformat.h | 10 ++++++++++ libavformat/demux.c | 3 +++ libavformat/options.c | 1 + libavformat/version.h | 2 +- 5 files changed, 18 insertions(+), 1 deletion(-) diff --git a/doc/APIchanges b/doc/APIchanges index 5857e67ae6..3d472b8963 100644 --- a/doc/APIchanges +++ b/doc/APIchanges @@ -14,6 +14,9 @@ libavutil: 2021-04-27 API changes, most recent first: +2022-06-xx - xxxxxxxxxx - lavf 59.26.100 - avformat.h + Add and set AVFormatContext.first_pts_wallclock field. + 2022-06-12 - xxxxxxxxxx - lavf 59.25.100 - avio.h Add avio_vprintf(), similar to avio_printf() but allow to use it from within a function taking a variable argument list as input. diff --git a/libavformat/avformat.h b/libavformat/avformat.h index f12fa7d904..56f9656a68 100644 --- a/libavformat/avformat.h +++ b/libavformat/avformat.h @@ -1808,6 +1808,16 @@ typedef struct AVFormatContext { */ int max_probe_packets; + /** + * Wallclock start time of the stream in real world time, in microseconds + * since the Unix epoch (00:00 1st January 1970). That is, the first packet + * with a set pts was received at this real world time. + * - demuxing: Set by libavformat. Users may want to use start_time_realtime + * if set. + * - muxing: unused. + */ + int64_t first_pts_wallclock; + /** * A callback for closing the streams opened with AVFormatContext.io_open(). * diff --git a/libavformat/demux.c b/libavformat/demux.c index 1620716716..9335a6efcd 100644 --- a/libavformat/demux.c +++ b/libavformat/demux.c @@ -628,6 +628,9 @@ FF_ENABLE_DEPRECATION_WARNINGS force_codec_ids(s, st); + if (s->first_pts_wallclock == AV_NOPTS_VALUE && pkt->pts != AV_NOPTS_VALUE) + s->first_pts_wallclock = av_gettime(); + /* TODO: audio: time filter; video: frame reordering (pts != dts) */ if (s->use_wallclock_as_timestamps) pkt->dts = pkt->pts = av_rescale_q(av_gettime(), AV_TIME_BASE_Q, st->time_base); diff --git a/libavformat/options.c b/libavformat/options.c index 0079a06d9a..4cc168939f 100644 --- a/libavformat/options.c +++ b/libavformat/options.c @@ -184,6 +184,7 @@ AVFormatContext *avformat_alloc_context(void) return NULL; } + s->first_pts_wallclock = AV_NOPTS_VALUE; si->shortest_end = AV_NOPTS_VALUE; return s; diff --git a/libavformat/version.h b/libavformat/version.h index 966ebb7ed3..0708d619c0 100644 --- a/libavformat/version.h +++ b/libavformat/version.h @@ -31,7 +31,7 @@ #include "version_major.h" -#define LIBAVFORMAT_VERSION_MINOR 25 +#define LIBAVFORMAT_VERSION_MINOR 26 #define LIBAVFORMAT_VERSION_MICRO 100 #define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \