From 1384df641994bf3d6cb51084290aa94752737bae Mon Sep 17 00:00:00 2001 From: Michael Niedermayer Date: Wed, 26 Sep 2012 15:55:16 +0200 Subject: lavf: Add an option for avoiding negative timestamps MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This is the same logic as is invoked on AVFMT_TS_NEGATIVE, but which can be enabled manually, or can be enabled in muxers which only need it in certain conditions. Also allow using the same mechanism to force streams to start at 0. Signed-off-by: Martin Storsjö --- libavformat/mux.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'libavformat/mux.c') diff --git a/libavformat/mux.c b/libavformat/mux.c index c80eb5bfb7..1e80e105d7 100644 --- a/libavformat/mux.c +++ b/libavformat/mux.c @@ -248,6 +248,13 @@ int avformat_write_header(AVFormatContext *s, AVDictionary **options) return ret; } + if (s->avoid_negative_ts == AVFMT_AVOID_NEG_TS_AUTO) { + if (s->oformat->flags & (AVFMT_TS_NEGATIVE | AVFMT_NOTIMESTAMPS)) { + s->avoid_negative_ts = 0; + } else + s->avoid_negative_ts = AVFMT_AVOID_NEG_TS_MAKE_NON_NEGATIVE; + } + return 0; } @@ -318,11 +325,12 @@ static int compute_pkt_fields2(AVFormatContext *s, AVStream *st, AVPacket *pkt) static int write_packet(AVFormatContext *s, AVPacket *pkt) { int ret; - if (!(s->oformat->flags & (AVFMT_TS_NEGATIVE | AVFMT_NOTIMESTAMPS))) { + if (s->avoid_negative_ts > 0) { AVRational time_base = s->streams[pkt->stream_index]->time_base; int64_t offset = 0; - if (!s->offset && pkt->dts != AV_NOPTS_VALUE && pkt->dts < 0) { + if (!s->offset && pkt->dts != AV_NOPTS_VALUE && + (pkt->dts < 0 || s->avoid_negative_ts == AVFMT_AVOID_NEG_TS_MAKE_ZERO)) { s->offset = -pkt->dts; s->offset_timebase = time_base; } -- cgit v1.2.3