Skip to content

Instantly share code, notes, and snippets.

@withmorten
Last active June 7, 2018 20:39
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save withmorten/ea585798076fa020b757437f23aca768 to your computer and use it in GitHub Desktop.
Save withmorten/ea585798076fa020b757437f23aca768 to your computer and use it in GitHub Desktop.
ffmpeg toeof patch
diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h
index f6c76bcc55..7c0b95853d 100644
--- a/fftools/ffmpeg.h
+++ b/fftools/ffmpeg.h
@@ -157,6 +157,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 100fa76e46..3947aab7b5 100644
--- a/fftools/ffmpeg_opt.c
+++ b/fftools/ffmpeg_opt.c
@@ -184,6 +184,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;
@@ -1094,6 +1095,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;
@@ -3406,6 +3414,8 @@ const OptionDef options[] = {
"duration" },
{ "to", HAS_ARG | OPT_TIME | OPT_OFFSET | 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 |
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment