From patchwork Sat Nov 18 07:36:51 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: vi0oss@gmail.com X-Patchwork-Id: 6182 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.2.161.94 with SMTP id m30csp2118272jah; Sat, 18 Nov 2017 11:42:29 -0800 (PST) X-Google-Smtp-Source: AGs4zMbWQJrfxrRZcnUdc0jmbFwYRxezbcvErxTdEVL6VpkRLLAoxtes94QBZlaLWIgRNW9FMI9V X-Received: by 10.223.152.66 with SMTP id v60mr7680224wrb.277.1511034149433; Sat, 18 Nov 2017 11:42:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1511034149; cv=none; d=google.com; s=arc-20160816; b=fLNXbLdbPBDaiV8kjIUJg6X7BGbt2IxOGCojS3GX4mwvxeFiK8WjQCuom6oKtXXBST KiU7gkMkk3mk7R84ezfO6K5mRlzTTAaQS6GxLSTWw+vUAVoDhdrw/is+m/kxYrjWqtZc d4x6Pv4o6kg/V+1HUHKCcmqb2NDu1owpH/Ldzt6qfhmT5q7WDzDpw4+ATUPvB4eXRNVy Z3toEsg9VSac2TJq844w3ER1DasVC69qLCPVOuUO+AKNujM7FLuhIGh/NsXPgykLKFqM Zl1y2NBWh+CI0ROLz9TLfZE0AnhhlK+YyAWruUVEF6+Feb8BJhiCTcfs1Ve6zUoxUnav ErqA== 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=FQ/VmYGE/PeTGg3fjgJ/cJBJP/dJSAGCdGi0+f5EynM=; b=Uw+p0v6rsDYl1Pptz1uil7+Zuj/tI2SQvu5zWMZSafGx7bPHRSXIUjDG4ZG0hoUcmc ZvAACXQ93UGHX9uIAFEWacxS8JDkgohCVrcjey20xKYQVWswTLdESz80CwcwSrVa23gd LBgDv2v47H+nJhHwUsf021JMO+6c3Mgb7jirMNSqnp0dBaNL4lT6Xn9qbZmvPvR57oOQ bDDTRh38pSJfCBMUYG2QKws25QL4Ec5E47Jm3Bcy2Pr5ZuyNUGFK8WsFOjkUEDTlOgfr +3NcB7DY4+FoWATO4nV8jXmZXb9SBq756iGKWa7ciHujCZR+i8+/5H+UWdPw0pPqAMy6 WALQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=eqUUlK/7; 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=NONE 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 u2si4924017wrd.139.2017.11.18.11.42.29; Sat, 18 Nov 2017 11:42:29 -0800 (PST) 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=eqUUlK/7; 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=NONE 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 9F45068A104; Sat, 18 Nov 2017 21:42:10 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-qt0-f195.google.com (mail-qt0-f195.google.com [209.85.216.195]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id F3C0B689A2A for ; Sat, 18 Nov 2017 09:44:14 +0200 (EET) Received: by mail-qt0-f195.google.com with SMTP id n32so9556874qtb.2 for ; Fri, 17 Nov 2017 23:44:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=zrWKuhSpb5pnXsmek6IgCZLxoljYmq1bDH9rWwezbCE=; b=eqUUlK/77GNga+fvB0yNp1NQm1araCi6Zj4ZJUqVwmhciMuuTH1a03vpqWFXYTjNOJ FNqF9vpeZviSGIWSF3IxHuqr1pyZJC851vQxwtu1f28b96MFUc9b34ALYaKER4SE9MfZ 7EW+NW20Ys+nSd/odRJMugHJd2wfXDchyoJAx3Z3caklN9lLj8lM/KHq6fj80enYNmC1 hyxdf0yQ7j5QlJrn1030SbL8DOP2ptJ21pt4kC52i7PuUmv6KmtfVAZ983TMUwkqpRAi 3QWOYomM5FuJNsI0KmnOolu7C6Vs8Cf1pNKIKiVAKxiyqm3mbnjicJcBxAqsAbw2OPBs S70g== 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=zrWKuhSpb5pnXsmek6IgCZLxoljYmq1bDH9rWwezbCE=; b=KYwoc+e1BQ6bp3VBvsvjTYd1r9p3F2pQtljbMbcDJir4xvWkQyjp5gszNq04UFca4m njw7Zx6TjPgXm7vqbPgE8M/dlHwRXgzWT7AO/Hi947MZtwwS58Sx4NbbTsPnMSafmT5N +Qa4SI56ObHnjE71BUYD3k/dRIhcFm7EH9CSy6J0beiNecqS5heD5ASd0Rf8Ck2+kuk0 Er2syyHYkArko4kDUF8TQ2K0+D7nWvvalSARIFwTNBmI0GDoiifa5WgZFCY8/wSrrr5i TDHY7jijNmeGDgm/qn1bG5IooPD3LvW9B2Joo4h8uiU3R3tG4EG1NxL/OfyZFuRq0urK KTqw== X-Gm-Message-State: AJaThX7gnZ6h+j1UD19qfXZw6ZfmKpRS6lTpeiPcBBCeqJyuAHsLg2UR HSGBVmmAHdzo8ALPTnCGjy55jg== X-Received: by 10.200.23.61 with SMTP id w58mr12611791qtj.341.1510990636689; Fri, 17 Nov 2017 23:37:16 -0800 (PST) Received: from localhost.localdomain ([2001:470:7bd6:1000::2]) by smtp.gmail.com with ESMTPSA id z7sm3813244qtz.40.2017.11.17.23.37.14 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 17 Nov 2017 23:37:15 -0800 (PST) From: vi0oss@gmail.com To: ffmpeg-devel@ffmpeg.org Date: Sat, 18 Nov 2017 10:36:51 +0300 Message-Id: <20171118073651.7644-1-vi0oss@gmail.com> X-Mailer: git-send-email 2.11.0 X-Mailman-Approved-At: Sat, 18 Nov 2017 21:42:09 +0200 Subject: [FFmpeg-devel] [PATCH] ffmpeg: Allow "-to" on input files in addition to "-t" 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: vi0oss@gmail.com MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" From: Vitaly _Vi Shukela For some strange reason "-t" option was only implemented for input files while both "-t" and "-to" were available for use for output files. This made extracting a range from input file inconvenient. This patch enables -to option for input so one can do ffmpeg -ss 1:23:20 -to 1:27:22.3 -i myinput.mkv ... Signed-off-by: Vitaly _Vi Shukela --- doc/ffmpeg.texi | 4 ++-- fftools/ffmpeg_opt.c | 17 ++++++++++++++++- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/doc/ffmpeg.texi b/doc/ffmpeg.texi index 7db80ebf6a..9a90d7327a 100644 --- a/doc/ffmpeg.texi +++ b/doc/ffmpeg.texi @@ -289,8 +289,8 @@ 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 -to @var{position} (@emph{output}) -Stop writing the output at @var{position}. +@item -to @var{position} (@emph{input/output}) +Stop writing the output or reading the input at @var{position}. @var{position} must be a time duration specification, see @ref{time duration syntax,,the Time duration section in the ffmpeg-utils(1) manual,ffmpeg-utils}. diff --git a/fftools/ffmpeg_opt.c b/fftools/ffmpeg_opt.c index 47d384166c..f66f672c3c 100644 --- a/fftools/ffmpeg_opt.c +++ b/fftools/ffmpeg_opt.c @@ -976,6 +976,21 @@ static int open_input_file(OptionsContext *o, const char *filename) char * data_codec_name = NULL; int scan_all_pmts_set = 0; + if (o->stop_time != INT64_MAX && o->recording_time != INT64_MAX) { + o->stop_time = INT64_MAX; + av_log(NULL, AV_LOG_WARNING, "-t and -to cannot be used together; using -t.\n"); + } + + 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) { + av_log(NULL, AV_LOG_ERROR, "-to value smaller than -ss; aborting.\n"); + exit_program(1); + } else { + o->recording_time = o->stop_time - start_time; + } + } + if (o->format) { if (!(file_iformat = av_find_input_format(o->format))) { av_log(NULL, AV_LOG_FATAL, "Unknown input format: '%s'\n", o->format); @@ -3407,7 +3422,7 @@ const OptionDef options[] = { OPT_INPUT | OPT_OUTPUT, { .off = OFFSET(recording_time) }, "record or transcode \"duration\" seconds of audio/video", "duration" }, - { "to", HAS_ARG | OPT_TIME | OPT_OFFSET | OPT_OUTPUT, { .off = OFFSET(stop_time) }, + { "to", HAS_ARG | OPT_TIME | OPT_OFFSET | OPT_INPUT | OPT_OUTPUT, { .off = OFFSET(stop_time) }, "record or transcode stop time", "time_stop" }, { "fs", HAS_ARG | OPT_INT64 | OPT_OFFSET | OPT_OUTPUT, { .off = OFFSET(limit_filesize) }, "set the limit file size in bytes", "limit_size" },