From patchwork Thu May 23 04:51:16 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Viney X-Patchwork-Id: 13255 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 E829C447E27 for ; Thu, 23 May 2019 07:51:34 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id C4A49680714; Thu, 23 May 2019 07:51:34 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm1-f49.google.com (mail-wm1-f49.google.com [209.85.128.49]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 1D24368056C for ; Thu, 23 May 2019 07:51:28 +0300 (EEST) Received: by mail-wm1-f49.google.com with SMTP id z23so209208wma.4 for ; Wed, 22 May 2019 21:51:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to; bh=OL0wOOqYPvzHrRJHnKZEhRtYOSl3O3fBEuTCS29Qdgk=; b=HhVqCby+zDrAry87E2asUJp5d3b06ZAOn3bVTNnqm4R2Bd5HCjpHGkex0xmewMBH/b qOv/Ojfr76JCGfxJVgYkrjwns/jxkkVi55taTXP8EwwJEc8HJIAHxotrRg2HBWAQLbzb 0IuPCGq0osIeE7rq+D+J22XvHTZsw+eIJKdN5Z0h88xJ8pe1mpehULdpeeGUKrNQpi3j jWmoaiTbRBxK+7YjNCMPA5vw5cPb6Rbx9sUiTD4zFm4/Y8LnmYtE78ZaCVVDdrfZ85qN 9cXfsZI+xP1WX4sjPYqzpssAAditJoZQ6Y2ws1ARFnfa+Mz5GWTkVtpYJnHgHtjCcXse P5uQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to; bh=OL0wOOqYPvzHrRJHnKZEhRtYOSl3O3fBEuTCS29Qdgk=; b=CkbYIBrLUFSpINk2jhUClj9iAFAZJ5WoJayg+s/j/1czD0H6A1r/QhBiEXBWX7bmo7 telPgEVeyTSBarXXdmkWLoAPH+AioB2N1yIGkt92FrODajfa5KLX57E6cTQCEWNs3xik OdWACRnaWgbO+RALGpj1wy37FmRm7ABaCoRZCNdNlasKKQ/6A90a2R736hvr3nVwEZjm /E4jN8PawXLsWTkPN9ksCKbQlMX3rG88abCchRDrulQBtDlVnshjo17rL6SXfC4TR6Uq cwRIIuq6TAM/S0ton3FqKzV340Me8DfOb5kfYOoLSNSmNt5oGl7RT0WkklknHIOyADPE /RRA== X-Gm-Message-State: APjAAAVQpyH+JipdcNtgu1brGYT1NhqrgdzT8uTkKeazQY6nbX4s0wWz Kj5Xzsdu2qgGTxxBYsttyHfNF5zRQ7IfHdh5lrlE9w== X-Google-Smtp-Source: APXvYqy8wqCfj6X6QR9Zgt/1QbB/QHSAFKUypaOhqmC4fkA/6m2gqLpKin44Dg/r/93k/eppzCgUOANKIVVDKFlUPLY= X-Received: by 2002:a1c:2c89:: with SMTP id s131mr9676867wms.142.1558587087395; Wed, 22 May 2019 21:51:27 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Jonathan Viney Date: Thu, 23 May 2019 16:51:16 +1200 Message-ID: To: FFmpeg development discussions and patches X-Content-Filtered-By: Mailman/MimeDel 2.1.20 Subject: Re: [FFmpeg-devel] [PATCH] avformat/rtsp: Add -first_rtcp_ntp_time_path option to write the first NTP time to a file. 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" Apologies, here is the patch in text/plain. On Thu, May 23, 2019 at 4:44 PM Jonathan Viney wrote: > Hi, > > The NTP time from the first RTCP packet is currently extracted in > libavformat/rtsp.c and stored in AVFormatContext.start_time_realtime. > However, there is no way to access this value when using ffmpeg from the > commandline. > > This patch adds an option when using an RTSP input to write the value to a > file when it is received. > > Eg: > ffmpeg -first_rtcp_ntp_time_path out.mp4.ntp -i rtsp://10.0.0.1/ -c copy > out.mp4 > > Regards, > -Jonathan. > From e16826736640f132f0d3a6f170337ab9696e0038 Mon Sep 17 00:00:00 2001 From: Jonathan Viney Date: Thu, 23 May 2019 14:24:16 +1200 Subject: [PATCH] avformat/rtsp: add -first_rtcp_ntp_time_path option to write the first NTP time to a file. Signed-off-by: Jonathan Viney --- libavformat/rtsp.c | 16 ++++++++++++++++ libavformat/rtsp.h | 6 ++++++ 2 files changed, 22 insertions(+) diff --git a/libavformat/rtsp.c b/libavformat/rtsp.c index c153cac88b..4b048701e2 100644 --- a/libavformat/rtsp.c +++ b/libavformat/rtsp.c @@ -96,6 +96,7 @@ const AVOption ff_rtsp_options[] = { { "min_port", "set minimum local UDP port", OFFSET(rtp_port_min), AV_OPT_TYPE_INT, {.i64 = RTSP_RTP_PORT_MIN}, 0, 65535, DEC|ENC }, { "max_port", "set maximum local UDP port", OFFSET(rtp_port_max), AV_OPT_TYPE_INT, {.i64 = RTSP_RTP_PORT_MAX}, 0, 65535, DEC|ENC }, { "listen_timeout", "set maximum timeout (in seconds) to wait for incoming connections (-1 is infinite, imply flag listen)", OFFSET(initial_timeout), AV_OPT_TYPE_INT, {.i64 = -1}, INT_MIN, INT_MAX, DEC }, + { "first_rtcp_ntp_time_path", "path to write first NTP time (in microseconds) received in RTCP packet", OFFSET(first_rtcp_ntp_time_path), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, DEC }, #if FF_API_OLD_RTSP_OPTIONS { "timeout", "set maximum timeout (in seconds) to wait for incoming connections (-1 is infinite, imply flag listen) (deprecated, use listen_timeout)", OFFSET(initial_timeout), AV_OPT_TYPE_INT, {.i64 = -1}, INT_MIN, INT_MAX, DEC }, { "stimeout", "set timeout (in microseconds) of socket TCP I/O operations", OFFSET(stimeout), AV_OPT_TYPE_INT, {.i64 = 0}, INT_MIN, INT_MAX, DEC }, @@ -2256,6 +2257,21 @@ redo: (uint64_t) rtpctx->st->time_base.num * 1000000, rtpctx->st->time_base.den); } + + // Write the NTP start time + if (rt->first_rtcp_ntp_time_path) { + AVIOContext *ioctx = NULL; + int ret; + ret = avio_open(&ioctx, rt->first_rtcp_ntp_time_path, AVIO_FLAG_WRITE); + if (ret < 0) { + av_log(s, AV_LOG_WARNING, "unable to open %s to write first rtcp ntp time\n", rt->first_rtcp_ntp_time_path); + } else { + char buf[21] = ""; + av_strlcatf(buf, sizeof(buf), "%lld", s->start_time_realtime); + avio_write(ioctx, buf, strlen(buf)); + avio_closep(&ioctx); + } + } } } if (ret == -RTCP_BYE) { diff --git a/libavformat/rtsp.h b/libavformat/rtsp.h index 54a9a30c16..4df24b743a 100644 --- a/libavformat/rtsp.h +++ b/libavformat/rtsp.h @@ -408,6 +408,12 @@ typedef struct RTSPState { */ char *user_agent; + /** + * Path to write the first RTCP unix time in microseconds, if + * it is received as part of the stream. + */ + char *first_rtcp_ntp_time_path; + char default_lang[4]; int buffer_size; int pkt_size;