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

Change subtitle renderer from Roku embedded to a custom task #982

Merged
merged 18 commits into from
Feb 21, 2023

Conversation

jkim2492
Copy link
Contributor

@jkim2492 jkim2492 commented Jan 27, 2023

Changes

Add an option to disable Roku's global captions and use custom captions renderer for CJK fonts
Issues

Related to issue #514

Crude subtitle renderer piggybacking on the JFVideo component
@sevenrats
Copy link
Member

sevenrats commented Jan 27, 2023

This is very cool but you have to download the fonts from somewhere at runtime. Roku will not publish any app over 4 mb.
sorry, it's clear from context you already know this.

@1hitsong
Copy link
Member

We should honor a user's closed captioning styles as set in the Roku global captionStyle: https://developer.roku.com/docs/references/scenegraph/media-playback-nodes/video.md#closed-caption-fields

@1hitsong
Copy link
Member

We can't include the font files, just 1 of them is larger than our max allowed app size.

But, the API does provide us a method to transfer fonts from the server over to the client and store them in a temp folder.

https://api.jellyfin.org/#tag/Subtitle/operation/GetFallbackFont

@1hitsong 1hitsong added the enhancement New feature or request label Jan 27, 2023
@1hitsong
Copy link
Member

That's all my notes for the first pass. Very cool enhancement!

JFVideo updates playerState for captionTask

Moved pkg:/fonts to pkg:/components/fonts
@jkim2492
Copy link
Contributor Author

We can't include the font files, just 1 of them is larger than our max allowed app size.

But, the API does provide us a method to transfer fonts from the server over to the client and store them in a temp folder.

https://api.jellyfin.org/#tag/Subtitle/operation/GetFallbackFont

This is great! I had considered downloading it from the web on boot but this would be more bandwidth friendly

@jkim2492

This comment was marked as resolved.

@sevenrats
Copy link
Member

Is it possible to change the position of the labels? If so, it would be nice to eventually extend this for full ssa/ass support as well.

@jkim2492
Copy link
Contributor Author

jkim2492 commented Jan 28, 2023 via email

@Lorde627
Copy link

We stan!

jkim2492 and others added 2 commits January 29, 2023 19:52
The project should validate now
Now it downloads from the fallback folder if available. Defaults to LargeBoldSystemFont. Subtitles are displayed with an outline instead of a background rectangle

TODO : take captionstyle into account
@jkim2492 jkim2492 requested a review from 1hitsong February 1, 2023 01:32
@1hitsong
Copy link
Member

1hitsong commented Feb 2, 2023

I selected a movie and within Roku settings enabled subtitles. It turned on the original subtitles, not the new ones.

@1hitsong
Copy link
Member

1hitsong commented Feb 2, 2023

When both global subtitles and new subtitles are enabled, they overlap.

image

@1hitsong
Copy link
Member

1hitsong commented Feb 2, 2023

We should clear the displayed subtitle when the track changes. When I changed tracks it kept the original one until it updated several seconds later.

Disable Roku subtitles on subtitle load

Subtitles are cleared as soon as subtitle track changes
Subtitle now follows Roku config

Subtitle now updates immediately when changing languages
@jkim2492
Copy link
Contributor Author

jkim2492 commented Feb 2, 2023

We should clear the displayed subtitle when the track changes. When I changed tracks it kept the original one until it updated several seconds later.

The subtitles should clear instantly now. Subtitle visibility will now follow Roku's settings and will not overlap i.e. if Roku settings is always on, it will be always on

@Lorde627
Copy link

Lorde627 commented Feb 2, 2023

Merge! Merge! Merge!

@1hitsong
Copy link
Member

1hitsong commented Feb 2, 2023

Do you mind changing the name of your feature branch? It's causing git to act very funky due to your feature branch also being named unstable.

@1hitsong
Copy link
Member

1hitsong commented Feb 2, 2023

Play movie, subtitles showing
Press Back
Play movie again, no subtitles

Console error: *** ERROR: Missing or invalid PHY: 'noto.otf'

After several seconds, subtitles show

@1hitsong
Copy link
Member

1hitsong commented Feb 2, 2023

If you click on a movie you've already watched part of and from the resume popup select Resume from %time% the subtitles start from the beginning and not from the resume point.

@jkim2492 jkim2492 deleted the branch jellyfin:unstable February 3, 2023 00:23
@jkim2492
Copy link
Contributor Author

jkim2492 commented Feb 8, 2023

What if we drop use of background color and opacity and instead support window color and opacity?

That would mean we support the rectangle "window" around the lines of text, and the text itself. The Background settings, which are an odd background-within-a-background setting to begin with, we ignore.

Perhaps we can implement both : window settings for the rectangle and background settings for the outline (or vice versa)

@1hitsong
Copy link
Member

1hitsong commented Feb 8, 2023

I suppose it's worth a shot, but at least on my Roku, that text outline looks bad.

@jkim2492
Copy link
Contributor Author

jkim2492 commented Feb 8, 2023 via email

Remove text outline
Add background rectangle
@jkim2492
Copy link
Contributor Author

