Liquid Glass and Apple Music touches for the Spotify iOS app. A GPL-3.0 fork of spoti.pw 0.21.1.
C
fix: lyrics over moving artwork falls back to the right look
My-Name-Is-Jeff153397469524
diff --git a/docs/tweaks.md b/docs/tweaks.mdindex 5c4a624c..bec2cfe2 100644--- a/docs/tweaks.md+++ b/docs/tweaks.md@@ -160,10 +160,15 @@ Shared:rows behind the words are blurred (Accelerate's tent blur) and faded in, every row of the cut isdarkened in one pass (0.25, and 0.6 across the words), and the words with a tight dark shadow aredrawn on; the encoder cuts the 3:4 middle as SGMotionClip.m does, so nothing is scaled on the CPU.- The IDs end in m and a tag of the file, so the clip arriving, or a Canvas after an animated cover,- re-offers the line showing. Until it comes, and for a track- with no moving artwork or one that will not read (a turned video), the lines are drawn as Lyrics- draws them, in the chosen style. Rendered on the Mac against harness/lyrics-clip/ (`motion`, over a+ The IDs end in the style and, over moving artwork, m and the first 16 characters of the file's name+ (SGLyricsClipLook), so the clip arriving, a Canvas after an animated cover, or a change of style+ re-offers the line showing. Until it comes, and for a track with no moving artwork, the lines are drawn+ as Lyrics draws them, in the chosen style; so are they over a video that will not draw (turned, its+ frames another size than it states, as a video with non-square pixels has, cut short or gone from the+ store), which is remembered for the launch and tried again only when handed over again. A track with+ no synced lines, or whose lines are not in yet, shows its moving artwork plain, as Moving artwork does:+ LyricsArtwork.x says so (SGLockMotionShowPlain) and LockScreenMotion.x shows it and takes it off for+ the lyrics' clips. Rendered on the Mac against harness/lyrics-clip/ (`motion`, over abright busy, a dark and any given videos). What reaches thesystem's now playing through this hook and Player/NowPlayingExtras.x is checked by harness/now-playing/AnimatedArtwork/ moving artwork (AnimatedArtwork.h): the track's Canvas, else Apple Music's animated album coverdiff --git a/harness/lyrics-clip/README.md b/harness/lyrics-clip/README.mdindex a992c181..cee81e12 100644--- a/harness/lyrics-clip/README.md+++ b/harness/lyrics-clip/README.md@@ -18,7 +18,10 @@ Apple Music cover's), and over any videos given: a line with the one before andstretch round the video's end, one longer than the video (written whole), a break and no words. Each isread back and checked: length, the 3:4 cut's size, H.264, frames at up to 30 fps, words in the middle andnothing white under the clock or the controls, the picture moving, and the preview the same as the first-frame. It prints each clip's time a frame against the video cut alone (`SGMotionClipShape`) and the+frame. A video whose frames decode at another size than it states (non-square pixels, made with ffmpeg's+`setsar=4/3`) must not be written and give no preview, so the line falls back to the cover; so must a video+that is gone or cut short. It also checks the artwork ID's ending (`SGLyricsClipLook`): another style or+another video gives another one. It prints each clip's time a frame against the video cut alone (`SGMotionClipShape`) and theAnimated lyrics clip, the contrast of the words with the brightest of the picture behind them, and thememory used.diff --git a/harness/lyrics-clip/motion.m b/harness/lyrics-clip/motion.mindex 2162386c..4ca775d8 100644--- a/harness/lyrics-clip/motion.m+++ b/harness/lyrics-clip/motion.m@@ -250,6 +250,36 @@ int motionMain(NSURL *out, int argc, char **argv) {NSMutableArray<NSURL *> *videos = [NSMutableArray array];NSURL *flag = [out URLByAppendingPathComponent:@"source-flag.mp4"], *dark = [out URLByAppendingPathComponent:@"source-dark.mp4"];check(makeVideo(flag, 720, 1280, 30, 6, drawFlag), @"made the bright stand-in, 720x1280, 30 fps, 6 s");++ // The end of the artwork ID (LyricsArtwork.x): a style change or another video gives another ID, so no clip is+ // kept past either; two store names that share their first four characters still differ.+ printf("artwork IDs\n");+ NSURL *a = [NSURL fileURLWithPath:@"/c/Motion/3f9a0c11d2e4b5a6978877665544332211009988.mp4"];+ NSURL *b = [NSURL fileURLWithPath:@"/c/Motion/3f9a77aa00bb11cc22dd33ee44ff556677889900.mp4"];+ check(![SGLyricsClipLook(a, SGLyricsClipStill) isEqual:SGLyricsClipLook(a, SGLyricsClipAnimated)],+ [NSString stringWithFormat:@"the style is in it over moving artwork (%@, %@)", SGLyricsClipLook(a, SGLyricsClipStill),+ SGLyricsClipLook(a, SGLyricsClipAnimated)]);+ check(![SGLyricsClipLook(a, SGLyricsClipStill) isEqual:SGLyricsClipLook(b, SGLyricsClipStill)], @"another video gives another one");+ check([SGLyricsClipLook(a, SGLyricsClipStill) isEqual:SGLyricsClipLook([a copy], SGLyricsClipStill)], @"the same video and style give the same one");+ check(![SGLyricsClipLook(nil, SGLyricsClipStill) isEqual:SGLyricsClipLook(a, SGLyricsClipStill)]+ && ![SGLyricsClipLook(nil, SGLyricsClipStill) isEqual:SGLyricsClipLook(nil, SGLyricsClipAnimated)], @"over the cover, the style alone");++ // A video gone from the store or cut short fails at once, with no preview, for LyricsArtwork.x to remember.+ printf("videos that will not read\n");+ NSURL *gone = [out URLByAppendingPathComponent:@"gone.mp4"], *cutShort = [out URLByAppendingPathComponent:@"cut-short.mp4"];+ [NSFileManager.defaultManager removeItemAtURL:gone error:nil];+ NSData *whole = [NSData dataWithContentsOfURL:flag];+ [[whole subdataWithRange:NSMakeRange(0, whole.length / 3)] writeToURL:cutShort atomically:YES];+ for (NSURL *bad in @[gone, cutShort]) {+ NSURL *clip = [out URLByAppendingPathComponent:[@"from-" stringByAppendingString:bad.lastPathComponent]];+ CFAbsoluteTime started = CFAbsoluteTimeGetCurrent();+ BOOL written = SGLyricsClipWriteOverMotion(clip, bad, nil, @"A line", @"the next", 1, 3);+ double ms = (CFAbsoluteTimeGetCurrent() - started) * 1000;+ CGImageRef preview = SGLyricsClipMotionFrame(bad, nil, @"A line", @"the next", 1);+ check(!written && !preview && ![NSFileManager.defaultManager fileExistsAtPath:clip.path],+ [NSString stringWithFormat:@"%@: not written (in %.0f ms) and no preview", bad.lastPathComponent, ms]);+ CGImageRelease(preview);+ }check(makeVideo(dark, 904, 1206, 24, 8, drawDark), @"made the dark stand-in, 904x1206, 24 fps, 8 s");[videos addObjectsFromArray:@[flag, dark]];for (int i = 0; i < argc; i++) [videos addObject:[NSURL fileURLWithPath:[NSString stringWithUTF8String:argv[i]]]];@@ -279,6 +309,26 @@ int motionMain(NSURL *out, int argc, char **argv) {CGSize cut = SGMotionClipCut(track.naturalSize, 0.75);printf("\n%s: %.0fx%.0f, %.2f s at %.0f fps, cut to %.0fx%.0f\n", name.UTF8String, track.naturalSize.width, track.naturalSize.height,length, fps, cut.width, cut.height);+ // drawOver refuses a decoded frame of another size than the track states, and the clip is then not written,+ // so LyricsArtwork.x draws the line over the cover. A video with non-square pixels does that: its natural size+ // is the shown one (960x1280 for 720x1280 at 4:3), its frames the stored one.+ BOOL matches;+ {+ AVAssetReader *reader = [AVAssetReader assetReaderWithAsset:asset error:nil];+ AVAssetReaderTrackOutput *output = [AVAssetReaderTrackOutput assetReaderTrackOutputWithTrack:track+ outputSettings:@{(id)kCVPixelBufferPixelFormatTypeKey: @(kCVPixelFormatType_32BGRA)}];+ [reader addOutput:output];+ [reader startReading];+ CMSampleBufferRef sample = [output copyNextSampleBuffer];+ CVPixelBufferRef buffer = sample ? CMSampleBufferGetImageBuffer(sample) : NULL;+ size_t w = buffer ? CVPixelBufferGetWidth(buffer) : 0, h = buffer ? CVPixelBufferGetHeight(buffer) : 0;+ matches = w == (size_t)round(track.naturalSize.width) && h == (size_t)round(track.naturalSize.height);+ printf(" %s\n", [NSString stringWithFormat:@"%@ at its natural size (%.3fx%.3f, frames %zux%zu, %zu bytes a row)",+ matches ? @"decodes" : @"does NOT decode", track.naturalSize.width, track.naturalSize.height, w, h,+ buffer ? CVPixelBufferGetBytesPerRow(buffer) : 0].UTF8String);+ if (sample) CFRelease(sample);+ [reader cancelReading];+ }// The video cut alone, the decode and encode with nothing drawn, to tell the drawing's share.start = CFAbsoluteTimeGetCurrent();SGMotionClipShape(video, 0.75, [out URLByAppendingPathComponent:[name stringByAppendingString:@"-cut.mp4"]]);@@ -290,6 +340,13 @@ int motionMain(NSURL *out, int argc, char **argv) {NSURL *url = [out URLByAppendingPathComponent:[NSString stringWithFormat:@"%@-%@.mp4", name, c[0]]];start = CFAbsoluteTimeGetCurrent();BOOL written = SGLyricsClipWriteOverMotion(url, video, c[1], c[2], c[3], from, seconds);+ if (!matches) {+ CGImageRef preview = SGLyricsClipMotionFrame(video, c[1], c[2], c[3], from);+ check(!written && !preview && ![NSFileManager.defaultManager fileExistsAtPath:url.path],+ @"not written and no preview, so the line falls back to the cover rather than showing without its words");+ CGImageRelease(preview);+ continue;+ }double ms = (CFAbsoluteTimeGetCurrent() - start) * 1000;printf(" footprint after writing %.1f MB\n", footprintMB(NO));printf(" %s\n", url.lastPathComponent.UTF8String);diff --git a/tweak/Sources/Shared/AnimatedArtwork/AnimatedArtwork.h b/tweak/Sources/Shared/AnimatedArtwork/AnimatedArtwork.hindex 2a39f447..9978c41c 100644--- a/tweak/Sources/Shared/AnimatedArtwork/AnimatedArtwork.h+++ b/tweak/Sources/Shared/AnimatedArtwork/AnimatedArtwork.h@@ -19,6 +19,10 @@ typedef NS_ENUM(NSInteger, SGLockArtwork) {};// Off below iOS 26, which has no animated artwork on the lock screen.SGLockArtwork SGLockScreenArtwork(void);+// Under Moving artwork with lyrics, LyricsArtwork.x says whether the playing track has no synced lines (YES), so+// LockScreenMotion.x shows its moving artwork plain, as Moving artwork does, or has them (NO), so it takes it off+// for the lyrics' clips. Main queue.+void SGLockMotionShowPlain(BOOL plain);static inline BOOL SGLockArtworkShowsLyrics(SGLockArtwork artwork) {return artwork == SGLockArtworkLyrics || artwork == SGLockArtworkMotionLyrics;}diff --git a/tweak/Sources/Shared/AnimatedArtwork/LockScreenMotion.x b/tweak/Sources/Shared/AnimatedArtwork/LockScreenMotion.xindex 79903110..ae03c16a 100644--- a/tweak/Sources/Shared/AnimatedArtwork/LockScreenMotion.x+++ b/tweak/Sources/Shared/AnimatedArtwork/LockScreenMotion.x@@ -103,6 +103,24 @@ static void show(NSURL *file) {});}+// Under Moving artwork with lyrics: the clip found for the track, and whether LyricsArtwork.x asked for it+// plain (the track has no synced lines) and it shows so.+static NSURL *sg_lyricsFile;+static BOOL sg_plain, sg_plainShown;++void SGLockMotionShowPlain(BOOL plain) {+ if (@available(iOS 26.0, *)) {+ sg_plain = plain;+ BOOL want = plain && sg_choice == SGLockArtworkMotionLyrics && sg_lyricsFile;+ if (want == sg_plainShown) return;+ sg_plainShown = want;+ if (want) show(sg_lyricsFile);+ else SGNowPlayingSetExtras(@"motion", nil, nil);+ SGLog(@"lock motion: %@", want ? [NSString stringWithFormat:@"%@ shown plain, the track has no synced lines", sg_lyricsFile.lastPathComponent]+ : @"the plain clip taken off for the lyrics");+ }+}+// The cover Spotify handed the system for `title`, read on the main thread as LyricsArtwork.x reads it,// then `then` on sg_queue with it, or with NULL when the info is another song's or has none.static void withCover(NSString *title, void (^then)(CGImageRef cover)) {@@ -160,6 +178,8 @@ static void showCover(NSString *picture) {sg_follower = [[SGMotionFollower alloc] initWithBegin:^BOOL(NSString *uri, SPTPlayerState *state) {sg_walk++;SGNowPlayingSetExtras(@"motion", nil, nil);+ sg_lyricsFile = nil;+ sg_plainShown = NO;NSDictionary *metadata = [state.track.metadata isKindOfClass:NSDictionary.class] ? state.track.metadata : nil;sg_title = state.track.trackTitle;sg_picture = pictureOf(state.track, metadata);@@ -169,6 +189,9 @@ static void showCover(NSString *picture) {// Under the lyrics instead, and never as this file's extra too: both would fill the same 3:4 key.if (sg_choice == SGLockArtworkMotionLyrics) {if (file) SGLyricsArtworkSetMotion(uri, file);+ // A track with no synced lines shows it plain, as Moving artwork would; LyricsArtwork.x says which.+ sg_lyricsFile = file;+ SGLockMotionShowPlain(sg_plain);SGLog(@"lock motion: %@ for the lyrics of %@", file ? file.lastPathComponent : @"no clip", uri);} else if (file) show(file);else if (sg_choice == SGLockArtworkEverySong) showCover(sg_picture);diff --git a/tweak/Sources/Shared/LockScreenLyrics/LyricsArtwork.x b/tweak/Sources/Shared/LockScreenLyrics/LyricsArtwork.xindex d2900a0d..73e6012d 100644--- a/tweak/Sources/Shared/LockScreenLyrics/LyricsArtwork.x+++ b/tweak/Sources/Shared/LockScreenLyrics/LyricsArtwork.x@@ -41,6 +41,24 @@ static const double kShortest = 2, kLongest = 8;static dispatch_source_t sg_timer;static NSString *sg_motionURI; // the track the moving artwork is for, and its file (SGLyricsArtworkSetMotion)static NSURL *sg_motion;+// Paths of moving artwork that would not draw (turned, its frames another size than it states, cut short, or+// gone from the store), so each line goes straight to the cover; a file handed over again is tried again. Read+// on main and both queues, so only under its own lock.+static NSMutableSet<NSString *> *sg_failedMotion;++static BOOL motionFailed(NSURL *file) {+ @synchronized (sg_failedMotion) {+ return [sg_failedMotion containsObject:file.path];+ }+}++static void markMotionFailed(NSURL *file, NSString *artworkID) {+ @synchronized (sg_failedMotion) {+ if ([sg_failedMotion containsObject:file.path]) return;+ [sg_failedMotion addObject:file.path];+ }+ SGLog(@"lock lyrics: %@ would not draw for %@, the lines go over the cover for it", file.lastPathComponent, artworkID);+}static NSString *sg_track; // the track the clips are forstatic UIImage *sg_cover; // its cover, once Spotify's now playing info has one for itstatic NSString *sg_shownID; // the artwork handed over last, nil for none; read on sg_queue too@@ -98,7 +116,9 @@ static NSURL *clipFile(NSString *artworkID) {static UIImage *previewFor(NSString *artworkID, SGLockLine *line, CGSize size) {UIImage *preview = [sg_previews objectForKey:artworkID];if (preview) return preview;- CGImageRef frame = line.motion ? SGLyricsClipMotionFrame(line.motion, line.previous, line.line, line.next, line.from) : NULL;+ BOOL tryMotion = line.motion && !motionFailed(line.motion);+ CGImageRef frame = tryMotion ? SGLyricsClipMotionFrame(line.motion, line.previous, line.line, line.next, line.from) : NULL;+ if (tryMotion && !frame) markMotionFailed(line.motion, artworkID);if (!frame) {CGImageRef backdrop = copyBackdropFor(line.cover, size);frame = SGLyricsClipFrame(backdrop, line.line, line.next, size);@@ -115,10 +135,11 @@ static BOOL writeClip(NSString *artworkID, SGLockLine *line, CGSize size) {NSURL *file = clipFile(artworkID);if ([NSFileManager.defaultManager fileExistsAtPath:file.path]) return YES;CFAbsoluteTime start = CFAbsoluteTimeGetCurrent();- BOOL over = line.motion && SGLyricsClipWriteOverMotion(file, line.motion, line.previous, line.line, line.next, line.from, line.seconds);+ BOOL tryMotion = line.motion && !motionFailed(line.motion);+ BOOL over = tryMotion && SGLyricsClipWriteOverMotion(file, line.motion, line.previous, line.line, line.next, line.from, line.seconds);+ if (tryMotion && !over) markMotionFailed(line.motion, artworkID);BOOL ok = over;if (!ok) {- if (line.motion) SGLog(@"lock lyrics: %@ could not be drawn over %@, drawn over the cover", artworkID, line.motion.lastPathComponent);CGImageRef backdrop = copyBackdropFor(line.cover, size);ok = SGLyricsClipWrite(file, backdrop, line.line, line.next, size, line.style);CGImageRelease(backdrop);@@ -183,6 +204,9 @@ static NSString *textAt(NSArray<SGKaraokeLine *> *lines, NSInteger index) {}void SGLyricsArtworkSetMotion(NSString *uri, NSURL *file) {+ @synchronized (sg_failedMotion) {+ if (file) [sg_failedMotion removeObject:file.path];+ }sg_motionURI = uri;sg_motion = file;}@@ -225,14 +249,16 @@ static void tick(void) {}NSArray<SGKaraokeLine *> *lines = SGKaraokeLinesForTrack(trackID);if (!lines) SGKaraokeRequestLyrics(trackID);- // Plain text has no line being sung; the lock screen keeps the cover.+ // Plain text has no line being sung, nor has a song whose lines are not in yet: the lock screen keeps the cover,+ // or under Moving artwork with lyrics shows the moving artwork plain (LockScreenMotion.x, which has it).if (!lines.count || SGKaraokeLinesTiming(lines) == SGKaraokeTimingNone) {static NSString *told;if (lines && ![told isEqualToString:trackID]) {told = trackID;- SGLog(@"lock lyrics: %@ has no synced lines, the lock screen keeps the cover", trackID);+ SGLog(@"lock lyrics: %@ has no synced lines, the lock screen keeps the cover or the moving artwork", trackID);}clear();+ SGLockMotionShowPlain(YES);return;}NSInteger position = SGKaraokePositionMs();@@ -244,10 +270,8 @@ static void tick(void) {SGLyricsClipStyle style = (SGLyricsClipStyle)SGInt(SGKeyLockScreenLyricsStyle, SGLyricsClipStill);NSURL *motion = SGLockScreenArtwork() == SGLockArtworkMotionLyrics && [sg_motionURI isEqualToString:SGURIString(state.track.URI)]? sg_motion : nil;- // The look ends the ID: m and a tag of the file over moving artwork, so a Canvas that comes after an animated- // cover redraws the line showing too; else the style.- NSString *look = motion ? [NSString stringWithFormat:@"m%04lx", (unsigned long)(motion.lastPathComponent.hash & 0xffff)]- : [NSString stringWithFormat:@"%ld", (long)style];+ if (motion && motionFailed(motion)) motion = nil;+ NSString *look = SGLyricsClipLook(motion, style);NSString *artworkID = [NSString stringWithFormat:@"%@-%ld%@-%@", trackID, (long)index, resting ? @"r" : @"", look];if ([artworkID isEqualToString:sg_shownID]) return;// Spotify's request block for its cover, read on main and kept once it is this track's.@@ -261,6 +285,7 @@ static void tick(void) {if (![sg_shownID hasPrefix:trackID]) SGLog(@"lock lyrics: lines offered for %@", trackID);if (motion && ![sg_shownID hasSuffix:[@"-" stringByAppendingString:look]]) SGLog(@"lock lyrics: the lines of %@ over %@", trackID, motion.lastPathComponent);setShown(artworkID);+ SGLockMotionShowPlain(NO);SGNowPlayingSetExtras(@"lyrics", @{MPNowPlayingInfoProperty3x4AnimatedArtwork:artworkFor(artworkID, lineAt(lines, index, resting, motion, sg_cover, style))},state.track.trackTitle);@@ -315,6 +340,7 @@ static void setTicking(BOOL on) {sg_queue = dispatch_queue_create("spotifyglass.lockscreen.lyrics", DISPATCH_QUEUE_SERIAL);sg_previewQueue = dispatch_queue_create("spotifyglass.lockscreen.lyrics.preview", DISPATCH_QUEUE_SERIAL);sg_previews = [NSCache new];+ sg_failedMotion = [NSMutableSet set];sg_previews.countLimit = 4;static SGLyricsArtwork *observer;observer = [SGLyricsArtwork new];diff --git a/tweak/Sources/Shared/LockScreenLyrics/SGLyricsClip.h b/tweak/Sources/Shared/LockScreenLyrics/SGLyricsClip.hindex b3260822..4e6dd962 100644--- a/tweak/Sources/Shared/LockScreenLyrics/SGLyricsClip.h+++ b/tweak/Sources/Shared/LockScreenLyrics/SGLyricsClip.h@@ -26,5 +26,9 @@ BOOL SGLyricsClipWrite(NSURL *file, CGImageRef backdrop, NSString *line, NSStrin// one that does not read. Blocks, so never on the main queue.BOOL SGLyricsClipWriteOverMotion(NSURL *file, NSURL *motion, NSString *previous, NSString *line, NSString *next,double from, double seconds);+// The end of a line's artwork ID, so a clip kept under it is the one wanted: the style, which a clip falling+// back to the cover is drawn in, and with moving artwork m and the first 16 characters of its file's name (the+// store names files by a SHA-1 of their address), so another video for the track redraws the line showing.+NSString *SGLyricsClipLook(NSURL *motion, SGLyricsClipStyle style);// That clip's first frame, for the preview image, NULL where the clip would not be written.CGImageRef SGLyricsClipMotionFrame(NSURL *motion, NSString *previous, NSString *line, NSString *next, double from) CF_RETURNS_RETAINED;diff --git a/tweak/Sources/Shared/LockScreenLyrics/SGLyricsClip.m b/tweak/Sources/Shared/LockScreenLyrics/SGLyricsClip.mindex c03ec946..c070a5c8 100644--- a/tweak/Sources/Shared/LockScreenLyrics/SGLyricsClip.m+++ b/tweak/Sources/Shared/LockScreenLyrics/SGLyricsClip.m@@ -254,7 +254,8 @@ static AVAssetTrack *motionTrack(AVURLAsset *asset, Motion *motion) {// shortcut: a turned video (none seen among Canvases or Apple Music's covers) falls back to the blurred// cover; drawing the words turned with it is the step up if one turns up.if (!track || !CGAffineTransformIsIdentity(track.preferredTransform)) return nil;- CGSize stored = track.naturalSize;+ // Whole pixels: the decoded frames are, and drawOver checks each against this.+ CGSize stored = CGSizeMake(round(track.naturalSize.width), round(track.naturalSize.height));double length = CMTimeGetSeconds(track.timeRange.duration);if (stored.width < 16 || stored.height < 16 || !(length > 0)) return nil;CGSize cut = stored.width / stored.height > 0.75 ? CGSizeMake(stored.height * 0.75, stored.height)@@ -317,8 +318,9 @@ static void freeOver(Over over) {// The softening, the dimming and the words, drawn into `buffer`, a BGRA frame of the video: the rows behind// the words blurred (Accelerate's tent blur) and faded in, every row of the cut darkened by its share in one-// pass, and one image the size of the words. All on the CPU.-static void drawOver(CVPixelBufferRef buffer, Motion motion, Over over) {+// pass, and one image the size of the words. All on the CPU. NO, with the frame left as it is, for a frame of+// another size or format than the track states, so the clip is not written without its words.+static BOOL drawOver(CVPixelBufferRef buffer, Motion motion, Over over) {CVPixelBufferLockBaseAddress(buffer, 0);uint8_t *base = CVPixelBufferGetBaseAddress(buffer);size_t bytesPerRow = CVPixelBufferGetBytesPerRow(buffer);@@ -331,7 +333,7 @@ static void drawOver(CVPixelBufferRef buffer, Motion motion, Over over) {|| frameWidth != (size_t)motion.stored.width || frameHeight != (size_t)motion.stored.height || bytesPerRow < frameWidth * 4|| !CGRectContainsRect(frame, cut) || (over.blurred && !CGRectContainsRect(frame, over.soft))) {CVPixelBufferUnlockBaseAddress(buffer, 0);- return;+ return NO;}if (over.blurred) {// An image counts its rows from the top, Core Graphics from the bottom.@@ -365,6 +367,7 @@ static void drawOver(CVPixelBufferRef buffer, Motion motion, Over over) {CGContextRelease(context);}CVPixelBufferUnlockBaseAddress(buffer, 0);+ return YES;}// Each frame of the video from `from` seconds (taken round its length) for `seconds`, round its end as often@@ -423,7 +426,7 @@ CGImageRef SGLyricsClipMotionFrame(NSURL *motionFile, NSString *previous, NSStri__block CGImageRef frame = NULL;eachFrame(asset, track, motion, from, motion.length, ^BOOL(CMSampleBufferRef sample) {CVPixelBufferRef buffer = CMSampleBufferGetImageBuffer(sample);- drawOver(buffer, motion, over);+ if (!drawOver(buffer, motion, over)) return NO;CVPixelBufferLockBaseAddress(buffer, kCVPixelBufferLock_ReadOnly);CGContextRef context = newContext(motion.stored, CVPixelBufferGetBaseAddress(buffer), CVPixelBufferGetBytesPerRow(buffer));CGImageRef whole = CGBitmapContextCreateImage(context);@@ -463,7 +466,10 @@ BOOL SGLyricsClipWriteOverMotion(NSURL *file, NSURL *motionFile, NSString *previOver over = makeOver(motion, previous, line, next);__block BOOL ok = YES, any = NO;BOOL read = eachFrame(asset, track, motion, from, seconds, ^BOOL(CMSampleBufferRef sample) {- drawOver(CMSampleBufferGetImageBuffer(sample), motion, over);+ if (!drawOver(CMSampleBufferGetImageBuffer(sample), motion, over)) {+ ok = NO;+ return NO;+ }while (!input.readyForMoreMediaData && writer.status == AVAssetWriterStatusWriting) [NSThread sleepForTimeInterval:0.002];ok = writer.status == AVAssetWriterStatusWriting && [input appendSampleBuffer:sample];any = YES;@@ -483,3 +489,9 @@ BOOL SGLyricsClipWriteOverMotion(NSURL *file, NSURL *motionFile, NSString *previ[NSFileManager.defaultManager removeItemAtURL:file error:nil];return [NSFileManager.defaultManager moveItemAtURL:partial toURL:file error:nil];}++NSString *SGLyricsClipLook(NSURL *motion, SGLyricsClipStyle style) {+ if (!motion) return [NSString stringWithFormat:@"%ld", (long)style];+ NSString *name = motion.lastPathComponent.stringByDeletingPathExtension;+ return [NSString stringWithFormat:@"m%@s%ld", name.length > 16 ? [name substringToIndex:16] : name, (long)style];+}