From patchwork Thu May 30 05:51:34 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Viney X-Patchwork-Id: 13333 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 47D92446FFD for ; Thu, 30 May 2019 08:58:13 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 312FA688372; Thu, 30 May 2019 08:58:13 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wr1-f68.google.com (mail-wr1-f68.google.com [209.85.221.68]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 403E1680A65 for ; Thu, 30 May 2019 08:58:06 +0300 (EEST) Received: by mail-wr1-f68.google.com with SMTP id l2so3252907wrb.9 for ; Wed, 29 May 2019 22:58:06 -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=qxUYoIueCrTFIkCafU8lgXr+eieJZU403E5ldwoKefE=; b=PNy/SEmaj87LFE/oEDYYBTL+F9x62QrDVG7ajJvMcMF8Gjm/G4eYqAsYq0afzUdGN2 Y8I166oOi6MMyVOdy9R1Zi5ZgMaNqHs1uODDVsmK4apVr4ALKwIl2rvXrDfiF/BnGxEY sQwE2A5qoAE2SHEg2UyikGlO+Y1oH7RjfXGza+/LsozPyuD39KnSSKiHUu+V4GN2ec6f hWWvM7pgTF5pcvsAyr/P9eEQINdYDGmK/tyaHRYLfto1ii+RqFz10swjtFX9DUKwDF/e GRyGqmBq5PiDQAMWBtbrX0rOaOPiVCkhC3MwbpbbEuebqudNb6Y8vDTigqNewnh8EqFH vekw== 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=qxUYoIueCrTFIkCafU8lgXr+eieJZU403E5ldwoKefE=; b=XKazoS2lyAygyvqA9rEiPwcfTbbt4Af5zcBPrj21G2HgFbhAaO86kMpnntROkC+Lnx 1g5NCMoEZugWPXPIbiF4+WHEo7f9El0oGG64fvWqrzt1OepKwwZDg/aNOX7tX+25XMK2 QmJU2LhKpp/5aEAR1fbsVUi0UkgOcrgWAthc7PGZWvTKeIGvzLFACKcYQkoEaHUJZX8P xnbU155jO8H8/tsxurZd5fgM8H9gXcpkTcimPnl4DhoMk+3axCvMFW5keN0M3UYDv+S/ eRoc68FEkvcr2u2AcWlXxO7WhQxX7h+Sx5I8pOEMxNYWVrj6mxC1anw9qLuF0VsCrWbz A4Ug== X-Gm-Message-State: APjAAAXLa4yFLPy4gfDJtiqqnQoAUZXN6jAVjG2k1q8X6d7cs9OSVXpO 4z1J+x6MRVHkH3hemYbfLAgZZektRleWNOZxf7zVe3Nw X-Google-Smtp-Source: APXvYqwca7udrb4ftjhUcacBI7O9J+TfSr4RCaNdlTfaSEU4XIZvPYehyEZcNB7aerLlYqeqHH1J4MqUDDoOCZaR4Fs= X-Received: by 2002:adf:db81:: with SMTP id u1mr1141569wri.296.1559195505362; Wed, 29 May 2019 22:51:45 -0700 (PDT) MIME-Version: 1.0 References: <20190523071414.GA14288@sunshine.barsnick.net> In-Reply-To: From: Jonathan Viney Date: Thu, 30 May 2019 17:51:34 +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" On Thu, May 23, 2019 at 8:10 PM Jonathan Viney wrote: > On Thu, May 23, 2019 at 7:14 PM Moritz Barsnick wrote: > >> On Thu, May 23, 2019 at 16:51:16 +1200, Jonathan Viney wrote: >> > > 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. >> >> Is this useful for anything? Would it be more useful in a metadata key? >> (Just wondering, not critisizing.) >> > > I agree having it transferred to a metadata key in the output would be > useful. That was my first thought, but seems like it would be a larger > patch and I wasn't sure if it would be able to write to the metadata for > streaming formats like fragmented MP4 (which is what I'm using) because the > RTCP packet arrives some time after the output metadata would have be > written (from what I understand). Please correct me if I'm wrong about that. > > >> >> > + av_strlcatf(buf, sizeof(buf), "%lld", >> s->start_time_realtime); >> >> start_time_realtime is int64_t, so the format identifier should be >> '"%" PRIi64'. >> > > Thanks - will update the patch. > Updated patch. Regards, -Jonathan. From d2e1b11161e825bc8d40a4a368180c8a69ed6a75 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..cda92be162 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), "%"PRIi64, 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;