Skip to content

Commit e23b54c

Browse files
JustAManTheOneric
andcommitted
Add dropAllAnimations feature
Original implementation by JustAMan, mostly in the following three commits sans unrelated changes. Backported by Oneric. jellyfin@d3bc472 jellyfin@a66e797 jellyfin@971a997 The commits have also been adjusted to apply on top of current upstream master, to use the animations detection from the previous commit instead of the faulty original logic and the scanned_events variable was added. Also added documentation which was missing in the original commits. Co-authored-by: Oneric <oneric@oneric.stub>
1 parent f57da58 commit e23b54c

File tree

5 files changed

+38
-1
lines changed

5 files changed

+38
-1
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,12 @@ When creating an instance of SubtitleOctopus, you can set the following options:
140140
- `maxRenderHeight`: The maximum rendering height of the subtitles canvas.
141141
Beyond this subtitles will be upscaled by the browser.
142142
(Default: `0` - no limit)
143+
- `dropAllAnimations`: If set to true, attempt to discard all animated tags.
144+
Enabling this may severly mangle complex subtitles and
145+
should only be considered as an last ditch effort of uncertain success
146+
for hardware otherwise incapable of displaing anything.
147+
Will not reliably work with manually edited or allocated events.
148+
(Default: `false` - do nothing)
143149

144150
### Rendering Modes
145151
#### JS Blending

src/SubtitleOctopus.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,8 @@ class SubtitleOctopus {
228228
private:
229229
ReusableBuffer2D m_blend;
230230
RenderBlendResult m_blendResult;
231+
bool drop_animations;
232+
int scanned_events; // next unscanned event index
231233
public:
232234
ASS_Library* ass_library;
233235
ASS_Renderer* ass_renderer;
@@ -245,12 +247,34 @@ class SubtitleOctopus {
245247
track = NULL;
246248
canvas_w = 0;
247249
canvas_h = 0;
250+
drop_animations = false;
251+
scanned_events = 0;
248252
}
249253

250254
void setLogLevel(int level) {
251255
log_level = level;
252256
}
253257

258+
void setDropAnimations(int value) {
259+
drop_animations = !!value;
260+
if (drop_animations)
261+
scanAnimations(scanned_events);
262+
}
263+
264+
/*
265+
* \brief Scan events starting at index i for animations
266+
* and discard animated tags when found.
267+
* Note that once animated tags were dropped they cannot be restored.
268+
* Updates the class memeber scanned_events to last scanned index.
269+
*/
270+
void scanAnimations(int i) {
271+
ASS_Event *cur = track->events;
272+
for (; i < track->n_events; i++) {
273+
_is_event_animated(track->events + i, drop_animations);
274+
}
275+
scanned_events = i;
276+
}
277+
254278
void initLibrary(int frame_w, int frame_h) {
255279
ass_library = ass_library_init();
256280
if (!ass_library) {
@@ -280,6 +304,7 @@ class SubtitleOctopus {
280304
fprintf(stderr, "jso: Failed to start a track\n");
281305
exit(4);
282306
}
307+
scanAnimations(0);
283308
}
284309

285310
void createTrackMem(char *buf, unsigned long bufsize) {
@@ -289,6 +314,7 @@ class SubtitleOctopus {
289314
fprintf(stderr, "jso: Failed to start a track\n");
290315
exit(4);
291316
}
317+
scanAnimations(0);
292318
}
293319

294320
void removeTrack() {

src/post-worker.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ self.nextIsRaf = false;
88
self.lastCurrentTimeReceivedAt = Date.now();
99
self.targetFps = 24;
1010
self.libassMemoryLimit = 0; // in MiB
11+
self.dropAllAnimations = false;
1112

1213
self.width = 0;
1314
self.height = 0;
@@ -565,6 +566,7 @@ function onMessageFromMainEmscriptenThread(message) {
565566
self.targetFps = message.data.targetFps || self.targetFps;
566567
self.libassMemoryLimit = message.data.libassMemoryLimit || self.libassMemoryLimit;
567568
self.libassGlyphLimit = message.data.libassGlyphLimit || 0;
569+
self.dropAllAnimations = !!message.data.dropAllAnimations || self.dropAllAnimations;
568570
removeRunDependency('worker-init');
569571
postMessage({
570572
target: "ready",

src/pre-worker.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ Module['onRuntimeInitialized'] = function () {
108108
self.blendH = Module._malloc(4);
109109

110110
self.octObj.initLibrary(screen.width, screen.height);
111+
self.octObj.setDropAnimations(self.dropAllAnimations);
111112
self.octObj.createTrack("/sub.ass");
112113
self.ass_track = self.octObj.track;
113114
self.ass_library = self.octObj.ass_library;

src/subtitles-octopus.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ var SubtitlesOctopus = function (options) {
2020
self.prescaleFactor = options.prescaleFactor || 1.0;
2121
self.prescaleHeightLimit = options.prescaleHeightLimit || 1080;
2222
self.maxRenderHeight = options.maxRenderHeight || 0; // 0 - no limit
23+
self.dropAllAnimations = options.dropAllAnimations || false; // attempt to remove all animations as a last ditch effort for displaying on weak hardware; may severly mangle subtitles if enabled
2324
self.isOurCanvas = false; // (internal) we created canvas and manage it
2425
self.video = options.video; // HTML video element (optional if canvas specified)
2526
self.canvasParent = null; // (internal) HTML canvas parent element
@@ -113,7 +114,8 @@ var SubtitlesOctopus = function (options) {
113114
debug: self.debug,
114115
targetFps: self.targetFps,
115116
libassMemoryLimit: self.libassMemoryLimit,
116-
libassGlyphLimit: self.libassGlyphLimit
117+
libassGlyphLimit: self.libassGlyphLimit,
118+
dropAllAnimations: self.dropAllAnimations
117119
});
118120
};
119121

0 commit comments

Comments
 (0)