* Grab chapter previews from the middle of the chapter instead of the very beginning.
This commit is contained in:
1 parent
a958753d3d
commit
2a75f36676
1 file changed
+8
-3
@@ -20,7 +20,7 @@
|
|||||||
return images;
|
return images;
|
||||||
}
|
}
|
||||||
|
|
||||||
+ (NSArray *)generatePreviewImagesAVFoundationFromChapters:(NSArray *)chapters andFile:(NSURL *)file {
|
+ (NSArray *)generatePreviewImagesAVFoundationFromChapters:(NSArray<MP42TextSample *> *)chapters andFile:(NSURL *)file {
|
||||||
NSMutableArray *images = [[NSMutableArray alloc] initWithCapacity:[chapters count]];
|
NSMutableArray *images = [[NSMutableArray alloc] initWithCapacity:[chapters count]];
|
||||||
|
|
||||||
AVAsset *asset = [AVAsset assetWithURL:file];
|
AVAsset *asset = [AVAsset assetWithURL:file];
|
||||||
@@ -32,8 +32,13 @@
|
|||||||
generator.requestedTimeToleranceBefore = kCMTimeZero;
|
generator.requestedTimeToleranceBefore = kCMTimeZero;
|
||||||
generator.requestedTimeToleranceAfter = kCMTimeZero;
|
generator.requestedTimeToleranceAfter = kCMTimeZero;
|
||||||
|
|
||||||
for (MP42TextSample *chapter in chapters) {
|
CGFloat thumbnailPosition = 0.5; // Middle of chapter
|
||||||
CMTime time = CMTimeMake([chapter timestamp] + 1800, 1000);
|
|
||||||
|
for (NSInteger idx = 0; idx < chapters.count; idx++)
|
||||||
|
{
|
||||||
|
MP42TextSample *chapter = chapters[idx];
|
||||||
|
MP42Duration nextChapterTimestamp = (idx < chapters.count - 1) ? [chapters[idx+1] timestamp] : CMTimeGetSeconds(asset.duration) * 1000;
|
||||||
|
CMTime time = CMTimeMake([chapter timestamp] + ((nextChapterTimestamp - [chapter timestamp]) * thumbnailPosition), 1000);
|
||||||
CGImageRef imgRef = [generator copyCGImageAtTime:time actualTime:NULL error:NULL];
|
CGImageRef imgRef = [generator copyCGImageAtTime:time actualTime:NULL error:NULL];
|
||||||
if (imgRef) {
|
if (imgRef) {
|
||||||
NSSize size = NSMakeSize(CGImageGetWidth(imgRef), CGImageGetHeight(imgRef));
|
NSSize size = NSMakeSize(CGImageGetWidth(imgRef), CGImageGetHeight(imgRef));
|
||||||
|
|||||||
Reference in new issue
Block a user