From patchwork Fri Jun 29 15:53:43 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: morten.with@gmail.com X-Patchwork-Id: 9553 Delivered-To: ffmpegpatchwork@gmail.com Received: by 2002:a02:104:0:0:0:0:0 with SMTP id c4-v6csp981950jad; Fri, 29 Jun 2018 08:59:57 -0700 (PDT) X-Google-Smtp-Source: AAOMgpeQJYFoixtYGuGQ2LOkcNemBvHFymhpvIvNiJBe70MZm29KjF3L9acefs5W+Ve8r6iv6gKN X-Received: by 2002:a1c:b1d7:: with SMTP id a206-v6mr2279248wmf.61.1530287996911; Fri, 29 Jun 2018 08:59:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530287996; cv=none; d=google.com; s=arc-20160816; b=h27aNSbiLxv9UQER4YozFRZdIYT/s/cbgcuNjNPASOH6+d9bPCkv+J+tT7AeRRnRv9 FpZjAXmx7fe43ydEArFvLl62DDCwCPUgqbBXslIKberZIypg9ZvOp6BlGgGCTsr4z/jV lsOxAUzkxP9p+Zh/l6sBk3mte8RRP+aJyITd7yOfhowrN4pGV4oLzytp1q4WNSTLHmKW OVyKrhzmVwioG5FcAb27MotUclZ7jiJpZDwa0V2CNAzVYNHPqmtLMYfbCo0ICX9g/PKz ABiu2Z8h5WaYGmQ5sWuBWMjKloNwcNAh84TiW2YaS8zp0Cb6ZwOSL+78flNetJ0AGf2W wYvA== 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=G2LBji4EJGLS2ChxtemOg/ooEEC5yBulqx6xSlVM1kk=; b=wcg3iPYkKBNzY6+5GAUxD2W9HpobZ9Tlvvnt7bKoxoXNqz5vz4P/OgcSOE0JoH7P41 bRr5fbZNUD2NDFKsCVXZXgXz0jOt4T6d21zpReatLQ1a7Po/6zYwCQFoW5S70PW4skfU fP4GdQQLipQDMyEu7aYTARMmW1ccA6M/fZk8tZ/b0m3iv/HMgRhXna8Djl1kzC5v2ySv K8I5+e9kGlyVgNc+R2ui0HjOkovPUlvrgtIsnZeyR9RXltF5R2UA/e7a1kFKxt05PCxy C4gGVyXEZdxe2X+MfPAl9kmkWJzwOJ+nbCi6bvmfpj91gV35aeJvJRKE21mb1/EybhmZ aqnA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=fzEn2WXR; 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; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id w82-v6si1736130wme.183.2018.06.29.08.59.54; Fri, 29 Jun 2018 08:59:55 -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=@gmail.com header.s=20161025 header.b=fzEn2WXR; 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; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 675DF68A6A5; Fri, 29 Jun 2018 18:59:50 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wr0-f195.google.com (mail-wr0-f195.google.com [209.85.128.195]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 26F7468825E for ; Fri, 29 Jun 2018 18:59:44 +0300 (EEST) Received: by mail-wr0-f195.google.com with SMTP id k6-v6so9322892wrp.4 for ; Fri, 29 Jun 2018 08:59:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=T45tDiL4LOEMt0GsVf/0tpamkDAQf8remPQbEuxShkw=; b=fzEn2WXRwSwravAn3mfT7qODPEvUmD7iFDcFC7dmWkEz6JkKKNAz2mdE8+p3caN33/ YsohAyFeLuEryLvrAW6GzqLvrU+yBwkxo9q6ZLI4jhCXj7Xf50O7BRYN4YzoNuIbgknZ sPcCy2E/YLBazE1ublmKpf4AmTIXqk0VSnK4WHQR+seVYHXL8AkVLcDBetXZXJ0KDj3d ppyESRQnqbFgQYRda6pTVU/7oc+4UL9CRIdk4v7V0THpgx5uRDGnUeN9L7vdfJtPyeH+ BPPv4xRLY7wWbmFDC+atxDp24KL+WQUXXlAONiFbwgcI4b/UnDZM4v+19xC9TyYo0Gp7 vV7g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=T45tDiL4LOEMt0GsVf/0tpamkDAQf8remPQbEuxShkw=; b=XihLnooDxK9/xgG0zcJNxiXvfB+g4ak1pS6tyo9nXWD2n7BWTi6+Ao6+VFc/vKTQJV 8V/KJHfH2eW1T+pVcebz+/vlcQcjihiX9hvSbBMaxLftn7vpQ8xeCNdRjJrZ/8EsMuUe oAfmxVa3WpQ8NU19jzHBEfmj6qhWvCI2kMTUYgmswK5cZr9z+jpXSlnimEFs+bTimWlY 6yDy4wdzel8KmTB2c1xKxs89QoMqxtzav8maxsrlhnTXbgjzzhHPO7QnkW2sZqijGRdV T4vLViDWW+AAUGW/gPJBIFbZcGDXl9RdDWJGX4O3Ig2Gzubylm7utfpGQQoTcLQ7MnQg AEPw== X-Gm-Message-State: APt69E3JL6HNh2feavHNd4llaQo+o8IicnpUOUwiiNVnvrT0RXyFQz2M mPIv69PVvZfqokdt4UYuTWRTp7Wm X-Received: by 2002:adf:8b8c:: with SMTP id o12-v6mr12744454wra.169.1530287645102; Fri, 29 Jun 2018 08:54:05 -0700 (PDT) Received: from localhost.localdomain ([46.165.220.247]) by smtp.gmail.com with ESMTPSA id q14-v6sm3370996wmd.20.2018.06.29.08.54.03 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 29 Jun 2018 08:54:04 -0700 (PDT) From: morten.with@gmail.com To: ffmpeg-devel@ffmpeg.org Date: Fri, 29 Jun 2018 17:53:43 +0200 Message-Id: <20180629155343.7196-1-morten.with@gmail.com> X-Mailer: git-send-email 2.17.1 Subject: [FFmpeg-devel] [PATCH] fftools/ffmpeg_opt: Add -toeof option to stop reading at position relative to EOF 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: withmorten MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" From: withmorten Fixes ticket #7155: Add option to stop writing at position relative to EOF Signed-off-by: Morten With --- doc/ffmpeg.texi | 6 ++++++ fftools/ffmpeg.h | 1 + fftools/ffmpeg_opt.c | 31 +++++++++++++++++++++++++++++++ 3 files changed, 38 insertions(+) diff --git a/doc/ffmpeg.texi b/doc/ffmpeg.texi index 3717f22d42..f627f0e8a5 100644 --- a/doc/ffmpeg.texi +++ b/doc/ffmpeg.texi @@ -488,6 +488,12 @@ see @ref{time duration syntax,,the Time duration section in the ffmpeg-utils(1) -to and -t are mutually exclusive and -t has priority. +@item -toeof @var{position} (@emph{input}) +Stop reading the input at @var{position} relative to the "end of file". That is, +larger negative values are later in the file, 0 is at EOF. + +-toeof and -to, as well as -toeof and -t, are mutually exclusive, and -to, or respectively -t, has priority. + @item -fs @var{limit_size} (@emph{output}) Set the file size limit, expressed in bytes. No further chunk of bytes is written after the limit is exceeded. The size of the output file is slightly more than the diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h index eb1eaf6363..70026b376e 100644 --- a/fftools/ffmpeg.h +++ b/fftools/ffmpeg.h @@ -149,6 +149,7 @@ typedef struct OptionsContext { int64_t recording_time; int64_t stop_time; + int64_t stop_time_eof; uint64_t limit_filesize; float mux_preload; float mux_max_delay; diff --git a/fftools/ffmpeg_opt.c b/fftools/ffmpeg_opt.c index 58ec13e5a8..30fd28ec3a 100644 --- a/fftools/ffmpeg_opt.c +++ b/fftools/ffmpeg_opt.c @@ -159,6 +159,7 @@ static void init_options(OptionsContext *o) memset(o, 0, sizeof(*o)); o->stop_time = INT64_MAX; + o->stop_time_eof = AV_NOPTS_VALUE; o->mux_max_delay = 0.7; o->start_time = AV_NOPTS_VALUE; o->start_time_eof = AV_NOPTS_VALUE; @@ -979,6 +980,16 @@ static int open_input_file(OptionsContext *o, const char *filename) av_log(NULL, AV_LOG_WARNING, "-t and -to cannot be used together; using -t.\n"); } + if (o->stop_time_eof != AV_NOPTS_VALUE && o->recording_time != INT64_MAX) { + o->stop_time_eof = AV_NOPTS_VALUE; + av_log(NULL, AV_LOG_WARNING, "-t and -toeof cannot be used together; using -t for %s.\n", filename); + } + + if (o->stop_time != INT64_MAX && o->stop_time_eof != AV_NOPTS_VALUE) { + o->stop_time_eof = AV_NOPTS_VALUE; + av_log(NULL, AV_LOG_WARNING, "-to and -toeof cannot be used together; using -to for %s.\n", filename); + } + if (o->stop_time != INT64_MAX && o->recording_time == INT64_MAX) { int64_t start_time = o->start_time == AV_NOPTS_VALUE ? 0 : o->start_time; if (o->stop_time <= start_time) { @@ -1122,6 +1133,24 @@ static int open_input_file(OptionsContext *o, const char *filename) } else av_log(NULL, AV_LOG_WARNING, "Cannot use -sseof, duration of %s not known\n", filename); } + + if (o->stop_time_eof != AV_NOPTS_VALUE) { + if (o->stop_time_eof >= 0) { + av_log(NULL, AV_LOG_ERROR, "-toeof value must be negative; aborting\n"); + exit_program(1); + } + if (ic->duration > 0) { + o->recording_time = ic->duration + o->stop_time_eof; + if (o->start_time != AV_NOPTS_VALUE) { + o->recording_time -= o->start_time; + if (o->recording_time <= 0) { + av_log(NULL, AV_LOG_WARNING, "-toeof value seeks to before start of file %s; ignored\n", filename); + o->recording_time += o->start_time; + } + } + } else + av_log(NULL, AV_LOG_WARNING, "Cannot use -toeof, duration of %s not known\n", filename); + } timestamp = (o->start_time == AV_NOPTS_VALUE) ? 0 : o->start_time; /* add the stream start time */ if (!o->seek_timestamp && ic->start_time != AV_NOPTS_VALUE) @@ -3347,6 +3376,8 @@ const OptionDef options[] = { "duration" }, { "to", HAS_ARG | OPT_TIME | OPT_OFFSET | OPT_INPUT | OPT_OUTPUT, { .off = OFFSET(stop_time) }, "record or transcode stop time", "time_stop" }, + { "toeof", HAS_ARG | OPT_TIME | OPT_OFFSET | OPT_INPUT, { .off = OFFSET(stop_time_eof) }, + "input stop time relative to EOF", "time_stop" }, { "fs", HAS_ARG | OPT_INT64 | OPT_OFFSET | OPT_OUTPUT, { .off = OFFSET(limit_filesize) }, "set the limit file size in bytes", "limit_size" }, { "ss", HAS_ARG | OPT_TIME | OPT_OFFSET |