We are using background rectangles instead of outlines now. They can be adjusted with Background/* settings

@jkim2492 jkim2492 requested a review from 1hitsong February 10, 2023 17:21
@1hitsong
Copy link
Member

Is the expectation for this PR that this only work for external subtitle files, or should this work for subtitles that are part of the video file as well?

I ask because it works for my videos with external files, but the files with encoded subtitles get the "old" build-in subtitle render that don't support the CJK font.

@jkim2492
Copy link
Contributor Author

Is the expectation for this PR that this only work for external subtitle files, or should this work for subtitles that are part of the video file as well?

I ask because it works for my videos with external files, but the files with encoded subtitles get the "old" build-in subtitle render that don't support the CJK font.

The intent was to make it for external files only but we can probably handle encoded ones in a separate PR later!

@1hitsong
Copy link
Member

we can probably handle encoded ones in a separate PR later!

Excellent. Cuts my testing in half!

I hope to have functional testing completed tonight and will do a code review pass after that.

@1hitsong
Copy link
Member

Functionality works great! Here are some updates we need to make for users.

  1. The fallback font API endpoint will always return any fonts, even if fallback fonts are disabled. We should only grab a fallback font if fallback fonts are enabled on the server

image

  1. This is an awesome update, but there WILL be people who complain we're not using the Roku default function. Can you add a user setting that allows users to opt-in to use custom subtitle functionality instead of default?


sub toggleCaption()
m.captionTask.playerState = m.top.state + m.top.globalCaptionMode
if m.top.globalCaptionMode = "On"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if m.top.globalCaptionMode = "On"
if LCase(m.top.globalCaptionMode) = "on"

String comparisons should always force a case.

end sub

sub updateCaption ()
while m.captionGroup.removeChildIndex(0)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of using a while loop to remove all the children, could we use the removechildrenindex function?

m.captionGroup.removeChildrenIndex(m.captionGroup.getChildCount(), 0)

if m.top.content.contenttype <> 4
m.top.unobserveField("position")
end if
' if m.top.content.contenttype <> 4
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Commented out code should just be removed

m.showNextEpisodeButtonAnimation.control = "start"
m.nextEpisodeButton.setFocus(true)
m.nextEpisodeButton.visible = true
if m.top.content.contenttype = 4
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of nesting this clause, let's just escape early.

At the top of showNextEpisodeButton() do if m.top.content.contenttype <> 4 then return

updateCount()
return
end if
if m.top.content.contenttype = 4
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above. Let's exit early.

if m.top.content.contenttype <> 4 then return

end if
end sub

function newlabel(txt):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
function newlabel(txt):
function newlabel(txt)


sub updateCaption ()
m.top.currentCaption = []
if m.top.playerState = "playingOn"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if m.top.playerState = "playingOn"
if LCase(m.top.playerState) = "playingon"

String comparisons should force case

lines = newLayoutGroup(labels)
rect = newRect(lines)
m.top.currentCaption = [rect, lines]
else if right(m.top.playerState, 4) = "Wait"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
else if right(m.top.playerState, 4) = "Wait"
else if LCase(right(m.top.playerState, 4)) = "wait"

@@ -87,6 +86,8 @@ function setupSubtitle(video, subtitles, subtitle_idx = -1) as integer

if selectedSubtitle.IsEncoded
' With encoded subtitles, turn off captions
?"Check2"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Debug code

@@ -177,6 +178,7 @@ sub turnoffSubtitles()
video = m.scene.focusedChild.focusedChild
current = video.SelectedSubtitle
video.SelectedSubtitle = -1
?"Check3"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Debug code

Custom subtitles can be enabled via * > Settings > Playback > Use Custom Subtitles

Fallback font downloaded only if it is enabled in system settings

Cleaned up various code
@jkim2492
Copy link
Contributor Author

Functionality works great! Here are some updates we need to make for users.

  1. The fallback font API endpoint will always return any fonts, even if fallback fonts are disabled. We should only grab a fallback font if fallback fonts are enabled on the server

image

  1. This is an awesome update, but there WILL be people who complain we're not using the Roku default function. Can you add a user setting that allows users to opt-in to use custom subtitle functionality instead of default?

This and all of the change requests should be fixed now. Hope there aren't new bugs!

@jkim2492 jkim2492 requested a review from 1hitsong February 19, 2023 18:34
@jkim2492 jkim2492 requested a review from 1hitsong February 20, 2023 22:40
@1hitsong
Copy link
Member

1hitsong commented Feb 21, 2023

@jkim2492 Double check the translations file. Github shows the entire file as modified.

42d3e5d#diff-0c39691ce17a12d65440b15c63dc5f7c12b526d1a105e0c99f568a5e9c2313bc

Added en-US translations for custom subtitle option
@jkim2492
Copy link
Contributor Author

@1hitsong Seems the line endings had changed for some reason. It should correctly show diffs now

@1hitsong
Copy link
Member

@jkim2492 Approved. Can you resolve the merge conflicts?

@jkim2492
Copy link
Contributor Author

@1hitsong Yup it should be good now

@1hitsong 1hitsong merged commit d10556e into jellyfin:unstable Feb 21, 2023
@1hitsong
Copy link
Member

Merged. For the follow up, please use a different name for the branch 😉

@depctg
Copy link

depctg commented Mar 3, 2023

Is it possible to change the position of the labels? If so, it would be nice to eventually extend this for full ssa/ass support as well.

As a follow up simple ass support is implemented in #1075

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants