ExoPlayer
ExoPlayer copied to clipboard
Add support for SSA (v4+) MarginL, MarginR, MarginV style
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 inStyle
lines. - In case we have a
{\pos}
override, then no margins will be applied neither fromDialogue
orStyle
(same as in VLC). - In case we have a
{\an}
override, then VLC ignores theDialogue
margin but applies theStyle
margin which makes no sense for me, so in our case I've just ignored bothDialogue
andStyle
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
.
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 inmedia.exolist.json
.
Yep, sounds good - I'll update the file as part of merging this.
@icbaker Ready to be reviewed again. :)
@icbaker Ready to be reviewed again. :)
Thx you, we've missed .ass/ssa support for years... I hope this can be merged soon.
@icbaker Ready to be reviewed again. :)
It's a pretty important merge, I hope this can be reviewed soon...
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.
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
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. :)
Is this ready to be merged ?
@icbaker could you please take a look at this
@icbaker what's up with this? should I resolve the conflicts or this is too outdated already? :)
@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
@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)