ExoPlayer icon indicating copy to clipboard operation
ExoPlayer copied to clipboard

Add support for SSA (v4+) MarginL, MarginR, MarginV style

Open szaboa opened this issue 2 years ago • 13 comments

This PR is about adding support for MarginL, MarginR, MarginV from both the Style and Dialogue lines. I've used VLC as reference.

  • Non-zero margins defined in Dialogue lines takes priority over the margins in Style lines.
  • In case we have a {\pos} override, then no margins will be applied neither from Dialogue or Style (same as in VLC).
  • In case we have a {\an} override, then VLC ignores the Dialogue margin but applies the Style margin which makes no sense for me, so in our case I've just ignored both Dialogue and Style margins (same as {\pos} case).

Suggestion: maybe we could update the https://storage.googleapis.com/exoplayer-test-media-1/ssa/test-subs-position.ass subtitle file with these new lines, then no need for a new media in media.exolist.json.

szaboa avatar Apr 09 '22 22:04 szaboa

Suggestion: maybe we could update the https://storage.googleapis.com/exoplayer-test-media-1/ssa/test-subs-position.ass subtitle file with these new lines, then no need for a new media in media.exolist.json.

Yep, sounds good - I'll update the file as part of merging this.

icbaker avatar Apr 13 '22 15:04 icbaker

@icbaker Ready to be reviewed again. :)

szaboa avatar Apr 17 '22 20:04 szaboa

@icbaker Ready to be reviewed again. :)

Thx you, we've missed .ass/ssa support for years... I hope this can be merged soon.

Rootax avatar May 08 '22 16:05 Rootax

@icbaker Ready to be reviewed again. :)

It's a pretty important merge, I hope this can be reviewed soon...

Rootax avatar May 22 '22 19:05 Rootax

Apologies for the delay on this - I'm looking at it now.

I've patched it internally and I'm going to make some changes before sending it for internal review, so please don't upload any more commits here. One thing I'm going to change is reshuffle the logic in SsaDecoder to avoid setting the cue.position and cue.line values without considering the margins, and then changing them later. Instead I plan to just calculate them once, considering the margin values from the beginning (if set). I think this will be easier to reason about.

icbaker avatar Jun 01 '22 09:06 icbaker

Another question: We currently use a default margin value of 5%: https://github.com/google/ExoPlayer/blob/c3866449e248bb7e7fce6c78b51f4960e14a0c91/library/extractor/src/main/java/com/google/android/exoplayer2/text/ssa/SsaDecoder.java#L59

https://github.com/google/ExoPlayer/blob/c3866449e248bb7e7fce6c78b51f4960e14a0c91/library/extractor/src/main/java/com/google/android/exoplayer2/text/ssa/SsaDecoder.java#L462-L474

This value is used if we don't know PlayResX or PlayResX or if the cue doesn't have a position override: https://github.com/google/ExoPlayer/blob/c3866449e248bb7e7fce6c78b51f4960e14a0c91/library/extractor/src/main/java/com/google/android/exoplayer2/text/ssa/SsaDecoder.java#L381-L390

I believe your current implementation still uses this default value as a starting point, and adds any margin from the SSA file on top. This doesn't really seem right (shouldn't we just use the file-specified margin directly?). But equally, removing this default completely would result in a file that doesn't specify a margin at all changing from 'nicely' indented cues to cues that are hard against the edge of the screen. This kinda seems 'correct' too - what do you think?

The other option is that we use the default margin when the file doesn't specify a margin (in neither style nor dialogue line).

icbaker avatar Jun 01 '22 12:06 icbaker

@icbaker

I believe your current implementation still uses this default value as a starting point, and adds any margin from the SSA file on top.

This is right.

If we want to keep strictly to the standard then removing the default margin is the way to go (VLC does the same, if no margin is specified then the subtitle is rendered on the edges). However probably a couple of devs/customers got used to the default margin, so I'd say we can go with this:

The other option is that we use the default margin when the file doesn't specify a margin (in neither style nor dialogue line).

Note that if you decide to remove the default margin in the end, then the unit tests needs to be corrected. :)

szaboa avatar Jun 01 '22 13:06 szaboa

Is this ready to be merged ?

Rootax avatar Jul 18 '22 20:07 Rootax

@icbaker could you please take a look at this

sjiawjbssj avatar Aug 24 '22 03:08 sjiawjbssj

@icbaker what's up with this? should I resolve the conflicts or this is too outdated already? :)

szaboa avatar Sep 05 '23 08:09 szaboa

@szaboa How to fix the problem ? My subtitleView is setApplyEmbeddedFontSizes(false); So can adjust ass text size. If size too large, still overlapping.

https://github.com/google/ExoPlayer/assets/3471963/ee3a4b52-7d6b-4177-999c-078ef0a2a811

FongMi avatar Nov 15 '23 07:11 FongMi

@icbaker what's up with this? should I resolve the conflicts or this is too outdated already? :)

I assume it's worth trying to fix the conflicts since at the very least it'd show implementing this much needed feature that a lot of other apps would immediately profit from wouldn't fail to implement due to lack of developer initiative.

Google certainly feels the need to keep up with media playback needs, that's obvious otherwise they wouldn't have just announced to switch to VideoLAN's AV1 software decoder for devices dating back to Android 12 even.

(they are switching away from their own developed decoder since it didn't reach VideoLAN's efficiency)

GlassedSilver avatar Apr 19 '24 20:04 GlassedSilver