PR #26317 opened by superuser404 URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/26317 Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/26317.patch
Matroska attachments only get a codec id under the legacy font MIME types. mkvmerge writes `font/ttf` and `font/otf` by default, and since v99 it also rewrites the legacy types to these when remuxing, so the fonts in current anime releases come out as `AV_CODEC_ID_NONE`. `vf_subtitles` already treats these types as fonts (af6081273f), the demuxer table was never updated. Besides the missing codec name, a `NONE` attachment fails `has_codec_parameters()` and never carries a packet, so `avformat_find_stream_info()` reads until its limit. On a 30 MB H.264 file with two such fonts, ffprobe read 3.07 MB (120 frames) before the change and 0.37 MB (8 frames) after it. I found this through a player that uses a 60 s analyzeduration, where a 970 MB release with 14 fonts read 36.7 MB before the first frame. The patch maps `font/ttf`, `font/sfnt` and `application/font-sfnt` to `AV_CODEC_ID_TTF` and `font/otf` to `AV_CODEC_ID_OTF`. `font/woff`, `font/woff2` and `font/collection` have no codec id, so I left them out. Testing: new `fate-matroska-font-mime-types` (needs no samples) muxes one attachment per type and probes the codec names. It fails on master with `unknown` for the four new types. `fate-matroska` (70 tests) and `fate-source` pass. >From 48445e2c5dbecae11ea7ad9652dccbe5fc741251 Mon Sep 17 00:00:00 2001 From: Vincent Herbst <[email protected]> Date: Tue, 24 Nov 2026 16:09:36 +0100 Subject: [PATCH] avformat/matroskadec: map the RFC 8081 font MIME types Attached fonts were only given a codec id under the legacy MIME types (application/x-truetype-font, application/x-font, application/vnd.ms-opentype). mkvmerge has written font/ttf and font/otf by default for years, and since v99 it rewrites the legacy types to those when it remuxes, so fonts in current files are exported as AV_CODEC_ID_NONE. vf_subtitles already treats these types as fonts (af6081273f). Besides the missing codec name, an attachment with AV_CODEC_ID_NONE fails has_codec_parameters() ("unknown codec"), and since it never carries a packet, avformat_find_stream_info() keeps reading until its duration or size limit. On a 30 MB H.264 file with two such fonts, ffprobe read 3.07 MB (120 frames) before this change and 0.37 MB (8 frames) after it. With a 60 s analyzeduration the gap grows with the bitrate: one host saw 36.7 MB read before the first frame. Map font/ttf, font/sfnt and application/font-sfnt to AV_CODEC_ID_TTF and font/otf to AV_CODEC_ID_OTF. Signed-off-by: Vincent Herbst <[email protected]> --- libavformat/matroskadec.c | 4 ++++ tests/fate/matroska.mak | 22 +++++++++++++++++++++- tests/ref/fate/matroska-font-mime-types | 6 ++++++ 3 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 tests/ref/fate/matroska-font-mime-types diff --git a/libavformat/matroskadec.c b/libavformat/matroskadec.c index 1cad8994c8f..3ce188bd705 100644 --- a/libavformat/matroskadec.c +++ b/libavformat/matroskadec.c @@ -848,6 +848,10 @@ static const CodecMime mkv_mime_tags[] = { {"application/x-truetype-font", AV_CODEC_ID_TTF}, {"application/x-font" , AV_CODEC_ID_TTF}, {"application/vnd.ms-opentype", AV_CODEC_ID_OTF}, + {"font/ttf" , AV_CODEC_ID_TTF}, + {"font/otf" , AV_CODEC_ID_OTF}, + {"font/sfnt" , AV_CODEC_ID_TTF}, + {"application/font-sfnt" , AV_CODEC_ID_TTF}, {"binary" , AV_CODEC_ID_BIN_DATA}, {"" , AV_CODEC_ID_NONE} diff --git a/tests/fate/matroska.mak b/tests/fate/matroska.mak index 0f50ae5e1d1..135f185f71a 100644 --- a/tests/fate/matroska.mak +++ b/tests/fate/matroska.mak @@ -426,9 +426,29 @@ fate-matroska-stereo3d-metadata: CMD = \ $(MATROSKA_STEREO3D_TAGGED) | ffmpeg -i pipe: -c copy -stereo3d:v:0 tb -metadata:s:v:0 stereo_mode= -f matroska - | \ $(MATROSKA_STEREO3D_PROBE) +# Attached fonts get a font codec id under the RFC 8081 MIME types (what +# mkvmerge writes by default) as well as under the legacy ones. Without one, +# avformat_find_stream_info() keeps reading until its duration limit, waiting +# for streams that never carry a packet. +FATE_MATROSKA_FONT_MIME-$(call ALLYES, FILE_PROTOCOL PIPE_PROTOCOL RAWVIDEO_DEMUXER RAWVIDEO_DECODER \ + MPEG4_ENCODER MATROSKA_MUXER MATROSKA_DEMUXER) \ + += fate-matroska-font-mime-types +fate-matroska-font-mime-types: tests/data/vsynth3.yuv +fate-matroska-font-mime-types: CMD = \ + ffmpeg -bitexact -s $(FATEW)x$(FATEH) -pix_fmt yuv420p -f rawvideo -i $(TARGET_PATH)/tests/data/vsynth3.yuv \ + -frames:v 1 -c:v mpeg4 \ + -attach $(TARGET_PATH)/tests/data/vsynth3.yuv -metadata:s:t:0 mimetype=font/ttf \ + -attach $(TARGET_PATH)/tests/data/vsynth3.yuv -metadata:s:t:1 mimetype=font/otf \ + -attach $(TARGET_PATH)/tests/data/vsynth3.yuv -metadata:s:t:2 mimetype=font/sfnt \ + -attach $(TARGET_PATH)/tests/data/vsynth3.yuv -metadata:s:t:3 mimetype=application/font-sfnt \ + -attach $(TARGET_PATH)/tests/data/vsynth3.yuv -metadata:s:t:4 mimetype=application/x-truetype-font \ + -f matroska - | \ + probe -v error -show_entries stream=index,codec_type,codec_name:stream_tags=mimetype -of csv=p=0 pipe: + FATE_SAMPLES_AVCONV += $(FATE_MATROSKA-yes) FATE_SAMPLES_FFPROBE += $(FATE_MATROSKA_FFPROBE-yes) FATE_SAMPLES_FFMPEG_FFPROBE += $(FATE_MATROSKA_FFMPEG_FFPROBE-yes) FATE_FFMPEG_FFPROBE += $(FATE_MATROSKA_STEREO3D-yes) +FATE_FFMPEG_FFPROBE += $(FATE_MATROSKA_FONT_MIME-yes) -fate-matroska: $(FATE_MATROSKA-yes) $(FATE_MATROSKA_FFPROBE-yes) $(FATE_MATROSKA_FFMPEG_FFPROBE-yes) $(FATE_MATROSKA_STEREO3D-yes) +fate-matroska: $(FATE_MATROSKA-yes) $(FATE_MATROSKA_FFPROBE-yes) $(FATE_MATROSKA_FFMPEG_FFPROBE-yes) $(FATE_MATROSKA_STEREO3D-yes) $(FATE_MATROSKA_FONT_MIME-yes) diff --git a/tests/ref/fate/matroska-font-mime-types b/tests/ref/fate/matroska-font-mime-types new file mode 100644 index 00000000000..3fef79d0d2d --- /dev/null +++ b/tests/ref/fate/matroska-font-mime-types @@ -0,0 +1,6 @@ +0,mpeg4,video +1,ttf,attachment,font/ttf +2,otf,attachment,font/otf +3,ttf,attachment,font/sfnt +4,ttf,attachment,application/font-sfnt +5,ttf,attachment,application/x-truetype-font -- 2.54.1 _______________________________________________ ffmpeg-devel mailing list -- [email protected] To unsubscribe send an email to [email protected]
