diff mbox

[FFmpeg-devel] Allow "-to" on input files as well

Message ID 20171116201511.9375-1-vi0oss@gmail.com
State Accepted
Commit 80ef3c83601881ff2b6a90fa5c6e82c83aad768f
Headers show

Commit Message

vi0oss@gmail.com Nov. 16, 2017, 8:15 p.m. UTC
From: Vitaly _Vi Shukela <vi0oss@gmail.com>

---

Notes:
    Second version.
    
    Please CC vi0oss@gmail.com when replying.
    
    Note that added code is a duplicate of the respective output option processing code.
    I'm not sure if it is worth factoring out.

 doc/ffmpeg.texi      |  4 ++--
 fftools/ffmpeg_opt.c | 17 ++++++++++++++++-
 2 files changed, 18 insertions(+), 3 deletions(-)

Comments

Michael Niedermayer Nov. 18, 2017, 2:54 a.m. UTC | #1
On Thu, Nov 16, 2017 at 11:15:11PM +0300, vi0oss@gmail.com wrote:
> From: Vitaly _Vi Shukela <vi0oss@gmail.com>
> 
> ---
> 
> Notes:
>     Second version.
>     
>     Please CC vi0oss@gmail.com when replying.
>     
>     Note that added code is a duplicate of the respective output option processing code.
>     I'm not sure if it is worth factoring out.


please submit a git patch with a useable commit message

[...]
Michael Niedermayer Nov. 18, 2017, 2:55 a.m. UTC | #2
On Sat, Nov 18, 2017 at 03:54:20AM +0100, Michael Niedermayer wrote:
> On Thu, Nov 16, 2017 at 11:15:11PM +0300, vi0oss@gmail.com wrote:
> > From: Vitaly _Vi Shukela <vi0oss@gmail.com>
> > 
> > ---
> > 
> > Notes:
> >     Second version.
> >     
> >     Please CC vi0oss@gmail.com when replying.
> >     
> >     Note that added code is a duplicate of the respective output option processing code.
> >     I'm not sure if it is worth factoring out.
> 
> 
> please submit a git patch with a useable commit message

Note: if i would apply this git am produces:

commit b259593b6a1f45c968bdaab35279fe8f507e78a2 (HEAD -> master)
Author: Vitaly _Vi Shukela <vi0oss@gmail.com>
Date:   Sat Nov 18 03:18:53 2017 +0100

    Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>




[...]
diff mbox

Patch

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 ca6f10d5ca..e453cb34c5 100644
--- a/fftools/ffmpeg_opt.c
+++ b/fftools/ffmpeg_opt.c
@@ -972,6 +972,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);
@@ -3403,7 +3418,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" },