From dd99c72343c9dd696b44eac3a91a07b2f944e78e Mon Sep 17 00:00:00 2001 From: John Stebbins Date: Wed, 20 Mar 2024 09:12:27 +0100 Subject: [PATCH 08/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 025f3dbd6f..afc88656cf 100644 --- a/libavcodec/dvdsubdec.c +++ b/libavcodec/dvdsubdec.c @@ -45,6 +45,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) @@ -534,10 +535,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; @@ -550,6 +554,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; @@ -561,6 +566,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) @@ -571,6 +577,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; } @@ -696,6 +704,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.5 (Apple Git-154)