[PR] avformat/dvdvideodec: do not drop out-of-order AC3 packets (PR #24280)

Yalda via ffmpeg-devel <[email protected]>
Newsgroups gmane.comp.video.ffmpeg.devel
Message-ID <[email protected]>
PR #24280 opened by Yalda
URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/24280
Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/24280.patch

Resolves audio drop outs in very early generation DVD-R/ROM discs.
This filtering was originally added to smooth out seeking and
chapter cutpoints, but after robust testing (>1000 discs), it was
discovered that certain encoders from 1997-era did produce valid
AC3 streams this way. Beside the point, it is an archival accuracy
concern.

Signed-off-by: Yalda <[email protected]>

# Summary of changes

Briefly describe what this PR does and why.

<!--
If this PR requires new FATE test samples, attach them to the PR and
list their target paths below (relative to the fate-suite root).

Attached filenames must match the sample's filename:

```fate-samples
# e.g. vorbis/new-sample.ogg
```
-->



>From 49058b577c11ab37b9dcc4de3c749e3ae49beea9 Mon Sep 17 00:00:00 2001
From: Yalda <[email protected]>
Date: Sat, 7 Mar 2026 19:35:37 -0600
Subject: [PATCH] avformat/dvdvideodec: do not drop out-of-order AC3 packets

Resolves audio drop outs in very early generation DVD-R/ROM discs.
This filtering was originally added to smooth out seeking and
chapter cutpoints, but after robust testing (>1000 discs), it was
discovered that certain encoders from 1997-era did produce valid
AC3 streams this way. Beside the point, it is an archival accuracy
concern.

Signed-off-by: Yalda <[email protected]>
---
 libavformat/dvdvideodec.c | 24 ++----------------------
 1 file changed, 2 insertions(+), 22 deletions(-)

diff --git a/libavformat/dvdvideodec.c b/libavformat/dvdvideodec.c
index 1e397e3bf5..14c878ff6c 100644
--- a/libavformat/dvdvideodec.c
+++ b/libavformat/dvdvideodec.c
@@ -168,7 +168,6 @@ typedef struct DVDVideoDemuxContext {
     int                         nb_angles;          /* number of angles in the current title */
     int                         play_started;       /* signal that playback has started */
     DVDVideoPlaybackState       play_state;         /* the active playback state */
-    int64_t                     *prev_pts;          /* track the previous PTS emitted per stream */
     int64_t                     pts_offset;         /* PTS discontinuity offset (ex. VOB change) */
     int                         seek_warned;        /* signal that we warned about seeking limits */
     int                         subdemux_reset;     /* signal that subdemuxer should be reset */
@@ -1580,7 +1579,7 @@ static int dvdvideo_read_header(AVFormatContext *s)
             (ret = dvdvideo_subdemux_open(s)) < 0)
         return ret;
 
-        goto end_ready;
+        return 0;
     }
 
     if (c->opt_pgc && (c->opt_chapter_start > 1 || c->opt_chapter_end > 0 || c->opt_preindex)) {
@@ -1617,14 +1616,6 @@ static int dvdvideo_read_header(AVFormatContext *s)
         (ret = dvdvideo_subdemux_open(s)) < 0)
         return ret;
 
-end_ready:
-    c->prev_pts = av_malloc(s->nb_streams * sizeof(int64_t));
-    if (!c->prev_pts)
-        return AVERROR(ENOMEM);
-
-    for (int i = 0; i < s->nb_streams; i++)
-        c->prev_pts[i] = AV_NOPTS_VALUE;
-
     return 0;
 }
 
@@ -1685,13 +1676,10 @@ static int dvdvideo_read_packet(AVFormatContext *s, AVPacket *pkt)
     if (pkt->pts < 0)
         goto discard;
 
-    /* clean up after DVD muxers which end seamless PGs on duplicate or partial AC3 samples */
+    /* clean up after DVD muxers which end seamless PGs on partial AC3 samples */
     if (st_subdemux->codecpar->codec_type == AVMEDIA_TYPE_AUDIO &&
         st_subdemux->codecpar->codec_id == AV_CODEC_ID_AC3) {
 
-        if (pkt->pts <= c->prev_pts[pkt->stream_index])
-            goto discard;
-
         ret = av_ac3_parse_header(pkt->buf->data, pkt->size,
                                   &ac3_bitstream_id, &ac3_frame_size);
 
@@ -1704,8 +1692,6 @@ static int dvdvideo_read_packet(AVFormatContext *s, AVPacket *pkt)
                             pkt->stream_index, pkt->pts, pkt->dts,
                             c->pts_offset, c->first_pts);
 
-    c->prev_pts[pkt->stream_index] = pkt->pts;
-
     return 0;
 
 discard:
@@ -1713,9 +1699,6 @@ discard:
            "Discarding frame @ st=%d pts=%" PRId64 " dts=%" PRId64 " is_key=%d st_mapped=%d\n",
            st_mapped ? pkt->stream_index : -1, pkt->pts, pkt->dts, is_key, st_mapped);
 
-    if (st_mapped)
-        c->prev_pts[pkt->stream_index] = pkt->pts;
-
     return FFERROR_REDO;
 }
 
@@ -1732,9 +1715,6 @@ static int dvdvideo_close(AVFormatContext *s)
 
     dvdvideo_ifo_close(s);
 
-    if (c->prev_pts)
-        av_freep(&c->prev_pts);
-
     return 0;
 }
 
-- 
2.52.0

_______________________________________________
ffmpeg-devel mailing list -- [email protected]
To unsubscribe send an email to [email protected]
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.