ffmpeg | branch: release/2.6 | Michael Niedermayer <michae...@gmx.at> | Tue May 
 5 12:44:20 2015 +0200| [5a8b43285baa744d5450a4a37d98bcfb500c18fe] | committer: 
James Almer

avformat/mux: Add avoid_negative_ts_use_pts

This allows using pts instead of dts for negative TS avoidance

Signed-off-by: Michael Niedermayer <michae...@gmx.at>
(cherry picked from commit 7ac5c38ec5baeea6ad647ccc9bb7e97564c50ec2)

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

 libavformat/internal.h |    2 ++
 libavformat/mux.c      |   36 ++++++++++++++++++++++++------------
 2 files changed, 26 insertions(+), 12 deletions(-)

diff --git a/libavformat/internal.h b/libavformat/internal.h
index 76ffcc5..5dacb45 100644
--- a/libavformat/internal.h
+++ b/libavformat/internal.h
@@ -97,6 +97,8 @@ struct AVFormatInternal {
     AVRational offset_timebase;
 
     int inject_global_side_data;
+
+    int avoid_negative_ts_use_pts;
 };
 
 #ifdef __GNUC__
diff --git a/libavformat/mux.c b/libavformat/mux.c
index 72d8e94..5dd0be8 100644
--- a/libavformat/mux.c
+++ b/libavformat/mux.c
@@ -554,10 +554,11 @@ static int write_packet(AVFormatContext *s, AVPacket *pkt)
     if (s->avoid_negative_ts > 0) {
         AVStream *st = s->streams[pkt->stream_index];
         int64_t offset = st->mux_ts_offset;
+        int64_t ts = s->internal->avoid_negative_ts_use_pts ? pkt->pts : 
pkt->dts;
 
-        if (s->internal->offset == AV_NOPTS_VALUE && pkt->dts != 
AV_NOPTS_VALUE &&
-            (pkt->dts < 0 || s->avoid_negative_ts == 
AVFMT_AVOID_NEG_TS_MAKE_ZERO)) {
-            s->internal->offset = -pkt->dts;
+        if (s->internal->offset == AV_NOPTS_VALUE && ts != AV_NOPTS_VALUE &&
+            (ts < 0 || s->avoid_negative_ts == AVFMT_AVOID_NEG_TS_MAKE_ZERO)) {
+            s->internal->offset = -ts;
             s->internal->offset_timebase = st->time_base;
         }
 
@@ -574,15 +575,26 @@ static int write_packet(AVFormatContext *s, AVPacket *pkt)
         if (pkt->pts != AV_NOPTS_VALUE)
             pkt->pts += offset;
 
-        av_assert2(pkt->dts == AV_NOPTS_VALUE || pkt->dts >= 0 || 
s->max_interleave_delta > 0);
-        if (pkt->dts != AV_NOPTS_VALUE && pkt->dts < 0) {
-            av_log(s, AV_LOG_WARNING,
-                   "Packets poorly interleaved, failed to avoid negative "
-                   "timestamp %s in stream %d.\n"
-                   "Try -max_interleave_delta 0 as a possible workaround.\n",
-                   av_ts2str(pkt->dts),
-                   pkt->stream_index
-            );
+        if (s->internal->avoid_negative_ts_use_pts) {
+            if (pkt->pts != AV_NOPTS_VALUE && pkt->pts < 0) {
+                av_log(s, AV_LOG_WARNING, "failed to avoid negative "
+                    "pts %s in stream %d.\n"
+                    "Try -avoid_negative_ts 1 as a possible workaround.\n",
+                    av_ts2str(pkt->dts),
+                    pkt->stream_index
+                );
+            }
+        } else {
+            av_assert2(pkt->dts == AV_NOPTS_VALUE || pkt->dts >= 0 || 
s->max_interleave_delta > 0);
+            if (pkt->dts != AV_NOPTS_VALUE && pkt->dts < 0) {
+                av_log(s, AV_LOG_WARNING,
+                    "Packets poorly interleaved, failed to avoid negative "
+                    "timestamp %s in stream %d.\n"
+                    "Try -max_interleave_delta 0 as a possible workaround.\n",
+                    av_ts2str(pkt->dts),
+                    pkt->stream_index
+                );
+            }
         }
     }
 

_______________________________________________
ffmpeg-cvslog mailing list
ffmpeg-cvslog@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog

Reply via email to