sd_lavc: support rendering bitmap subtitles with libaribcaption #11648
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
libaribcaption is a library for decoding / rendering ARIB STD-B24 based TV broadcast captions (subtitles). The library supports ouputting decoded subtitles in two ways: ASS subtitles or bitmap subtitles. Building recent version of ffmpeg with libaribcaption also enables ARIB subtitles rendering on mpv.
Currently mpv only supports rendering ARIB subtitles with ASS subtitles driver when libaribcaption codec is in use, which renders poorly compared to bitmap subtitles driver. ASS subtitles lack black transparent background that makes subtitles more readable. Subtitles decoded with libaribcaption render best when rendered with bitmap subtitles driver.
New mpv commandline option: sd-lavc-o
On ffplay you can use
-sub_type=bitmap
option to render ARIB subtitles as bitmap.There is currenly no way to set the same option to subtitle decoders on mpv unfortunately, so I added one. This would also allow configuring other libaribcaption options like font from mpv.
libaribcaption support
mpv only uses bitmap subtitles driver only for codecs listed here:
mpv/sub/sd_lavc.c
Lines 79 to 89 in 6234a70
To render subtitles correctly when
sub_type
is set tobitmap
, I added some code that choose subtitles driver based on the value of this option.Since ffmpeg's libaribcaption codec defaults to ASS subtitles, just adding
AV_CODEC_ID_ARIB_CAPTION
to the list breaks rendering, because mpv expects bitmap subtitles, and the codec still outputs ASS subtitles.Building
--enable-libaribcaption
. I used this revision: https://github.com/FFmpeg/FFmpeg/tree/2f8690c5d450b984640bd27dd7fd3a96d77ecc6b-Ddvbin=enabled
if you want to test ASS subtitles support too.Running
Tested on NixOS 22.11. Without
--cache=no
, subtitles does not show up until I seek (Probably because of this issue): #9646libaribb24 probably has the same problem as libaribcaption and this PR may fix it, I just haven't tested with libaribb24 yet.
Do I need to send m2ts files to mpv developers for testing?
Rendering subtitles with bitmap subtitles driver:
Rendering subtitles with ASS subtitles driver (Requires mpv to be built with
-Ddvbin=enabled
):mpv defaults to ASS subtitles if sub_type is not set: