[FFmpeg-cvslog] lavf: add output_ts_offset option to AVFormatContext

Stefano Sabatini git at videolan.org
Sun Feb 2 13:16:52 CET 2014


ffmpeg | branch: master | Stefano Sabatini <stefasab at gmail.com> | Mon Jan 27 19:16:45 2014 +0100| [5871ee5072f725fce77cd51597ee91570de3743d] | committer: Stefano Sabatini

lavf: add output_ts_offset option to AVFormatContext

This option can be generally useful to set an output offset, needed when
setting an absolute index in the output.

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=5871ee5072f725fce77cd51597ee91570de3743d
---

 doc/APIchanges              |    3 +++
 doc/formats.texi            |   12 ++++++++++++
 libavformat/avformat.h      |    5 +++++
 libavformat/mux.c           |   10 ++++++++++
 libavformat/options_table.h |    1 +
 libavformat/version.h       |    4 ++--
 6 files changed, 33 insertions(+), 2 deletions(-)

diff --git a/doc/APIchanges b/doc/APIchanges
index c6cbe77..af74c93 100644
--- a/doc/APIchanges
+++ b/doc/APIchanges
@@ -15,6 +15,9 @@ libavutil:     2012-10-22
 
 API changes, most recent first:
 
+2014-02-02 - xxxxxxx - lavf 55.29.100 - avformat.h
+  Add output_ts_offset muxing option to AVFormatContext.
+
 2014-01-27 - 102bd64 - lavd 55.7.100 - avdevice.h
                        lavf 55.28.100 - avformat.h
   Add avdevice_dev_to_app_control_message() function.
diff --git a/doc/formats.texi b/doc/formats.texi
index ba9d277..bdd144e 100644
--- a/doc/formats.texi
+++ b/doc/formats.texi
@@ -148,6 +148,18 @@ Correct single timestamp overflows if set to 1. Default is 1.
 Flush the underlying I/O stream after each packet. Default 1 enables it, and
 has the effect of reducing the latency; 0 disables it and may slightly
 increase performance in some cases.
+
+ at item output_ts_offset @var{offset} (@emph{output})
+Set the output time offset.
+
+ at var{offset} must be a time duration specification,
+see @ref{time duration syntax,,the Time duration section in the ffmpeg-utils(1) manual,ffmpeg-utils}.
+
+The offset is added by the muxer to the output timestamps.
+
+Specifying a positive offset means that the corresponding streams are
+delayed bt the time duration specified in @var{offset}. Default value
+is @code{0} (meaning that no offset is applied).
 @end table
 
 @c man end FORMAT OPTIONS
diff --git a/libavformat/avformat.h b/libavformat/avformat.h
index 76b0652..50b7108 100644
--- a/libavformat/avformat.h
+++ b/libavformat/avformat.h
@@ -1380,6 +1380,11 @@ typedef struct AVFormatContext {
      */
     av_format_control_message control_message_cb;
 
+    /**
+     * Output timestamp offset, in microseconds.
+     * Muxing: set by user via AVOptions (NO direct access)
+     */
+    int64_t output_ts_offset;
 } AVFormatContext;
 
 int av_format_get_probe_score(const AVFormatContext *s);
diff --git a/libavformat/mux.c b/libavformat/mux.c
index bd50191..70b6064 100644
--- a/libavformat/mux.c
+++ b/libavformat/mux.c
@@ -510,6 +510,16 @@ static int write_packet(AVFormatContext *s, AVPacket *pkt)
 {
     int ret, did_split;
 
+    if (s->output_ts_offset) {
+        AVStream *st = s->streams[pkt->stream_index];
+        int64_t offset = av_rescale_q(s->output_ts_offset, AV_TIME_BASE_Q, st->time_base);
+
+        if (pkt->dts != AV_NOPTS_VALUE)
+            pkt->dts += offset;
+        if (pkt->pts != AV_NOPTS_VALUE)
+            pkt->pts += offset;
+    }
+
     if (s->avoid_negative_ts > 0) {
         AVStream *st = s->streams[pkt->stream_index];
         int64_t offset = st->mux_ts_offset;
diff --git a/libavformat/options_table.h b/libavformat/options_table.h
index 3221042..b42a762 100644
--- a/libavformat/options_table.h
+++ b/libavformat/options_table.h
@@ -78,6 +78,7 @@ static const AVOption avformat_options[] = {
 {"correct_ts_overflow", "correct single timestamp overflows", OFFSET(correct_ts_overflow), AV_OPT_TYPE_INT, {.i64 = 1}, 0, 1, D},
 {"flush_packets", "enable flushing of the I/O context after each packet", OFFSET(flush_packets), AV_OPT_TYPE_INT, {.i64 = 1}, 0, 1, E},
 {"metadata_header_padding", "set number of bytes to be written as padding in a metadata header", OFFSET(metadata_header_padding), AV_OPT_TYPE_INT, {.i64 = -1}, -1, INT_MAX, E},
+{"output_ts_offset", "set output timestamp offset", OFFSET(output_ts_offset), AV_OPT_TYPE_DURATION, {.i64 = 0}, -INT64_MAX, INT64_MAX, E},
 {NULL},
 };
 
diff --git a/libavformat/version.h b/libavformat/version.h
index a052d3c..38945a5 100644
--- a/libavformat/version.h
+++ b/libavformat/version.h
@@ -30,8 +30,8 @@
 #include "libavutil/version.h"
 
 #define LIBAVFORMAT_VERSION_MAJOR 55
-#define LIBAVFORMAT_VERSION_MINOR 28
-#define LIBAVFORMAT_VERSION_MICRO 101
+#define LIBAVFORMAT_VERSION_MINOR 29
+#define LIBAVFORMAT_VERSION_MICRO 100
 
 #define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \
                                                LIBAVFORMAT_VERSION_MINOR, \



More information about the ffmpeg-cvslog mailing list