Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ package org.jellyfin.androidtv.data.compat
class VideoOptions : AudioOptions() {
var audioStreamIndex: Int? = null
var subtitleStreamIndex: Int? = null
var alwaysBurnInSubtitleWhenTranscoding: Boolean = false
}
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,11 @@ class UserPreferences(context: Context) : SharedPreferenceStore(
*/
var assDirectPlay = booleanPreference("libass_enabled", false)

/**
* Always burn in subtitles when transcoding.
*/
var subtitlesBurnDuringTranscode = booleanPreference("subtitles_burn_during_transcode", false)

/**
* Enable PGS subtitle direct-play.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,23 @@
protected VideoOptions mCurrentOptions;
private int mDefaultAudioIndex = -1;
protected boolean burningSubs = false;

// The server does not update the subtitle delivery method when alwaysBurnInSubtitleWhenTranscoding
// is set, so we need to assume subs are burned in when transcoding with the option enabled.
protected boolean shouldBurnInSubtitles(PlayMethod playMethod) {
Comment thread
nielsvanvelzen marked this conversation as resolved.

Check notice

Code scanning / Android Lint

Unknown nullness Note

Unknown nullability; explicitly declare as @Nullable or @NonNull to improve Kotlin interoperability; see https://developer.android.com/kotlin/interop#nullability_annotations
return userPreferences.getValue().get(UserPreferences.Companion.getSubtitlesBurnDuringTranscode())
&& playMethod == PlayMethod.TRANSCODE;
}

private void updateBurningSubs(StreamInfo response) {
if (response.getSubtitleDeliveryMethod() == SubtitleDeliveryMethod.DROP) {
burningSubs = false;
return;
}

burningSubs = response.getSubtitleDeliveryMethod() == SubtitleDeliveryMethod.ENCODE
|| shouldBurnInSubtitles(response.getPlayMethod());
}
private float mRequestedPlaybackSpeed = -1.0f;

private Runnable mReportLoop;
Expand Down Expand Up @@ -502,6 +519,7 @@
VideoOptions internalOptions = new VideoOptions();
internalOptions.setItemId(item.getId());
internalOptions.setMediaSources(item.getMediaSources());
internalOptions.setAlwaysBurnInSubtitleWhenTranscoding(userPreferences.getValue().get(UserPreferences.Companion.getSubtitlesBurnDuringTranscode()));
if (playbackRetries > 0 || (isLiveTv && !directStreamLiveTv)) internalOptions.setEnableDirectPlay(false);
if (playbackRetries > 1) internalOptions.setEnableDirectStream(false);
if (mCurrentOptions != null) {
Expand Down Expand Up @@ -564,7 +582,7 @@
if (mVideoManager == null)
return;
mCurrentOptions = internalOptions;
if (internalOptions.getSubtitleStreamIndex() == null) burningSubs = internalResponse.getSubtitleDeliveryMethod() == SubtitleDeliveryMethod.ENCODE;
updateBurningSubs(internalResponse);
Comment thread
nielsvanvelzen marked this conversation as resolved.
startItem(item, position, internalResponse);
}

Expand Down Expand Up @@ -995,6 +1013,9 @@
public void onResponse(StreamInfo response) {
if (!isActive()) return;
mCurrentStreamInfo = response;

updateBurningSubs(response);
Comment thread
nielsvanvelzen marked this conversation as resolved.

if (mVideoManager != null) {
mVideoManager.setMediaStreamInfo(api.getValue(), response);
mVideoManager.start();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@ fun PlaybackController.setSubtitleIndex(index: Int, force: Boolean = false) {
return setSubtitleIndex(-1)
}

when (stream.deliveryMethod) {
SubtitleDeliveryMethod.ENCODE -> {
when {
stream.deliveryMethod == SubtitleDeliveryMethod.ENCODE || shouldBurnInSubtitles(currentStreamInfo.playMethod) -> {
Timber.i("Restarting playback for subtitle baking")

stop()
Expand All @@ -109,9 +109,9 @@ fun PlaybackController.setSubtitleIndex(index: Int, force: Boolean = false) {
play(mCurrentPosition, index)
}

SubtitleDeliveryMethod.EXTERNAL,
SubtitleDeliveryMethod.EMBED,
SubtitleDeliveryMethod.HLS -> {
stream.deliveryMethod == SubtitleDeliveryMethod.EXTERNAL ||
stream.deliveryMethod == SubtitleDeliveryMethod.EMBED ||
stream.deliveryMethod == SubtitleDeliveryMethod.HLS -> {
// External subtitles need to be resolved differently
val group = if (stream.deliveryMethod == SubtitleDeliveryMethod.EXTERNAL) {
mVideoManager.mExoPlayer.currentTracks.groups.firstOrNull { group ->
Expand Down Expand Up @@ -155,7 +155,7 @@ fun PlaybackController.setSubtitleIndex(index: Int, force: Boolean = false) {
}
}

SubtitleDeliveryMethod.DROP, null -> {
stream.deliveryMethod == SubtitleDeliveryMethod.DROP || stream.deliveryMethod == null -> {
Timber.i("Dropping subtitles")
setSubtitleIndex(-1)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ class PlaybackManager(
allowVideoStreamCopy = true,
allowAudioStreamCopy = true,
autoOpenLiveStream = true,
alwaysBurnInSubtitleWhenTranscoding = options.alwaysBurnInSubtitleWhenTranscoding,
)
).content
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,17 @@ fun SettingsPlaybackAdvancedScreen() {
)
}

item {
var subtitlesBurnDuringTranscode by rememberPreference(userPreferences, UserPreferences.subtitlesBurnDuringTranscode)

ListButton(
headingContent = { Text(stringResource(R.string.pref_burn_subtitles_when_transcoding)) },
captionContent = { Text(stringResource(R.string.pref_burn_subtitles_when_transcoding_description)) },
trailingContent = { Checkbox(checked = subtitlesBurnDuringTranscode) },
onClick = { subtitlesBurnDuringTranscode = !subtitlesBurnDuringTranscode }
)
}

item { ListSection(headingContent = { Text(stringResource(R.string.pref_live_tv_cat)) }) }

item {
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -542,6 +542,8 @@
<string name="rewind">Rewind</string>
<string name="preference_enable_libass">Enable Advanced SubStation Alpha subtitle client rendering</string>
<string name="preference_enable_pgs">Direct play PGS subtitles</string>
<string name="pref_burn_subtitles_when_transcoding">Burn in subtitles when transcoding</string>
<string name="pref_burn_subtitles_when_transcoding_description">Always burn subtitles into the video during transcoding. This can fix subtitle sync issues but disables subtitle customization.</string>
<string name="speech_error_no_permission">No permission to use the microphone. Please enable it in system settings.</string>
<string name="speech_error_unavailable">Speech recognition is unavailable on your device.</string>
<string name="speech_error_unknown">An unexpected error occurred during speech recognition.</string>
Expand Down
Loading