PR #24560 opened by sahitya-chandra URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/24560 Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/24560.patch
Fixes #24184 When an ASS header has no styles, the `mov_text` encoder uses the fallback font Serif but omits its five bytes from the font-table size calculation, this produces an 18-byte ftab box that incorrectly declares its size as 13 bytes This PR corrects the size calculation and adds an API regression test covering both the fallback font and an explicitly defined Serif style >From f5660b489e6c899345cb72f857d3b5255d901992 Mon Sep 17 00:00:00 2001 From: Sahitya Chandra <[email protected]> Date: Fri, 18 Sep 2026 23:19:23 +0530 Subject: [PATCH 1/2] avcodec/movtextenc: account for the fallback font name in ftab size Include the fallback Serif font name in the size calculation so that an ASS header without styles produces an ftab box declaring 18 bytes, not 13. Fixes: https://code.ffmpeg.org/FFmpeg/FFmpeg/issues/24184 Signed-off-by: Sahitya Chandra <[email protected]> --- libavcodec/movtextenc.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/libavcodec/movtextenc.c b/libavcodec/movtextenc.c index a5f0325595..589540e115 100644 --- a/libavcodec/movtextenc.c +++ b/libavcodec/movtextenc.c @@ -283,8 +283,10 @@ static int encode_sample_description(AVCodecContext *avctx) font_names_total_len += strlen(ass->styles[i].font_name); } } - } else + } else { av_dynarray_add(&s->fonts, &s->font_count, (char*)"Serif"); + font_names_total_len = strlen("Serif"); + } // FontTableBox { p = buf; -- 2.52.0 >From fce46426138bbc5d642e40fd99f4b7aec6d53331 Mon Sep 17 00:00:00 2001 From: Sahitya Chandra <[email protected]> Date: Fri, 18 Sep 2026 23:19:23 +0530 Subject: [PATCH 2/2] tests/api: cover mov_text fallback font table size Add an API regression test checking the serialized font table for ASS headers without styles and with an explicit Serif style. Signed-off-by: Sahitya Chandra <[email protected]> --- tests/api/Makefile | 1 + tests/api/api-movtext-test.c | 83 ++++++++++++++++++++++++++++++++++++ tests/fate/api.mak | 5 +++ 3 files changed, 89 insertions(+) create mode 100644 tests/api/api-movtext-test.c diff --git a/tests/api/Makefile b/tests/api/Makefile index 953325f89d..f2738d4cba 100644 --- a/tests/api/Makefile +++ b/tests/api/Makefile @@ -3,6 +3,7 @@ APITESTPROGS-$(call ENCDEC, FLAC, FLAC) += api-flac APITESTPROGS-$(call DEMDEC, H264, H264) += api-h264 APITESTPROGS-$(call DEMDEC, H264, H264) += api-h264-slice APITESTPROGS-$(CONFIG_MOV_MUXER) += api-movenc +APITESTPROGS-$(CONFIG_MOVTEXT_ENCODER) += api-movtext APITESTPROGS-yes += api-seek api-dump-stream-meta APITESTPROGS-$(call DEMDEC, H263, H263) += api-band APITESTPROGS-$(HAVE_THREADS) += api-threadmessage diff --git a/tests/api/api-movtext-test.c b/tests/api/api-movtext-test.c new file mode 100644 index 0000000000..78abac8f58 --- /dev/null +++ b/tests/api/api-movtext-test.c @@ -0,0 +1,83 @@ +/* + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include <stdio.h> +#include <string.h> + +#include "libavcodec/avcodec.h" +#include "libavutil/intreadwrite.h" +#include "libavutil/mem.h" + +/** + * Check the serialized font table for a header using the Serif font. + */ +static int check_font_table(const AVCodec *codec, const char *header) +{ + AVCodecContext *ctx = avcodec_alloc_context3(codec); + int ret = 1; + + if (!ctx) + return 1; + + ctx->subtitle_header = (uint8_t *)av_strdup(header); + if (!ctx->subtitle_header) + goto end; + ctx->subtitle_header_size = strlen(header); + ctx->time_base = (AVRational){ 1, 1000 }; + + if (avcodec_open2(ctx, codec, NULL) < 0) + goto end; + + /* The 30-byte sample description is followed by one 18-byte font table: + * box header (8), entry count (2), font ID (2), name length (1), Serif (5). */ + if (ctx->extradata_size != 48 || + AV_RB32(ctx->extradata + 30) != 18 || + memcmp(ctx->extradata + 34, "ftab", 4) || + AV_RB16(ctx->extradata + 38) != 1 || + AV_RB16(ctx->extradata + 40) != 1 || + ctx->extradata[42] != 5 || + memcmp(ctx->extradata + 43, "Serif", 5)) { + fprintf(stderr, "Invalid mov_text font table for header:\n%s", header); + goto end; + } + + ret = 0; +end: + avcodec_free_context(&ctx); + return ret; +} + +int main(void) +{ + const AVCodec *codec = avcodec_find_encoder(AV_CODEC_ID_MOV_TEXT); + int ret; + + if (!codec) + return 1; + + ret = check_font_table(codec, + "[Script Info]\n" + "ScriptType: v4.00+\n"); + ret |= check_font_table(codec, + "[Script Info]\n" + "ScriptType: v4.00+\n" + "[V4+ Styles]\n" + "Format: Name, Fontname, Fontsize\n" + "Style: Default,Serif,18\n"); + return ret; +} diff --git a/tests/fate/api.mak b/tests/fate/api.mak index a740db1f0a..69b591fa82 100644 --- a/tests/fate/api.mak +++ b/tests/fate/api.mak @@ -7,6 +7,11 @@ fate-api-flac: $(APITESTSDIR)/api-flac-test$(EXESUF) fate-api-flac: CMD = run $(APITESTSDIR)/api-flac-test$(EXESUF) fate-api-flac: CMP = null +FATE_API_LIBAVCODEC-$(CONFIG_MOVTEXT_ENCODER) += fate-api-movtext +fate-api-movtext: $(APITESTSDIR)/api-movtext-test$(EXESUF) +fate-api-movtext: CMD = run $(APITESTSDIR)/api-movtext-test$(EXESUF) +fate-api-movtext: CMP = null + FATE_API_LIBAVCODEC-$(call ALLYES, H261_ENCODER H261_PARSER) += fate-api-enc-parser fate-api-enc-parser-cif fate-api-enc-parser: $(APITESTSDIR)/api-enc-parser-test$(EXESUF) fate-api-enc-parser: CMD = run $(APITESTSDIR)/api-enc-parser-test$(EXESUF) h261 176 144 -- 2.52.0 _______________________________________________ ffmpeg-devel mailing list -- [email protected] To unsubscribe send an email to [email protected]
