diff options
author | Clément Bœsch <u@pkh.me> | 2015-09-10 21:17:44 +0200 |
---|---|---|
committer | Clément Bœsch <u@pkh.me> | 2015-09-10 21:18:34 +0200 |
commit | 4f26c999124531ce52329de6fa83c82d15a8b43c (patch) | |
tree | 9c6693e84067172d5816fc5a86addcf6436ebb42 /libavformat/subtitles.c | |
parent | 4f7189f09e5c0274905cccccaa792942b7a77133 (diff) | |
download | ffmpeg-4f26c999124531ce52329de6fa83c82d15a8b43c.tar.gz |
avformat/subtitles: drop duplicated events
Fix Ticket #4843
Diffstat (limited to 'libavformat/subtitles.c')
-rw-r--r-- | libavformat/subtitles.c | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/libavformat/subtitles.c b/libavformat/subtitles.c index 5bdbc8dc51..f25aa0e387 100644 --- a/libavformat/subtitles.c +++ b/libavformat/subtitles.c @@ -166,6 +166,34 @@ static int cmp_pkt_sub_pos_ts(const void *a, const void *b) return s1->pos > s2->pos ? 1 : -1; } +static void drop_dups(FFDemuxSubtitlesQueue *q) +{ + int i, drop = 0; + + for (i = 1; i < q->nb_subs; i++) { + const int last_id = i - 1 - drop; + const AVPacket *last = &q->subs[last_id]; + + if (q->subs[i].pts == last->pts && + q->subs[i].duration == last->duration && + !strcmp(q->subs[i].data, last->data)) { + + av_free_packet(&q->subs[i]); + drop++; + } else if (drop) { + q->subs[last_id + 1] = q->subs[i]; + memset(&q->subs[i], 0, sizeof(q->subs[i])); // for safety + } + } + + if (drop) { + q->nb_subs -= drop; + + // TODO: forward log context down here + av_log(NULL, AV_LOG_WARNING, "Dropping %d duplicated subtitle events\n", drop); + } +} + void ff_subtitles_queue_finalize(FFDemuxSubtitlesQueue *q) { int i; @@ -176,6 +204,7 @@ void ff_subtitles_queue_finalize(FFDemuxSubtitlesQueue *q) for (i = 0; i < q->nb_subs; i++) if (q->subs[i].duration == -1 && i < q->nb_subs - 1) q->subs[i].duration = q->subs[i + 1].pts - q->subs[i].pts; + drop_dups(q); } int ff_subtitles_queue_read_packet(FFDemuxSubtitlesQueue *q, AVPacket *pkt) |