From patchwork Tue May 15 23:06:24 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aman Karmani X-Patchwork-Id: 8984 Delivered-To: ffmpegpatchwork@gmail.com Received: by 2002:a02:155:0:0:0:0:0 with SMTP id c82-v6csp2058794jad; Tue, 15 May 2018 16:06:38 -0700 (PDT) X-Google-Smtp-Source: AB8JxZrQ4HASTWt1Kl3+HtFTaFjK1Tj0g/Pxudp+MIsdvFf3qfZL8/Q48U0m/nZYtWEP40b62pTI X-Received: by 2002:a1c:e006:: with SMTP id x6-v6mr8579259wmg.80.1526425597936; Tue, 15 May 2018 16:06:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526425597; cv=none; d=google.com; s=arc-20160816; b=anAzmVyhu0uLP7xxc8c/6Og0J1Vnvfg73RQhlA3IUEIBckPHYoCsGCXeiKGK7Q2Lw2 uwl7fCnxAl3n8xLEJSv51MMrFw29BVT5tlaiVdwXPXZLwyPS8LB4TED+E+OMvQuwdEod NgG8zv2u9Qb/j3IPaKCGmtabRXvVx6L6eD0fs2AwAsYL1iRrMcG30NJX++CKYvj3jGQj yLa02AOAzAtQ6YbZe8u10h7vW4G4L0rR4x5LGbEnTNi+OwNB9kIU1p9UNoDs0AdLYU9p vkVVM4KKnwqit9cnXqfWA3/iXZSD+jYscN3gfWXQOcflwCm69dgXt1YRtnTgITCf5OET R45A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:message-id:date:to:from:dkim-signature :delivered-to:arc-authentication-results; bh=e0yLcA5xBP14uLWrruv6E2hz0Ps0cVSjY88y/agaCXM=; b=Yl7r8/aDfSeC3V9ysh729HV/cbgiGRVDsFUTjo3fmgzsF45s++6xNrvYr6hibmgtkS b9Y8Ae0izOFD5T/GevBCsHtm/2RbhyVyCijgpwfvN5E8q7R36rhNkauHd2YW+nNbdYFc DrvAlJU9S+PzgDM8UCGP0JIVMnMx7TiMOsQa/J+AUeckrnHFTcQAb9OWSWr1yXQw41vi bMmeHUPsvG16xTxMXfwLGSRK1e74UlOzAibU7bKmPUX7GzyI2VCIxFTiobtiYjZrpTqg vjX2mtftuxgEcj/2fsMI8pRaSNTEOWgFMgZhD/P7mQgfbYtgLtkyqh/U0wvAwBPI0hX+ hRHA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@tmm1-net.20150623.gappssmtp.com header.s=20150623 header.b=Ybk/CjHO; 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 j1-v6si979441wrj.103.2018.05.15.16.06.37; Tue, 15 May 2018 16:06:37 -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; dkim=neutral (body hash did not verify) header.i=@tmm1-net.20150623.gappssmtp.com header.s=20150623 header.b=Ybk/CjHO; 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 6FCA068972B; Wed, 16 May 2018 02:05:57 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pg0-f66.google.com (mail-pg0-f66.google.com [74.125.83.66]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 8A724680C0B for ; Wed, 16 May 2018 02:05:51 +0300 (EEST) Received: by mail-pg0-f66.google.com with SMTP id k2-v6so697834pgc.1 for ; Tue, 15 May 2018 16:06:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tmm1-net.20150623.gappssmtp.com; s=20150623; h=sender:from:to:cc:subject:date:message-id; bh=1esmSmuc8sVgRT+vSAX6Z1nTFu8t5UL+43xvcIaLr9c=; b=Ybk/CjHOwUBKLkgPyGBWDKFrXgU0z1ISyFzpa1HzYu+QSHzlqhH4jrAscwsGeT1CGa NDtJhO6nX0j1QBym8GbtACqRkAYbEFNioOKoVYpv6l0ewMia4jVIQxVXsp11Q9iwFPDP DqkL2MPpRm5O4+zNwRJDuM6CZbRRSm0ojZc4mzvBQ+Bu48UsY3k8Ga6cXvbfn5/HWG7I 9dd7rQ1NGlbDUpxpR71Yk1pcWe21YfISLbPQ4YOwptpYLprY3OcITVDrBQhBURHh6raM jMowwdd6GY/C2OZo91AJIqUIRBBc/9CdfEzUZlfCGZnqHzd5yumDhzaL/GgN37VinaKI 8tAQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id; bh=1esmSmuc8sVgRT+vSAX6Z1nTFu8t5UL+43xvcIaLr9c=; b=g/31iD3mH1JTEZoAsztnOy/EpPwfLdFFyPnImiukTNuqaNaBxEYQYwPr4vgEYdNYol zvHYd3FAP0/Waal6K2LrePpiIQmKWOGH2SV6J4zAG39vBpM3UoGNKRTSRI+lBHTJ8JL2 klm2n89vNZ3LkyET04dPfHkINfvYmln7wZBD2mT2O1DCnTW+zRVAU7MhnXOYNVnaoM4B QR3HwXmGVWAcQTCSg5wcSXcAePR71ylAopvJ38/aSiIW0LygasqIovjbWpI+pORnd84n ymgaOmvl+0rgqs9eF7txsH/ax/5pslIS50stHUZKCKwWxrkRCnkfgkr71QDI3Tbx3G/R d/Pw== X-Gm-Message-State: ALKqPwdwP39vlXgeF8cvQiMfRzyRHT1SMHWDKWTgX/szEwY1Xa1+lVpF EzQx5ZXJbaljhCLyIQtE2LPFBunU X-Received: by 2002:a65:5d8e:: with SMTP id f14-v6mr14046164pgt.25.1526425588021; Tue, 15 May 2018 16:06:28 -0700 (PDT) Received: from localhost.localdomain (c-69-181-54-242.hsd1.ca.comcast.net. [69.181.54.242]) by smtp.gmail.com with ESMTPSA id o4-v6sm1481592pfg.129.2018.05.15.16.06.26 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 15 May 2018 16:06:27 -0700 (PDT) From: Aman Gupta To: ffmpeg-devel@ffmpeg.org Date: Tue, 15 May 2018 16:06:24 -0700 Message-Id: <20180515230624.87953-1-ffmpeg@tmm1.net> X-Mailer: git-send-email 2.14.2 Subject: [FFmpeg-devel] [PATCH] avformat: add skip_estimate_duration_from_pts 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 Cc: Aman Gupta MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" From: Aman Gupta For seekable mpegts streams, duration is calculated from pts by seeking to the end of the file for a pts and subtracting the initial pts to compute a duration. This can be expensive in terms of added latency during probe, especially when streaming over a network. This new option lets you skip the duration calculation, which is useful when you don't care about the value and want to save some overhead. This patch is particularly useful when dealing with live mpegts streams. Normally such streams are not seekable, so durations are not calculated. However in my case I am dealing with a seekable live mpegts stream (networked access to a .ts file which is still being appended to). Signed-off-by: Aman Gupta --- libavformat/avformat.h | 7 +++++++ libavformat/options_table.h | 1 + libavformat/utils.c | 6 ++++++ 3 files changed, 14 insertions(+) diff --git a/libavformat/avformat.h b/libavformat/avformat.h index a2fe7c6bb2..669ddb423e 100644 --- a/libavformat/avformat.h +++ b/libavformat/avformat.h @@ -1926,6 +1926,13 @@ typedef struct AVFormatContext { * - decoding: set by user */ int max_streams; + + /** + * Skip duration calcuation in estimate_timings_from_pts. + * - encoding: unused + * - decoding: set by user + */ + int skip_estimate_duration_from_pts; } AVFormatContext; #if FF_API_FORMAT_GET_SET diff --git a/libavformat/options_table.h b/libavformat/options_table.h index 7c4d84798e..6ba6d6ad33 100644 --- a/libavformat/options_table.h +++ b/libavformat/options_table.h @@ -108,6 +108,7 @@ static const AVOption avformat_options[] = { {"protocol_whitelist", "List of protocols that are allowed to be used", OFFSET(protocol_whitelist), AV_OPT_TYPE_STRING, { .str = NULL }, CHAR_MIN, CHAR_MAX, D }, {"protocol_blacklist", "List of protocols that are not allowed to be used", OFFSET(protocol_blacklist), AV_OPT_TYPE_STRING, { .str = NULL }, CHAR_MIN, CHAR_MAX, D }, {"max_streams", "maximum number of streams", OFFSET(max_streams), AV_OPT_TYPE_INT, { .i64 = 1000 }, 0, INT_MAX, D }, +{"skip_estimate_duration_from_pts", "skip duration calculation in estimate_timings_from_pts (for live streams)", OFFSET(skip_estimate_duration_from_pts), AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, D}, {NULL}, }; diff --git a/libavformat/utils.c b/libavformat/utils.c index c25eab4d49..636fae3779 100644 --- a/libavformat/utils.c +++ b/libavformat/utils.c @@ -2812,6 +2812,11 @@ static void estimate_timings_from_pts(AVFormatContext *ic, int64_t old_offset) } } + if (ic->skip_estimate_duration_from_pts) { + av_log(ic, AV_LOG_INFO, "Skipping duration calculation in estimate_timings_from_pts\n"); + goto skip_duration_calc; + } + av_opt_set(ic, "skip_changes", "1", AV_OPT_SEARCH_CHILDREN); /* estimate the end time (duration) */ /* XXX: may need to support wrapping */ @@ -2896,6 +2901,7 @@ static void estimate_timings_from_pts(AVFormatContext *ic, int64_t old_offset) } } } +skip_duration_calc: fill_all_stream_timings(ic); avio_seek(ic->pb, old_offset, SEEK_SET);