Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sd_lavc: support rendering bitmap subtitles with libaribcaption #11648

Closed
wants to merge 2 commits into from

Conversation

vroad
Copy link

@vroad vroad commented May 1, 2023

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

// Supported codecs must be known to decode to paletted bitmaps
switch (cid) {
case AV_CODEC_ID_DVB_SUBTITLE:
case AV_CODEC_ID_DVB_TELETEXT:
case AV_CODEC_ID_HDMV_PGS_SUBTITLE:
case AV_CODEC_ID_XSUB:
case AV_CODEC_ID_DVD_SUBTITLE:
break;
default:
return -1;
}

To render subtitles correctly when sub_type is set to bitmap, 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

Running

Tested on NixOS 22.11. Without --cache=no, subtitles does not show up until I seek (Probably because of this issue): #9646

libaribb24 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:

mpv --deinterlace \
--sd-lavc-o-add=sub_type=bitmap \
--sd-lavc-o-add=font='Rounded M+ 1m for ARIB' \
--cache=no \
--sid=1 \
/path/to/video.m2ts

Rendering subtitles with ASS subtitles driver (Requires mpv to be built with -Ddvbin=enabled):

mpv --deinterlace \
--sd-lavc-o=sub_type=ass \
--cache=no \
--sid=1 \
/path/to/video.m2ts

mpv defaults to ASS subtitles if sub_type is not set:

mpv --deinterlace \
--cache=no \
--sid=1 \
/path/to/video.m2ts

sd-lavc-o allows setting libavcodec options to subtitle decoders.
mpv now correctly render subtitles with bitmap subtitles driver
when ARIB caption codec is in use and sd-lavc-o.sub_type is set
to bitmap. Previousonly only ASS subtitles driver was supported
for ARIB captions.
@vroad
Copy link
Author

vroad commented May 1, 2023

I followed @dyphire 's suggestion and updated PR branch, but his comment is gone? 🤔

@dyphire
Copy link
Contributor

dyphire commented May 1, 2023

I followed @dyphire 's suggestion and updated PR branch, but his comment is gone? 🤔

Ah, that's just my personal opinion, and later I thought it would be up to the maintainers to review whether this behavior change was reasonable.

@vroad
Copy link
Author

vroad commented May 1, 2023

@dyphire
I changed my mind, mpv should follow libraries' default as you said.

VLC exposes libaribcaption (and libaribb24?)'s option in easy-to-understand GUI, mpv's GUI/CLI interface does not.
Instead, mpv's CLI interface exposes libaribcaption options directly via sd-lavc-o option. Following ffmpeg's default probably make it easy to understand mpv's behavior for users, I guess.

I removed the code for changing default value for sub_type to bitmap from PR. If everyone thinks that changing default value for sub_type is a good idea, we can do it later with another PR.

@vroad vroad changed the title sd_lavc: Support rendering bitmap subtitles with libaribcaption sd_lavc: support rendering bitmap subtitles with libaribcaption May 2, 2023
@Dudemanguy
Copy link
Member

@vroad: Not sure if you're still interested in this but coincidentally 02a20b4 just added --sub-lavc-o so if you want to pick this up from there that would be appreciated.

@kasper93
Copy link
Contributor

Similar change would be needed for AV_CODEC_ID_DVB_TELETEXT to fix #13471

@kasper93
Copy link
Contributor

Superseded by #13752

I've made it work also for teletext and checked actual context defaults too, not only our options.

@kasper93 kasper93 closed this Mar 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants