summaryrefslogtreecommitdiff
path: root/libavformat/mux.c
diff options
context:
space:
mode:
authorMichael Niedermayer <michaelni@gmx.at>2012-09-26 15:55:16 +0200
committerMartin Storsjö <martin@martin.st>2014-11-07 12:11:35 +0200
commit1384df641994bf3d6cb51084290aa94752737bae (patch)
tree2a6afda25be9445d37d7e5436efaa7e3e5479132 /libavformat/mux.c
parent4981baf9b803f3c4866b2e97fdadb008c62dc7ad (diff)
lavf: Add an option for avoiding negative timestamps
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ö <martin@martin.st>
Diffstat (limited to 'libavformat/mux.c')
-rw-r--r--libavformat/mux.c12
1 files changed, 10 insertions, 2 deletions
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;
}