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

Is ffmpeg's bitmap subtitle supported on mpv? #11582

Closed
vroad opened this issue Apr 14, 2023 · 3 comments
Closed

Is ffmpeg's bitmap subtitle supported on mpv? #11582

vroad opened this issue Apr 14, 2023 · 3 comments

Comments

@vroad
Copy link

vroad commented Apr 14, 2023

On mpv running on NixOS (Linux), I want to play Japanese TV broadcasts recorded as MPEG-2 TS files, which contains subtitles in ARIB STD-B24 format.

Recent development version of ffmepg support rendering ARIB STD-B24 subtitles when compiled with libaribcaption library and --enable-libaribcaption option. Applying patches are no longer required on recent version.
Enabling libaribcaption will add those options to ffplay:

aribcaption decoder AVOptions:
  -sub_type          <int>        .D...S..... subtitle rendering type (from 0 to 3) (default ass)
     none            0            .D...S..... do nothing
     bitmap          1            .D...S..... bitmap rendering
     text            2            .D...S..... plain text
     ass             3            .D...S..... formatted text
  -caption_encoding  <int>        .D...S..... encoding scheme of subtitle text (from 0 to 3) (default auto)
     auto            0            .D...S..... automatically detect encoding scheme
     jis             1            .D...S..... 8bit-char JIS encoding (Japanese ISDB captions)
     utf8            2            .D...S..... UTF-8 encoding (Philippines ISDB-T captions)
     latin           3            .D...S..... latin characters (SBTVD / ISDB-Tb captions used in South America)
  -ass_single_rect   <boolean>    .D...S..... workaround of ASS subtitle for players which can't handle multi-rectangle [ass] (default false)
  -font              <string>     .D...S..... comma-separated font family [ass, bitmap]
  -replace_fullwidth_ascii <boolean>    .D...S..... replace MSZ fullwidth alphanumerics with halfwidth alphanumerics [ass, bitmap] (default true)
  -force_outline_text <boolean>    .D...S..... always render characters with outline [(ass), bitmap] (default false)
  -ignore_background <boolean>    .D...S..... ignore rendering caption background [(ass), bitmap] (default false)
  -ignore_ruby       <boolean>    .D...S..... ignore ruby-like characters [ass, bitmap] (default false)
  -outline_width     <float>      .D...S..... outline width of text [(ass), bitmap] (from 0 to 3) (default 1.5)
  -replace_drcs      <boolean>    .D...S..... replace known DRCS [bitmap] (default true)
  -canvas_size       <image_size> .D...S..... set input video size (WxH or abbreviation) [bitmap]

I already confirmed that ffplay can render ARIB STD-B24 subtitles already. I just needed to add -sub_type bitmap to ffplay arguments.

However, I don't know how I can pass sub_type option to mpv. --vd-lavc-o does not work for this case.

AVOption 'sub_type' not found.

By default sub_type is set to ass. On ffplay ASS subtitles do not show up at all.
On mpv, ASS subtitles do show up, however does not look as nice as subtitles rendered with -sub_type bitmap on ffplay: ASS subtitles lack transparent background, font color, gaiji (additional emoji) rendering, etc.
Subtitles rendered with -sub_type bitmap on ffplay look best.

Still, I was able to set sub_type to mpeg by modifying ffmpeg's source code like this:
vroad/FFmpeg@66c8dd7

Now I get log messages like this instad:

 (+) Video --vid=1 (mpeg2video 1440x1080 29.970fps)
 (+) Audio --aid=1 (aac 2ch 48000Hz)
 (+) Subs  --sid=1 (arib_caption)
AV: 00:00:02 / 01:55:00 (0%) A-V:  0.000 Cache: 44s/65MB
[sub/ass] Ignoring bitmap subtitle.
[sub/ass] Ignoring bitmap subtitle.

Does this mean that mpv does not support rendering bitmap subtitles rendered by ffmpeg?
Looks like mpv do nothing even when the AVSubtitle contains bitmap subtitles, even on the latest version. Or am I mssing something?

MP_WARN(priv, "Ignoring bitmap subtitle.\n");

Log file

mpv-log-ignoring-bitmap-subtitle.txt

@sfan5
Copy link
Member

sfan5 commented Apr 14, 2023

Bitmap subtitles go through here:

static int init(struct sd *sd)

@vroad
Copy link
Author

vroad commented Apr 28, 2023

@sfan5 Thanks. After digging it with debugger, I found that I just needed to add single line to sd_lavc.c to show ARIB subtitles (because Supported codecs must be known to decode to paletted bitmaps):

https://github.com/vroad/mpv/blob/4a754c3e87767782bc4748b5d44f5dd725dd5ada/sub/sd_lavc.c#L87

Without this, mpv tries to decode it as ASS subtitle and fail, even if I change ffmpeg's source code to output bitmap subtitles for libaribcaption subtitles by default.

I will ask a separate question for how to implement libaribcaption support properly (without changing ffmpeg source code to change libaribcaption defaults) on mpv.

@vroad vroad closed this as completed Apr 28, 2023
@vroad
Copy link
Author

vroad commented May 1, 2023

I was able to render libaribcaption with bitmap subtitles driver after making some modifications to mpv, and I submitted PR here: #11648

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants