From 1c4f9fafaa17df4e1eddea06329f34537af1ef50 Mon Sep 17 00:00:00 2001 From: Damiano Galassi Date: Sat, 16 Jul 2022 10:02:27 +0200 Subject: [PATCH 2/2] 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. Original patch by John Stebbins. --- libavcodec/dvdsubdec.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/libavcodec/dvdsubdec.c b/libavcodec/dvdsubdec.c index fdeead372b..13e7ccad9d 100644 --- a/libavcodec/dvdsubdec.c +++ b/libavcodec/dvdsubdec.c @@ -43,6 +43,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) @@ -522,10 +523,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; @@ -538,6 +542,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; @@ -549,6 +554,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) @@ -559,6 +565,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; } @@ -684,6 +692,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.32.1 (Apple Git-133)