[FFmpeg-devel] [PATCH v3 1/5] avcodec/parser: merge packets from the same frame

Nicolas Gaullier nicolas.gaullier at cji.paris
Mon Mar 4 19:32:15 EET 2024


The mpegts demuxer splits packets according to its max_packet_size.
This currently fills the AVCodecParserContext s->cur_frame_* arrays with
kind of 'empty' entries: no pts/dts.
This patch merges these entries, so the parser behaviour is independent
from the demuxer settings.
This patch is required for the following patch which will fetch 'past'
timestamps from past cur_frames.

Signed-off-by: Nicolas Gaullier <nicolas.gaullier at cji.paris>
---
 libavcodec/parser.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/libavcodec/parser.c b/libavcodec/parser.c
index efc28b8918..90461075fd 100644
--- a/libavcodec/parser.c
+++ b/libavcodec/parser.c
@@ -142,6 +142,8 @@ int av_parser_parse2(AVCodecParserContext *s, AVCodecContext *avctx,
         memset(dummy_buf, 0, sizeof(dummy_buf));
         buf = dummy_buf;
     } else if (s->cur_offset + buf_size != s->cur_frame_end[s->cur_frame_start_index]) { /* skip remainder packets */
+        if (pos != s->cur_frame_pos[s->cur_frame_start_index] || pos <= 0 ||
+            pts != AV_NOPTS_VALUE || dts != AV_NOPTS_VALUE ) {
         /* add a new packet descriptor */
         i = (s->cur_frame_start_index + 1) & (AV_PARSER_PTS_NB - 1);
         s->cur_frame_start_index = i;
@@ -150,6 +152,9 @@ int av_parser_parse2(AVCodecParserContext *s, AVCodecContext *avctx,
         s->cur_frame_pts[i]      = pts;
         s->cur_frame_dts[i]      = dts;
         s->cur_frame_pos[i]      = pos;
+        } else {
+            s->cur_frame_end[s->cur_frame_start_index] = s->cur_offset + buf_size;
+        }
     }
 
     if (s->fetch_timestamp) {
-- 
2.30.2



More information about the ffmpeg-devel mailing list