[FFmpeg-devel] fftools/ffmpeg: Disable copy_ts on timestamp wraparound

Submitted by Michael Niedermayer on May 3, 2019, 3:36 p.m.

Details

Message ID 20190503153607.26133-1-michael@niedermayer.cc
State New
Headers show

Commit Message

Michael Niedermayer May 3, 2019, 3:36 p.m.
This allows handling more than 26.5h of mpeg* input

Fixes: Ticket 7876

Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
---
 fftools/ffmpeg.c | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

Comments

Panagiotis Malakoudis May 4, 2019, 1:30 p.m.
Στις Παρ, 3 Μαΐ 2019 στις 6:39 μ.μ., ο/η Michael Niedermayer
<michael@niedermayer.cc> έγραψε:
>
> This allows handling more than 26.5h of mpeg* input
>
> Fixes: Ticket 7876
>

I confirm it fixes the case described in the ticket. Will now test it
in realtime environment, so it will take 26,5 hours to report back.
Thank you
Aleksey Skripka May 9, 2019, 12:40 p.m.
Greetings!

> On 3 May 2019, at 18:36, Michael Niedermayer <michael@niedermayer.cc> wrote:
> 
> This allows handling more than 26.5h of mpeg* input
> 
> Fixes: Ticket 7876
> 

not sure how this correlated, but facing my '26.5 hours problem' i found next:

running on plain ts-file is ok:
./ffmpeg -copyts -i 27hours.ts -c copy -f null -

but if this ts-file is wrapped in m3u8, any of this commands:
./ffmpeg  -i 27hours.m3u8 -c copy -f null -
./ffmpeg -copyts -i 27hours.m3u8 -c copy -f null -

fails with:
[mpegts @ 0x2cf6680] DTS 788 < 8589931780 out of order
[hls @ 0x2cf3400] DTS 788 < 8589931780 out of order
[null @ 0x2e28980] Application provided invalid, non monotonically increasing dts to muxer in stream 0: 8589805780 >= -125212
[null @ 0x2e28980] Application provided invalid, non monotonically increasing dts to muxer in stream 0: 8589805780 >= -121612


$ cat 27hours.m3u8
#EXTM3U
#EXT-X-VERSION:3
#EXT-X-TARGETDURATION:97200
#EXT-X-PLAYLIST-TYPE:VOD
#EXTINF: 97200,
27hours.ts
#EXT-X-ENDLIST


ps: ffmpeg = git-master + patch from this mail

Patch hide | download patch | download mbox

diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
index 01f04103cf..b58336679d 100644
--- a/fftools/ffmpeg.c
+++ b/fftools/ffmpeg.c
@@ -4262,6 +4262,7 @@  static int process_input(int file_index)
     int ret, thread_ret, i, j;
     int64_t duration;
     int64_t pkt_dts;
+    int disable_discontinuity_correction = copy_ts;
 
     is  = ifile->ctx;
     ret = get_input_packet(ifile, &pkt);
@@ -4463,10 +4464,20 @@  static int process_input(int file_index)
         pkt.dts += duration;
 
     pkt_dts = av_rescale_q_rnd(pkt.dts, ist->st->time_base, AV_TIME_BASE_Q, AV_ROUND_NEAR_INF|AV_ROUND_PASS_MINMAX);
+
+    if (copy_ts && pkt_dts != AV_NOPTS_VALUE && ist->next_dts != AV_NOPTS_VALUE &&
+        (is->iformat->flags & AVFMT_TS_DISCONT) && ist->st->pts_wrap_bits < 60) {
+        int64_t wrap_dts = av_rescale_q_rnd(pkt.dts + (1LL<<ist->st->pts_wrap_bits),
+                                            ist->st->time_base, AV_TIME_BASE_Q,
+                                            AV_ROUND_NEAR_INF|AV_ROUND_PASS_MINMAX);
+        if (FFABS(wrap_dts - ist->next_dts) < FFABS(pkt_dts - ist->next_dts)/10)
+            disable_discontinuity_correction = 0;
+    }
+
     if ((ist->dec_ctx->codec_type == AVMEDIA_TYPE_VIDEO ||
          ist->dec_ctx->codec_type == AVMEDIA_TYPE_AUDIO) &&
          pkt_dts != AV_NOPTS_VALUE && ist->next_dts != AV_NOPTS_VALUE &&
-        !copy_ts) {
+        !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 ||