[FFmpeg-cvslog] lavf: Add support offset timestamps on muxing.
Michael Niedermayer
git at videolan.org
Wed Sep 26 16:32:12 CEST 2012
ffmpeg | branch: master | Michael Niedermayer <michaelni at gmx.at> | Wed Sep 26 15:55:16 2012 +0200| [3ba0dab76ac32f0c9f50c916a73bc64e43c1fdf9] | committer: Michael Niedermayer
lavf: Add support offset timestamps on muxing.
This allows avoiding negative timestamps.
Signed-off-by: Michael Niedermayer <michaelni at gmx.at>
> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=3ba0dab76ac32f0c9f50c916a73bc64e43c1fdf9
---
libavformat/avformat.h | 18 ++++++++++++++++++
libavformat/options_table.h | 1 +
libavformat/utils.c | 24 ++++++++++++++++++++++--
libavformat/version.h | 2 +-
4 files changed, 42 insertions(+), 3 deletions(-)
diff --git a/libavformat/avformat.h b/libavformat/avformat.h
index 166fdbb..de53c26 100644
--- a/libavformat/avformat.h
+++ b/libavformat/avformat.h
@@ -832,6 +832,13 @@ typedef struct AVStream {
* its lifetime differs from info which is why its not in that structure.
*/
int nb_decoded_frames;
+
+ /**
+ * Timestamp offset added to timestamps before muxing
+ * NOT PART OF PUBLIC API
+ */
+ int64_t mux_ts_offset;
+
} AVStream;
#define AV_PROGRAM_RUNNING 1
@@ -1111,6 +1118,17 @@ typedef struct AVFormatContext {
*/
int use_wallclock_as_timestamps;
+ /**
+ * Avoids negative timestamps during muxing
+ * 0 -> allow negative timestamps
+ * 1 -> avoid negative timestamps
+ * -1 -> choose automatically (default)
+ * Note, this is only works when interleave_packet_per_dts is in use
+ * - encoding: Set by user via AVOptions (NO direct access)
+ * - decoding: unused
+ */
+ int avoid_negative_ts;
+
/*****************************************************************
* All fields below this line are not part of the public API. They
* may not be used outside of libavformat and can be changed and
diff --git a/libavformat/options_table.h b/libavformat/options_table.h
index a1cfaaa..778c740 100644
--- a/libavformat/options_table.h
+++ b/libavformat/options_table.h
@@ -71,6 +71,7 @@ static const AVOption options[]={
{"compliant", "consider all spec non compliancies as errors", 0, AV_OPT_TYPE_CONST, {.i64 = AV_EF_COMPLIANT }, INT_MIN, INT_MAX, D, "err_detect"},
{"aggressive", "consider things that a sane encoder shouldnt do as an error", 0, AV_OPT_TYPE_CONST, {.i64 = AV_EF_AGGRESSIVE }, INT_MIN, INT_MAX, D, "err_detect"},
{"use_wallclock_as_timestamps", "use wallclock as timestamps", OFFSET(use_wallclock_as_timestamps), AV_OPT_TYPE_INT, {.i64 = 0}, 0, INT_MAX-1, D},
+{"avoid_negative_ts", "avoid negative timestamps", OFFSET(avoid_negative_ts), AV_OPT_TYPE_INT, {.i64 = -1}, -1, 1, E},
{NULL},
};
diff --git a/libavformat/utils.c b/libavformat/utils.c
index 5bc5ada..5cb380a 100644
--- a/libavformat/utils.c
+++ b/libavformat/utils.c
@@ -3699,16 +3699,36 @@ int ff_interleave_packet_per_dts(AVFormatContext *s, AVPacket *out,
}
}
if(stream_count && flush){
+ AVStream *st;
pktl= s->packet_buffer;
*out= pktl->pkt;
+ st = s->streams[out->stream_index];
s->packet_buffer= pktl->next;
if(!s->packet_buffer)
s->packet_buffer_end= NULL;
- if(s->streams[out->stream_index]->last_in_packet_buffer == pktl)
- s->streams[out->stream_index]->last_in_packet_buffer= NULL;
+ if(st->last_in_packet_buffer == pktl)
+ st->last_in_packet_buffer= NULL;
av_freep(&pktl);
+
+ if (s->avoid_negative_ts > 0) {
+ if (out->dts != AV_NOPTS_VALUE) {
+ if (!st->mux_ts_offset && out->dts < 0) {
+ for(i=0; i < s->nb_streams; i++) {
+ s->streams[i]->mux_ts_offset =
+ av_rescale_q_rnd(-out->dts,
+ st->time_base,
+ s->streams[i]->time_base,
+ AV_ROUND_UP);
+ }
+ }
+ out->dts += st->mux_ts_offset;
+ }
+ if (out->pts != AV_NOPTS_VALUE)
+ out->pts += st->mux_ts_offset;
+ }
+
return 1;
}else{
av_init_packet(out);
diff --git a/libavformat/version.h b/libavformat/version.h
index 55c7638..65412fb 100644
--- a/libavformat/version.h
+++ b/libavformat/version.h
@@ -30,7 +30,7 @@
#include "libavutil/avutil.h"
#define LIBAVFORMAT_VERSION_MAJOR 54
-#define LIBAVFORMAT_VERSION_MINOR 28
+#define LIBAVFORMAT_VERSION_MINOR 29
#define LIBAVFORMAT_VERSION_MICRO 101
#define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \
More information about the ffmpeg-cvslog
mailing list