[FFmpeg-devel] [PATCH] ffmpeg: add -skip_initial_offset option

Stefano Sabatini stefasab at gmail.com
Tue Nov 20 18:57:58 CET 2012


Sometimes the user wants to preserve the initial offset, e.g. in order to
preserve external synchronization, which is removed by default in order
to ease playback support.

TODO: update changelog
---
 doc/ffmpeg.texi |    6 ++++++
 ffmpeg.c        |    2 ++
 ffmpeg.h        |    1 +
 ffmpeg_opt.c    |    3 +++
 4 files changed, 12 insertions(+)

diff --git a/doc/ffmpeg.texi b/doc/ffmpeg.texi
index d39ad22..27ed0a5 100644
--- a/doc/ffmpeg.texi
+++ b/doc/ffmpeg.texi
@@ -379,6 +379,12 @@ employed by portable scripts.
 
 See also the option @code{-fdebug ts}.
 
+ at item -keep_initial_offset (@emph{global})
+Keep the initial input timestamps offset. By default @command{ffmpeg}
+subtracts the value of the first timestamps to all the input
+timestamps, in order to remove the initial timestamp offset
+delay. Selecting this option allows to preserve the timestamp values.
+
 @item -attach @var{filename} (@emph{output})
 Add an attachment to the output file. This is supported by a few formats
 like Matroska for e.g. fonts used in rendering subtitles. Attachments
diff --git a/ffmpeg.c b/ffmpeg.c
index 0c98fb7..4150325 100644
--- a/ffmpeg.c
+++ b/ffmpeg.c
@@ -2776,6 +2776,7 @@ static int process_input(int file_index)
         }
     }
 
+    if (!keep_initial_offset) {
     if (pkt.dts != AV_NOPTS_VALUE)
         pkt.dts += av_rescale_q(ifile->ts_offset, AV_TIME_BASE_Q, ist->st->time_base);
     if (pkt.pts != AV_NOPTS_VALUE)
@@ -2785,6 +2786,7 @@ static int process_input(int file_index)
         pkt.pts *= ist->ts_scale;
     if (pkt.dts != AV_NOPTS_VALUE)
         pkt.dts *= ist->ts_scale;
+    }
 
     if (pkt.dts != AV_NOPTS_VALUE && ist->next_dts != AV_NOPTS_VALUE &&
         !copy_ts) {
diff --git a/ffmpeg.h b/ffmpeg.h
index e981a74..96eb9b5 100644
--- a/ffmpeg.h
+++ b/ffmpeg.h
@@ -380,6 +380,7 @@ extern int do_pkt_dump;
 extern int copy_ts;
 extern int copy_tb;
 extern int debug_ts;
+extern int keep_initial_offset;
 extern int exit_on_error;
 extern int print_stats;
 extern int qp_hist;
diff --git a/ffmpeg_opt.c b/ffmpeg_opt.c
index 0baa3b1..a35e388 100644
--- a/ffmpeg_opt.c
+++ b/ffmpeg_opt.c
@@ -80,6 +80,7 @@ int do_pkt_dump       = 0;
 int copy_ts           = 0;
 int copy_tb           = -1;
 int debug_ts          = 0;
+int keep_initial_offset = 0;
 int exit_on_error     = 0;
 int print_stats       = 1;
 int qp_hist           = 0;
@@ -2369,6 +2370,8 @@ const OptionDef options[] = {
         "extract an attachment into a file", "filename" },
     { "debug_ts",       OPT_BOOL | OPT_EXPERT,                       { &debug_ts },
         "print timestamp debugging info" },
+    { "keep_initial_offset", OPT_BOOL | OPT_EXPERT, { &keep_initial_offset },
+      "keep initial input timestamps offset" },
 
     /* video options */
     { "vframes",      OPT_VIDEO | HAS_ARG  | OPT_PERFILE,                        { .func_arg = opt_video_frames },
-- 
1.7.9.5



More information about the ffmpeg-devel mailing list