diff mbox series

[FFmpeg-devel,v3] ffmpeg: allow full range of dts_delta_threshold

Message ID 20200416054926.1079-1-ffmpeg@gyani.pro
State New
Headers show
Series [FFmpeg-devel,v3] ffmpeg: allow full range of dts_delta_threshold
Related show

Checks

Context Check Description
andriy/default pending
andriy/make success Make finished
andriy/make_fate success Make fate finished

Commit Message

Gyan Doshi April 16, 2020, 5:49 a.m. UTC
For inputs from demuxers with AVFMT_TS_DISCONT flag,
the existing condition,

  delta < -1LL*dts_delta_threshold*AV_TIME_BASE

is rendered superflous due to the fixed threshold in

pkt_dts + AV_TIME_BASE/10 < FFMAX(ist->pts, ist->dts)

This prevents users from setting a high threshold to
avoid discontinuity correction due to errant timestamps.

Now, if threshold is set by user, it is honoured, else existing
behaviour is maintained.
---
Tested with multiple satellite MPEG-TS inputs.

 fftools/ffmpeg.c     | 13 ++++++++-----
 fftools/ffmpeg_opt.c |  2 +-
 2 files changed, 9 insertions(+), 6 deletions(-)
diff mbox series

Patch

diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
index 0578265c1e..84a1e6543e 100644
--- a/fftools/ffmpeg.c
+++ b/fftools/ffmpeg.c
@@ -4439,8 +4439,9 @@  static int process_input(int file_index)
         pkt_dts != AV_NOPTS_VALUE && ist->next_dts == AV_NOPTS_VALUE && !copy_ts
         && (is->iformat->flags & AVFMT_TS_DISCONT) && ifile->last_ts != AV_NOPTS_VALUE) {
         int64_t delta   = pkt_dts - ifile->last_ts;
-        if (delta < -1LL*dts_delta_threshold*AV_TIME_BASE ||
-            delta >  1LL*dts_delta_threshold*AV_TIME_BASE){
+        int64_t effective_threshold = !dts_delta_threshold ? 10*AV_TIME_BASE : dts_delta_threshold*AV_TIME_BASE;
+        if (delta < -1LL*effective_threshold ||
+            delta >  1LL*effective_threshold){
             ifile->ts_offset -= delta;
             av_log(NULL, AV_LOG_DEBUG,
                    "Inter stream timestamp discontinuity %"PRId64", new offset= %"PRId64"\n",
@@ -4478,9 +4479,11 @@  static int process_input(int file_index)
         !disable_discontinuity_correction) {
         int64_t delta   = pkt_dts - ist->next_dts;
         if (is->iformat->flags & AVFMT_TS_DISCONT) {
-            if (delta < -1LL*dts_delta_threshold*AV_TIME_BASE ||
-                delta >  1LL*dts_delta_threshold*AV_TIME_BASE ||
-                pkt_dts + AV_TIME_BASE/10 < FFMAX(ist->pts, ist->dts)) {
+            int64_t effective_delta_threshold    = !dts_delta_threshold ? 10*AV_TIME_BASE : dts_delta_threshold*AV_TIME_BASE;
+            int64_t effective_negative_threshold = !dts_delta_threshold ? AV_TIME_BASE/10 : dts_delta_threshold*AV_TIME_BASE;
+            if (delta < -1LL*effective_delta_threshold ||
+                delta >  1LL*effective_delta_threshold ||
+                pkt_dts + effective_negative_threshold < FFMAX(ist->pts, ist->dts)) {
                 ifile->ts_offset -= delta;
                 av_log(NULL, AV_LOG_DEBUG,
                        "timestamp discontinuity for stream #%d:%d "
diff --git a/fftools/ffmpeg_opt.c b/fftools/ffmpeg_opt.c
index 93b3d96205..58fa1d7854 100644
--- a/fftools/ffmpeg_opt.c
+++ b/fftools/ffmpeg_opt.c
@@ -146,7 +146,7 @@  char *vstats_filename;
 char *sdp_filename;
 
 float audio_drift_threshold = 0.1;
-float dts_delta_threshold   = 10;
+float dts_delta_threshold   = 0;
 float dts_error_threshold   = 3600*30;
 
 int audio_volume      = 256;