[FFmpeg-devel] [PATCH] fftools/ffmpeg_opt: Add -toeof option to stop writing relative to EOF

morten.with at gmail.com morten.with at gmail.com
Sun Jun 10 19:31:18 EEST 2018


From: withmorten <morten.with at gmail.com>

Signed-off-by: Morten With <morten.with at gmail.com>
---
 doc/ffmpeg.texi      | 4 ++++
 fftools/ffmpeg.h     | 1 +
 fftools/ffmpeg_opt.c | 9 +++++++++
 3 files changed, 14 insertions(+)

diff --git a/doc/ffmpeg.texi b/doc/ffmpeg.texi
index 3717f22d42..fe635d0e42 100644
--- a/doc/ffmpeg.texi
+++ b/doc/ffmpeg.texi
@@ -488,6 +488,10 @@ see @ref{time duration syntax,,the Time duration section in the ffmpeg-utils(1)
 
 -to and -t are mutually exclusive and -t has priority.
 
+ at item -toeof @var{position} (@emph{input})
+Stop writing the output at @var{position} relative to the "end of file". That is negative
+values are later in the file, 0 is at EOF.
+
 @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 a2ecddae71..ed28111dc4 100644
--- a/fftools/ffmpeg_opt.c
+++ b/fftools/ffmpeg_opt.c
@@ -1103,6 +1103,13 @@ static int open_input_file(OptionsContext *o, const char *filename)
         }
     }
 
+    if (o->stop_time_eof != AV_NOPTS_VALUE) {
+        if (ic->duration>0) {
+            o->recording_time = ic->duration + o->stop_time_eof;
+        } else
+            av_log(NULL, AV_LOG_WARNING, "Cannot use -toeof, duration of %s not known\n", filename);
+    }
+
     if (o->start_time_eof != AV_NOPTS_VALUE) {
         if (ic->duration>0) {
             o->start_time = o->start_time_eof + ic->duration;
@@ -3334,6 +3341,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) },
+        "record or transcode 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 |
-- 
2.17.1



More information about the ffmpeg-devel mailing list