From 2bae41702e2a558ebea370b888e040875ac16779 Mon Sep 17 00:00:00 2001 From: John Stebbins Date: Wed, 20 Mar 2024 09:12:27 +0100 Subject: [PATCH 07/16] dvdsubdec: use pts of initial packet When the source is DVD, only the initial packet of a subtitle that spans multiple packets will have a pts value. --- libavcodec/dvdsubdec.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/libavcodec/dvdsubdec.c b/libavcodec/dvdsubdec.c index 146996bc23..2dd10b4d8b 100644 --- a/libavcodec/dvdsubdec.c +++ b/libavcodec/dvdsubdec.c @@ -44,6 +44,7 @@ typedef struct DVDSubContext int buf_size; int forced_subs_only; uint8_t used_color[256]; + int64_t pts; } DVDSubContext; static void yuv_a_to_rgba(const uint8_t *ycbcr, const uint8_t *alpha, uint32_t *rgba, int num_values) @@ -533,10 +534,13 @@ static int dvdsub_decode(AVCodecContext *avctx, AVSubtitle *sub, int appended = 0; int is_menu; + if (ctx->pts == AV_NOPTS_VALUE && sub->pts != AV_NOPTS_VALUE) + ctx->pts = sub->pts; if (ctx->buf_size) { int ret = append_to_cached_buf(avctx, buf, buf_size); if (ret < 0) { *data_size = 0; + ctx->pts = AV_NOPTS_VALUE; return ret; } buf = ctx->buf; @@ -549,6 +553,7 @@ static int dvdsub_decode(AVCodecContext *avctx, AVSubtitle *sub, *data_size = 0; int ret = appended ? 0 : append_to_cached_buf(avctx, buf, buf_size); if (ret < 0) { + ctx->pts = AV_NOPTS_VALUE; return ret; } return buf_size; @@ -560,6 +565,7 @@ static int dvdsub_decode(AVCodecContext *avctx, AVSubtitle *sub, reset_rects(sub); *data_size = 0; + ctx->pts = AV_NOPTS_VALUE; return buf_size; } if (!is_menu && find_smallest_bounding_rectangle(ctx, sub) == 0) @@ -570,6 +576,8 @@ static int dvdsub_decode(AVCodecContext *avctx, AVSubtitle *sub, ctx->buf_size = 0; *data_size = 1; + sub->pts = ctx->pts; + ctx->pts = AV_NOPTS_VALUE; return buf_size; } @@ -695,6 +703,7 @@ static av_cold int dvdsub_init(AVCodecContext *avctx) av_log(avctx, AV_LOG_DEBUG, " 0x%06"PRIx32, ctx->palette[i]); av_log(avctx, AV_LOG_DEBUG, "\n"); } + ctx->pts = AV_NOPTS_VALUE; return 1; } -- 2.39.3 (Apple Git-146)